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 {NULL, NULL},
95 {"", NULL},
96 {"-", "./-"},
97 {"blabla-", "blabla-"},
98 {"\r\n\t", "\\\r\\\n\\\t"},
99 {"'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)"},
100 {"a b c ", "a\\ b\\ c\\ "},
101 {"#", "\\#"},
102 {"blabla#", "blabla#"},
103 {"~", "\\~"},
104 {"blabla~", "blabla~"},
105 };
106
107
108
109
110 START_PARAMETRIZED_TEST (name_quote_test, data_source2)
111
112 {
113
114 char *actual_string;
115
116
117 actual_string = name_quote (data->input_string, FALSE);
118
119
120 mctest_assert_str_eq (actual_string, data->expected_string);
121
122 g_free (actual_string);
123 }
124
125 END_PARAMETRIZED_TEST
126
127
128
129
130 int
131 main (void)
132 {
133 TCase *tc_core;
134
135 tc_core = tcase_create ("Core");
136
137 tcase_add_checked_fixture (tc_core, setup, teardown);
138
139
140 mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1);
141 mctest_add_parameterized_test (tc_core, name_quote_test, data_source2);
142
143
144 return mctest_run_all (tc_core);
145 }
146
147