Usermode/utests - Fix DNS utest, update libc utests to new format (no more EXP files)
[tpg/acess2.git] / Usermode / Libraries / libnet.so_src / TEST_dns_proto.c
1 /*
2  */
3 #include <utest_common.h>
4 #include "include/dns_int.h"
5 #include <string.h>
6 #include <stdio.h>
7 #include <stdint.h>
8
9 // Complex response from "Q ssh.ucc.asn.au A IN"
10 const uint8_t test_packet_1[] = {
11         0xac, 0x00, 0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x03, 0x73, 0x73, 0x68, 0x03, 0x75, 0x63, 0x63, 0x03, 0x61, 0x73, 0x6e, 0x02, 0x61, 0x75, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x77, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x78, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x79, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x61, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x7a, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x62, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x75, 0xc0, 0x18, 0xc0, 0x18, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x01, 0x76, 0xc0, 0x18, 0xc0, 0x2c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc0, 0x05, 0xc0, 0x3c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc2, 0x05, 0xc0, 0x4c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc4, 0x05, 0xc0, 0x5c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x3a, 0x41, 0xfe, 0x49, 0xc0, 0x6c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x25, 0xd1, 0xc6, 0x05, 0xc0, 0x7c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0x3a, 0x41, 0xfd, 0x49, 0xc0, 0x8c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0xd3, 0x1d, 0x85, 0x20, 0xc0, 0x9c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xe6, 0xd6, 0x00, 0x04, 0xca, 0x0c, 0x1f, 0x8d, 
12         };
13 const uint8_t test_packet_2[] ={
14         0xac,0x00,0x81,0x80,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x03,0x73,0x73,0x68,0x03,0x75,0x63,0x63,0x03,0x61,0x73,0x6e,0x02,0x61,0x75,0x00,0x00,0x01,0x00,0x01,0xc0,0x0c,0x00,0x01,0x00,0x01,0x00,0x00,0x0e,0x10,0x00,0x04,0x82,0x5f,0x0d,0x0b
15 };
16
17 int test_response_parse_1_cb(void *info, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata)
18 {
19         int* stagep = info;
20         int curstage = *stagep;
21         *stagep = -1;
22         switch( curstage )
23         {
24         case 0:
25                 TEST_REL_INT(0, ==, strcmp(name, "w.au."));
26                 break;
27         case 1:
28                 TEST_REL_INT(0, ==, strcmp(name, "x.au."));
29                 break;
30         }
31         *stagep = curstage + 1;
32         return 0;
33 }
34 int test_response_parse_1(void)
35 {
36         int stage = 0;
37         TEST_REL_INT(0, ==, DNS_int_ParseResponse(test_packet_1, sizeof(test_packet_1), &stage, test_response_parse_1_cb) );
38         TEST_REL_INT(stage, ==, 8);
39         return 0;
40 }
41
42 int test_response_parse_2_cb(void *info, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata)
43 {
44         int* stagep = info;
45         int curstage = *stagep;
46         *stagep = -1;
47         switch( curstage )
48         {
49         case 0:
50                 TEST_REL_INT(0, ==, strcmp(name, "ssh.ucc.asn.au."));
51                 TEST_REL_INT(TYPE_A, ==, type);
52                 TEST_REL_INT(CLASS_IN, ==, class);
53                 TEST_REL_INT(4, ==, rdlength);
54                 TEST_REL_INT(130, ==, ((uint8_t*)rdata)[0]);
55                 TEST_REL_INT( 95, ==, ((uint8_t*)rdata)[1]);
56                 TEST_REL_INT( 13, ==, ((uint8_t*)rdata)[2]);
57                 TEST_REL_INT( 11, ==, ((uint8_t*)rdata)[3]);
58                 break;
59         }
60         *stagep = curstage + 1;
61         return 0;
62 }
63 int test_response_parse_2(void)
64 {
65         int stage = 0;
66         TEST_REL_INT(0, ==, DNS_int_ParseResponse(test_packet_2, sizeof(test_packet_2), &stage, test_response_parse_2_cb) );
67         TEST_REL_INT(stage, ==, 1); 
68         return 0;
69 }
70
71 int main(void)
72 {
73          int rv = 0;
74         // - Name Encode
75         // - Name Decode
76         // - Response parsing
77         rv |= test_response_parse_1();
78         rv |= test_response_parse_2();
79         return rv;
80 }

UCC git Repository :: git.ucc.asn.au