2011-12-28 22:45:16 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <psyc.h>
|
|
|
|
#include <psyc/packet.h>
|
|
|
|
#include <psyc/render.h>
|
|
|
|
|
2012-02-06 14:05:08 +00:00
|
|
|
uint8_t verbose;
|
|
|
|
|
2011-12-28 22:45:16 +00:00
|
|
|
int
|
|
|
|
packet_id (char *context, size_t contextlen,
|
|
|
|
char *source, size_t sourcelen,
|
|
|
|
char *target, size_t targetlen,
|
|
|
|
char *counter, size_t counterlen,
|
|
|
|
char *fragment, size_t fragmentlen,
|
|
|
|
char *result, size_t resultlen)
|
|
|
|
{
|
2012-02-06 14:05:08 +00:00
|
|
|
PsycList list;
|
|
|
|
PsycElem elems[PSYC_PACKET_ID_ELEMS];
|
|
|
|
memset(&list, 0, sizeof(PsycList));
|
|
|
|
memset(elems, 0, sizeof(PsycElem) * PSYC_PACKET_ID_ELEMS);
|
|
|
|
|
|
|
|
psyc_packet_id(&list, elems, context, contextlen,
|
|
|
|
source, sourcelen, target, targetlen,
|
|
|
|
counter, counterlen, fragment, fragmentlen);
|
|
|
|
|
|
|
|
size_t idlen = list.length;
|
2011-12-28 22:45:16 +00:00
|
|
|
char *id = malloc(idlen);
|
2012-02-06 14:05:08 +00:00
|
|
|
|
|
|
|
psyc_render_list(&list, id, idlen);
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
printf("[%.*s]\n", (int)idlen, id);
|
2011-12-28 22:45:16 +00:00
|
|
|
int ret = idlen == resultlen && memcmp(result, id, idlen) == 0;
|
|
|
|
free(id);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2012-02-06 14:05:08 +00:00
|
|
|
verbose = argc > 1;
|
|
|
|
|
2011-12-28 22:45:16 +00:00
|
|
|
if (!packet_id(PSYC_C2ARG(""),
|
|
|
|
PSYC_C2ARG("psyc://example.net/~alice"),
|
|
|
|
PSYC_C2ARG("psyc://example.net/~bob"),
|
|
|
|
PSYC_C2ARG("1337"),
|
|
|
|
PSYC_C2ARG("42"),
|
2012-02-06 14:05:08 +00:00
|
|
|
PSYC_C2ARG("|| psyc://example.net/~alice"
|
|
|
|
"| psyc://example.net/~bob"
|
|
|
|
"| 1337| 42")))
|
2011-12-28 22:45:16 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!packet_id(PSYC_C2ARG("psyc://example.net/@bar"),
|
|
|
|
PSYC_C2ARG("psyc://example.net/~alice"),
|
|
|
|
PSYC_C2ARG(""),
|
|
|
|
PSYC_C2ARG("1337"),
|
|
|
|
PSYC_C2ARG("42"),
|
2012-02-06 14:05:08 +00:00
|
|
|
PSYC_C2ARG("| psyc://example.net/@bar"
|
|
|
|
"| psyc://example.net/~alice|"
|
|
|
|
"| 1337| 42")))
|
2011-12-28 22:45:16 +00:00
|
|
|
return 2;
|
|
|
|
|
|
|
|
if (!packet_id(PSYC_C2ARG("psyc://example.net/@bar"),
|
|
|
|
PSYC_C2ARG(""),
|
|
|
|
PSYC_C2ARG("psyc://example.net/~alice"),
|
|
|
|
PSYC_C2ARG("1337"),
|
|
|
|
PSYC_C2ARG("42"),
|
2012-02-06 14:05:08 +00:00
|
|
|
PSYC_C2ARG("| psyc://example.net/@bar|"
|
|
|
|
"| psyc://example.net/~alice"
|
|
|
|
"| 1337| 42")))
|
2011-12-28 22:45:16 +00:00
|
|
|
return 3;
|
|
|
|
|
|
|
|
if (!packet_id(PSYC_C2ARG("psyc://example.net/@bar"),
|
|
|
|
PSYC_C2ARG(""),
|
|
|
|
PSYC_C2ARG(""),
|
|
|
|
PSYC_C2ARG(""),
|
|
|
|
PSYC_C2ARG(""),
|
2012-02-06 14:05:08 +00:00
|
|
|
PSYC_C2ARG("| psyc://example.net/@bar||||")))
|
2011-12-28 22:45:16 +00:00
|
|
|
return 4;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|