Changeset 955135


Ignore:
Timestamp:
02/10/09 19:10:40 (3 years ago)
Author:
Erik Ekman <yarrick@…>
Branches:
master
Children:
1cdba3
Parents:
b6fc3f
git-author:
Erik Ekman <yarrick@…> (02/10/09 19:10:40)
git-committer:
Erik Ekman <erik@…> (02/04/12 20:34:00)
Message:

refactored tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/read.c

    r0836ad r955135  
    8484END_TEST 
    8585 
    86 START_TEST(test_read_name) 
     86START_TEST(test_read_name_empty_loop) 
    8787{ 
    8888        unsigned char emptyloop[] = { 
    8989                'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    9090                0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01 }; 
     91        char buf[1024]; 
     92        char *data; 
     93        int rv; 
     94 
     95        memset(buf, 0, sizeof(buf)); 
     96        data = (char*) emptyloop + sizeof(HEADER); 
     97        buf[1023] = 'A'; 
     98        rv = readname((char *) emptyloop, sizeof(emptyloop), &data, buf, 1023); 
     99        fail_unless(buf[1023] == 'A'); 
     100} 
     101END_TEST 
     102 
     103START_TEST(test_read_name_inf_loop) 
     104{ 
    91105        unsigned char infloop[] = { 
    92106                'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    93107                0x01, 'A', 0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01 }; 
     108        char buf[1024]; 
     109        char *data; 
     110        int rv; 
     111 
     112        memset(buf, 0, sizeof(buf)); 
     113        data = (char*) infloop + sizeof(HEADER); 
     114        buf[4] = '\a'; 
     115        rv = readname((char*) infloop, sizeof(infloop), &data, buf, 4); 
     116        fail_unless(buf[4] == '\a'); 
     117} 
     118END_TEST 
     119 
     120START_TEST(test_read_name_longname) 
     121{ 
    94122        unsigned char longname[] = 
    95123                "AA\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00" 
     
    101129                "\x3FzBCDEFGHIJKLMNOPQURSTUVXYZ0123456789abcdefghijklmnopqrstuvxyzAA" 
    102130                "\x00\x00\x01\x00\x01"; 
     131        char buf[1024]; 
     132        char *data; 
     133        int rv; 
     134 
     135        memset(buf, 0, sizeof(buf)); 
     136        data = (char*) longname + sizeof(HEADER); 
     137        buf[256] = '\a'; 
     138        rv = readname((char*) longname, sizeof(longname), &data, buf, 256); 
     139        fail_unless(buf[256] == '\a'); 
     140} 
     141END_TEST 
     142 
     143START_TEST(test_read_name_onejump) 
     144{ 
    103145        unsigned char onejump[] = 
    104146                "AA\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00" 
    105147                "\x02hh\xc0\x15\x00\x01\x00\x01\x05zBCDE\x00"; 
    106         unsigned char badjump[] = { 
    107                 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    108                 0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 
    109         unsigned char badjump2[] = { 
    110                 'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    111                 0x02, 'B', 'A', 0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 
    112         unsigned char *jumper; 
    113         char buf[1024]; 
    114         char *data; 
    115         int rv; 
    116  
    117         memset(buf, 0, sizeof(buf)); 
    118         data = (char*) emptyloop + sizeof(HEADER); 
    119         buf[1023] = 'A'; 
    120         rv = readname((char *) emptyloop, sizeof(emptyloop), &data, buf, 1023); 
    121         fail_unless(buf[1023] == 'A', NULL); 
    122  
    123         memset(buf, 0, sizeof(buf)); 
    124         data = (char*) infloop + sizeof(HEADER); 
    125         buf[4] = '\a'; 
    126         rv = readname((char*) infloop, sizeof(infloop), &data, buf, 4); 
    127         fail_unless(buf[4] == '\a', NULL); 
    128  
    129         memset(buf, 0, sizeof(buf)); 
    130         data = (char*) longname + sizeof(HEADER); 
    131         buf[256] = '\a'; 
    132         rv = readname((char*) longname, sizeof(longname), &data, buf, 256); 
    133         fail_unless(buf[256] == '\a', NULL); 
     148        char buf[1024]; 
     149        char *data; 
     150        int rv; 
    134151 
    135152        memset(buf, 0, sizeof(buf)); 
    136153        data = (char*) onejump + sizeof(HEADER); 
    137154        rv = readname((char*) onejump, sizeof(onejump), &data, buf, 256); 
    138         fail_unless(rv == 9, NULL); 
    139  
    140         /* These two tests use malloc to cause segfault if jump is executed */ 
     155        fail_unless(rv == 9); 
     156} 
     157END_TEST 
     158 
     159START_TEST(test_read_name_badjump_start) 
     160{ 
     161        unsigned char badjump[] = { 
     162                'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
     163                0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 
     164        unsigned char *jumper; 
     165        char buf[1024]; 
     166        char *data; 
     167        int rv; 
     168 
     169        /* This test uses malloc to cause segfault if jump is executed */ 
    141170        memset(buf, 0, sizeof(buf)); 
    142171        jumper = malloc(sizeof(badjump)); 
     
    146175                rv = readname((char*) jumper, sizeof(badjump), &data, buf, 256); 
    147176 
    148                 fail_unless(rv == 0, NULL); 
    149                 fail_unless(buf[0] == 0, NULL); 
     177                fail_unless(rv == 0); 
     178                fail_unless(buf[0] == 0); 
    150179        } 
    151180        free(jumper); 
    152  
     181} 
     182END_TEST 
     183 
     184START_TEST(test_read_name_badjump_second) 
     185{ 
     186        unsigned char badjump2[] = { 
     187                'A', 'A', 0x81, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
     188                0x02, 'B', 'A', 0xfe, 0xcc, 0x00, 0x01, 0x00, 0x01 }; 
     189        unsigned char *jumper; 
     190        char buf[1024]; 
     191        char *data; 
     192        int rv; 
     193 
     194        /* This test uses malloc to cause segfault if jump is executed */ 
    153195        memset(buf, 0, sizeof(buf)); 
    154196        jumper = malloc(sizeof(badjump2)); 
     
    158200                rv = readname((char*) jumper, sizeof(badjump2), &data, buf, 256); 
    159201 
    160                 fail_unless(rv == 4, NULL); 
     202                fail_unless(rv == 4); 
    161203                fail_unless(strcmp("BA.", buf) == 0, 
    162204                                "buf is not BA: %s", buf); 
     
    181223        ret = putname(&b, 256, domain); 
    182224 
    183         fail_unless(ret == strlen(domain) + 1, NULL); 
     225        fail_unless(ret == strlen(domain) + 1); 
    184226        fail_unless(strncmp(buf, out, ret) == 0, "Happy flow failed"); 
    185227} 
     
    202244        ret = putname(&b, 256, nodot); 
    203245 
    204         fail_unless(ret == -1, NULL); 
    205         fail_unless(b == buf, NULL); 
     246        fail_unless(ret == -1); 
     247        fail_unless(b == buf); 
    206248} 
    207249END_TEST 
     
    227269        ret = putname(&b, 256, toolong); 
    228270 
    229         fail_unless(ret == -1, NULL); 
    230         fail_unless(b == buf, NULL); 
     271        fail_unless(ret == -1); 
     272        fail_unless(b == buf); 
    231273} 
    232274END_TEST 
     
    242284        tcase_add_test(tc, test_read_putshort); 
    243285        tcase_add_test(tc, test_read_putlong); 
    244         tcase_add_test(tc, test_read_name); 
     286        tcase_add_test(tc, test_read_name_empty_loop); 
     287        tcase_add_test(tc, test_read_name_inf_loop); 
     288        tcase_add_test(tc, test_read_name_longname); 
     289        tcase_add_test(tc, test_read_name_onejump); 
     290        tcase_add_test(tc, test_read_name_badjump_start); 
     291        tcase_add_test(tc, test_read_name_badjump_second); 
    245292        tcase_add_test(tc, test_putname); 
    246293        tcase_add_test(tc, test_putname_nodot); 
Note: See TracChangeset for help on using the changeset viewer.