From 05927b97e483997da6e2eaa2f402b8fc2a3451b4 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sun, 11 Feb 2007 01:46:45 +0000 Subject: [PATCH] Fix testcases after refactoring --- tests/dns.c | 58 ------------------------------------------- tests/read.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 58 deletions(-) diff --git a/tests/dns.c b/tests/dns.c index 0e0b9df..db82dd1 100644 --- a/tests/dns.c +++ b/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); diff --git a/tests/read.c b/tests/read.c index 4c9cccf..4a43efd 100644 --- a/tests/read.c +++ b/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; }