Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /**
4 : : *
5 : : * Testing database creation attempt in missing directory
6 : : *
7 : : */
8 : 2 : Return test0020_1(void)
9 : : {
10 : 2 : INITTEST;
11 : :
12 : 2 : create(char,result);
13 : :
14 : 2 : create(char,pattern);
15 : :
16 : 2 : const char *filename = "templates/0020_001.txt";
17 : :
18 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
19 : :
20 : 2 : const char *arguments = "--update --database=nonexistent_directory/database1.db "
21 : : "tests/fixtures/diffs/diff1";
22 : :
23 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
24 : :
25 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
26 : :
27 : : // Match the result against the pattern
28 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
29 : :
30 : : // Clean to use it iteratively
31 : 2 : del(pattern);
32 : 2 : del(result);
33 : :
34 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
35 : : }
36 : :
37 : : /**
38 : : *
39 : : * Testing attempt to open DB with --update when database is missing
40 : : *
41 : : */
42 : 2 : Return test0020_2(void)
43 : : {
44 : 2 : INITTEST;
45 : :
46 : 2 : create(char,result);
47 : :
48 : 2 : create(char,pattern);
49 : :
50 : 2 : const char *filename = "templates/0020_002.txt";
51 : :
52 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
53 : :
54 : 2 : const char *arguments = "--update --database=nonexistent_database1.db "
55 : : "tests/fixtures/diffs/diff1";
56 : :
57 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
58 : :
59 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
60 : :
61 : : // Match the result against the pattern
62 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
63 : :
64 : : // Clean to use it iteratively
65 : 2 : del(pattern);
66 : 2 : del(result);
67 : :
68 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
69 : : }
70 : :
71 : : /**
72 : : *
73 : : * Testing DB creation in write protected directory
74 : : *
75 : : */
76 : 2 : Return test0020_3(void)
77 : : {
78 : 2 : INITTEST;
79 : :
80 : 2 : create(char,result);
81 : :
82 : 2 : create(char,pattern);
83 : :
84 : 2 : const char *command = "cd ${TMPDIR} && "
85 : : "mkdir write_protected_directory && "
86 : : "chmod a-rwx write_protected_directory";
87 : :
88 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
89 : :
90 : 2 : const char *filename = "templates/0020_003.txt";
91 : :
92 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
93 : :
94 : 2 : const char *arguments = "--database=write_protected_directory/database1.db "
95 : : "tests/fixtures/diffs/diff1";
96 : :
97 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
98 : :
99 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
100 : :
101 : : // Match the result against the pattern
102 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
103 : :
104 : : // Clean to use it iteratively
105 : 2 : del(pattern);
106 : 2 : del(result);
107 : :
108 : 2 : command = "cd ${TMPDIR} && "
109 : : "chmod a+rwx write_protected_directory && "
110 : : "rm -rf write_protected_directory";
111 : :
112 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
113 : :
114 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
115 : : }
116 : :
117 : : /**
118 : : *
119 : : * Testing attempt to open DB with write protected database file
120 : : *
121 : : */
122 : 2 : Return test0020_4(void)
123 : : {
124 : 2 : INITTEST;
125 : :
126 : 2 : create(char,result);
127 : :
128 : 2 : create(char,pattern);
129 : :
130 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
131 : :
132 : 2 : const char *arguments = "--database=write_protected_database1.db "
133 : : "tests/fixtures/diffs/diff1";
134 : :
135 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
136 : :
137 : 2 : arguments = "--database=database2.db tests/fixtures/diffs/diff2";
138 : :
139 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
140 : :
141 : 2 : const char *command = "cd ${TMPDIR} && "
142 : : "chmod a-rwx write_protected_database1.db";
143 : :
144 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
145 : :
146 : 2 : const char *filename = "templates/0020_004.txt";
147 : :
148 : 2 : arguments = "--compare write_protected_database1.db database2.db";
149 : :
150 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
151 : :
152 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
153 : :
154 : : // Match the result against the pattern
155 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
156 : :
157 : : // Clean to use it iteratively
158 : 2 : del(pattern);
159 : 2 : del(result);
160 : :
161 : 2 : command = "cd ${TMPDIR} && "
162 : : "rm database2.db";
163 : :
164 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
165 : :
166 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
167 : : }
168 : :
169 : : /**
170 : : *
171 : : * Testing attempt to update DB with --update when database file is write protected
172 : : *
173 : : */
174 : 2 : Return test0020_5(void)
175 : : {
176 : 2 : INITTEST;
177 : :
178 : 2 : create(char,result);
179 : :
180 : 2 : create(char,pattern);
181 : :
182 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
183 : :
184 : 2 : const char *filename = "templates/0020_005.txt";
185 : :
186 : 2 : const char *arguments = "--update --database=write_protected_database1.db "
187 : : "tests/fixtures/diffs/diff1";
188 : :
189 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
190 : :
191 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
192 : :
193 : : // Match the result against the pattern
194 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
195 : :
196 : : // Clean to use it iteratively
197 : 2 : del(pattern);
198 : 2 : del(result);
199 : :
200 : 2 : const char *command = "cd ${TMPDIR} && "
201 : : "rm -f write_protected_database1.db";
202 : :
203 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
204 : :
205 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
206 : : }
207 : :
208 : : /**
209 : : *
210 : : * Attempt to change the primary path in the database
211 : : *
212 : : */
213 : 2 : Return test0020_6(void)
214 : : {
215 : 2 : INITTEST;
216 : :
217 : 2 : create(char,result);
218 : :
219 : 2 : create(char,pattern);
220 : :
221 : 2 : const char *filename = "templates/0020_006.txt";
222 : :
223 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
224 : :
225 : 2 : const char *arguments = "--database=database1.db tests/fixtures/diffs/diff1";
226 : :
227 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
228 : :
229 : 2 : arguments = "--update --database=database1.db tests/fixtures/diffs/diff2";
230 : :
231 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
232 : :
233 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
234 : :
235 : : // Match the result against the pattern
236 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
237 : :
238 : : // Clean to use it iteratively
239 : 2 : del(pattern);
240 : 2 : del(result);
241 : :
242 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
243 : : }
244 : :
245 : : /**
246 : : *
247 : : * Replace the primary path in the database
248 : : *
249 : : */
250 : 2 : Return test0020_7(void)
251 : : {
252 : 2 : INITTEST;
253 : :
254 : 2 : create(char,result);
255 : :
256 : 2 : create(char,pattern);
257 : :
258 : 2 : const char *filename = "templates/0020_007.txt";
259 : :
260 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
261 : :
262 : 2 : const char *arguments = "--update --force --database=database1.db "
263 : : "tests/fixtures/diffs/diff2";
264 : :
265 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
266 : :
267 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
268 : :
269 : : // Match the result against the pattern
270 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
271 : :
272 : : // Clean to use it iteratively
273 : 2 : del(pattern);
274 : 2 : del(result);
275 : :
276 : 2 : const char *command = "cd ${TMPDIR} && "
277 : : "rm -f database1.db";
278 : :
279 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
280 : :
281 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
282 : : }
283 : :
284 : 2 : Return test0020(void)
285 : : {
286 : 2 : INITTEST;
287 : :
288 [ + - ]: 2 : TEST(test0020_1,"DB creation in missing directory…")
289 [ + - ]: 2 : TEST(test0020_2,"Attempt to open DB with --update when database is missing…")
290 [ + - ]: 2 : TEST(test0020_3,"DB creation in write protected directory…")
291 [ + - ]: 2 : TEST(test0020_4,"Attempt to open DB with write protected database file…")
292 [ + - ]: 2 : TEST(test0020_5,"Attempt to update DB with --update when database file is write protected…")
293 [ + - ]: 2 : TEST(test0020_6,"Attempt to change the primary path in the database…")
294 [ + - ]: 2 : TEST(test0020_7,"Replace the primary path in the database…")
295 : :
296 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
297 : : }
|