Changeset 3ee493
- Timestamp:
- 02/09/09 19:46:17 (3 years ago)
- Branches:
- master
- Children:
- b6fc3f
- Parents:
- 0f7ce5
- git-author:
- Erik Ekman <yarrick@…> (02/09/09 19:46:17)
- git-committer:
- Erik Ekman <erik@…> (02/04/12 20:34:00)
- Location:
- tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/base32.c
r7b7661 r3ee493 25 25 #include "test.h" 26 26 27 #define TUPLES 5 28 27 29 static struct tuple 28 30 { 29 31 char *a; 30 32 char *b; 31 } testpairs[ ] = {33 } testpairs[TUPLES] = { 32 34 { "iodinetestingtesting", "nfxwi0lomv0gk21unfxgo3dfon0gs1th" }, 33 35 { "abc123", "mfrggmjsgm" }, 34 { NULL, NULL } 36 { "test", "orsxg3a" }, 37 { "tst", "orzxi" }, 38 { "", "" }, 35 39 }; 36 40 … … 41 45 struct encoder *b32; 42 46 int val; 43 int i;44 47 45 48 b32 = get_base32_encoder(); 46 49 47 for (i = 0; testpairs[i].a != NULL; i++) { 48 len = sizeof(buf); 49 val = b32->encode(buf, &len, testpairs[i].a, strlen(testpairs[i].a)); 50 len = sizeof(buf); 51 val = b32->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); 50 52 51 fail_unless(val > 0, strerror(errno)); 52 fail_unless(strcmp(buf, testpairs[i].b) == 0, 53 "'%s' != '%s'", buf, testpairs[i].b); 54 } 53 fail_unless(strcmp(buf, testpairs[_i].b) == 0, 54 "'%s' != '%s'", buf, testpairs[_i].b); 55 55 } 56 56 END_TEST … … 62 62 struct encoder *b32; 63 63 int val; 64 int i;65 64 66 65 b32 = get_base32_encoder(); 67 66 68 for (i = 0; testpairs[i].a != NULL; i++) { 69 len = sizeof(buf); 70 val = b32->decode(buf, &len, testpairs[i].b, strlen(testpairs[i].b)); 67 len = sizeof(buf); 68 val = b32->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); 71 69 72 fail_unless(val > 0, strerror(errno)); 73 fail_unless(buf != NULL, "buf == NULL"); 74 fail_unless(strcmp(buf, testpairs[i].a) == 0, 75 "'%s' != '%s'", buf, testpairs[i].a); 76 } 70 fail_unless(buf != NULL, "buf == NULL"); 71 fail_unless(strcmp(buf, testpairs[_i].a) == 0, 72 "'%s' != '%s'", buf, testpairs[_i].a); 77 73 } 78 74 END_TEST … … 96 92 97 93 tc = tcase_create("Base32"); 98 tcase_add_ test(tc, test_base32_encode);99 tcase_add_ test(tc, test_base32_decode);94 tcase_add_loop_test(tc, test_base32_encode, 0, TUPLES); 95 tcase_add_loop_test(tc, test_base32_decode, 0, TUPLES); 100 96 tcase_add_test(tc, test_base32_5to8_8to5); 101 97 -
tests/base64.c
r7b7661 r3ee493 25 25 #include "test.h" 26 26 27 #define TUPLES 5 28 27 29 static struct tuple 28 30 { 29 31 char *a; 30 32 char *b; 31 } testpairs[ ] = {33 } testpairs[TUPLES] = { 32 34 { "iodinetestingtesting", "Aw8KAw4LDgvZDgLUz2rLC2rPBMC" }, 33 35 { "abc1231", "ywjJmtiZmq" }, … … 60 62 "0-ZYXWVUTSRQfHKwfHGsHGFEDCBAzyxwvutsrqponmlkjihgfedcba" 61 63 }, 62 { NULL, NULL}64 { "", "" } 63 65 }; 64 66 … … 69 71 struct encoder *b64; 70 72 int val; 71 int i;72 73 73 74 b64 = get_base64_encoder(); 74 75 75 for (i = 0; testpairs[i].a != NULL; i++) { 76 len = sizeof(buf); 77 val = b64->encode(buf, &len, testpairs[i].a, strlen(testpairs[i].a)); 76 len = sizeof(buf); 77 val = b64->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); 78 78 79 fail_unless(val > 0, strerror(errno)); 80 fail_unless(strcmp(buf, testpairs[i].b) == 0, 81 "'%s' != '%s'", buf, testpairs[i].b); 82 } 79 fail_unless(strcmp(buf, testpairs[_i].b) == 0, 80 "'%s' != '%s'", buf, testpairs[_i].b); 83 81 } 84 82 END_TEST … … 90 88 struct encoder *b64; 91 89 int val; 92 int i;93 90 94 91 b64 = get_base64_encoder(); 95 92 96 for (i = 0; testpairs[i].a != NULL; i++) { 97 len = sizeof(buf); 98 val = b64->decode(buf, &len, testpairs[i].b, strlen(testpairs[i].b)); 93 len = sizeof(buf); 94 val = b64->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); 99 95 100 fail_unless(val > 0, strerror(errno)); 101 fail_unless(buf != NULL, "buf == NULL"); 102 fail_unless(strcmp(buf, testpairs[i].a) == 0, 103 "'%s' != '%s'", buf, testpairs[i].a); 104 } 96 fail_unless(buf != NULL, "buf == NULL"); 97 fail_unless(strcmp(buf, testpairs[_i].a) == 0, 98 "'%s' != '%s'", buf, testpairs[_i].a); 105 99 } 106 100 END_TEST … … 112 106 113 107 tc = tcase_create("Base64"); 114 tcase_add_ test(tc, test_base64_encode);115 tcase_add_ test(tc, test_base64_decode);108 tcase_add_loop_test(tc, test_base64_encode, 0, TUPLES); 109 tcase_add_loop_test(tc, test_base64_decode, 0, TUPLES); 116 110 117 111 return tc; -
tests/login.c
r7b7661 r3ee493 29 29 int seed; 30 30 31 len = 16;31 len = sizeof(ans); 32 32 seed = 15; 33 33 … … 35 35 login_calculate(ans, len, pass, seed); 36 36 fail_unless(strncmp(ans, good, len) == 0, NULL); 37 } 38 END_TEST 39 40 START_TEST(test_login_hash_short) 41 { 42 char ans[8]; 43 char check[sizeof(ans)]; 44 char pass[32] = "iodine is the shit"; 45 int len; 46 int seed; 47 48 len = sizeof(ans); 49 seed = 15; 50 51 memset(ans, 0, sizeof(ans)); 52 memset(check, 0, sizeof(check)); 53 54 /* If len < 16, it should do nothing */ 55 login_calculate(ans, len, pass, seed); 56 fail_if(memcmp(ans, check, sizeof(ans))); 37 57 } 38 58 END_TEST … … 45 65 tc = tcase_create("Login"); 46 66 tcase_add_test(tc, test_login_hash); 67 tcase_add_test(tc, test_login_hash_short); 47 68 48 69 return tc;
Note: See TracChangeset
for help on using the changeset viewer.
