This source file includes following definitions.
- setup
- teardown
- START_PARAMETRIZED_TEST
- START_PARAMETRIZED_TEST
- main
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 #define TEST_SUITE_NAME "/lib/util"
27
28 #include "tests/mctest.h"
29
30 #include "lib/util.h"
31
32
33
34
35 static void
36 setup (void)
37 {
38 }
39
40
41 static void
42 teardown (void)
43 {
44 }
45
46
47
48
49
50 static const struct data_source1
51 {
52 gboolean input_quote_percent;
53 const char *input_string;
54
55 const char *expected_string;
56 } data_source1[] =
57 {
58 { TRUE, "%%", "%%%%"},
59 { FALSE, "%%", "%%"},
60 };
61
62
63
64
65 START_PARAMETRIZED_TEST (quote_percent_test, data_source1)
66
67 {
68
69 char *actual_string;
70
71
72 actual_string = name_quote (data->input_string, data->input_quote_percent);
73
74
75 mctest_assert_str_eq (actual_string, data->expected_string);
76
77 g_free (actual_string);
78 }
79
80 END_PARAMETRIZED_TEST
81
82
83
84
85
86
87 static const struct data_source2
88 {
89 const char *input_string;
90
91 const char *expected_string;
92 } data_source2[] =
93 {
94 {"-", "./-"},
95 {"blabla-", "blabla-"},
96 {"\r\n\t", "\\\r\\\n\\\t"},
97 {"'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)"},
98 {"a b c ", "a\\ b\\ c\\ "},
99 {"#", "\\#"},
100 {"blabla#", "blabla#"},
101 {"~", "\\~"},
102 {"blabla~", "blabla~"},
103 };
104
105
106
107
108 START_PARAMETRIZED_TEST (name_quote_test, data_source2)
109
110 {
111
112 char *actual_string;
113
114
115 actual_string = name_quote (data->input_string, FALSE);
116
117
118 mctest_assert_str_eq (actual_string, data->expected_string);
119
120 g_free (actual_string);
121 }
122
123 END_PARAMETRIZED_TEST
124
125
126
127
128 int
129 main (void)
130 {
131 TCase *tc_core;
132
133 tc_core = tcase_create ("Core");
134
135 tcase_add_checked_fixture (tc_core, setup, teardown);
136
137
138 mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1);
139 mctest_add_parameterized_test (tc_core, name_quote_test, data_source2);
140
141
142 return mctest_run_all (tc_core);
143 }
144
145