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

53 lines
1.8 KiB
C
Raw Normal View History

2011-10-13 22:29:32 +00:00
#include <psyc/uniform.h>
#include <stdlib.h>
#include <stdio.h>
#include <lib.h>
void
2011-10-31 19:04:16 +00:00
testUniform (char *str, int ret) {
2011-10-31 19:26:47 +00:00
PsycUniform *uni = malloc(sizeof(PsycUniform));
memset(uni, 0, sizeof(PsycUniform));
2011-10-13 22:29:32 +00:00
printf("%s\n", str);
2011-10-31 19:04:16 +00:00
int r = psyc_uniform_parse(uni, str, strlen(str));
2011-10-13 22:29:32 +00:00
2011-11-01 11:22:30 +00:00
PP(("[%.*s] : [%.*s] [%.*s] : [%.*s] [%.*s] / [%.*s] # [%.*s]\n[%.*s]\n[%.*s] [%.*s]\n[%.*s]\n\n",
2011-10-13 23:16:09 +00:00
(int)PSYC_S2ARG2(uni->scheme),
(int)PSYC_S2ARG2(uni->slashes),
(int)PSYC_S2ARG2(uni->host),
(int)PSYC_S2ARG2(uni->port),
(int)PSYC_S2ARG2(uni->transport),
(int)PSYC_S2ARG2(uni->resource),
(int)PSYC_S2ARG2(uni->channel),
2011-11-01 11:22:30 +00:00
(int)PSYC_S2ARG2(uni->entity),
2011-10-13 23:16:09 +00:00
(int)PSYC_S2ARG2(uni->root),
(int)PSYC_S2ARG2(uni->nick),
(int)PSYC_S2ARG2(uni->body)));
2011-10-13 22:29:32 +00:00
free(uni);
if (r != ret) {
2011-10-31 19:04:16 +00:00
fprintf(stderr, "ERROR: psyc_uniform_parse returned %d instead of %d\n", r, ret);
2011-10-13 22:29:32 +00:00
exit(1);
}
}
2011-10-31 19:04:16 +00:00
int main () {
2011-10-13 22:29:32 +00:00
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);
2011-10-31 19:04:16 +00:00
printf("SUCCESS: psyc_uniform_parse passed all tests.\n");
2011-10-13 22:29:32 +00:00
return 0;
}