-
Notifications
You must be signed in to change notification settings - Fork 3
/
domain_length_test.cpp
45 lines (39 loc) · 1.34 KB
/
domain_length_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "dns.h"
#include <stdint.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char** argv)
{
char root[] = { 0 }; // '.'
char goodname[] = { 7, 't', 'r', 'a', 'n', 's', 'i', 'p', 2, 'n', 'l', 0 };
char badname[] = { 7, 't', 'r', 'a', 'n', 's', 'i', 'p', 3, 'n', 'l', 0 };
char reallybadname[] = { 7, 't', 'r', 'a', 'n', 's', 'i', 'p', -9, 'n', 'l', 0 };
int res = 0;
bool failed = false;
printf("Testing a few names for domain_name_length\n");
res = dns_domain_length(root, sizeof(root));
if (res != sizeof(root)) {
printf("Failed root test, got %d instead of %lu\n", res, sizeof(root));
failed = true;
}
res = dns_domain_length(goodname, sizeof(goodname));
if (res != sizeof(goodname)) {
printf("Failed goodname test, got %d instead of %lu\n", res, sizeof(goodname));
failed = true;
}
res = dns_domain_length(badname, sizeof(badname));
if (res != 0) {
printf("Failed badname test, got %d instead of 0\n", res);
failed = true;
}
res = dns_domain_length(reallybadname, sizeof(reallybadname));
if (res != 0) {
printf("Failed reallybadname test, got %d instead of 0\n", res);
}
if (failed) {
printf("Some tests failed!\n");
return 1;
}
printf("Tests successfull for all names\n");
return 0;
}