libpsyc/test/testRender.c

51 lines
1.8 KiB
C
Raw Normal View History

2011-04-22 09:50:13 +00:00
#include <stdlib.h>
2011-04-25 19:57:03 +00:00
#include <unistd.h>
2011-04-22 09:50:13 +00:00
#include "../include/psyc/lib.h"
#include "../include/psyc/render.h"
#include "../include/psyc/syntax.h"
2011-04-22 09:50:13 +00:00
#define myUNI "psyc://10.100.1000/~ludwig"
/* example renderer generating a presence packet */
2011-04-25 21:49:27 +00:00
int testPresence(const char *avail, int availlen, const char *desc, int desclen, const char *rendered)
2011-04-25 19:57:03 +00:00
{
psycModifier routing[] = {
2011-04-25 21:49:27 +00:00
// psyc_newModifier2(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_source"), PSYC_C2ARG(myUNI),
// PSYC_MODIFIER_ROUTING),
psyc_newModifier2(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_context"), PSYC_C2ARG(myUNI),
PSYC_MODIFIER_ROUTING),
2011-04-25 19:57:03 +00:00
};
psycModifier entity[] = {
2011-04-25 19:57:03 +00:00
// presence is to be assigned permanently in distributed state
psyc_newModifier2(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_degree_availability"),
2011-04-25 19:57:03 +00:00
avail, availlen, PSYC_PACKET_CHECK_LENGTH),
psyc_newModifier2(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_description_presence"),
2011-04-25 19:57:03 +00:00
desc, desclen, PSYC_PACKET_CHECK_LENGTH),
};
psycPacket packet = psyc_newPacket2(routing, PSYC_NUM_ELEM(routing),
2011-04-25 20:01:13 +00:00
entity, PSYC_NUM_ELEM(entity),
2011-04-25 19:57:03 +00:00
PSYC_C2ARG("_notice_presence"),
2011-04-25 20:01:13 +00:00
NULL, 0,
//PSYC_C2ARG("foobar"),
2011-04-25 19:57:03 +00:00
PSYC_PACKET_CHECK_LENGTH);
char buffer[512];
psyc_render(&packet, buffer, sizeof(buffer));
2011-04-25 21:49:27 +00:00
// write(0, buffer, packet.length);
return strncmp(rendered, buffer, packet.length);
2011-04-22 09:50:13 +00:00
}
int main() {
2011-04-25 21:58:07 +00:00
int rc = testPresence(PSYC_C2ARG("_here"), PSYC_C2ARG("I'm omnipresent right now"), "\
:_context\t" myUNI "\n\
2011-04-25 21:49:27 +00:00
\n\
=_degree_availability\t_here\n\
=_description_presence\tI'm omnipresent right now\n\
_notice_presence\n\
|\n");
2011-04-25 21:58:07 +00:00
unless (rc) puts("psyc_render passed the test.");
return rc;
2011-04-22 09:50:13 +00:00
}