Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /**
4 : : * @brief Verify `--maxdepth` behavior for initial traversal and later update
5 : : *
6 : : * Both depth-limited and unlimited traversals are repeated through configuration
7 : : * from an empty database. The depth-limited database remains for the later update
8 : : *
9 : : * @return Return status code
10 : : */
11 : 2 : Return test0018_1(void)
12 : : {
13 : 2 : INITTEST;
14 : :
15 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
16 : :
17 : 2 : const struct argument_test_case cases[] = {
18 : : /* File system traversal with a maximum depth of 3 */
19 : : {"--maxdepth=3 --database=database3.db "
20 : : "$TMPDIR/tests/fixtures/levels",COMPLETED,"templates/0018_001_1.txt",STDERR_MUST_BE_EMPTY},
21 : : {0}
22 : : };
23 : :
24 : : // Match the result against the pattern
25 : 2 : ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
26 : :
27 : : /* Repeat the limited traversal from the same empty state */
28 : 2 : ASSERT(SUCCESS == delete_path("database3.db"));
29 : 2 : ASSERT(SUCCESS == copy_path("tests/templates/0018_001_1.conf","0018_001_1.conf"));
30 : 2 : ASSERT(SUCCESS == replace_placeholder_in_file("$TMPDIR/0018_001_1.conf","%ROOT_PATH%","$TMPDIR/tests/fixtures/levels"));
31 : 2 : const struct argument_test_case file_cases[] = {
32 : : {"--config=0018_001_1.conf",COMPLETED,"templates/0018_001_1.txt",STDERR_MUST_BE_EMPTY},
33 : : {0}
34 : : };
35 : 2 : ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
36 : 2 : call(delete_path_if_present("0018_001_1.conf"));
37 : :
38 : 2 : const struct argument_test_case unlimited_cases[] = {
39 : : /* File system traversal with unlimited depth */
40 : : {"--database=database4.db "
41 : : "$TMPDIR/tests/fixtures/levels",COMPLETED,"templates/0018_001_2.txt",STDERR_MUST_BE_EMPTY},
42 : : {0}
43 : : };
44 : :
45 : 2 : ASSERT(SUCCESS == run_and_match_templates(unlimited_cases,NULL,NULL));
46 : :
47 : : /* Repeat the unlimited traversal, starting without its database */
48 : 2 : ASSERT(SUCCESS == delete_path("database4.db"));
49 : 2 : ASSERT(SUCCESS == copy_from_origin("tests/templates/0018_001_2.conf","0018_001_2.conf",REQUIRE_SOURCE_EXISTS));
50 : 2 : ASSERT(SUCCESS == replace_placeholder_in_file("$TMPDIR/0018_001_2.conf","%ROOT_PATH%","$TMPDIR/tests/fixtures/levels"));
51 : 2 : const struct argument_test_case unlimited_file_cases[] = {
52 : : {"--config=0018_001_2.conf",COMPLETED,"templates/0018_001_2.txt",STDERR_MUST_BE_EMPTY},
53 : : {0}
54 : : };
55 : 2 : ASSERT(SUCCESS == run_and_match_templates(unlimited_file_cases,NULL,NULL));
56 : :
57 : 2 : call(delete_path_if_present("0018_001_2.conf"));
58 : :
59 : : // Clean up test results
60 : 2 : ASSERT(SUCCESS == delete_path("database4.db"));
61 : :
62 : 2 : RETURN_STATUS;
63 : : }
64 : :
65 : : /**
66 : : * @brief Verify update output after rerunning the maxdepth fixture without the depth limit
67 : : *
68 : : * @return Return status code
69 : : */
70 : 2 : Return test0018_2(void)
71 : : {
72 : 2 : INITTEST;
73 : :
74 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
75 : :
76 : : /* File system traversal with unlimited depth */
77 : 2 : const struct argument_test_case cases[] = {
78 : : {"--update --check-level=QUICK --database=database3.db "
79 : : "$TMPDIR/tests/fixtures/levels",COMPLETED,"templates/0018_002.txt",STDERR_MUST_BE_EMPTY},
80 : : {0}
81 : : };
82 : :
83 : : // Match the result against the pattern
84 : 2 : ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
85 : :
86 : : // Clean up test results
87 : 2 : ASSERT(SUCCESS == delete_path("database3.db"));
88 : :
89 : 2 : RETURN_STATUS;
90 : : }
91 : :
92 : : /**
93 : : * @brief Verify template diff generation through compare_memory_strings
94 : : *
95 : : * This test loads the two saved outputs produced by the depth-limited and
96 : : * unlimited traversal scenarios into string-mode memory descriptors. It then
97 : : * compares those descriptors through compare_memory_strings() and stores the
98 : : * resulting unified diff directly in another string-mode descriptor
99 : : *
100 : : * The test verifies that compare_memory_strings():
101 : : * - accepts file content loaded into string-mode memory descriptors
102 : : * - writes the produced unified diff directly into a destination descriptor
103 : : * - produces the exact diff text expected by template `0018_003`
104 : : *
105 : : * @return Return status code
106 : : */
107 : 2 : Return test0018_3(void)
108 : : {
109 : 2 : INITTEST;
110 : :
111 : 2 : m_create(char,text1,MEMORY_STRING);
112 : 2 : m_create(char,text2,MEMORY_STRING);
113 : 2 : m_create(char,pattern,MEMORY_STRING);
114 : 2 : m_create(char,diff_buffer,MEMORY_STRING);
115 : :
116 : : /* 0018 001 */
117 : 2 : ASSERT(SUCCESS == get_file_content("templates/0018_001_1.txt",text1));
118 : :
119 : 2 : ASSERT(SUCCESS == get_file_content("templates/0018_001_2.txt",text2));
120 : :
121 : 2 : ASSERT(SUCCESS == compare_memory_strings(diff_buffer,text1,text2));
122 : :
123 : 2 : const char *filename = "templates/0018_003.txt";
124 : :
125 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
126 : 2 : ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
127 : :
128 : 2 : m_del(text1);
129 : 2 : m_del(text2);
130 : 2 : m_del(pattern);
131 : 2 : m_del(diff_buffer);
132 : :
133 : 2 : RETURN_STATUS;
134 : : }
135 : :
136 : : /**
137 : : * @brief Verify updated traversal diff generation through compare_memory_strings
138 : : *
139 : : * This test loads the original depth-limited traversal output together with the
140 : : * later `--update` output into string-mode memory descriptors. It compares them
141 : : * through compare_memory_strings() and checks the produced unified diff against
142 : : * the expected template `0018_004`
143 : : *
144 : : * The test verifies that compare_memory_strings():
145 : : * - accepts saved traversal outputs as string-mode memory descriptors
146 : : * - stores the unified diff directly in the destination descriptor
147 : : * - produces the exact diff text expected for the update scenario
148 : : *
149 : : * @return Return status code
150 : : */
151 : 2 : Return test0018_4(void)
152 : : {
153 : 2 : INITTEST;
154 : :
155 : 2 : m_create(char,text1,MEMORY_STRING);
156 : 2 : m_create(char,text2,MEMORY_STRING);
157 : 2 : m_create(char,pattern,MEMORY_STRING);
158 : 2 : m_create(char,diff_buffer,MEMORY_STRING);
159 : :
160 : : /* 0018 001 */
161 : 2 : ASSERT(SUCCESS == get_file_content("templates/0018_001_1.txt",text1));
162 : :
163 : 2 : ASSERT(SUCCESS == get_file_content("templates/0018_002.txt",text2));
164 : :
165 : 2 : ASSERT(SUCCESS == compare_memory_strings(diff_buffer,text1,text2));
166 : :
167 : 2 : const char *filename = "templates/0018_004.txt";
168 : :
169 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
170 : 2 : ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
171 : :
172 : 2 : m_del(text1);
173 : 2 : m_del(text2);
174 : 2 : m_del(pattern);
175 : 2 : m_del(diff_buffer);
176 : :
177 : 2 : RETURN_STATUS;
178 : : }
179 : :
180 : : /**
181 : : * @brief Reject an empty maxdepth value through CLI and configuration
182 : : *
183 : : * `--maxdepth=` does not contain a number and must fail argument parsing instead
184 : : * of silently selecting depth zero. An empty configuration value must also
185 : : * fail and report its line number
186 : : *
187 : : * @return Return status code
188 : : */
189 : 2 : static Return test0018_5(void)
190 : : {
191 : 2 : INITTEST;
192 : :
193 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
194 : :
195 : 2 : const struct argument_test_case cases[] = {
196 : : {"--maxdepth= tests/fixtures/diffs/diff1",FAILURE,"templates/0018_005_1.txt","templates/0018_005_2.txt"},
197 : : {0}
198 : : };
199 : :
200 : 2 : ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
201 : :
202 : 2 : ASSERT(SUCCESS == copy_path("tests/templates/0018_005.conf","0018_005.conf"));
203 : 2 : const struct argument_test_case file_cases[] = {
204 : : {"--config=0018_005.conf",FAILURE,"templates/0018_005_3.txt","templates/0018_005_4.txt"},
205 : : {0}
206 : : };
207 : 2 : ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
208 : 2 : call(delete_path_if_present("0018_005.conf"));
209 : :
210 : 2 : RETURN_STATUS;
211 : : }
212 : :
213 : : /**
214 : : * @brief Check traversal depth and explicit database paths
215 : : * @return Return status for traversal, output comparisons, and database filenames
216 : : */
217 : 2 : Return test0018(void)
218 : : {
219 : 2 : INITTEST;
220 : :
221 : 2 : TEST(test0018_1,"Traversal with limited depth");
222 : 2 : TEST(test0018_2,"Update DB w/o depth limits");
223 : 2 : TEST(test0018_3,"Comparing templates w/ and w/o depth limits")
224 : 2 : TEST(test0018_4,"Comparing templates after update w/o depth limits")
225 : 2 : TEST(test0018_5,"Empty --maxdepth value should fail argument parsing")
226 : :
227 : 2 : RETURN_STATUS;
228 : : }
|