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 : m_create(char,result,MEMORY_STRING);
13 : :
14 : 2 : m_create(char,pattern,MEMORY_STRING);
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 : m_del(pattern);
32 : 2 : m_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 : m_create(char,result,MEMORY_STRING);
47 : :
48 : 2 : m_create(char,pattern,MEMORY_STRING);
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 : m_del(pattern);
66 : 2 : m_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 : m_create(char,result,MEMORY_STRING);
81 : :
82 : 2 : m_create(char,pattern,MEMORY_STRING);
83 : :
84 : 2 : ASSERT(SUCCESS == create_directory("write_protected_directory"));
85 : 2 : ASSERT(SUCCESS == change_mode("write_protected_directory",0000));
86 : :
87 : 2 : const char *filename = "templates/0020_003.txt";
88 : :
89 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
90 : :
91 : 2 : const char *arguments = "--database=write_protected_directory/database1.db "
92 : : "tests/fixtures/diffs/diff1";
93 : :
94 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
95 : :
96 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
97 : :
98 : : // Match the result against the pattern
99 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
100 : :
101 : : // Clean to use it iteratively
102 : 2 : m_del(pattern);
103 : 2 : m_del(result);
104 : :
105 : 2 : ASSERT(SUCCESS == change_mode("write_protected_directory",0777));
106 : 2 : ASSERT(SUCCESS == delete_path("write_protected_directory"));
107 : :
108 : 2 : RETURN_STATUS;
109 : : }
110 : :
111 : : /**
112 : : *
113 : : * Testing attempt to open DB with write protected database file
114 : : *
115 : : */
116 : 2 : Return test0020_4(void)
117 : : {
118 : 2 : INITTEST;
119 : :
120 : 2 : m_create(char,result,MEMORY_STRING);
121 : :
122 : 2 : m_create(char,pattern,MEMORY_STRING);
123 : :
124 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
125 : :
126 : 2 : const char *arguments = "--database=write_protected_database1.db "
127 : : "tests/fixtures/diffs/diff1";
128 : :
129 : 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
130 : :
131 : 2 : arguments = "--database=database2.db tests/fixtures/diffs/diff2";
132 : :
133 : 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
134 : :
135 : 2 : ASSERT(SUCCESS == change_mode("write_protected_database1.db",0000));
136 : :
137 : 2 : const char *filename = "templates/0020_004.txt";
138 : :
139 : 2 : arguments = "--compare write_protected_database1.db database2.db";
140 : :
141 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
142 : :
143 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
144 : :
145 : : // Match the result against the pattern
146 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
147 : :
148 : : // Clean to use it iteratively
149 : 2 : m_del(pattern);
150 : 2 : m_del(result);
151 : :
152 : 2 : ASSERT(SUCCESS == delete_path("database2.db"));
153 : :
154 : 2 : RETURN_STATUS;
155 : : }
156 : :
157 : : /**
158 : : *
159 : : * Testing attempt to update DB with --update when database file is write protected
160 : : *
161 : : */
162 : 2 : Return test0020_5(void)
163 : : {
164 : 2 : INITTEST;
165 : :
166 : 2 : m_create(char,result,MEMORY_STRING);
167 : :
168 : 2 : m_create(char,pattern,MEMORY_STRING);
169 : :
170 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
171 : :
172 : 2 : const char *filename = "templates/0020_005.txt";
173 : :
174 : 2 : const char *arguments = "--update --database=write_protected_database1.db "
175 : : "tests/fixtures/diffs/diff1";
176 : :
177 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,FAILURE,ALLOW_BOTH));
178 : :
179 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
180 : :
181 : : // Match the result against the pattern
182 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
183 : :
184 : : // Clean to use it iteratively
185 : 2 : m_del(pattern);
186 : 2 : m_del(result);
187 : :
188 : 2 : ASSERT(SUCCESS == change_mode("write_protected_database1.db",0666));
189 : 2 : ASSERT(SUCCESS == delete_path("write_protected_database1.db"));
190 : :
191 : 2 : RETURN_STATUS;
192 : : }
193 : :
194 : : /**
195 : : *
196 : : * Attempt to change the primary path in the database
197 : : *
198 : : */
199 : 2 : Return test0020_6(void)
200 : : {
201 : 2 : INITTEST;
202 : :
203 : 2 : m_create(char,result,MEMORY_STRING);
204 : :
205 : 2 : m_create(char,pattern,MEMORY_STRING);
206 : :
207 : 2 : const char *filename = "templates/0020_006.txt";
208 : :
209 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
210 : :
211 : 2 : const char *arguments = "--database=database1.db tests/fixtures/diffs/diff1";
212 : :
213 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
214 : :
215 : 2 : arguments = "--update --database=database1.db tests/fixtures/diffs/diff2";
216 : :
217 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
218 : :
219 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
220 : :
221 : : // Match the result against the pattern
222 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
223 : :
224 : : // Clean to use it iteratively
225 : 2 : m_del(pattern);
226 : 2 : m_del(result);
227 : :
228 : 2 : RETURN_STATUS;
229 : : }
230 : :
231 : : /**
232 : : *
233 : : * Replace the primary path in the database
234 : : *
235 : : */
236 : 2 : Return test0020_7(void)
237 : : {
238 : 2 : INITTEST;
239 : :
240 : 2 : m_create(char,result,MEMORY_STRING);
241 : :
242 : 2 : m_create(char,pattern,MEMORY_STRING);
243 : :
244 : 2 : const char *filename = "templates/0020_007.txt";
245 : :
246 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
247 : :
248 : 2 : const char *arguments = "--update --force --database=database1.db "
249 : : "tests/fixtures/diffs/diff2";
250 : :
251 : 2 : ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
252 : :
253 : 2 : ASSERT(SUCCESS == get_file_content(filename,pattern));
254 : :
255 : : // Match the result against the pattern
256 : 2 : ASSERT(SUCCESS == match_pattern(result,pattern,filename));
257 : :
258 : : // Clean to use it iteratively
259 : 2 : m_del(pattern);
260 : 2 : m_del(result);
261 : :
262 : 2 : ASSERT(SUCCESS == delete_path("database1.db"));
263 : :
264 : 2 : RETURN_STATUS;
265 : : }
266 : :
267 : 2 : Return test0020(void)
268 : : {
269 : 2 : INITTEST;
270 : :
271 : 2 : TEST(test0020_1,"DB creation in missing directory")
272 : 2 : TEST(test0020_2,"Attempt to open DB with --update when database is missing")
273 : 2 : TEST(test0020_3,"DB creation in write protected directory")
274 : 2 : TEST(test0020_4,"Attempt to open DB with write protected database file")
275 : 2 : TEST(test0020_5,"Attempt to update DB with --update when database file is write protected")
276 : 2 : TEST(test0020_6,"Attempt to change the primary path in the database")
277 : 2 : TEST(test0020_7,"Replace the primary path in the database")
278 : :
279 : 2 : RETURN_STATUS;
280 : : }
|