File: isds-hash_algorithm.c

package info (click to toggle)
libisds 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,348 kB
  • ctags: 1,659
  • sloc: ansic: 24,898; sh: 11,772; makefile: 393; xml: 375; sed: 16
file content (53 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "../test.h"
#include "isds.c"

static int test_string2hashalgorithm(const xmlChar *name,
        const isds_error error, const isds_hash_algorithm type) {
    isds_error err;
    isds_hash_algorithm new_type = -1; /* ??? GCC-4.7.3 at -O3 complains on
                                          possibly undefined new_type in the
                                          `type != new_type' code. */

    err = string2isds_hash_algorithm(name, &new_type);
    if (err != error)
        FAIL_TEST("string2isds_hash_algorithm() returned unexpected code");

    if (err)
        PASS_TEST;

    if (type != new_type)
        FAIL_TEST("conversion returned wrong algorithm");

    PASS_TEST;
}

int main(int argc, char **argv) {
    INIT_TEST("isds_hash_algorithm conversion");
   
    xmlChar *names[] = {
        BAD_CAST "MD5",
        BAD_CAST "SHA-1",
        BAD_CAST "SHA-224",
        BAD_CAST "SHA-256",
        BAD_CAST "SHA-384",
        BAD_CAST "SHA-512"
    };

    isds_hash_algorithm algos[] =  {
        HASH_ALGORITHM_MD5,
        HASH_ALGORITHM_SHA_1,
        HASH_ALGORITHM_SHA_224,
        HASH_ALGORITHM_SHA_256,
        HASH_ALGORITHM_SHA_384,
        HASH_ALGORITHM_SHA_512,
    };

    for (int i = 0; i < sizeof(algos)/sizeof(algos[0]); i++)
        TEST(names[i], test_string2hashalgorithm, names[i], IE_SUCCESS,
                algos[i]);

    TEST("X-Invalid_Type", test_string2hashalgorithm, BAD_CAST "X-Invalid_Type",
            IE_ENUM, 0);

    SUM_TEST();
}