More dns tests

This commit is contained in:
Erik Ekman 2007-01-28 03:28:02 +00:00
parent 10a8c6711c
commit 22c66af914

View file

@ -29,6 +29,21 @@
#include "test.h" #include "test.h"
START_TEST(test_encode_hostname) 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]; char buf[256];
int len; int len;
@ -42,6 +57,16 @@ START_TEST(test_encode_hostname)
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
, buf, len); , buf, len);
fail_unless(ret == -1, NULL); 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); memset(buf, 0, 256);
ret = dns_encode_hostname( // More chars than fits into array ret = dns_encode_hostname( // More chars than fits into array
@ -65,6 +90,8 @@ test_dns_create_tests()
tc = tcase_create("Dns"); tc = tcase_create("Dns");
tcase_add_test(tc, test_encode_hostname); tcase_add_test(tc, test_encode_hostname);
tcase_add_test(tc, test_encode_hostname_nodot);
tcase_add_test(tc, test_encode_hostname_toolong);
return tc; return tc;
} }