1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

testRender now automaticable

This commit is contained in:
psyc://psyced.org/~lynX 2011-04-25 23:49:27 +02:00
parent d1ec497ef3
commit b5f604c352

View file

@ -7,11 +7,11 @@
#define myUNI "psyc://10.100.1000/~ludwig"
/* example renderer generating a presence packet */
int writePresence(const char *avail, int availlen, const char *desc, int desclen)
int testPresence(const char *avail, int availlen, const char *desc, int desclen, const char *rendered)
{
psycModifier routing[] = {
psyc_newModifier2(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_source"), PSYC_C2ARG(myUNI),
PSYC_MODIFIER_ROUTING),
// 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),
};
@ -33,41 +33,17 @@ int writePresence(const char *avail, int availlen, const char *desc, int desclen
char buffer[512];
psyc_render(&packet, buffer, sizeof(buffer));
write(0, buffer, packet.length);
/*
psycRenderState *pb; // a chunk of mem will host both struct and buf1
// char *t;
// unsigned int l;
unless (availlen) availlen = strlen(avail);
unless (desclen) desclen = strlen(desc);
if (!(pb = malloc(512))) {
P0(("Out of memory\n"))
return -1;
}
// if (psyc_initBuffer(pb, WHATEVER)) die("psyc_initBuffer hates me");
(void) psyc_renderModifier(pb, "_context", 0,
myUNI, sizeof(myUNI), PSYC_RENDER_ROUTING, 0);
// the first call to psyc_renderHeader() without PSYC_RENDER_ROUTING adds the
// extra newline to the buffer. later vars with PSYC_RENDER_ROUTING cause an error.
(void) psyc_renderModifier(pb, "_degree_availability", 0, avail, availlen, 0, C_GLYPH_OPERATOR_ASSIGN);
(void) psyc_renderModifier(pb, "_description_presence", 0, desc, desclen, 0, C_GLYPH_OPERATOR_ASSIGN);
// presence is to be assigned permanently in distributed state
(void) psyc_renderBody(pb, "_notice_presence", 0,
NULL, 0); // no data in packet
// (void) psyc_doneRender(pb, &t, &l);
// write(stdout, t, l);
free(pb);
*/
return 0;
// write(0, buffer, packet.length);
return strncmp(rendered, buffer, packet.length);
}
int main() {
return writePresence(PSYC_C2ARG("_here"), PSYC_C2ARG("I'm omnipresent right now"));
return testPresence(PSYC_C2ARG("_here"), PSYC_C2ARG("I'm omnipresent right now"), "\
:_context\tpsyc://10.100.1000/~ludwig\n\
\n\
=_degree_availability\t_here\n\
=_description_presence\tI'm omnipresent right now\n\
_notice_presence\n\
|\n");
}