Statistics
| Branch: | Tag: | Revision:

sssimulator / Matrix / Test / tokens_test.c @ master

History | View | Annotate | Download (1.56 KB)

1 692b6c80 luca
/*
2
 * This is SSSim: the Simple & Stupid Simulator
3
 *
4
 *  Copyright (c) 2015 Luca Baldesi
5
 *
6
 *  This is free software; see gpl-3.0.txt
7
 */
8
9
#include <assert.h>
10
#include <string.h>
11
#include <stdio.h>
12
13
#include <tokens.h>
14
15
void tokens_create_test()
16
{
17
        char ** toks;
18
        uint32_t n;
19
        
20
        toks = tokens_create(NULL, ' ', NULL);
21
        assert(toks == NULL);
22
23
        toks = tokens_create(NULL, ' ', &n);
24
        assert(toks == NULL);
25
26
        toks = tokens_create("ciao mondo", ' ', NULL);
27
        assert(toks == NULL);
28
29
        toks = tokens_create("ciao mondo", ' ', &n);
30
        assert(toks);
31
        assert(n == 2);
32
        assert(strcmp(toks[0], "ciao") == 0);
33
        assert(strcmp(toks[1], "mondo") == 0);
34
        tokens_destroy(&toks, n);
35
36
        toks = tokens_create("ciao,mondo", ',', &n);
37
        assert(toks);
38
        assert(n == 2);
39
        assert(strcmp(toks[0], "ciao") == 0);
40
        assert(strcmp(toks[1], "mondo") == 0);
41
        tokens_destroy(&toks, n);
42
43
        fprintf(stderr,"%s successfully passed!\n",__func__);
44
}
45
46
void tokens_destroy_test()
47
{
48
        char ** toks;
49
        uint32_t n;
50
51
        tokens_destroy(NULL, 3);
52
53
        toks = tokens_create("ciao,mondo", ',', &n);
54
        tokens_destroy(&toks, n);
55
        assert(toks == NULL);
56
57
        fprintf(stderr,"%s successfully passed!\n",__func__);
58
}
59
60 ec88b090 luca
void tokens_check_test()
61
{
62
        char ** toks;
63
        uint32_t n;
64
        int32_t res;
65
        
66
        toks = tokens_create("ciao mondo", ' ', &n);
67
        assert(tokens_check(toks, n, "ciao") == 0);
68
        assert(tokens_check(toks, n, "mondo") == 1);
69
        assert(tokens_check(toks, n, "zio") < 0);
70
        tokens_destroy(&toks, n);
71
72
        fprintf(stderr,"%s successfully passed!\n",__func__);
73
}
74
75 692b6c80 luca
int main(char ** argc,int argv)
76
{
77
        tokens_create_test();
78
        tokens_destroy_test();
79 ec88b090 luca
        tokens_check_test();
80 692b6c80 luca
        return 0;
81
}