Changeset 93a313


Ignore:
Timestamp:
09/20/09 10:43:49 (3 years ago)
Author:
Erik Ekman <yarrick@…>
Branches:
master
Children:
379ca5
Parents:
a1a2e3
git-author:
Erik Ekman <yarrick@…> (09/20/09 10:43:49)
git-committer:
Erik Ekman <erik@…> (02/04/12 20:34:03)
Message:

Added new test, found and fixed an actual bug

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/encoding.c

    ra1a2e3 r93a313  
    4242        b += strlen(buf); 
    4343 
     44        /* move b back one step to see if the dot is there */ 
     45        b--; 
    4446        if (*b != '.')  
    45                 *b++ = '.'; 
     47                *++b = '.'; 
     48        b++; 
     49        /* move b ahead of the string so we can copy to it */ 
    4650 
    4751        strncpy(b, topdomain, strlen(topdomain)+1); 
  • tests/encoding.c

    rdc17bc r93a313  
    2222#include "encoding.h" 
    2323#include "test.h" 
     24#include "base32.h" 
     25#include "base64.h" 
    2426 
    25 struct tuple 
     27#define TUPLES 4 
     28 
     29static struct tuple 
    2630{ 
    2731        char *a; 
     
    4044START_TEST(test_inline_dotify) 
    4145{ 
    42         unsigned i; 
    4346        char temp[1024]; 
    4447        char *b; 
    4548 
    46         i = 0; 
    47         while (dottests[i].a) { 
    48                 memset(temp, 0, sizeof(temp)); 
    49                 strcpy(temp, dottests[i].a); 
    50                 b = temp; 
    51                 inline_dotify(b, sizeof(temp)); 
     49        memset(temp, 0, sizeof(temp)); 
     50        strcpy(temp, dottests[_i].a); 
     51        b = temp; 
     52        inline_dotify(b, sizeof(temp)); 
    5253 
    53                 fail_unless(strcmp(dottests[i].b, temp) == 0, 
    54                                 "'%s' != '%s'", temp, dottests[i].b); 
    55                 i++; 
    56         } 
     54        fail_unless(strcmp(dottests[_i].b, temp) == 0, 
     55                        "'%s' != '%s'", temp, dottests[_i].b); 
    5756} 
    5857END_TEST 
     
    6059START_TEST(test_inline_undotify) 
    6160{ 
    62         unsigned i; 
    6361        char temp[1024]; 
    6462        char *b; 
    6563 
    66         i = 0; 
    67         while (dottests[i].a) { 
    68                 memset(temp, 0, sizeof(temp)); 
    69                 strcpy(temp, dottests[i].b); 
    70                 b = temp; 
    71                 inline_undotify(b, sizeof(temp)); 
     64        memset(temp, 0, sizeof(temp)); 
     65        strcpy(temp, dottests[_i].b); 
     66        b = temp; 
     67        inline_undotify(b, sizeof(temp)); 
    7268 
    73                 fail_unless(strcmp(dottests[i].a, temp) == 0, 
    74                                 "'%s' != '%s'", temp, dottests[i].a); 
    75                 i++; 
     69        fail_unless(strcmp(dottests[_i].a, temp) == 0, 
     70                        "'%s' != '%s'", temp, dottests[_i].a); 
     71} 
     72END_TEST 
     73 
     74START_TEST(test_build_hostname) 
     75{ 
     76        char data[256]; 
     77        char buf[1024]; 
     78        char *topdomain = "a.c"; 
     79        int buflen; 
     80        int i; 
     81 
     82        for (i = 0; i < sizeof(data); i++) { 
     83                data[i] = i & 0xFF; 
     84        } 
     85 
     86        buflen = sizeof(buf); 
     87         
     88        for (i = 1; i < sizeof(data); i++) { 
     89                int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder()); 
     90 
     91                fail_if(len > i); 
     92                fail_if(strstr(buf, ".."), "Found double dots when encoding data len %d! buf: %s", i, buf); 
    7693        } 
    7794} 
     
    84101 
    85102        tc = tcase_create("Encoding"); 
    86         tcase_add_test(tc, test_inline_dotify); 
    87         tcase_add_test(tc, test_inline_undotify); 
     103        tcase_add_loop_test(tc, test_inline_dotify, 0, TUPLES); 
     104        tcase_add_loop_test(tc, test_inline_undotify, 0, TUPLES); 
     105        tcase_add_test(tc, test_build_hostname); 
    88106 
    89107        return tc; 
Note: See TracChangeset for help on using the changeset viewer.