1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-22 21:16:07 +03:00

Added new test, found and fixed an actual bug

This commit is contained in:
Erik Ekman 2009-09-20 08:43:49 +00:00 committed by Erik Ekman
parent a1a2e3cefe
commit 93a313b130
2 changed files with 47 additions and 25 deletions

View File

@ -41,8 +41,12 @@ build_hostname(char *buf, size_t buflen,
b = buf; b = buf;
b += strlen(buf); b += strlen(buf);
/* move b back one step to see if the dot is there */
b--;
if (*b != '.') if (*b != '.')
*b++ = '.'; *++b = '.';
b++;
/* move b ahead of the string so we can copy to it */
strncpy(b, topdomain, strlen(topdomain)+1); strncpy(b, topdomain, strlen(topdomain)+1);

View File

@ -21,8 +21,12 @@
#include "encoding.h" #include "encoding.h"
#include "test.h" #include "test.h"
#include "base32.h"
#include "base64.h"
struct tuple #define TUPLES 4
static struct tuple
{ {
char *a; char *a;
char *b; char *b;
@ -39,40 +43,53 @@ struct tuple
START_TEST(test_inline_dotify) START_TEST(test_inline_dotify)
{ {
unsigned i;
char temp[1024]; char temp[1024];
char *b; char *b;
i = 0; memset(temp, 0, sizeof(temp));
while (dottests[i].a) { strcpy(temp, dottests[_i].a);
memset(temp, 0, sizeof(temp)); b = temp;
strcpy(temp, dottests[i].a); inline_dotify(b, sizeof(temp));
b = temp;
inline_dotify(b, sizeof(temp));
fail_unless(strcmp(dottests[i].b, temp) == 0, fail_unless(strcmp(dottests[_i].b, temp) == 0,
"'%s' != '%s'", temp, dottests[i].b); "'%s' != '%s'", temp, dottests[_i].b);
i++;
}
} }
END_TEST END_TEST
START_TEST(test_inline_undotify) START_TEST(test_inline_undotify)
{ {
unsigned i;
char temp[1024]; char temp[1024];
char *b; char *b;
i = 0; memset(temp, 0, sizeof(temp));
while (dottests[i].a) { strcpy(temp, dottests[_i].b);
memset(temp, 0, sizeof(temp)); b = temp;
strcpy(temp, dottests[i].b); inline_undotify(b, sizeof(temp));
b = temp;
inline_undotify(b, sizeof(temp));
fail_unless(strcmp(dottests[i].a, temp) == 0, fail_unless(strcmp(dottests[_i].a, temp) == 0,
"'%s' != '%s'", temp, dottests[i].a); "'%s' != '%s'", temp, dottests[_i].a);
i++; }
END_TEST
START_TEST(test_build_hostname)
{
char data[256];
char buf[1024];
char *topdomain = "a.c";
int buflen;
int i;
for (i = 0; i < sizeof(data); i++) {
data[i] = i & 0xFF;
}
buflen = sizeof(buf);
for (i = 1; i < sizeof(data); i++) {
int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder());
fail_if(len > i);
fail_if(strstr(buf, ".."), "Found double dots when encoding data len %d! buf: %s", i, buf);
} }
} }
END_TEST END_TEST
@ -83,8 +100,9 @@ test_encoding_create_tests()
TCase *tc; TCase *tc;
tc = tcase_create("Encoding"); tc = tcase_create("Encoding");
tcase_add_test(tc, test_inline_dotify); tcase_add_loop_test(tc, test_inline_dotify, 0, TUPLES);
tcase_add_test(tc, test_inline_undotify); tcase_add_loop_test(tc, test_inline_undotify, 0, TUPLES);
tcase_add_test(tc, test_build_hostname);
return tc; return tc;
} }