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

packet id

This commit is contained in:
tg(x) 2011-12-28 23:45:16 +01:00
parent 07901658f3
commit 30351302bc
9 changed files with 137 additions and 1 deletions

View file

@ -3,7 +3,7 @@ DEBUG = 2
CFLAGS = -I../include -I../src -Wall -std=c99 ${OPT}
LDFLAGS = -L../lib
LOADLIBES = -lpsyc -lm
TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_is_routing var_type uniform_parse test_table
TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_is_routing var_type uniform_parse test_list test_table test_packet_id
O = test.o
WRAPPER =
DIET = diet
@ -48,7 +48,9 @@ test: ${TARGETS}
./var_is_routing
./var_type
./uniform_parse
./test_list
./test_table
./test_packet_id
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./test_psyc -f $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./test_psyc -rf $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x

70
test/test_packet_id.c Normal file
View file

@ -0,0 +1,70 @@
#include <stdlib.h>
#include <stdio.h>
#include <psyc.h>
#include <psyc/packet.h>
#include <psyc/render.h>
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)
{
size_t idlen = psyc_packet_id_length(contextlen, sourcelen, targetlen,
counterlen, fragmentlen);
char *id = malloc(idlen);
psyc_render_packet_id(context, contextlen,
source, sourcelen,
target, targetlen,
counter, counterlen,
fragment, fragmentlen,
id, idlen);
printf("%.*s\n", (int)idlen, id);
int ret = idlen == resultlen && memcmp(result, id, idlen) == 0;
free(id);
return ret;
}
int
main (int argc, char **argv)
{
if (!packet_id(PSYC_C2ARG(""),
PSYC_C2ARG("psyc://example.net/~alice"),
PSYC_C2ARG("psyc://example.net/~bob"),
PSYC_C2ARG("1337"),
PSYC_C2ARG("42"),
PSYC_C2ARG("||psyc://example.net/~alice|psyc://example.net/~bob"
"|1337|42")))
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"),
PSYC_C2ARG("|psyc://example.net/@bar|psyc://example.net/~alice|"
"|1337|42")))
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"),
PSYC_C2ARG("|psyc://example.net/@bar||psyc://example.net/~alice"
"|1337|42")))
return 3;
if (!packet_id(PSYC_C2ARG("psyc://example.net/@bar"),
PSYC_C2ARG(""),
PSYC_C2ARG(""),
PSYC_C2ARG(""),
PSYC_C2ARG(""),
PSYC_C2ARG("|psyc://example.net/@bar||||")))
return 4;
return 0;
}