Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /**
4 : : * Runs precizer with the given arguments and validates output with optional
5 : : * stdout/stderr regex templates.
6 : : */
7 : 52 : static Return assert_compare_output(
8 : : const char *arguments,
9 : : const int expected_return_code,
10 : : const char *stdout_pattern_file,
11 : : const char *stderr_pattern_file)
12 : : {
13 : 52 : INITTEST;
14 : :
15 : 52 : create(char,stdout_result);
16 : 52 : create(char,stderr_result);
17 : 52 : create(char,stdout_pattern);
18 : 52 : create(char,stderr_pattern);
19 : :
20 [ + - + - ]: 52 : ASSERT(arguments != NULL);
21 : :
22 : 52 : unsigned int capture_policy = ALLOW_BOTH;
23 : :
24 [ + + - + ]: 52 : if(expected_return_code != COMPLETED || stderr_pattern_file != NULL)
25 : : {
26 : 20 : capture_policy = STDERR_ALLOW;
27 : : }
28 : :
29 [ + - + - ]: 52 : ASSERT(SUCCESS == runit(arguments,stdout_result,stderr_result,expected_return_code,capture_policy));
30 : :
31 [ + + ]: 52 : if(stdout_pattern_file != NULL)
32 : : {
33 [ + - + - ]: 46 : ASSERT(SUCCESS == get_file_content(stdout_pattern_file,stdout_pattern));
34 [ + - + - ]: 46 : ASSERT(SUCCESS == match_pattern(stdout_result,stdout_pattern,stdout_pattern_file));
35 : : }
36 : :
37 [ + + ]: 52 : if(stderr_pattern_file != NULL)
38 : : {
39 [ + - + - ]: 20 : ASSERT(SUCCESS == get_file_content(stderr_pattern_file,stderr_pattern));
40 [ + - + - ]: 20 : ASSERT(SUCCESS == match_pattern(stderr_result,stderr_pattern,stderr_pattern_file));
41 : : }
42 : :
43 : 52 : del(stderr_pattern);
44 : 52 : del(stdout_pattern);
45 : 52 : del(stderr_result);
46 : 52 : del(stdout_result);
47 : :
48 [ - + - - : 52 : deliver(status);
- + + - ]
49 : : }
50 : :
51 : : /**
52 : : * Prepares two databases with known differences for compare-filter tests.
53 : : */
54 : 2 : static Return prepare_compare_filter_differences_fixture(void)
55 : : {
56 : 2 : INITTEST;
57 : :
58 : 2 : create(char,result);
59 : :
60 : 2 : const char *command = "cd ${TMPDIR};"
61 : : "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
62 : : "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
63 : :
64 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
65 : :
66 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
67 : :
68 : 2 : const char *arguments = "--silent --database=database1.db tests/fixtures/diffs/diff1";
69 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
70 : :
71 [ - + ]: 2 : if(result->length > 0)
72 : : {
73 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
74 : 0 : status = FAILURE;
75 : : }
76 : :
77 : 2 : command = "cd ${TMPDIR};"
78 : : "rm tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/a.txt;"
79 : : "echo -n AFAKDSJ >> tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;"
80 : : "echo -n WNEURHGO > tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/b.txt;";
81 : :
82 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
83 : :
84 : 2 : arguments = "--silent --database=database2.db tests/fixtures/diffs/diff1";
85 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
86 : :
87 [ - + ]: 2 : if(result->length > 0)
88 : : {
89 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
90 : 0 : status = FAILURE;
91 : : }
92 : :
93 : 2 : del(result);
94 : :
95 [ - + - - : 2 : deliver(status);
- + + - ]
96 : : }
97 : :
98 : : /**
99 : : * Cleans temporary files created by the "differences" fixture.
100 : : */
101 : 2 : static Return cleanup_compare_filter_differences_fixture(void)
102 : : {
103 : 2 : INITTEST;
104 : :
105 : 2 : const char *command = "cd ${TMPDIR} && "
106 : : "rm database1.db database2.db && "
107 : : "rm -rf tests/fixtures/diffs/diff1 && "
108 : : "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
109 : :
110 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
111 : :
112 [ - + - - : 2 : deliver(status);
- + + - ]
113 : : }
114 : :
115 : : /**
116 : : * Prepares two equal databases for compare-filter tests.
117 : : */
118 : 2 : static Return prepare_compare_filter_equal_fixture(void)
119 : : {
120 : 2 : INITTEST;
121 : :
122 : 2 : create(char,result);
123 : :
124 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
125 : :
126 : 2 : const char *arguments = "--silent --database=database1.db tests/fixtures/diffs/diff1";
127 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
128 : :
129 [ - + ]: 2 : if(result->length > 0)
130 : : {
131 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
132 : 0 : status = FAILURE;
133 : : }
134 : :
135 : 2 : arguments = "--silent --database=database2.db tests/fixtures/diffs/diff1";
136 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
137 : :
138 [ - + ]: 2 : if(result->length > 0)
139 : : {
140 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
141 : 0 : status = FAILURE;
142 : : }
143 : :
144 : 2 : del(result);
145 : :
146 [ - + - - : 2 : deliver(status);
- + + - ]
147 : : }
148 : :
149 : : /**
150 : : * Cleans temporary files created by the "equal" fixture.
151 : : */
152 : 2 : static Return cleanup_compare_filter_equal_fixture(void)
153 : : {
154 : 2 : INITTEST;
155 : :
156 : 2 : const char *command = "cd ${TMPDIR} && "
157 : : "rm database1.db database2.db;";
158 : :
159 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
160 : :
161 [ - + - - : 2 : deliver(status);
- + + - ]
162 : : }
163 : :
164 : : /**
165 : : * One file is removed, updated, and added at a time
166 : : */
167 : 2 : static Return test0028_1(void)
168 : : {
169 : 2 : INITTEST;
170 : :
171 : : // Create memory for the result
172 : 2 : create(char,result);
173 : 2 : create(char,pattern);
174 : :
175 : 2 : const char *command = "cd ${TMPDIR};"
176 : : "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
177 : : "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
178 : :
179 : : // Preparation for tests
180 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
181 : :
182 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
183 : :
184 : 2 : const char *arguments = "--silent --database=database1.db tests/fixtures/diffs/diff1";
185 : :
186 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
187 : :
188 [ - + ]: 2 : if(result->length > 0)
189 : : {
190 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
191 : 0 : status = FAILURE;
192 : : #if 0
193 : : echo(STDOUT,"%s\n",getcstring(result));
194 : : #endif
195 : : }
196 : :
197 : 2 : command = "cd ${TMPDIR};"
198 : : "rm tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/a.txt;" // Remove
199 : : "echo -n AFAKDSJ >> tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;" // Modify
200 : : "echo -n WNEURHGO > tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
201 : :
202 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
203 : :
204 : 2 : arguments = "--silent --database=database2.db tests/fixtures/diffs/diff1";
205 : :
206 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
207 : :
208 [ - + ]: 2 : if(result->length > 0)
209 : : {
210 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
211 : 0 : status = FAILURE;
212 : : #if 0
213 : : echo(STDOUT,"%s\n",getcstring(result));
214 : : #endif
215 : : }
216 : :
217 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
218 : :
219 : 2 : arguments = "--compare database1.db database2.db";
220 : :
221 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
222 : :
223 : 2 : const char *filename = "templates/0028_001.txt";
224 : :
225 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
226 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
227 : :
228 : 2 : del(pattern);
229 : 2 : del(result);
230 : :
231 : : // Clean up test results
232 : 2 : command = "cd ${TMPDIR} && "
233 : : "rm database1.db database2.db && "
234 : : "rm -rf tests/fixtures/diffs/diff1 && "
235 : : "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
236 : :
237 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
238 : :
239 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
240 : : }
241 : :
242 : : /**
243 : : * One file is removed. It should be reflected as a change in one of the databases.
244 : : */
245 : 2 : static Return test0028_2(void)
246 : : {
247 : 2 : INITTEST;
248 : :
249 : : // Create memory for the result
250 : 2 : create(char,result);
251 : 2 : create(char,pattern);
252 : :
253 : 2 : const char *command = "cd ${TMPDIR};"
254 : : "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
255 : : "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
256 : :
257 : : // Preparation for tests
258 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
259 : :
260 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
261 : :
262 : 2 : const char *arguments = "--silent --database=database1.db tests/fixtures/diffs/diff1";
263 : :
264 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
265 : :
266 [ - + ]: 2 : if(result->length > 0)
267 : : {
268 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
269 : 0 : status = FAILURE;
270 : : #if 0
271 : : echo(STDOUT,"%s\n",getcstring(result));
272 : : #endif
273 : : }
274 : :
275 : 2 : command = "cd ${TMPDIR};"
276 : : "rm tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/a.txt;"; // Remove
277 : :
278 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
279 : :
280 : 2 : arguments = "--silent --database=database2.db tests/fixtures/diffs/diff1";
281 : :
282 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
283 : :
284 [ - + ]: 2 : if(result->length > 0)
285 : : {
286 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
287 : 0 : status = FAILURE;
288 : : #if 0
289 : : echo(STDOUT,"%s\n",getcstring(result));
290 : : #endif
291 : : }
292 : :
293 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
294 : :
295 : 2 : arguments = "--compare database1.db database2.db";
296 : :
297 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
298 : :
299 : 2 : const char *filename = "templates/0028_002.txt";
300 : :
301 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
302 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
303 : :
304 : 2 : del(pattern);
305 : 2 : del(result);
306 : :
307 : : // Clean up test results
308 : 2 : command = "cd ${TMPDIR} && "
309 : : "rm database1.db database2.db && "
310 : : "rm -rf tests/fixtures/diffs/diff1 && "
311 : : "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
312 : :
313 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
314 : :
315 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
316 : : }
317 : :
318 : : /**
319 : : * One file is added. It should be reflected as a change in one of the databases.
320 : : */
321 : 2 : static Return test0028_3(void)
322 : : {
323 : 2 : INITTEST;
324 : :
325 : : // Create memory for the result
326 : 2 : create(char,result);
327 : 2 : create(char,pattern);
328 : :
329 : 2 : const char *command = "cd ${TMPDIR};"
330 : : "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
331 : : "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
332 : :
333 : : // Preparation for tests
334 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
335 : :
336 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
337 : :
338 : 2 : const char *arguments = "--silent --database=database1.db tests/fixtures/diffs/diff1";
339 : :
340 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
341 : :
342 [ - + ]: 2 : if(result->length > 0)
343 : : {
344 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
345 : 0 : status = FAILURE;
346 : : #if 0
347 : : echo(STDOUT,"%s\n",getcstring(result));
348 : : #endif
349 : : }
350 : :
351 : 2 : command = "cd ${TMPDIR};"
352 : : "echo -n WNEURHGO > tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
353 : :
354 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
355 : :
356 : 2 : arguments = "--silent --database=database2.db tests/fixtures/diffs/diff1";
357 : :
358 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
359 : :
360 [ - + ]: 2 : if(result->length > 0)
361 : : {
362 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
363 : 0 : status = FAILURE;
364 : : #if 0
365 : : echo(STDOUT,"%s\n",getcstring(result));
366 : : #endif
367 : : }
368 : :
369 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
370 : :
371 : 2 : arguments = "--compare database1.db database2.db";
372 : :
373 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
374 : :
375 : 2 : const char *filename = "templates/0028_003.txt";
376 : :
377 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
378 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
379 : :
380 : 2 : del(pattern);
381 : 2 : del(result);
382 : :
383 : : // Clean up test results
384 : 2 : command = "cd ${TMPDIR} && "
385 : : "rm database1.db database2.db && "
386 : : "rm -rf tests/fixtures/diffs/diff1 && "
387 : : "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
388 : :
389 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
390 : :
391 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
392 : : }
393 : :
394 : : /**
395 : : * One file is updated and its checksum should change
396 : : */
397 : 2 : static Return test0028_4(void)
398 : : {
399 : 2 : INITTEST;
400 : :
401 : : // Create memory for the result
402 : 2 : create(char,result);
403 : 2 : create(char,pattern);
404 : :
405 : 2 : const char *command = "cd ${TMPDIR};"
406 : : "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
407 : : "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
408 : :
409 : : // Preparation for tests
410 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
411 : :
412 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
413 : :
414 : 2 : const char *arguments = "--silent --database=database1.db tests/fixtures/diffs/diff1";
415 : :
416 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
417 : :
418 [ - + ]: 2 : if(result->length > 0)
419 : : {
420 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
421 : 0 : status = FAILURE;
422 : : #if 0
423 : : echo(STDOUT,"%s\n",getcstring(result));
424 : : #endif
425 : : }
426 : :
427 : 2 : command = "cd ${TMPDIR};"
428 : : "echo -n AFAKDSJ >> tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;"; // Modify
429 : :
430 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
431 : :
432 : 2 : arguments = "--silent --database=database2.db tests/fixtures/diffs/diff1";
433 : :
434 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
435 : :
436 [ - + ]: 2 : if(result->length > 0)
437 : : {
438 : 0 : echo(STDERR,"STDOUT buffer is not empty. It contains characters: %zu\n",result->length);
439 : 0 : status = FAILURE;
440 : : #if 0
441 : : echo(STDOUT,"%s\n",getcstring(result));
442 : : #endif
443 : : }
444 : :
445 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
446 : :
447 : 2 : arguments = "--compare database1.db database2.db";
448 : :
449 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
450 : :
451 : 2 : const char *filename = "templates/0028_004.txt";
452 : :
453 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
454 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
455 : :
456 : 2 : del(pattern);
457 : 2 : del(result);
458 : :
459 : : // Clean up test results
460 : 2 : command = "cd ${TMPDIR} && "
461 : : "rm database1.db database2.db && "
462 : : "rm -rf tests/fixtures/diffs/diff1 && "
463 : : "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
464 : :
465 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
466 : :
467 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
468 : : }
469 : :
470 : : /**
471 : : * Nothing changes. The databases should be equivalent
472 : : */
473 : 2 : static Return test0028_5(void)
474 : : {
475 : 2 : INITTEST;
476 : :
477 : : // Create memory for the result
478 : 2 : create(char,result);
479 : 2 : create(char,pattern);
480 : :
481 : 2 : const char *arguments = "--database=database1.db tests/fixtures/diffs/diff1";
482 : :
483 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
484 : :
485 : 2 : arguments = "--database=database2.db tests/fixtures/diffs/diff1";
486 : :
487 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
488 : :
489 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
490 : :
491 : 2 : arguments = "--compare database1.db database2.db";
492 : :
493 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
494 : :
495 : 2 : const char *filename = "templates/0028_005.txt";
496 : :
497 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
498 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
499 : :
500 : 2 : del(pattern);
501 : 2 : del(result);
502 : :
503 : : // Clean up test results
504 : 2 : const char *command = "cd ${TMPDIR} && "
505 : : "rm database1.db database2.db;";
506 : :
507 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
508 : :
509 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
510 : : }
511 : :
512 : : /**
513 : : * Compare-filter combinations in compare mode and argument validation.
514 : : */
515 : 2 : static Return test0028_6(void)
516 : : {
517 : 2 : INITTEST;
518 : :
519 : : struct compare_filter_case {
520 : : const char *arguments;
521 : : int expected_return_code;
522 : : const char *stdout_pattern_file;
523 : : const char *stderr_pattern_file;
524 : : };
525 : :
526 : 2 : const struct compare_filter_case equal_cases[] = {
527 : : // Valid combinations with --compare for equal databases
528 : : {"--compare database1.db database2.db",COMPLETED,"templates/0028_005.txt",NULL},
529 : : {"--compare --compare-filter=checksum-mismatch database1.db database2.db",COMPLETED,"templates/0028_014.txt",NULL},
530 : : {"--compare --compare-filter=first-source-only database1.db database2.db",COMPLETED,"templates/0028_015.txt",NULL},
531 : : {"--compare --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_015.txt",NULL},
532 : : {"--compare --compare-filter=first-source-only --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_015.txt",NULL},
533 : : {"--compare --compare-filter=checksum-mismatch --compare-filter=first-source-only database1.db database2.db",COMPLETED,"templates/0028_016.txt",NULL},
534 : : {"--compare --compare-filter=checksum-mismatch --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_016.txt",NULL},
535 : : {"--compare --compare-filter=checksum-mismatch --compare-filter=first-source-only --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_005.txt",NULL}
536 : : };
537 : :
538 : 2 : const struct compare_filter_case differences_cases[] = {
539 : : // Valid combinations with --compare for databases with all difference categories
540 : : {"--compare database1.db database2.db",COMPLETED,"templates/0028_001.txt",NULL},
541 : : {"--compare --compare-filter=checksum-mismatch database1.db database2.db",COMPLETED,"templates/0028_004.txt",NULL},
542 : : {"--compare --compare-filter=first-source-only database1.db database2.db",COMPLETED,"templates/0028_008.txt",NULL},
543 : : {"--compare --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_009.txt",NULL},
544 : : {"--compare --compare-filter=checksum-mismatch --compare-filter=first-source-only database1.db database2.db",COMPLETED,"templates/0028_010.txt",NULL},
545 : : {"--compare --compare-filter=checksum-mismatch --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_011.txt",NULL},
546 : : {"--compare --compare-filter=first-source-only --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_006.txt",NULL},
547 : : {"--compare --compare-filter=checksum-mismatch --compare-filter=first-source-only --compare-filter=second-source-only database1.db database2.db",COMPLETED,"templates/0028_001.txt",NULL}
548 : : };
549 : :
550 : 2 : const struct compare_filter_case invalid_cases[] = {
551 : : // Invalid combinations: --compare-filter=value without --compare
552 : : {"--compare-filter=checksum-mismatch database1.db database2.db",FAILURE,"templates/0028_012_1.txt","templates/0028_012_2.txt"},
553 : : {"--compare-filter=first-source-only database1.db database2.db",FAILURE,"templates/0028_012_1.txt","templates/0028_012_2.txt"},
554 : : {"--compare-filter=second-source-only database1.db database2.db",FAILURE,"templates/0028_012_1.txt","templates/0028_012_2.txt"},
555 : : {"--compare-filter=checksum-mismatch --compare-filter=first-source-only database1.db database2.db",FAILURE,"templates/0028_012_1.txt","templates/0028_012_2.txt"},
556 : : {"--compare-filter=checksum-mismatch --compare-filter=second-source-only database1.db database2.db",FAILURE,"templates/0028_012_1.txt","templates/0028_012_2.txt"},
557 : : {"--compare-filter=first-source-only --compare-filter=second-source-only database1.db database2.db",FAILURE,"templates/0028_012_1.txt","templates/0028_012_2.txt"},
558 : : {"--compare-filter=checksum-mismatch --compare-filter=first-source-only --compare-filter=second-source-only database1.db database2.db",FAILURE,"templates/0028_012_1.txt","templates/0028_012_2.txt"},
559 : :
560 : : // Invalid combinations: --compare-filter without argument
561 : : {"--compare database1.db database2.db --compare-filter",FAILURE,NULL,"templates/0028_013.txt"},
562 : : {"--compare-filter",FAILURE,NULL,"templates/0028_013.txt"}
563 : : };
564 : :
565 [ + - + - ]: 2 : ASSERT(SUCCESS == prepare_compare_filter_equal_fixture());
566 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
567 : :
568 [ + + + - ]: 18 : for(size_t i = 0; (i < sizeof(equal_cases) / sizeof(equal_cases[0])) && (SUCCESS == status); i++)
569 : : {
570 [ + - + - ]: 16 : ASSERT(SUCCESS == assert_compare_output(
571 : : equal_cases[i].arguments,
572 : : equal_cases[i].expected_return_code,
573 : : equal_cases[i].stdout_pattern_file,
574 : : equal_cases[i].stderr_pattern_file));
575 : : }
576 : :
577 [ + - + - ]: 2 : ASSERT(SUCCESS == cleanup_compare_filter_equal_fixture());
578 : :
579 [ + - + - ]: 2 : ASSERT(SUCCESS == prepare_compare_filter_differences_fixture());
580 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
581 : :
582 [ + + + - ]: 18 : for(size_t i = 0; (i < sizeof(differences_cases) / sizeof(differences_cases[0])) && (SUCCESS == status); i++)
583 : : {
584 [ + - + - ]: 16 : ASSERT(SUCCESS == assert_compare_output(
585 : : differences_cases[i].arguments,
586 : : differences_cases[i].expected_return_code,
587 : : differences_cases[i].stdout_pattern_file,
588 : : differences_cases[i].stderr_pattern_file));
589 : : }
590 : :
591 [ + - + - ]: 2 : ASSERT(SUCCESS == cleanup_compare_filter_differences_fixture());
592 : :
593 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
594 : :
595 [ + + + - ]: 20 : for(size_t i = 0; (i < sizeof(invalid_cases) / sizeof(invalid_cases[0])) && (SUCCESS == status); i++)
596 : : {
597 [ + - + - ]: 18 : ASSERT(SUCCESS == assert_compare_output(
598 : : invalid_cases[i].arguments,
599 : : invalid_cases[i].expected_return_code,
600 : : invalid_cases[i].stdout_pattern_file,
601 : : invalid_cases[i].stderr_pattern_file));
602 : : }
603 : :
604 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
605 : : }
606 : :
607 : : /**
608 : : * Invalid --compare-filter value should fail argument parsing
609 : : */
610 : 2 : static Return test0028_7(void)
611 : : {
612 : 2 : INITTEST;
613 : :
614 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
615 : :
616 : 2 : const char *arguments = "--compare --compare-filter=invalid-value database1.db database2.db";
617 : :
618 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_compare_output(arguments,FAILURE,NULL,"templates/0028_007.txt"));
619 : :
620 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
621 : : }
622 : :
623 : : /**
624 : : *
625 : : * Testing the --compare mode across different types of responses
626 : : *
627 : : */
628 : 2 : Return test0028(void)
629 : : {
630 : 2 : INITTEST;
631 : :
632 [ + - ]: 2 : TEST(test0028_1,"One file is removed, updated, and added at a time…");
633 [ + - ]: 2 : TEST(test0028_2,"One file is removed. It should be reflected as a change in one of the databases…");
634 [ + - ]: 2 : TEST(test0028_3,"One file is added. It should be reflected as a change in one of the databases…");
635 [ + - ]: 2 : TEST(test0028_4,"One file is updated and its checksum should change…");
636 [ + - ]: 2 : TEST(test0028_5,"Nothing changes. The databases should be equivalent…");
637 [ + - ]: 2 : TEST(test0028_6,"All supported --compare-filter combinations should behave as expected…");
638 [ + - ]: 2 : TEST(test0028_7,"Invalid --compare-filter value should fail with an argument parsing error…");
639 : :
640 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
641 : : }
|