Line data Source code
1 : #include "sute.h"
2 :
3 : /**
4 : * One file is removed, updated, and added at a time
5 : */
6 2 : static Return test0028_1_test(void)
7 : {
8 2 : INITTEST;
9 :
10 : // Create memory for the result
11 2 : create(char,result);
12 2 : create(char,pattern);
13 :
14 2 : const char *command = "cd ${TMPDIR};"
15 : "mv tests/examples/ tests/examples_backup/;"
16 : "cp -a tests/examples_backup/ tests/examples/;";
17 :
18 : // Preparation for tests
19 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
20 :
21 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
22 :
23 2 : const char *arguments = "--silent --database=database1.db tests/examples/diffs/diff1";
24 :
25 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
26 :
27 2 : if(result->length > 0)
28 : {
29 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
30 0 : status = FAILURE;
31 : #if 0
32 : echo(STDOUT,"%s\n",getcstring(result));
33 : #endif
34 : }
35 :
36 2 : command = "cd ${TMPDIR};"
37 : "rm tests/examples/diffs/diff1/2/AAA/BBB/CZC/a.txt;" // Remove
38 : "echo -n AFAKDSJ >> tests/examples/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;" // Modify
39 : "echo -n WNEURHGO > tests/examples/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
40 :
41 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
42 :
43 2 : arguments = "--silent --database=database2.db tests/examples/diffs/diff1";
44 :
45 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
46 :
47 2 : if(result->length > 0)
48 : {
49 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
50 0 : status = FAILURE;
51 : #if 0
52 : echo(STDOUT,"%s\n",getcstring(result));
53 : #endif
54 : }
55 :
56 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
57 :
58 2 : arguments = "--compare database1.db database2.db";
59 :
60 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
61 :
62 2 : const char *filename = "templates/0028_001.txt";
63 :
64 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
65 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
66 :
67 2 : del(pattern);
68 2 : del(result);
69 :
70 : // Clean up test results
71 2 : ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
72 : "rm database1.db database2.db && "
73 : "rm -rf tests/examples/ && "
74 : "mv tests/examples_backup/ tests/examples/",COMPLETED,ALLOW_BOTH));
75 :
76 2 : RETURN_STATUS;
77 : }
78 :
79 : /**
80 : * One file is removed. It should be reflected as a change in one of the databases.
81 : */
82 2 : static Return test0028_2_test(void)
83 : {
84 2 : INITTEST;
85 :
86 : // Create memory for the result
87 2 : create(char,result);
88 2 : create(char,pattern);
89 :
90 2 : const char *command = "cd ${TMPDIR};"
91 : "mv tests/examples/ tests/examples_backup/;"
92 : "cp -a tests/examples_backup/ tests/examples/;";
93 :
94 : // Preparation for tests
95 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
96 :
97 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
98 :
99 2 : const char *arguments = "--silent --database=database1.db tests/examples/diffs/diff1";
100 :
101 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
102 :
103 2 : if(result->length > 0)
104 : {
105 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
106 0 : status = FAILURE;
107 : #if 0
108 : echo(STDOUT,"%s\n",getcstring(result));
109 : #endif
110 : }
111 :
112 2 : command = "cd ${TMPDIR};"
113 : "rm tests/examples/diffs/diff1/2/AAA/BBB/CZC/a.txt;"; // Remove
114 :
115 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
116 :
117 2 : arguments = "--silent --database=database2.db tests/examples/diffs/diff1";
118 :
119 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
120 :
121 2 : if(result->length > 0)
122 : {
123 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
124 0 : status = FAILURE;
125 : #if 0
126 : echo(STDOUT,"%s\n",getcstring(result));
127 : #endif
128 : }
129 :
130 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
131 :
132 2 : arguments = "--compare database1.db database2.db";
133 :
134 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
135 :
136 2 : const char *filename = "templates/0028_002.txt";
137 :
138 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
139 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
140 :
141 2 : del(pattern);
142 2 : del(result);
143 :
144 : // Clean up test results
145 2 : ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
146 : "rm database1.db database2.db && "
147 : "rm -rf tests/examples/ && "
148 : "mv tests/examples_backup/ tests/examples/",COMPLETED,ALLOW_BOTH));
149 :
150 2 : RETURN_STATUS;
151 : }
152 :
153 : /**
154 : * One file is added. It should be reflected as a change in one of the databases.
155 : */
156 2 : static Return test0028_3_test(void)
157 : {
158 2 : INITTEST;
159 :
160 : // Create memory for the result
161 2 : create(char,result);
162 2 : create(char,pattern);
163 :
164 2 : const char *command = "cd ${TMPDIR};"
165 : "mv tests/examples/ tests/examples_backup/;"
166 : "cp -a tests/examples_backup/ tests/examples/;";
167 :
168 : // Preparation for tests
169 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
170 :
171 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
172 :
173 2 : const char *arguments = "--silent --database=database1.db tests/examples/diffs/diff1";
174 :
175 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
176 :
177 2 : if(result->length > 0)
178 : {
179 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
180 0 : status = FAILURE;
181 : #if 0
182 : echo(STDOUT,"%s\n",getcstring(result));
183 : #endif
184 : }
185 :
186 2 : command = "cd ${TMPDIR};"
187 : "echo -n WNEURHGO > tests/examples/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
188 :
189 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
190 :
191 2 : arguments = "--silent --database=database2.db tests/examples/diffs/diff1";
192 :
193 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
194 :
195 2 : if(result->length > 0)
196 : {
197 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
198 0 : status = FAILURE;
199 : #if 0
200 : echo(STDOUT,"%s\n",getcstring(result));
201 : #endif
202 : }
203 :
204 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
205 :
206 2 : arguments = "--compare database1.db database2.db";
207 :
208 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
209 :
210 2 : const char *filename = "templates/0028_003.txt";
211 :
212 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
213 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
214 :
215 2 : del(pattern);
216 2 : del(result);
217 :
218 : // Clean up test results
219 2 : ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
220 : "rm database1.db database2.db && "
221 : "rm -rf tests/examples/ && "
222 : "mv tests/examples_backup/ tests/examples/",COMPLETED,ALLOW_BOTH));
223 :
224 2 : RETURN_STATUS;
225 : }
226 :
227 : /**
228 : * One file is updated and its checksum should change
229 : */
230 2 : static Return test0028_4_test(void)
231 : {
232 2 : INITTEST;
233 :
234 : // Create memory for the result
235 2 : create(char,result);
236 2 : create(char,pattern);
237 :
238 2 : const char *command = "cd ${TMPDIR};"
239 : "mv tests/examples/ tests/examples_backup/;"
240 : "cp -a tests/examples_backup/ tests/examples/;";
241 :
242 : // Preparation for tests
243 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
244 :
245 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
246 :
247 2 : const char *arguments = "--silent --database=database1.db tests/examples/diffs/diff1";
248 :
249 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
250 :
251 2 : if(result->length > 0)
252 : {
253 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
254 0 : status = FAILURE;
255 : #if 0
256 : echo(STDOUT,"%s\n",getcstring(result));
257 : #endif
258 : }
259 :
260 2 : command = "cd ${TMPDIR};"
261 : "echo -n AFAKDSJ >> tests/examples/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;"; // Modify
262 :
263 2 : ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
264 :
265 2 : arguments = "--silent --database=database2.db tests/examples/diffs/diff1";
266 :
267 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
268 :
269 2 : if(result->length > 0)
270 : {
271 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
272 0 : status = FAILURE;
273 : #if 0
274 : echo(STDOUT,"%s\n",getcstring(result));
275 : #endif
276 : }
277 :
278 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
279 :
280 2 : arguments = "--compare database1.db database2.db";
281 :
282 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
283 :
284 2 : const char *filename = "templates/0028_004.txt";
285 :
286 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
287 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
288 :
289 2 : del(pattern);
290 2 : del(result);
291 :
292 : // Clean up test results
293 2 : ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
294 : "rm database1.db database2.db && "
295 : "rm -rf tests/examples/ && "
296 : "mv tests/examples_backup/ tests/examples/",COMPLETED,ALLOW_BOTH));
297 :
298 2 : RETURN_STATUS;
299 : }
300 :
301 : /**
302 : * Nothing changes. The databases should be equivalent
303 : */
304 2 : static Return test0028_5_test(void)
305 : {
306 2 : INITTEST;
307 :
308 : // Create memory for the result
309 2 : create(char,result);
310 2 : create(char,pattern);
311 :
312 2 : const char *arguments = "--database=database1.db tests/examples/diffs/diff1";
313 :
314 2 : ASSERT(SUCCESS == runit(arguments,NULL,COMPLETED,ALLOW_BOTH));
315 :
316 2 : arguments = "--database=database2.db tests/examples/diffs/diff1";
317 :
318 2 : ASSERT(SUCCESS == runit(arguments,NULL,COMPLETED,ALLOW_BOTH));
319 :
320 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
321 :
322 2 : arguments = "--compare database1.db database2.db";
323 :
324 2 : ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
325 :
326 2 : const char *filename = "templates/0028_005.txt";
327 :
328 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
329 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
330 :
331 2 : del(pattern);
332 2 : del(result);
333 :
334 : // Clean up test results
335 2 : ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
336 : "rm database1.db database2.db;",COMPLETED,ALLOW_BOTH));
337 :
338 2 : RETURN_STATUS;
339 : }
340 :
341 : /**
342 : *
343 : * Testing the --compare mode across different types of responses
344 : *
345 : */
346 2 : Return test0028(void)
347 : {
348 2 : INITTEST;
349 :
350 2 : TEST(test0028_1_test,"One file is removed, updated, and added at a time…");
351 2 : TEST(test0028_2_test,"One file is removed. It should be reflected as a change in one of the databases…");
352 2 : TEST(test0028_3_test,"One file is added. It should be reflected as a change in one of the databases…");
353 2 : TEST(test0028_4_test,"One file is updated and its checksum should change…");
354 2 : TEST(test0028_5_test,"Nothing changes. The databases should be equivalent…");
355 :
356 2 : RETURN_STATUS;
357 : }
|