mirror of
https://github.com/yarrick/iodine.git
synced 2025-12-05 20:01:50 +00:00
Extended test cases
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user