mirror of
https://github.com/yarrick/iodine.git
synced 2024-12-24 00:28:19 +00:00
Fix testcases after refactoring
This commit is contained in:
parent
b56a4d23f5
commit
05927b97e4
58
tests/dns.c
58
tests/dns.c
@ -54,61 +54,6 @@ static char *topdomain = "kryo.se";
|
||||
static char *queryData = "HELLO this is the test data";
|
||||
static char *recData = "AHELLO this is the test data"; // The A flag is added
|
||||
|
||||
START_TEST(test_encode_hostname)
|
||||
{
|
||||
char out[] = "\x06" "BADGER\x06" "BADGER\x04" "KRYO\x02" "SE\x00";
|
||||
char buf[256];
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
ret = dns_encode_hostname("BADGER.BADGER.KRYO.SE", buf, len);
|
||||
fail_unless(strncmp(buf, out, ret) == 0, "Happy flow failed");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_encode_hostname_nodot)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
ret = dns_encode_hostname( // More than 63 chars between dots
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
, buf, len);
|
||||
fail_unless(ret == -1, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_encode_hostname_toolong)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
ret = dns_encode_hostname( // More chars than fits into array
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
, buf, len);
|
||||
|
||||
fail_unless(ret == -1, NULL);
|
||||
fail_unless(strlen(buf) < len, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_encode_query)
|
||||
{
|
||||
char buf[512];
|
||||
@ -231,9 +176,6 @@ test_dns_create_tests()
|
||||
TCase *tc;
|
||||
|
||||
tc = tcase_create("Dns");
|
||||
tcase_add_test(tc, test_encode_hostname);
|
||||
tcase_add_test(tc, test_encode_hostname_nodot);
|
||||
tcase_add_test(tc, test_encode_hostname_toolong);
|
||||
tcase_add_test(tc, test_encode_query);
|
||||
tcase_add_test(tc, test_decode_query);
|
||||
tcase_add_test(tc, test_encode_response);
|
||||
|
70
tests/read.c
70
tests/read.c
@ -165,6 +165,73 @@ START_TEST(test_read_name)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_putname)
|
||||
{
|
||||
char out[] = "\x06" "BADGER\x06" "BADGER\x04" "KRYO\x02" "SE\x00";
|
||||
char buf[256];
|
||||
char *domain = "BADGER.BADGER.KRYO.SE";
|
||||
char *b;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
b = buf;
|
||||
ret = putname(&b, 256, domain);
|
||||
|
||||
fail_unless(ret == strlen(domain) + 1, NULL);
|
||||
fail_unless(strncmp(buf, out, ret) == 0, "Happy flow failed");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_putname_nodot)
|
||||
{
|
||||
char buf[256];
|
||||
char *nodot =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
char *b;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
b = buf;
|
||||
ret = putname(&b, 256, nodot);
|
||||
|
||||
fail_unless(ret == -1, NULL);
|
||||
fail_unless(b == buf, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_putname_toolong)
|
||||
{
|
||||
char buf[256];
|
||||
char *toolong =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ.";
|
||||
char *b;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
len = 256;
|
||||
|
||||
memset(buf, 0, 256);
|
||||
b = buf;
|
||||
ret = putname(&b, 256, toolong);
|
||||
|
||||
fail_unless(ret == -1, NULL);
|
||||
fail_unless(b == buf, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
TCase *
|
||||
test_read_create_tests()
|
||||
{
|
||||
@ -175,6 +242,9 @@ test_read_create_tests()
|
||||
tcase_add_test(tc, test_read_putshort);
|
||||
tcase_add_test(tc, test_read_putlong);
|
||||
tcase_add_test(tc, test_read_name);
|
||||
tcase_add_test(tc, test_putname);
|
||||
tcase_add_test(tc, test_putname_nodot);
|
||||
tcase_add_test(tc, test_putname_toolong);
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user