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 static const struct data_source1
50 {
51 gboolean input_quote_percent;
52 const char *input_string;
53
54 const char *expected_string;
55 } data_source1[] = {
56 { TRUE, "%%", "%%%%" },
57 { FALSE, "%%", "%%" },
58 };
59
60
61 START_PARAMETRIZED_TEST (quote_percent_test, data_source1)
62 {
63
64 char *actual_string;
65
66
67 actual_string = name_quote (data->input_string, data->input_quote_percent);
68
69
70 mctest_assert_str_eq (actual_string, data->expected_string);
71
72 g_free (actual_string);
73 }
74 END_PARAMETRIZED_TEST
75
76
77
78
79 static const struct data_source2
80 {
81 const char *input_string;
82
83 const char *expected_string;
84 } data_source2[] = {
85 { "", NULL },
86 { "-", "./-" },
87 { "blabla-", "blabla-" },
88 { "\r\n\t", "\\\r\\\n\\\t" },
89 { "'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)" },
90 { "a b c ", "a\\ b\\ c\\ " },
91 { "#", "\\#" },
92 { "blabla#", "blabla#" },
93 { "~", "\\~" },
94 { "blabla~", "blabla~" },
95 {
96 NULL,
97 NULL,
98 },
99 };
100
101
102 START_PARAMETRIZED_TEST (name_quote_test, data_source2)
103 {
104
105 char *actual_string;
106
107
108 actual_string = name_quote (data->input_string, FALSE);
109
110
111 mctest_assert_str_eq (actual_string, data->expected_string);
112
113 g_free (actual_string);
114 }
115 END_PARAMETRIZED_TEST
116
117
118
119 int
120 main (void)
121 {
122 TCase *tc_core;
123
124 tc_core = tcase_create ("Core");
125
126 tcase_add_checked_fixture (tc_core, setup, teardown);
127
128
129 mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1);
130 mctest_add_parameterized_test (tc_core, name_quote_test, data_source2);
131
132
133 return mctest_run_all (tc_core);
134 }
135
136