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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* blogc: A blog compiler.
* Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
*
* This program can be distributed under the terms of the BSD License.
* See the file LICENSE.
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include "../../src/blogc-make/rules.h"
#include "../../src/common/utils.h"
static void
test_rule_parse_args(void **state)
{
bc_trie_t *t = bm_rule_parse_args("bola:foo=" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 1);
assert_string_equal(bc_trie_lookup(t, "foo"), "");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 1);
assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=,baz=lol" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 2);
assert_string_equal(bc_trie_lookup(t, "foo"), "");
assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 2);
assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
assert_string_equal(bc_trie_lookup(t, "baz"), "");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 2);
assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=,baz=lol,asd=qwe" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 3);
assert_string_equal(bc_trie_lookup(t, "foo"), "");
assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=,asd=qwe" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 3);
assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
assert_string_equal(bc_trie_lookup(t, "baz"), "");
assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 3);
assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
assert_string_equal(bc_trie_lookup(t, "asd"), "");
bc_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=qwe" + 4);
assert_non_null(t);
assert_int_equal(bc_trie_size(t), 3);
assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
bc_trie_free(t);
}
static void
test_rule_parse_args_error(void **state)
{
assert_null(bm_rule_parse_args(NULL));
assert_null(bm_rule_parse_args("bola" + 4));
assert_null(bm_rule_parse_args("bola:" + 4));
assert_null(bm_rule_parse_args("bola:asd" + 4));
assert_null(bm_rule_parse_args("bola:asd=foo,lol" + 4));
assert_null(bm_rule_parse_args("bola:asd=foo,qwe=bar,lol" + 4));
assert_null(bm_rule_parse_args("bolaasd" + 4));
}
int
main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_rule_parse_args),
cmocka_unit_test(test_rule_parse_args_error),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
|