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