|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: JavaCaptain Main |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <locale.h> |
|
20 |
|
21 #include "filetestconsts.h" |
|
22 #include "filetestutils.h" |
|
23 |
|
24 using namespace std; |
|
25 using namespace java::filetest; |
|
26 |
|
27 void doCreateMainDir() |
|
28 { |
|
29 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
30 FileTestUtils::createDir(mainDirPath); |
|
31 } |
|
32 |
|
33 void doInitTestExists() |
|
34 { |
|
35 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
36 mainDirPath+=L"testexists/"; |
|
37 FileTestUtils::createDir(mainDirPath); |
|
38 |
|
39 wstring dir1 = mainDirPath; |
|
40 dir1 += L"testExistsDir/"; |
|
41 FileTestUtils::createDir(dir1); |
|
42 |
|
43 wstring file1 = mainDirPath; |
|
44 file1 += L"testExistsFile"; |
|
45 FileTestUtils::createNormalFile(file1); |
|
46 } |
|
47 |
|
48 void doInitTestCreate() |
|
49 { |
|
50 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
51 mainDirPath+=L"testcreate/"; |
|
52 FileTestUtils::createDir(mainDirPath); |
|
53 |
|
54 // Relates to testFileCreateFailure() |
|
55 wstring file1 = mainDirPath; |
|
56 file1 += L"FileCreateFailureTest0"; |
|
57 FileTestUtils::createNormalFile(file1); |
|
58 |
|
59 wstring file2 = mainDirPath; |
|
60 file2 += L"pää.txt"; |
|
61 FileTestUtils::createNormalFile(file2); |
|
62 |
|
63 wstring dir = mainDirPath; |
|
64 dir += L"FileCreateFailureOnDirTest/"; |
|
65 FileTestUtils::createDir(dir); |
|
66 } |
|
67 |
|
68 void doInitTestIsFile() |
|
69 { |
|
70 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
71 mainDirPath+=L"testisfile/"; |
|
72 FileTestUtils::createDir(mainDirPath); |
|
73 |
|
74 wstring file1 = mainDirPath; |
|
75 file1 += L"testOnFileTest"; |
|
76 FileTestUtils::createNormalFile(file1); |
|
77 |
|
78 wstring dir = mainDirPath; |
|
79 dir += L"testOnDirTest/"; |
|
80 FileTestUtils::createDir(dir); |
|
81 } |
|
82 |
|
83 void doInitTestIsDir() |
|
84 { |
|
85 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
86 mainDirPath+=L"testisdir/"; |
|
87 FileTestUtils::createDir(mainDirPath); |
|
88 |
|
89 wstring file1 = mainDirPath; |
|
90 file1 += L"testOnFileTest"; |
|
91 FileTestUtils::createNormalFile(file1); |
|
92 |
|
93 wstring dir = mainDirPath; |
|
94 dir += L"testOnDirTest/"; |
|
95 FileTestUtils::createDir(dir); |
|
96 } |
|
97 |
|
98 void doInitTestCanRead() |
|
99 { |
|
100 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
101 mainDirPath+=L"testcanread/"; |
|
102 FileTestUtils::createDir(mainDirPath); |
|
103 |
|
104 wstring file1 = mainDirPath; |
|
105 file1 += L"testOnReadOnlyFile"; |
|
106 FileTestUtils::createReadOnlyFile(file1); |
|
107 |
|
108 wstring dir = mainDirPath; |
|
109 dir += L"testOnReadOnlyDir/"; |
|
110 FileTestUtils::createReadOnlyDir(dir); |
|
111 |
|
112 wstring file2 = mainDirPath; |
|
113 file2 += L"testOnFile"; |
|
114 FileTestUtils::createNormalFile(file2); |
|
115 } |
|
116 |
|
117 void doInitTestCanWrite() |
|
118 { |
|
119 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
120 mainDirPath+=L"testcanwrite/"; |
|
121 FileTestUtils::createDir(mainDirPath); |
|
122 |
|
123 wstring file1 = mainDirPath; |
|
124 file1 += L"testOnReadOnlyFile"; |
|
125 FileTestUtils::createReadOnlyFile(file1); |
|
126 |
|
127 wstring dir = mainDirPath; |
|
128 dir += L"testOnReadOnlyDir/"; |
|
129 FileTestUtils::createReadOnlyDir(dir); |
|
130 |
|
131 wstring file2 = mainDirPath; |
|
132 file2 += L"testOnFile"; |
|
133 FileTestUtils::createNormalFile(file2); |
|
134 } |
|
135 |
|
136 |
|
137 void doInitTestFileSize() |
|
138 { |
|
139 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
140 mainDirPath+=L"testfilesize/"; |
|
141 FileTestUtils::createDir(mainDirPath); |
|
142 |
|
143 wstring file2 = mainDirPath; |
|
144 file2 += L"testOnFile"; |
|
145 FileTestUtils::createNormalFile(file2); |
|
146 FileTestUtils::writeDataInLoop(file2, 1, 1000); |
|
147 |
|
148 wstring dir = mainDirPath; |
|
149 dir += L"testOnDir/"; |
|
150 FileTestUtils::createDir(dir); |
|
151 } |
|
152 |
|
153 void doInitTestLastModified() |
|
154 { |
|
155 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
156 mainDirPath+=L"testlastmodified/"; |
|
157 FileTestUtils::createDir(mainDirPath); |
|
158 } |
|
159 |
|
160 void doInitTestDirCreate() |
|
161 { |
|
162 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
163 mainDirPath+=L"testdircreate/"; |
|
164 FileTestUtils::createDir(mainDirPath); |
|
165 |
|
166 wstring dir = mainDirPath; |
|
167 dir += L"FileCreateFailureTestDir0/"; |
|
168 FileTestUtils::createDir(dir); |
|
169 |
|
170 wstring dir1 = mainDirPath; |
|
171 dir1 += L"pääDirTest/"; |
|
172 FileTestUtils::createDir(dir1); |
|
173 |
|
174 wstring dir2 = mainDirPath; |
|
175 dir2 += L"FileCreateFailureOnDirTest/"; |
|
176 FileTestUtils::createDir(dir2); |
|
177 } |
|
178 |
|
179 void doInitTestRename() |
|
180 { |
|
181 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
182 mainDirPath+=L"testrename/"; |
|
183 FileTestUtils::createDir(mainDirPath); |
|
184 |
|
185 wstring file2 = mainDirPath; |
|
186 file2 += L"FileUtilsTestFileRename.txt"; |
|
187 FileTestUtils::createNormalFile(file2); |
|
188 |
|
189 wstring dir = mainDirPath; |
|
190 dir += L"FileUtilsTestFileRename/"; |
|
191 FileTestUtils::createDir(dir); |
|
192 } |
|
193 |
|
194 void doInitTestInputStream() |
|
195 { |
|
196 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
197 mainDirPath+=L"testinputstream/"; |
|
198 FileTestUtils::createDir(mainDirPath); |
|
199 |
|
200 wstring file1 = mainDirPath; |
|
201 file1 += L"inputFile.txt"; |
|
202 FileTestUtils::createNormalFile(file1); |
|
203 FileTestUtils::writeDataInLoop(file1, 1, 1000); |
|
204 |
|
205 wstring file2 = mainDirPath; |
|
206 file2 += L"inputFile001.txt"; |
|
207 FileTestUtils::createNormalFile(file2); |
|
208 FileTestUtils::writeDataInLoop(file2, 1, 1000); |
|
209 FileTestUtils::writeDataInLoop(file2, 2, 1000); |
|
210 FileTestUtils::writeDataInLoop(file2, 3, 1000); |
|
211 FileTestUtils::writeDataInLoop(file2, 4, 1000); |
|
212 |
|
213 wstring file3 = mainDirPath; |
|
214 file3 += L"inputFileMark.txt"; |
|
215 FileTestUtils::createNormalFile(file3); |
|
216 FileTestUtils::writeDataInLoop(file3, 5, 20); |
|
217 FileTestUtils::writeDataInLoop(file3, 6, 10); |
|
218 FileTestUtils::writeDataInLoop(file3, 7, 15); |
|
219 } |
|
220 |
|
221 void doInitTestOutputStream() |
|
222 { |
|
223 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
224 mainDirPath+=L"testoutputstream/"; |
|
225 FileTestUtils::createDir(mainDirPath); |
|
226 } |
|
227 |
|
228 void doInitTestDirListing() |
|
229 { |
|
230 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
231 mainDirPath+=L"testlist/"; |
|
232 FileTestUtils::createDir(mainDirPath); |
|
233 |
|
234 wstring dir = mainDirPath; |
|
235 dir += L"folder1/"; |
|
236 FileTestUtils::createDir(dir); |
|
237 |
|
238 wstring dir1 = mainDirPath; |
|
239 dir1 += L"folder2/"; |
|
240 FileTestUtils::createDir(dir1); |
|
241 |
|
242 dir1 = mainDirPath; |
|
243 dir1 += L"folder3/"; |
|
244 FileTestUtils::createDir(dir1); |
|
245 |
|
246 dir1 = mainDirPath; |
|
247 FileTestUtils::createHiddenDir(dir1, L"folder4/"); |
|
248 |
|
249 wstring file1 = mainDirPath; |
|
250 file1 += L"inputFile.txt"; |
|
251 FileTestUtils::createNormalFile(file1); |
|
252 |
|
253 file1 = mainDirPath; |
|
254 file1 += L"inputFile1.txt"; |
|
255 FileTestUtils::createNormalFile(file1); |
|
256 |
|
257 file1 = mainDirPath; |
|
258 file1 += L"inputFile2.txt"; |
|
259 FileTestUtils::createNormalFile(file1); |
|
260 |
|
261 file1 = mainDirPath; |
|
262 file1 += L"inputFile3.txt"; |
|
263 FileTestUtils::createNormalFile(file1); |
|
264 |
|
265 file1 = mainDirPath; |
|
266 file1 += L"pää.txt"; |
|
267 FileTestUtils::createNormalFile(file1); |
|
268 |
|
269 file1 = mainDirPath; |
|
270 FileTestUtils::createHiddenFile(file1, L"hidden.txt"); |
|
271 |
|
272 } |
|
273 |
|
274 void doInitTestDelete() |
|
275 { |
|
276 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
277 mainDirPath+=L"testdelete/"; |
|
278 FileTestUtils::createDir(mainDirPath); |
|
279 |
|
280 wstring dir = mainDirPath; |
|
281 dir += L"folder1/"; |
|
282 FileTestUtils::createDir(dir); |
|
283 |
|
284 wstring file1 = mainDirPath; |
|
285 file1 += L"inputFile.txt"; |
|
286 FileTestUtils::createNormalFile(file1); |
|
287 |
|
288 wstring file3 = mainDirPath; |
|
289 file3 += L"inputStreamFile.txt"; |
|
290 FileTestUtils::createNormalFile(file3); |
|
291 FileTestUtils::writeDataInLoop(file3, 5, 20); |
|
292 |
|
293 file3 = mainDirPath; |
|
294 file3 += L"outputStreamFile.txt"; |
|
295 FileTestUtils::createNormalFile(file3); |
|
296 } |
|
297 |
|
298 void doInitTestMkdirs() |
|
299 { |
|
300 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
301 mainDirPath+=L"testmkdirs/"; |
|
302 FileTestUtils::createDir(mainDirPath); |
|
303 } |
|
304 |
|
305 void doInitTestFileCopy() |
|
306 { |
|
307 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
308 mainDirPath+=L"testfilecopy/"; |
|
309 FileTestUtils::createDir(mainDirPath); |
|
310 } |
|
311 |
|
312 void doInitTestFileMove() |
|
313 { |
|
314 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
315 mainDirPath+=L"testfilemove/"; |
|
316 FileTestUtils::createDir(mainDirPath); |
|
317 |
|
318 mainDirPath += L"folderToMove/"; |
|
319 FileTestUtils::createDir(mainDirPath); |
|
320 |
|
321 wstring dir = mainDirPath; |
|
322 dir += L"folder1/"; |
|
323 FileTestUtils::createDir(dir); |
|
324 |
|
325 dir = mainDirPath; |
|
326 dir += L"folder2/"; |
|
327 FileTestUtils::createDir(dir); |
|
328 |
|
329 wstring dir1 = dir; |
|
330 dir1 += L"nestedfolder1/"; |
|
331 FileTestUtils::createDir(dir1); |
|
332 |
|
333 wstring file = mainDirPath; |
|
334 file += L"file1.txt"; |
|
335 FileTestUtils::createNormalFile(file); |
|
336 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
337 |
|
338 file = mainDirPath; |
|
339 file += L"file2.txt"; |
|
340 FileTestUtils::createNormalFile(file); |
|
341 |
|
342 file = mainDirPath; |
|
343 file += L"file3.txt"; |
|
344 FileTestUtils::createNormalFile(file); |
|
345 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
346 |
|
347 file = mainDirPath; |
|
348 file += L"file4.txt"; |
|
349 FileTestUtils::createNormalFile(file); |
|
350 } |
|
351 |
|
352 void doInitTestFileCopyAll() |
|
353 { |
|
354 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
355 mainDirPath+=L"testfilecopyall/"; |
|
356 FileTestUtils::createDir(mainDirPath); |
|
357 |
|
358 mainDirPath += L"source/"; |
|
359 FileTestUtils::createDir(mainDirPath); |
|
360 |
|
361 wstring dir = mainDirPath; |
|
362 dir += L"folder1/"; |
|
363 FileTestUtils::createDir(dir); |
|
364 |
|
365 dir = mainDirPath; |
|
366 dir += L"folder2/"; |
|
367 FileTestUtils::createDir(dir); |
|
368 |
|
369 wstring dir1 = dir; |
|
370 dir1 += L"nestedfolder1/"; |
|
371 FileTestUtils::createDir(dir1); |
|
372 |
|
373 wstring file = mainDirPath; |
|
374 file += L"file1.txt"; |
|
375 FileTestUtils::createNormalFile(file); |
|
376 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
377 |
|
378 file = mainDirPath; |
|
379 file += L"file2.txt"; |
|
380 FileTestUtils::createNormalFile(file); |
|
381 |
|
382 file = mainDirPath; |
|
383 file += L"file3.txt"; |
|
384 FileTestUtils::createNormalFile(file); |
|
385 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
386 |
|
387 file = mainDirPath; |
|
388 file += L"file4.txt"; |
|
389 FileTestUtils::createNormalFile(file); |
|
390 |
|
391 |
|
392 mainDirPath = FileTestConsts::KDefaultTestPath; |
|
393 mainDirPath+=L"testfilecopyall/"; |
|
394 |
|
395 mainDirPath += L"source1/"; |
|
396 FileTestUtils::createDir(mainDirPath); |
|
397 |
|
398 dir = mainDirPath; |
|
399 dir += L"folder1/"; |
|
400 FileTestUtils::createDir(dir); |
|
401 |
|
402 dir = mainDirPath; |
|
403 dir += L"folder2/"; |
|
404 FileTestUtils::createDir(dir); |
|
405 |
|
406 dir1 = dir; |
|
407 dir1 += L"nestedfolder1/"; |
|
408 FileTestUtils::createDir(dir1); |
|
409 |
|
410 file = mainDirPath; |
|
411 file += L"file1.txt"; |
|
412 FileTestUtils::createNormalFile(file); |
|
413 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
414 |
|
415 file = mainDirPath; |
|
416 file += L"file2.txt"; |
|
417 FileTestUtils::createNormalFile(file); |
|
418 |
|
419 file = mainDirPath; |
|
420 file += L"file3.txt"; |
|
421 FileTestUtils::createNormalFile(file); |
|
422 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
423 |
|
424 file = mainDirPath; |
|
425 file += L"file4.txt"; |
|
426 FileTestUtils::createNormalFile(file); |
|
427 } |
|
428 |
|
429 void doInitTestFileDeleteAll() |
|
430 { |
|
431 wstring mainDirPath = FileTestConsts::KDefaultTestPath; |
|
432 mainDirPath+=L"testfiledeleteall/"; |
|
433 FileTestUtils::createDir(mainDirPath); |
|
434 |
|
435 mainDirPath += L"source/"; |
|
436 FileTestUtils::createDir(mainDirPath); |
|
437 |
|
438 wstring dir = mainDirPath; |
|
439 dir += L"folder1/"; |
|
440 FileTestUtils::createDir(dir); |
|
441 |
|
442 dir = mainDirPath; |
|
443 dir += L"folder2/"; |
|
444 FileTestUtils::createDir(dir); |
|
445 |
|
446 wstring file = mainDirPath; |
|
447 file += L"file1.txt"; |
|
448 FileTestUtils::createNormalFile(file); |
|
449 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
450 |
|
451 file = mainDirPath; |
|
452 file += L"file2.txt"; |
|
453 FileTestUtils::createNormalFile(file); |
|
454 |
|
455 file = mainDirPath; |
|
456 file += L"file3.txt"; |
|
457 FileTestUtils::createNormalFile(file); |
|
458 FileTestUtils::writeDataInLoop(file, 5, 20); |
|
459 |
|
460 file = mainDirPath; |
|
461 file += L"file4.txt"; |
|
462 FileTestUtils::createNormalFile(file); |
|
463 } |
|
464 |
|
465 |
|
466 int main(int /*argc*/, char** /*argv*/) |
|
467 { |
|
468 setlocale(LC_ALL, ""); |
|
469 |
|
470 // Create the main folder within which tests are executed. |
|
471 doCreateMainDir(); |
|
472 |
|
473 doInitTestExists(); |
|
474 |
|
475 doInitTestCreate(); |
|
476 |
|
477 doInitTestIsFile(); |
|
478 |
|
479 doInitTestIsDir(); |
|
480 |
|
481 doInitTestCanRead(); |
|
482 |
|
483 doInitTestCanWrite(); |
|
484 |
|
485 doInitTestFileSize(); |
|
486 |
|
487 doInitTestLastModified(); |
|
488 |
|
489 doInitTestDirCreate(); |
|
490 |
|
491 doInitTestRename(); |
|
492 |
|
493 doInitTestInputStream(); |
|
494 |
|
495 doInitTestOutputStream(); |
|
496 |
|
497 doInitTestDirListing(); |
|
498 |
|
499 doInitTestDelete(); |
|
500 |
|
501 doInitTestMkdirs(); |
|
502 |
|
503 doInitTestFileCopy(); |
|
504 |
|
505 doInitTestFileMove(); |
|
506 |
|
507 doInitTestFileCopyAll(); |
|
508 |
|
509 doInitTestFileDeleteAll(); |
|
510 } |