Branch data Line data Source code
1 : : #include "sute.h"
2 : : #include "mocks.h"
3 : : #include <errno.h>
4 : :
5 : : #define READ_FAIL_REL_PATH "tests/fixtures/diffs/diff1/path1/AAA/ZAW/D/e/f/b_file.txt"
6 : :
7 : : /**
8 : : * Simulate fread failure for a specific file to verify error handling.
9 : : */
10 : 1 : Return test0031(void)
11 : : {
12 : 1 : INITTEST;
13 : :
14 : 1 : create(char,result);
15 : 1 : create(char,pattern);
16 : 1 : create(char,error_buffer);
17 : :
18 [ + - + - ]: 1 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
19 : :
20 : 1 : const char *command = "cd ${TMPDIR};"
21 : : "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
22 : : "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
23 : :
24 [ + - + - ]: 1 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
25 : :
26 : 1 : const char *arguments = "--database=read_fail.db --progress"
27 : : " tests/fixtures/diffs/diff1";
28 : :
29 : : /* Configure the fread mock to fail once for the target file only. */
30 : 1 : mocks_fread_reset();
31 : 1 : mocks_fread_set_target_suffix(READ_FAIL_REL_PATH);
32 : 1 : mocks_fread_enable(true);
33 : 1 : mocks_fread_set_errno(EIO);
34 : :
35 [ + - + - ]: 1 : ASSERT(SUCCESS == runit(arguments,result,error_buffer,COMPLETED,ALLOW_BOTH));
36 : :
37 : : /* Always disable the mock and restore the previous run mode. */
38 : 1 : mocks_fread_enable(false);
39 : :
40 [ - + ]: 1 : if(error_buffer->length > 0)
41 : : {
42 : 0 : echo(STDOUT,"stderr buffer:\n%s\n",getcstring(error_buffer));
43 : : }
44 : :
45 : 1 : const char *filename = "templates/0031_001.txt";
46 : :
47 [ + - + - ]: 1 : ASSERT(SUCCESS == get_file_content(filename,pattern));
48 [ + - + - ]: 1 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
49 : :
50 : 1 : command = "cd ${TMPDIR} && "
51 : : "rm -f read_fail.db && "
52 : : "rm -rf tests/fixtures/diffs/diff1 && "
53 : : "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
54 : :
55 [ + - + - ]: 1 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
56 : :
57 : : /* The wrapper should have injected exactly one read failure. */
58 [ + - + - ]: 1 : ASSERT(mocks_fread_call_count() == 1);
59 : 1 : mocks_fread_reset();
60 : :
61 : 1 : del(pattern);
62 : 1 : del(result);
63 : 1 : del(error_buffer);
64 : :
65 [ + - - + : 1 : RETURN_STATUS;
- - - + +
- ]
66 : : }
|