This source file includes following definitions.
- 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 const struct data_source1
36 {
37 gboolean input_quote_percent;
38 const char *input_string;
39
40 const char *expected_string;
41 } data_source1[] = {
42 { TRUE, "%%", "%%%%" },
43 { FALSE, "%%", "%%" },
44 };
45
46
47 START_PARAMETRIZED_TEST (quote_percent_test, data_source1)
48 {
49
50 GString *actual_string;
51
52
53 actual_string = name_quote (data->input_string, data->input_quote_percent);
54
55
56 mctest_assert_str_eq (actual_string->str, data->expected_string);
57
58 g_string_free (actual_string, TRUE);
59 }
60 END_PARAMETRIZED_TEST
61
62
63
64
65 static const struct data_source2
66 {
67 const char *input_string;
68
69 const char *expected_string;
70 } data_source2[] = {
71 { "", NULL },
72 { "-", "./-" },
73 { "blabla-", "blabla-" },
74 { "\r\n\t", "\\\r\\\n\\\t" },
75 { "'\\\";?|[]{}<>`!$&*()", "\\'\\\\\\\"\\;\\?\\|\\[\\]\\{\\}\\<\\>\\`\\!\\$\\&\\*\\(\\)" },
76 { "a b c ", "a\\ b\\ c\\ " },
77 { "#", "\\#" },
78 { "blabla#", "blabla#" },
79 { "~", "\\~" },
80 { "blabla~", "blabla~" },
81 {
82 NULL,
83 NULL,
84 },
85 };
86
87
88 START_PARAMETRIZED_TEST (name_quote_test, data_source2)
89 {
90
91 GString *actual_string;
92
93
94 actual_string = name_quote (data->input_string, FALSE);
95
96
97 if (actual_string == NULL)
98 {
99 mctest_assert_ptr_eq (NULL, data->expected_string);
100 }
101 else
102 {
103 mctest_assert_str_eq (actual_string->str, data->expected_string);
104 g_string_free (actual_string, TRUE);
105 }
106 }
107 END_PARAMETRIZED_TEST
108
109
110
111 int
112 main (void)
113 {
114 TCase *tc_core;
115
116 tc_core = tcase_create ("Core");
117
118
119 mctest_add_parameterized_test (tc_core, quote_percent_test, data_source1);
120 mctest_add_parameterized_test (tc_core, name_quote_test, data_source2);
121
122
123 return mctest_run_all (tc_core);
124 }
125
126