libpsyc/test/uniform_parse.c

87 lines
3.0 KiB
C
Raw Normal View History

2013-07-16 14:53:51 +00:00
/*
This file is part of libpsyc.
Copyright (C) 2011,2012 Carlo v. Loesch, Gabor X Toth, Mathias L. Baumann,
and other contributing authors.
libpsyc is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version. As a special exception, libpsyc is distributed with additional
permissions to link libpsyc libraries with non-AGPL works.
libpsyc is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.
You should have received a copy of the GNU Affero General Public License and
the linking exception along with libpsyc in a COPYING file.
*/
2011-10-13 22:29:32 +00:00
#include <psyc/uniform.h>
#include <stdlib.h>
#include <stdio.h>
#include <lib.h>
void
2011-11-11 21:18:24 +00:00
testUniform (char *str, int ret)
{
PsycUniform *uni = malloc(sizeof(PsycUniform));
memset(uni, 0, sizeof(PsycUniform));
printf("%s\n", str);
int r = psyc_uniform_parse(uni, str, strlen(str));
2011-10-13 22:29:32 +00:00
2011-11-11 21:18:24 +00:00
PP(("[%.*s] : [%.*s] [%.*s] : [%.*s] [%.*s] / "
2012-01-25 17:05:44 +00:00
"[%.*s] # [%.*s]\n"
"[%.*s]\n"
"[%.*s] [%.*s]\n"
"[%.*s]\n"
"[%.*s]\n\n",
2011-11-11 21:18:24 +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),
(int)PSYC_S2ARG2(uni->entity),
(int)PSYC_S2ARG2(uni->root),
(int)PSYC_S2ARG2(uni->nick),
2012-01-25 17:05:44 +00:00
(int)PSYC_S2ARG2(uni->path),
2011-11-11 21:18:24 +00:00
(int)PSYC_S2ARG2(uni->body)));
2011-10-13 22:29:32 +00:00
2011-11-11 21:18:24 +00:00
free(uni);
if (r != ret) {
fprintf(stderr, "ERROR: psyc_uniform_parse returned %d instead of %d\n",
r, ret);
exit(1);
}
2011-10-13 22:29:32 +00:00
}
2011-11-11 21:18:24 +00:00
int
main ()
{
testUniform("psyc://foo.tld:4404d/@bar#baz", PSYC_SCHEME_PSYC);
2012-01-25 17:05:44 +00:00
testUniform("psyc://foo.tld:4404d/#baz", PSYC_SCHEME_PSYC);
2011-11-11 21:18:24 +00:00
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:-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);
2011-10-13 22:29:32 +00:00
2011-11-11 21:18:24 +00:00
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-13 22:29:32 +00:00
2011-11-11 21:18:24 +00:00
printf("SUCCESS: psyc_uniform_parse passed all tests.\n");
return 0;
2011-10-13 22:29:32 +00:00
}