Changeset 93a313
- Timestamp:
- 09/20/09 10:43:49 (3 years ago)
- 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)
- Files:
-
- 2 edited
-
src/encoding.c (modified) (1 diff)
-
tests/encoding.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/encoding.c
ra1a2e3 r93a313 42 42 b += strlen(buf); 43 43 44 /* move b back one step to see if the dot is there */ 45 b--; 44 46 if (*b != '.') 45 *b++ = '.'; 47 *++b = '.'; 48 b++; 49 /* move b ahead of the string so we can copy to it */ 46 50 47 51 strncpy(b, topdomain, strlen(topdomain)+1); -
tests/encoding.c
rdc17bc r93a313 22 22 #include "encoding.h" 23 23 #include "test.h" 24 #include "base32.h" 25 #include "base64.h" 24 26 25 struct tuple 27 #define TUPLES 4 28 29 static struct tuple 26 30 { 27 31 char *a; … … 40 44 START_TEST(test_inline_dotify) 41 45 { 42 unsigned i;43 46 char temp[1024]; 44 47 char *b; 45 48 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)); 52 53 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); 57 56 } 58 57 END_TEST … … 60 59 START_TEST(test_inline_undotify) 61 60 { 62 unsigned i;63 61 char temp[1024]; 64 62 char *b; 65 63 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)); 72 68 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 } 72 END_TEST 73 74 START_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); 76 93 } 77 94 } … … 84 101 85 102 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); 88 106 89 107 return tc;
Note: See TracChangeset
for help on using the changeset viewer.
