From 3ee49377e8fd0901dbf1150f484bd961860c04a7 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Mon, 9 Feb 2009 18:46:17 +0000 Subject: [PATCH] Extended test cases --- tests/base32.c | 38 +++++++++++++++++--------------------- tests/base64.c | 36 +++++++++++++++--------------------- tests/login.c | 23 ++++++++++++++++++++++- 3 files changed, 54 insertions(+), 43 deletions(-) diff --git a/tests/base32.c b/tests/base32.c index a3f95bb..0b77a03 100644 --- a/tests/base32.c +++ b/tests/base32.c @@ -24,14 +24,18 @@ #include "base32.h" #include "test.h" +#define TUPLES 5 + static struct tuple { char *a; char *b; -} testpairs[] = { +} testpairs[TUPLES] = { { "iodinetestingtesting", "nfxwi0lomv0gk21unfxgo3dfon0gs1th" }, { "abc123", "mfrggmjsgm" }, - { NULL, NULL } + { "test", "orsxg3a" }, + { "tst", "orzxi" }, + { "", "" }, }; START_TEST(test_base32_encode) @@ -40,18 +44,14 @@ START_TEST(test_base32_encode) char buf[4096]; struct encoder *b32; int val; - int i; b32 = get_base32_encoder(); - for (i = 0; testpairs[i].a != NULL; i++) { - len = sizeof(buf); - val = b32->encode(buf, &len, testpairs[i].a, strlen(testpairs[i].a)); + len = sizeof(buf); + val = b32->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); - fail_unless(val > 0, strerror(errno)); - fail_unless(strcmp(buf, testpairs[i].b) == 0, - "'%s' != '%s'", buf, testpairs[i].b); - } + fail_unless(strcmp(buf, testpairs[_i].b) == 0, + "'%s' != '%s'", buf, testpairs[_i].b); } END_TEST @@ -61,19 +61,15 @@ START_TEST(test_base32_decode) char buf[4096]; struct encoder *b32; int val; - int i; b32 = get_base32_encoder(); - for (i = 0; testpairs[i].a != NULL; i++) { - len = sizeof(buf); - val = b32->decode(buf, &len, testpairs[i].b, strlen(testpairs[i].b)); + len = sizeof(buf); + val = b32->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); - fail_unless(val > 0, strerror(errno)); - fail_unless(buf != NULL, "buf == NULL"); - fail_unless(strcmp(buf, testpairs[i].a) == 0, - "'%s' != '%s'", buf, testpairs[i].a); - } + fail_unless(buf != NULL, "buf == NULL"); + fail_unless(strcmp(buf, testpairs[_i].a) == 0, + "'%s' != '%s'", buf, testpairs[_i].a); } END_TEST @@ -95,8 +91,8 @@ test_base32_create_tests() TCase *tc; tc = tcase_create("Base32"); - tcase_add_test(tc, test_base32_encode); - tcase_add_test(tc, test_base32_decode); + tcase_add_loop_test(tc, test_base32_encode, 0, TUPLES); + tcase_add_loop_test(tc, test_base32_decode, 0, TUPLES); tcase_add_test(tc, test_base32_5to8_8to5); return tc; diff --git a/tests/base64.c b/tests/base64.c index 280963e..ccd71c4 100644 --- a/tests/base64.c +++ b/tests/base64.c @@ -24,11 +24,13 @@ #include "base64.h" #include "test.h" +#define TUPLES 5 + static struct tuple { char *a; char *b; -} testpairs[] = { +} testpairs[TUPLES] = { { "iodinetestingtesting", "Aw8KAw4LDgvZDgLUz2rLC2rPBMC" }, { "abc1231", "ywjJmtiZmq" }, { @@ -59,7 +61,7 @@ static struct tuple "776543210-ZYXWVUTSRQfHKwfHGsHGFEDCBAzyxwvutsrqponmlkjihgfedcba+987654321" "0-ZYXWVUTSRQfHKwfHGsHGFEDCBAzyxwvutsrqponmlkjihgfedcba" }, - { NULL, NULL } + { "", "" } }; START_TEST(test_base64_encode) @@ -68,18 +70,14 @@ START_TEST(test_base64_encode) char buf[4096]; struct encoder *b64; int val; - int i; b64 = get_base64_encoder(); - for (i = 0; testpairs[i].a != NULL; i++) { - len = sizeof(buf); - val = b64->encode(buf, &len, testpairs[i].a, strlen(testpairs[i].a)); + len = sizeof(buf); + val = b64->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); - fail_unless(val > 0, strerror(errno)); - fail_unless(strcmp(buf, testpairs[i].b) == 0, - "'%s' != '%s'", buf, testpairs[i].b); - } + fail_unless(strcmp(buf, testpairs[_i].b) == 0, + "'%s' != '%s'", buf, testpairs[_i].b); } END_TEST @@ -89,19 +87,15 @@ START_TEST(test_base64_decode) char buf[4096]; struct encoder *b64; int val; - int i; b64 = get_base64_encoder(); - for (i = 0; testpairs[i].a != NULL; i++) { - len = sizeof(buf); - val = b64->decode(buf, &len, testpairs[i].b, strlen(testpairs[i].b)); + len = sizeof(buf); + val = b64->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); - fail_unless(val > 0, strerror(errno)); - fail_unless(buf != NULL, "buf == NULL"); - fail_unless(strcmp(buf, testpairs[i].a) == 0, - "'%s' != '%s'", buf, testpairs[i].a); - } + fail_unless(buf != NULL, "buf == NULL"); + fail_unless(strcmp(buf, testpairs[_i].a) == 0, + "'%s' != '%s'", buf, testpairs[_i].a); } END_TEST @@ -111,8 +105,8 @@ test_base64_create_tests() TCase *tc; tc = tcase_create("Base64"); - tcase_add_test(tc, test_base64_encode); - tcase_add_test(tc, test_base64_decode); + tcase_add_loop_test(tc, test_base64_encode, 0, TUPLES); + tcase_add_loop_test(tc, test_base64_decode, 0, TUPLES); return tc; } diff --git a/tests/login.c b/tests/login.c index 2745c92..1ef23f4 100644 --- a/tests/login.c +++ b/tests/login.c @@ -28,7 +28,7 @@ START_TEST(test_login_hash) int len; int seed; - len = 16; + len = sizeof(ans); seed = 15; memset(ans, 0, sizeof(ans)); @@ -37,6 +37,26 @@ START_TEST(test_login_hash) } END_TEST +START_TEST(test_login_hash_short) +{ + char ans[8]; + char check[sizeof(ans)]; + char pass[32] = "iodine is the shit"; + int len; + int seed; + + len = sizeof(ans); + seed = 15; + + memset(ans, 0, sizeof(ans)); + memset(check, 0, sizeof(check)); + + /* If len < 16, it should do nothing */ + login_calculate(ans, len, pass, seed); + fail_if(memcmp(ans, check, sizeof(ans))); +} +END_TEST + TCase * test_login_create_tests() { @@ -44,6 +64,7 @@ test_login_create_tests() tc = tcase_create("Login"); tcase_add_test(tc, test_login_hash); + tcase_add_test(tc, test_login_hash_short); return tc; }