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

uniform parser

This commit is contained in:
tg(x) 2011-10-14 00:29:32 +02:00
parent 1e3368e66a
commit 01358610fd
9 changed files with 387 additions and 77 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 = testPsyc testPsycSpeed testParser testMatch testRender testText isRoutingVar getVarType
TARGETS = testPsyc testPsycSpeed testParser testMatch testRender testText isRoutingVar getVarType parseUniform
O = test.o
WRAPPER =
DIET = diet
@ -47,6 +47,7 @@ test: ${TARGETS}
./testText
./isRoutingVar
./getVarType
./parseUniform
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testPsyc -f $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testPsyc -rf $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x

51
test/parseUniform.c Normal file
View file

@ -0,0 +1,51 @@
#include <psyc/uniform.h>
#include <stdlib.h>
#include <stdio.h>
#include <lib.h>
void
testUniform(char *str, int ret) {
psycUniform *uni = malloc(sizeof(psycUniform));
memset(uni, 0, sizeof(psycUniform));
printf("%s\n", str);
int r = psyc_parseUniform2(uni, str, strlen(str));
PP(("[%.*s] : [%.*s] [%.*s] : [%.*s] [%.*s] / [%.*s] # [%.*s]\n[%.*s] [%.*s]\n[%.*s]\n\n",
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_SCHEME]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_SLASHES]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_HOST]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_PORT]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_TRANSPORT]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_RESOURCE]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_CHANNEL]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_ROOT]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_NICK]),
(int)PSYC_S2ARG2((*uni)[PSYC_UNIFORM_BODY])));
free(uni);
if (r != ret) {
fprintf(stderr, "ERROR: psyc_parseUniform returned %d instead of %d\n", r, ret);
exit(1);
}
}
int main() {
testUniform("psyc://foo.tld:4404d/@bar#baz", PSYC_SCHEME_PSYC);
testUniform("psyc://foo:4405/~bar", PSYC_SCHEME_PSYC);
testUniform("psyc://foo:1234", PSYC_SCHEME_PSYC);
testUniform("psyc://foo:1234d", PSYC_SCHEME_PSYC);
testUniform("psyc://foo/", PSYC_SCHEME_PSYC);
testUniform("psyc://foo", PSYC_SCHEME_PSYC);
testUniform("psyc://1234567890abcdef:g/~foo", PSYC_SCHEME_PSYC);
testUniform("xmpp:user@host", PSYC_PARSE_UNIFORM_INVALID_SCHEME);
testUniform("psyc:host", PSYC_PARSE_UNIFORM_INVALID_SLASHES);
testUniform("psyc://", PSYC_PARSE_UNIFORM_INVALID_HOST);
testUniform("psyc://:123/", PSYC_PARSE_UNIFORM_INVALID_HOST);
testUniform("psyc://host:/~foo", PSYC_PARSE_UNIFORM_INVALID_PORT);
testUniform("psyc://host:d/~foo", PSYC_PARSE_UNIFORM_INVALID_PORT);
testUniform("psyc://1234567890abcdef:1g/~foo", PSYC_PARSE_UNIFORM_INVALID_TRANSPORT);
printf("SUCCESS: psyc_parseUniform passed all tests.\n");
return 0;
}