Changeset 3ee493


Ignore:
Timestamp:
02/09/09 19:46:17 (3 years ago)
Author:
Erik Ekman <yarrick@…>
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)
Message:

Extended test cases

Location:
tests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tests/base32.c

    r7b7661 r3ee493  
    2525#include "test.h" 
    2626 
     27#define TUPLES 5 
     28 
    2729static struct tuple 
    2830{ 
    2931        char *a; 
    3032        char *b; 
    31 } testpairs[] = { 
     33} testpairs[TUPLES] = { 
    3234        { "iodinetestingtesting", "nfxwi0lomv0gk21unfxgo3dfon0gs1th" }, 
    3335        { "abc123", "mfrggmjsgm" }, 
    34         { NULL, NULL } 
     36        { "test", "orsxg3a" }, 
     37        { "tst", "orzxi" }, 
     38        { "", "" }, 
    3539}; 
    3640 
     
    4145        struct encoder *b32; 
    4246        int val; 
    43         int i; 
    4447 
    4548        b32 = get_base32_encoder(); 
    4649 
    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)); 
    5052 
    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); 
    5555} 
    5656END_TEST 
     
    6262        struct encoder *b32; 
    6363        int val; 
    64         int i; 
    6564         
    6665        b32 = get_base32_encoder(); 
    6766 
    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)); 
    7169 
    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); 
    7773} 
    7874END_TEST 
     
    9692 
    9793        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); 
    10096        tcase_add_test(tc, test_base32_5to8_8to5); 
    10197 
  • tests/base64.c

    r7b7661 r3ee493  
    2525#include "test.h" 
    2626 
     27#define TUPLES 5 
     28 
    2729static struct tuple 
    2830{ 
    2931        char *a; 
    3032        char *b; 
    31 } testpairs[] = { 
     33} testpairs[TUPLES] = { 
    3234        { "iodinetestingtesting", "Aw8KAw4LDgvZDgLUz2rLC2rPBMC" }, 
    3335        { "abc1231", "ywjJmtiZmq" }, 
     
    6062          "0-ZYXWVUTSRQfHKwfHGsHGFEDCBAzyxwvutsrqponmlkjihgfedcba" 
    6163        }, 
    62         { NULL, NULL } 
     64        { "", "" } 
    6365}; 
    6466 
     
    6971        struct encoder *b64; 
    7072        int val; 
    71         int i; 
    7273 
    7374        b64 = get_base64_encoder(); 
    7475 
    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)); 
    7878 
    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); 
    8381} 
    8482END_TEST 
     
    9088        struct encoder *b64; 
    9189        int val; 
    92         int i; 
    9390 
    9491        b64 = get_base64_encoder(); 
    9592 
    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)); 
    9995 
    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); 
    10599} 
    106100END_TEST 
     
    112106 
    113107        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); 
    116110 
    117111        return tc; 
  • tests/login.c

    r7b7661 r3ee493  
    2929        int seed; 
    3030 
    31         len = 16; 
     31        len = sizeof(ans); 
    3232        seed = 15; 
    3333 
     
    3535        login_calculate(ans, len, pass, seed); 
    3636        fail_unless(strncmp(ans, good, len) == 0, NULL); 
     37} 
     38END_TEST 
     39 
     40START_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))); 
    3757} 
    3858END_TEST 
     
    4565        tc = tcase_create("Login"); 
    4666        tcase_add_test(tc, test_login_hash); 
     67        tcase_add_test(tc, test_login_hash_short); 
    4768 
    4869        return tc; 
Note: See TracChangeset for help on using the changeset viewer.