1 | Unit FileUtilsUnitTests;
|
---|
2 |
|
---|
3 | // NewView - a new OS/2 Help Viewer
|
---|
4 | // Copyright 2006-2009 Ronald Brill (rbri at rbri dot de)
|
---|
5 | // This software is released under the GNU Public License - see readme.txt
|
---|
6 |
|
---|
7 | // UnitTests for FileUtilsUnit
|
---|
8 |
|
---|
9 | Interface
|
---|
10 |
|
---|
11 | uses
|
---|
12 | Classes,
|
---|
13 | TestAssert,
|
---|
14 | FileUtilsUnit;
|
---|
15 |
|
---|
16 | const
|
---|
17 | // TODO read environment var
|
---|
18 | TEST_PATH = 'P:\newview_dev';
|
---|
19 |
|
---|
20 | FUNCTION getFileUtilsUnitTests : TList;
|
---|
21 |
|
---|
22 |
|
---|
23 | Implementation
|
---|
24 |
|
---|
25 | Procedure testAddDirectorySeparator_Empty;
|
---|
26 | var
|
---|
27 | tmpResult : String;
|
---|
28 | begin
|
---|
29 | tmpResult := AddDirectorySeparator('');
|
---|
30 |
|
---|
31 | assertEqualsString('testAddDirectorySeparator_Empty', '\', tmpResult);
|
---|
32 | end;
|
---|
33 |
|
---|
34 | Procedure testAddDirectorySeparator_SingleChar;
|
---|
35 | var
|
---|
36 | tmpResult : String;
|
---|
37 | begin
|
---|
38 | tmpResult := AddDirectorySeparator('x');
|
---|
39 |
|
---|
40 | assertEqualsString('testAddDirectorySeparator_SingleChar', 'x\', tmpResult);
|
---|
41 | end;
|
---|
42 |
|
---|
43 | Procedure testAddDirectorySeparator_ManyChars;
|
---|
44 | var
|
---|
45 | tmpResult : String;
|
---|
46 | begin
|
---|
47 | tmpResult := AddDirectorySeparator('xyz dkdj ');
|
---|
48 |
|
---|
49 | assertEqualsString('testAddDirectorySeparator_ManyChars', 'xyz dkdj \', tmpResult);
|
---|
50 | end;
|
---|
51 |
|
---|
52 |
|
---|
53 | Procedure testAddDirectorySeparator_SlashAtEnd;
|
---|
54 | var
|
---|
55 | tmpResult : String;
|
---|
56 | begin
|
---|
57 | tmpResult := AddDirectorySeparator('xy\');
|
---|
58 |
|
---|
59 | assertEqualsString('testAddDirectorySeparator_SlashAtEnd', 'xy\', tmpResult);
|
---|
60 | end;
|
---|
61 |
|
---|
62 |
|
---|
63 | // ----------------------------------------------------------
|
---|
64 |
|
---|
65 |
|
---|
66 | Procedure testAddDirectorySeparatorIfNotEmpty_Empty;
|
---|
67 | var
|
---|
68 | tmpResult : String;
|
---|
69 | begin
|
---|
70 | tmpResult := AddDirectorySeparatorIfNotEmpty('');
|
---|
71 |
|
---|
72 | assertEqualsString('testAddDirectorySeparatorIfNotEmpty_Empty', '', tmpResult);
|
---|
73 | end;
|
---|
74 |
|
---|
75 | Procedure testAddDirectorySeparatorIfNotEmpty_SingleChar;
|
---|
76 | var
|
---|
77 | tmpResult : String;
|
---|
78 | begin
|
---|
79 | tmpResult := AddDirectorySeparatorIfNotEmpty('x');
|
---|
80 |
|
---|
81 | assertEqualsString('testAddDirectorySeparatorIfNotEmpty_SingleChar', 'x\', tmpResult);
|
---|
82 | end;
|
---|
83 |
|
---|
84 | Procedure testAddDirectorySeparatorIfNotEmpty_ManyChars;
|
---|
85 | var
|
---|
86 | tmpResult : String;
|
---|
87 | begin
|
---|
88 | tmpResult := AddDirectorySeparatorIfNotEmpty('xyz dkdj ');
|
---|
89 |
|
---|
90 | assertEqualsString('testAddDirectorySeparatorIfNotEmpty_ManyChars', 'xyz dkdj \', tmpResult);
|
---|
91 | end;
|
---|
92 |
|
---|
93 |
|
---|
94 | Procedure testAddDirectorySeparatorIfNotEmpty_SlashAtEnd;
|
---|
95 | var
|
---|
96 | tmpResult : String;
|
---|
97 | begin
|
---|
98 | tmpResult := AddDirectorySeparatorIfNotEmpty('xy\');
|
---|
99 |
|
---|
100 | assertEqualsString('testAddDirectorySeparatorIfNotEmpty_SlashAtEnd', 'xy\', tmpResult);
|
---|
101 | end;
|
---|
102 |
|
---|
103 |
|
---|
104 | // ----------------------------------------------------------
|
---|
105 |
|
---|
106 |
|
---|
107 | Procedure testRemoveRightDirectorySeparator_Empty;
|
---|
108 | var
|
---|
109 | tmpResult : String;
|
---|
110 | begin
|
---|
111 | tmpResult := RemoveRightDirectorySeparator('');
|
---|
112 |
|
---|
113 | assertEqualsString('testRemoveRightDirectorySeparator_Empty', '', tmpResult);
|
---|
114 | end;
|
---|
115 |
|
---|
116 |
|
---|
117 | Procedure testRemoveRightDirectorySeparator_WithoutSlash;
|
---|
118 | var
|
---|
119 | tmpResult : String;
|
---|
120 | begin
|
---|
121 | tmpResult := RemoveRightDirectorySeparator('abc');
|
---|
122 |
|
---|
123 | assertEqualsString('testRemoveRightDirectorySeparator_WithoutSlash', 'abc', tmpResult);
|
---|
124 | end;
|
---|
125 |
|
---|
126 |
|
---|
127 | Procedure testRemoveRightDirectorySeparator_WithSlash;
|
---|
128 | var
|
---|
129 | tmpResult : String;
|
---|
130 | begin
|
---|
131 | tmpResult := RemoveRightDirectorySeparator('abc\');
|
---|
132 |
|
---|
133 | assertEqualsString('testRemoveRightDirectorySeparator_WithSlash', 'abc', tmpResult);
|
---|
134 | end;
|
---|
135 |
|
---|
136 |
|
---|
137 | // ----------------------------------------------------------
|
---|
138 |
|
---|
139 | Procedure testExpandPath_BothEmpty;
|
---|
140 | var
|
---|
141 | tmpResult : String;
|
---|
142 | begin
|
---|
143 | tmpResult := ExpandPath('', '');
|
---|
144 |
|
---|
145 | assertEqualsString('testExpandPath_BothEmpty', '', tmpResult);
|
---|
146 | end;
|
---|
147 |
|
---|
148 |
|
---|
149 | Procedure testExpandPath_PathEmpty;
|
---|
150 | var
|
---|
151 | tmpResult : String;
|
---|
152 | begin
|
---|
153 | tmpResult := ExpandPath('\abc\def', '');
|
---|
154 |
|
---|
155 | assertEqualsString('testExpandPath_PathEmpty', '\abc\def', tmpResult);
|
---|
156 | end;
|
---|
157 |
|
---|
158 |
|
---|
159 | Procedure testExpandPath_PathEmptyDirEndsWithSlash;
|
---|
160 | var
|
---|
161 | tmpResult : String;
|
---|
162 | begin
|
---|
163 | tmpResult := ExpandPath('\abc\def\', '');
|
---|
164 |
|
---|
165 | assertEqualsString('testExpandPath_PathEmpty', '\abc\def', tmpResult);
|
---|
166 | end;
|
---|
167 |
|
---|
168 |
|
---|
169 | Procedure testExpandPath_AbsolutePath;
|
---|
170 | var
|
---|
171 | tmpResult : String;
|
---|
172 | begin
|
---|
173 | tmpResult := ExpandPath('\abc\def', 'c:\test');
|
---|
174 |
|
---|
175 | assertEqualsString('testExpandPath_AbsolutePath', 'c:\test', tmpResult);
|
---|
176 | end;
|
---|
177 |
|
---|
178 |
|
---|
179 | Procedure testExpandPath_DriveWithSlash;
|
---|
180 | var
|
---|
181 | tmpResult : String;
|
---|
182 | begin
|
---|
183 | tmpResult := ExpandPath('\abc\def', 'c:\');
|
---|
184 |
|
---|
185 | assertEqualsString('testExpandPath_DriveWithSlash', 'c:\', tmpResult);
|
---|
186 | end;
|
---|
187 |
|
---|
188 |
|
---|
189 | Procedure testExpandPath_DriveWithoutSlash;
|
---|
190 | var
|
---|
191 | tmpResult : String;
|
---|
192 | begin
|
---|
193 | tmpResult := ExpandPath('\abc\def', 'c:');
|
---|
194 |
|
---|
195 | assertEqualsString('testExpandPath_DriveWithoutSlash', 'c:\', tmpResult);
|
---|
196 | end;
|
---|
197 |
|
---|
198 |
|
---|
199 | Procedure testExpandPath_RootPathForDrive;
|
---|
200 | var
|
---|
201 | tmpResult : String;
|
---|
202 | begin
|
---|
203 | tmpResult := ExpandPath('d:\abc\def', '\');
|
---|
204 |
|
---|
205 | assertEqualsString('testExpandPath_RootPathForDrive', 'd:\', tmpResult);
|
---|
206 | end;
|
---|
207 |
|
---|
208 |
|
---|
209 | Procedure testExpandPath_RootDirForDrive;
|
---|
210 | var
|
---|
211 | tmpResult : String;
|
---|
212 | begin
|
---|
213 | tmpResult := ExpandPath('d:\abc\def', '\xy');
|
---|
214 |
|
---|
215 | assertEqualsString('testExpandPath_RootDirForDrive', 'd:\xy', tmpResult);
|
---|
216 | end;
|
---|
217 |
|
---|
218 |
|
---|
219 | Procedure testExpandPath_RootPathWithoutDrive;
|
---|
220 | var
|
---|
221 | tmpResult : String;
|
---|
222 | begin
|
---|
223 | tmpResult := ExpandPath('abc\def', '\');
|
---|
224 |
|
---|
225 | assertEqualsString('testExpandPath_RootPathWithoutDrive', '\', tmpResult);
|
---|
226 | end;
|
---|
227 |
|
---|
228 |
|
---|
229 | Procedure testExpandPath_RootDirWithoutDrive;
|
---|
230 | var
|
---|
231 | tmpResult : String;
|
---|
232 | begin
|
---|
233 | tmpResult := ExpandPath('abc\def', '\xyz');
|
---|
234 |
|
---|
235 | assertEqualsString('testExpandPath_RootDirWithoutDrive', '\xyz', tmpResult);
|
---|
236 | end;
|
---|
237 |
|
---|
238 |
|
---|
239 | Procedure testExpandPath_AppendWithSlash;
|
---|
240 | var
|
---|
241 | tmpResult : String;
|
---|
242 | begin
|
---|
243 | tmpResult := ExpandPath('abc\def\', 'xyz');
|
---|
244 |
|
---|
245 | assertEqualsString('testExpandPath_AppendWithSlash', 'abc\def\xyz', tmpResult);
|
---|
246 | end;
|
---|
247 |
|
---|
248 |
|
---|
249 | Procedure testExpandPath_AppendWithoutSlash;
|
---|
250 | var
|
---|
251 | tmpResult : String;
|
---|
252 | begin
|
---|
253 | tmpResult := ExpandPath('abc\def', 'xyz');
|
---|
254 |
|
---|
255 | assertEqualsString('testExpandPath_AppendWithoutSlash', 'abc\def\xyz', tmpResult);
|
---|
256 | end;
|
---|
257 |
|
---|
258 |
|
---|
259 | Procedure testExpandPath_AppendWithSlashAtEnd;
|
---|
260 | var
|
---|
261 | tmpResult : String;
|
---|
262 | begin
|
---|
263 | tmpResult := ExpandPath('abc\def', 'xyz\');
|
---|
264 |
|
---|
265 | assertEqualsString('testExpandPath_AppendWithSlashAtEnd', 'abc\def\xyz', tmpResult);
|
---|
266 | end;
|
---|
267 |
|
---|
268 |
|
---|
269 | Procedure testExpandPath_WithDot;
|
---|
270 | var
|
---|
271 | tmpResult : String;
|
---|
272 | begin
|
---|
273 | tmpResult := ExpandPath('abc\def', 'xyz\.\abc');
|
---|
274 |
|
---|
275 | assertEqualsString('testExpandPath_WithDot', 'abc\def\xyz\abc', tmpResult);
|
---|
276 | end;
|
---|
277 |
|
---|
278 |
|
---|
279 | Procedure testExpandPath_WithDotAtEnd;
|
---|
280 | var
|
---|
281 | tmpResult : String;
|
---|
282 | begin
|
---|
283 | tmpResult := ExpandPath('abc\def', 'xyz\.');
|
---|
284 |
|
---|
285 | assertEqualsString('testExpandPath_WithDotAtEnd', 'abc\def\xyz', tmpResult);
|
---|
286 | end;
|
---|
287 |
|
---|
288 |
|
---|
289 | Procedure testExpandPath_WithDots;
|
---|
290 | var
|
---|
291 | tmpResult : String;
|
---|
292 | begin
|
---|
293 | tmpResult := ExpandPath('abc\def', 'xyz\..\abc');
|
---|
294 |
|
---|
295 | assertEqualsString('testExpandPath_WithDots', 'abc\def\abc', tmpResult);
|
---|
296 | end;
|
---|
297 |
|
---|
298 |
|
---|
299 | Procedure testExpandPath_WithDotsAtEnd;
|
---|
300 | var
|
---|
301 | tmpResult : String;
|
---|
302 | begin
|
---|
303 | tmpResult := ExpandPath('abc\def', 'xyz\..');
|
---|
304 |
|
---|
305 | assertEqualsString('testExpandPath_WithDotsAtEnd', 'abc\def', tmpResult);
|
---|
306 | end;
|
---|
307 |
|
---|
308 |
|
---|
309 | Procedure testExpandPath_WithDotsInFront;
|
---|
310 | var
|
---|
311 | tmpResult : String;
|
---|
312 | begin
|
---|
313 | tmpResult := ExpandPath('abc\def', '..\xyz');
|
---|
314 |
|
---|
315 | assertEqualsString('testExpandPath_WithDotsInFront', 'abc\xyz', tmpResult);
|
---|
316 | end;
|
---|
317 |
|
---|
318 |
|
---|
319 | Procedure testExpandPath_WithDotsInFrontReachingRoot;
|
---|
320 | var
|
---|
321 | tmpResult : String;
|
---|
322 | begin
|
---|
323 | tmpResult := ExpandPath('abc\def', '..\..\xyz');
|
---|
324 |
|
---|
325 | assertEqualsString('testExpandPath_WithDotsInFrontReachingRoot', '\xyz', tmpResult);
|
---|
326 | end;
|
---|
327 |
|
---|
328 |
|
---|
329 | Procedure testExpandPath_WithDotsInFrontReachingDrive;
|
---|
330 | var
|
---|
331 | tmpResult : String;
|
---|
332 | begin
|
---|
333 | tmpResult := ExpandPath('c:\abc\def', '..\..\xyz');
|
---|
334 |
|
---|
335 | assertEqualsString('testExpandPath_WithDotsInFront', 'c:\xyz', tmpResult);
|
---|
336 | end;
|
---|
337 |
|
---|
338 |
|
---|
339 | Procedure testExpandPath_WithDotsInFrontLeavingRoot;
|
---|
340 | var
|
---|
341 | tmpResult : String;
|
---|
342 | begin
|
---|
343 | tmpResult := ExpandPath('abc\def', '..\..\..\xyz');
|
---|
344 |
|
---|
345 | assertEqualsString('testExpandPath_WithDotsInFrontLeavingRoot', '\xyz', tmpResult);
|
---|
346 | end;
|
---|
347 |
|
---|
348 |
|
---|
349 | Procedure testExpandPath_WithDotsInFrontLeavingDrive;
|
---|
350 | var
|
---|
351 | tmpResult : String;
|
---|
352 | begin
|
---|
353 | tmpResult := ExpandPath('c:\abc\def', '..\..\..\xyz');
|
---|
354 |
|
---|
355 | assertEqualsString('testExpandPath_WithDotsInFrontLeavingDrive', 'c:\xyz', tmpResult);
|
---|
356 | end;
|
---|
357 |
|
---|
358 |
|
---|
359 | // ----------------------------------------------------------
|
---|
360 |
|
---|
361 |
|
---|
362 | Procedure testGetLogFilesDir;
|
---|
363 | var
|
---|
364 | tmpResult : String;
|
---|
365 | begin
|
---|
366 | tmpResult := GetLogFilesDir;
|
---|
367 |
|
---|
368 | assertEqualsString('testGetLogFilesDir', 'C:\var\log\', tmpResult);
|
---|
369 | end;
|
---|
370 |
|
---|
371 |
|
---|
372 | // ----------------------------------------------------------
|
---|
373 |
|
---|
374 | Procedure testSearchPath_Found;
|
---|
375 | var
|
---|
376 | tmpResult : Boolean;
|
---|
377 | tmpResultFilename : String;
|
---|
378 | begin
|
---|
379 | tmpResult := SearchPath('BOOKSHELF', 'CMDREF.INF', tmpResultFilename);
|
---|
380 |
|
---|
381 | assertTrue('testSearchPath_Found', tmpResult);
|
---|
382 | assertEqualsString('testSearchPath_Found', 'C:\OS2\BOOK\CMDREF.INF', tmpResultFilename);
|
---|
383 | end;
|
---|
384 |
|
---|
385 |
|
---|
386 | Procedure testSearchPath_FoundMixedCase;
|
---|
387 | var
|
---|
388 | tmpResult : Boolean;
|
---|
389 | tmpResultFilename : String;
|
---|
390 | begin
|
---|
391 | tmpResult := SearchPath('BOOKSHELF', 'cMdRef.iNf', tmpResultFilename);
|
---|
392 |
|
---|
393 | assertTrue('testSearchPath_FoundMixedCase', tmpResult);
|
---|
394 | assertEqualsString('testSearchPath_FoundMixedCase', 'C:\OS2\BOOK\cMdRef.iNf', tmpResultFilename);
|
---|
395 | end;
|
---|
396 |
|
---|
397 |
|
---|
398 | Procedure testSearchPath_NotFound;
|
---|
399 | var
|
---|
400 | tmpResult : Boolean;
|
---|
401 | tmpResultFilename : String;
|
---|
402 | begin
|
---|
403 | tmpResult := SearchPath('BOOKSHELF', 'RBRi.INF', tmpResultFilename);
|
---|
404 |
|
---|
405 | assertFalse('testSearchPath_NotFound', tmpResult);
|
---|
406 | assertEqualsString('testSearchPath_NotFound', '', tmpResultFilename);
|
---|
407 | end;
|
---|
408 |
|
---|
409 |
|
---|
410 | Procedure testSearchPath_NotExistingEnvironment;
|
---|
411 | var
|
---|
412 | tmpResult : Boolean;
|
---|
413 | tmpResultFilename : String;
|
---|
414 | begin
|
---|
415 | tmpResult := SearchPath('BUECHER', 'RBRi.INF', tmpResultFilename);
|
---|
416 |
|
---|
417 | assertFalse('testSearchPath_NotExistingEnvironment', tmpResult);
|
---|
418 | assertEqualsString('testSearchPath_NotExistingEnvironment', '', tmpResultFilename);
|
---|
419 | end;
|
---|
420 |
|
---|
421 | // ----------------------------------------------------------
|
---|
422 |
|
---|
423 | Procedure testSearchHelpPaths_FoundBookshelf;
|
---|
424 | var
|
---|
425 | tmpResult : Boolean;
|
---|
426 | tmpResultFilename : String;
|
---|
427 | begin
|
---|
428 | tmpResult := SearchHelpPaths('CMDREF.INF', tmpResultFilename, false);
|
---|
429 |
|
---|
430 | assertTrue('testSearchHelpPaths_FoundBookshelf', tmpResult);
|
---|
431 | assertEqualsString('testSearchHelpPaths_FoundBookshelf', 'C:\OS2\BOOK\CMDREF.INF', tmpResultFilename);
|
---|
432 | end;
|
---|
433 |
|
---|
434 |
|
---|
435 | Procedure testSearchHelpPaths_FoundHelp;
|
---|
436 | var
|
---|
437 | tmpResult : Boolean;
|
---|
438 | tmpResultFilename : String;
|
---|
439 | begin
|
---|
440 | tmpResult := SearchHelpPaths('WPHELP.HLP', tmpResultFilename, false);
|
---|
441 |
|
---|
442 | assertTrue('testSearchHelpPaths_FoundHelp', tmpResult);
|
---|
443 | assertEqualsString('testSearchHelpPaths_FoundHelp', 'C:\OS2\HELP\WPHELP.HLP', tmpResultFilename);
|
---|
444 | end;
|
---|
445 |
|
---|
446 | { . is part of the helppath
|
---|
447 | Procedure testSearchHelpPaths_DontSearchInAppDir;
|
---|
448 | var
|
---|
449 | tmpResult : Boolean;
|
---|
450 | tmpResultFilename : String;
|
---|
451 | begin
|
---|
452 | tmpResult := SearchHelpPaths('NewViewTests.EXE', tmpResultFilename, False);
|
---|
453 |
|
---|
454 | assertFalse('testSearchHelpPaths_DontSearchInAppDir', tmpResult);
|
---|
455 | assertEqualsString('testSearchHelpPaths_DontSearchInAppDir', '', tmpResultFilename);
|
---|
456 | end;
|
---|
457 | }
|
---|
458 |
|
---|
459 | Procedure testSearchHelpPaths_FoundInAppDir;
|
---|
460 | var
|
---|
461 | tmpResult : Boolean;
|
---|
462 | tmpResultFilename : String;
|
---|
463 | begin
|
---|
464 | tmpResult := SearchHelpPaths('NewViewTests.EXE', tmpResultFilename, True);
|
---|
465 |
|
---|
466 | assertTrue('testSearchHelpPaths_FoundInAppDir', tmpResult);
|
---|
467 | assertEqualsString('testSearchHelpPaths_FoundInAppDir', TEST_PATH + '\build\unittest\NewViewTests.EXE', tmpResultFilename);
|
---|
468 | end;
|
---|
469 |
|
---|
470 |
|
---|
471 | Procedure testSearchHelpPaths_NotFoundInAppDir;
|
---|
472 | var
|
---|
473 | tmpResult : Boolean;
|
---|
474 | tmpResultFilename : String;
|
---|
475 | begin
|
---|
476 | tmpResult := SearchHelpPaths('NewView.EXE', tmpResultFilename, True);
|
---|
477 |
|
---|
478 | assertFalse('testSearchHelpPaths_NotFoundInAppDir', tmpResult);
|
---|
479 | assertEqualsString('testSearchHelpPaths_NotFoundInAppDir', '', tmpResultFilename);
|
---|
480 | end;
|
---|
481 |
|
---|
482 | // ----------------------------------------------------------
|
---|
483 |
|
---|
484 | Procedure testFindDefaultLanguageHelpFile;
|
---|
485 | var
|
---|
486 | tmpResult : String;
|
---|
487 | begin
|
---|
488 | tmpResult := FindDefaultLanguageHelpFile('NewView', '');
|
---|
489 |
|
---|
490 | assertEqualsIgnoreCaseString('testFindDefaultLanguageHelpFile', 'C:\ecs\help\NewView.hlp', tmpResult);
|
---|
491 | end;
|
---|
492 |
|
---|
493 | Procedure testFindDefaultLanguageHelpFile_it;
|
---|
494 | var
|
---|
495 | tmpResult : String;
|
---|
496 | begin
|
---|
497 | tmpResult := FindDefaultLanguageHelpFile('NewView', 'it');
|
---|
498 |
|
---|
499 | assertEqualsIgnoreCaseString('testFindDefaultLanguageHelpFile_it', 'C:\ecs\help\NewView_it.hlp', tmpResult);
|
---|
500 | end;
|
---|
501 |
|
---|
502 | Procedure testFindDefaultLanguageHelpFile_it_UpperCase;
|
---|
503 | var
|
---|
504 | tmpResult : String;
|
---|
505 | begin
|
---|
506 | tmpResult := FindDefaultLanguageHelpFile('NewView', 'IT');
|
---|
507 |
|
---|
508 | assertEqualsIgnoreCaseString('testFindDefaultLanguageHelpFile_it_UpperCase', 'C:\ecs\help\NewView_IT.hlp', tmpResult);
|
---|
509 | end;
|
---|
510 |
|
---|
511 |
|
---|
512 | // ----------------------------------------------------------
|
---|
513 |
|
---|
514 |
|
---|
515 | Procedure testGetDirsInPath_Unknown;
|
---|
516 | var
|
---|
517 | tmpResult : TStringList;
|
---|
518 | begin
|
---|
519 | tmpResult := TStringList.Create;
|
---|
520 | tmpResult.Add('Tester');
|
---|
521 |
|
---|
522 | GetDirsInPath('Unknown', tmpResult);
|
---|
523 |
|
---|
524 | assertEqualsInt('testGetDirsInPath_Unknown', 0, tmpResult.count);
|
---|
525 |
|
---|
526 | tmpResult.Destroy;
|
---|
527 | end;
|
---|
528 |
|
---|
529 |
|
---|
530 | Procedure testGetDirsInPath_Help;
|
---|
531 | var
|
---|
532 | tmpResult : TStringList;
|
---|
533 | begin
|
---|
534 | tmpResult := TStringList.Create;
|
---|
535 | tmpResult.Add('Tester');
|
---|
536 |
|
---|
537 | GetDirsInPath('HELP', tmpResult);
|
---|
538 |
|
---|
539 | assertEqualsInt('testGetDirsInPath_Help', 11, tmpResult.count);
|
---|
540 | assertEqualsString('testGetDirsInPath_Help', 'D:\progs\watcom\BINP\HELP', tmpResult[0]);
|
---|
541 | assertEqualsString('testGetDirsInPath_Help', 'C:\PROGRAMS\4OS2', tmpResult[10]);
|
---|
542 |
|
---|
543 | tmpResult.Destroy;
|
---|
544 | end;
|
---|
545 |
|
---|
546 | // ----------------------------------------------------------
|
---|
547 |
|
---|
548 | Procedure testListFilesInDirectory_NoFiles;
|
---|
549 | var
|
---|
550 | tmpResult : TStringList;
|
---|
551 | begin
|
---|
552 | tmpResult := TStringList.Create;
|
---|
553 |
|
---|
554 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.jonas', false, tmpResult);
|
---|
555 |
|
---|
556 | assertEqualsInt('testListFilesInDirectory_NoFiles', 0, tmpResult.count);
|
---|
557 | end;
|
---|
558 |
|
---|
559 |
|
---|
560 | Procedure testListFilesInDirectory_EmptyFilter;
|
---|
561 | var
|
---|
562 | tmpResult : TStringList;
|
---|
563 | begin
|
---|
564 | tmpResult := TStringList.Create;
|
---|
565 |
|
---|
566 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '', false, tmpResult);
|
---|
567 |
|
---|
568 | assertEqualsInt('testListFilesInDirectory_EmptyFilter', 0, tmpResult.count);
|
---|
569 |
|
---|
570 | tmpResult.Destroy;
|
---|
571 | end;
|
---|
572 |
|
---|
573 |
|
---|
574 | Procedure testListFilesInDirectory_OneFile;
|
---|
575 | var
|
---|
576 | tmpResult : TStringList;
|
---|
577 | begin
|
---|
578 | tmpResult := TStringList.Create;
|
---|
579 |
|
---|
580 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.txt', false, tmpResult);
|
---|
581 |
|
---|
582 | assertEqualsInt('testListFilesInDirectory_OneFile', 1, tmpResult.count);
|
---|
583 | assertEqualsString('testListFilesInDirectory_OneFile', 'readme.txt', tmpResult[0]);
|
---|
584 |
|
---|
585 | tmpResult.Destroy;
|
---|
586 | end;
|
---|
587 |
|
---|
588 |
|
---|
589 | Procedure testListFilesInDirectory_ManyFiles;
|
---|
590 | var
|
---|
591 | tmpResult : TStringList;
|
---|
592 | begin
|
---|
593 | tmpResult := TStringList.Create;
|
---|
594 |
|
---|
595 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.*', false, tmpResult);
|
---|
596 |
|
---|
597 | assertEqualsInt('testListFilesInDirectory_ManyFiles', 6, tmpResult.count);
|
---|
598 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'file0', tmpResult[0]);
|
---|
599 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'file1.ex1', tmpResult[1]);
|
---|
600 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'file2.ex1', tmpResult[2]);
|
---|
601 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'file3.ex3', tmpResult[3]);
|
---|
602 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'file4.ext4', tmpResult[4]);
|
---|
603 |
|
---|
604 | tmpResult.Destroy;
|
---|
605 | end;
|
---|
606 |
|
---|
607 |
|
---|
608 | Procedure testListFilesInDirectory_ManyFilter;
|
---|
609 | var
|
---|
610 | tmpResult : TStringList;
|
---|
611 | begin
|
---|
612 | tmpResult := TStringList.Create;
|
---|
613 |
|
---|
614 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.txt;f*.ex1', false, tmpResult);
|
---|
615 |
|
---|
616 | assertEqualsInt('testListFilesInDirectory_ManyFilter', 3, tmpResult.count);
|
---|
617 | assertEqualsString('testListFilesInDirectory_ManyFilter', 'readme.txt', tmpResult[0]);
|
---|
618 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'file1.ex1', tmpResult[1]);
|
---|
619 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'file2.ex1', tmpResult[2]);
|
---|
620 |
|
---|
621 | tmpResult.Destroy;
|
---|
622 | end;
|
---|
623 |
|
---|
624 |
|
---|
625 | // ----------------------------------------------------------
|
---|
626 |
|
---|
627 |
|
---|
628 | Procedure testListFilesInDirectoryWithDirectoryInResult_NoFiles;
|
---|
629 | var
|
---|
630 | tmpResult : TStringList;
|
---|
631 | begin
|
---|
632 | tmpResult := TStringList.Create;
|
---|
633 |
|
---|
634 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.jonas', true, tmpResult);
|
---|
635 |
|
---|
636 | assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_NoFiles', 0, tmpResult.count);
|
---|
637 | end;
|
---|
638 |
|
---|
639 |
|
---|
640 | Procedure testListFilesInDirectoryWithDirectoryInResult_EmptyFilter;
|
---|
641 | var
|
---|
642 | tmpResult : TStringList;
|
---|
643 | begin
|
---|
644 | tmpResult := TStringList.Create;
|
---|
645 |
|
---|
646 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '', true, tmpResult);
|
---|
647 |
|
---|
648 | assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_EmptyFilter', 0, tmpResult.count);
|
---|
649 |
|
---|
650 | tmpResult.Destroy;
|
---|
651 | end;
|
---|
652 |
|
---|
653 |
|
---|
654 | Procedure testListFilesInDirectoryWithDirectoryInResult_OneFile;
|
---|
655 | var
|
---|
656 | tmpResult : TStringList;
|
---|
657 | begin
|
---|
658 | tmpResult := TStringList.Create;
|
---|
659 |
|
---|
660 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.txt', true, tmpResult);
|
---|
661 |
|
---|
662 | assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_OneFile', 1, tmpResult.count);
|
---|
663 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_OneFile', TEST_PATH + '\unittests\testdir' + '\readme.txt', tmpResult[0]);
|
---|
664 |
|
---|
665 | tmpResult.Destroy;
|
---|
666 | end;
|
---|
667 |
|
---|
668 |
|
---|
669 | Procedure testListFilesInDirectoryWithDirectoryInResult_ManyFiles;
|
---|
670 | var
|
---|
671 | tmpResult : TStringList;
|
---|
672 | begin
|
---|
673 | tmpResult := TStringList.Create;
|
---|
674 |
|
---|
675 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.*', true, tmpResult);
|
---|
676 |
|
---|
677 | assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', 6, tmpResult.count);
|
---|
678 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', TEST_PATH + '\unittests\testdir' + '\file0', tmpResult[0]);
|
---|
679 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', TEST_PATH + '\unittests\testdir' + '\file1.ex1', tmpResult[1]);
|
---|
680 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', TEST_PATH + '\unittests\testdir' + '\file2.ex1', tmpResult[2]);
|
---|
681 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', TEST_PATH + '\unittests\testdir' + '\file3.ex3', tmpResult[3]);
|
---|
682 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', TEST_PATH + '\unittests\testdir' + '\file4.ext4', tmpResult[4]);
|
---|
683 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', TEST_PATH + '\unittests\testdir' + '\readme.txt', tmpResult[5]);
|
---|
684 |
|
---|
685 | tmpResult.Destroy;
|
---|
686 | end;
|
---|
687 |
|
---|
688 |
|
---|
689 | Procedure testListFilesInDirectoryWithDirectoryInResult_ManyFilter;
|
---|
690 | var
|
---|
691 | tmpResult : TStringList;
|
---|
692 | begin
|
---|
693 | tmpResult := TStringList.Create;
|
---|
694 |
|
---|
695 | ListFilesInDirectory(TEST_PATH + '\unittests\testdir', '*.txt;f*.ex1', true, tmpResult);
|
---|
696 |
|
---|
697 | assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_ManyFilter', 3, tmpResult.count);
|
---|
698 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFilter', TEST_PATH + '\unittests\testdir' + '\readme.txt', tmpResult[0]);
|
---|
699 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFilter', TEST_PATH + '\unittests\testdir' + '\file1.ex1', tmpResult[1]);
|
---|
700 | assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFilter', TEST_PATH + '\unittests\testdir' + '\file2.ex1', tmpResult[2]);
|
---|
701 |
|
---|
702 | tmpResult.Destroy;
|
---|
703 | end;
|
---|
704 |
|
---|
705 | // ----------------------------------------------------------
|
---|
706 |
|
---|
707 | Procedure testListSubDirectories_None;
|
---|
708 | var
|
---|
709 | tmpResult : TStringList;
|
---|
710 | begin
|
---|
711 | tmpResult := TStringList.Create;
|
---|
712 |
|
---|
713 | ListSubDirectories(TEST_PATH + '\unittests\testdir\subdir1', false, tmpResult);
|
---|
714 |
|
---|
715 | assertEqualsInt('testListSubDirectories_None', 0, tmpResult.count);
|
---|
716 |
|
---|
717 | tmpResult.Destroy;
|
---|
718 | end;
|
---|
719 |
|
---|
720 |
|
---|
721 | Procedure testListSubDirectories_NoneWithHidden;
|
---|
722 | var
|
---|
723 | tmpResult : TStringList;
|
---|
724 | begin
|
---|
725 | tmpResult := TStringList.Create;
|
---|
726 |
|
---|
727 | ListSubDirectories(TEST_PATH + '\unittests\testdir\subdir1', true, tmpResult);
|
---|
728 |
|
---|
729 | assertEqualsInt('testListSubDirectories_NoneWithHidden', 0, tmpResult.count);
|
---|
730 |
|
---|
731 | tmpResult.Destroy;
|
---|
732 | end;
|
---|
733 |
|
---|
734 |
|
---|
735 | Procedure testListSubDirectories_Many;
|
---|
736 | var
|
---|
737 | tmpResult : TStringList;
|
---|
738 | begin
|
---|
739 | tmpResult := TStringList.Create;
|
---|
740 |
|
---|
741 | ListSubDirectories(TEST_PATH + '\unittests\testdir', false, tmpResult);
|
---|
742 |
|
---|
743 | assertEqualsInt('testListSubDirectories_Many', 3, tmpResult.count);
|
---|
744 | assertEqualsString('testListSubDirectories_Many', TEST_PATH + '\unittests\testdir\dir_archived', tmpResult[0]);
|
---|
745 | assertEqualsString('testListSubDirectories_Many', TEST_PATH + '\unittests\testdir\dir_readonly', tmpResult[1]);
|
---|
746 | assertEqualsString('testListSubDirectories_Many', TEST_PATH + '\unittests\testdir\subdir1', tmpResult[2]);
|
---|
747 |
|
---|
748 | tmpResult.Destroy;
|
---|
749 | end;
|
---|
750 |
|
---|
751 |
|
---|
752 | Procedure testListSubDirectories_ManyWithHidden;
|
---|
753 | var
|
---|
754 | tmpResult : TStringList;
|
---|
755 | begin
|
---|
756 | tmpResult := TStringList.Create;
|
---|
757 |
|
---|
758 | ListSubDirectories(TEST_PATH + '\unittests\testdir', true, tmpResult);
|
---|
759 |
|
---|
760 | assertEqualsInt('testListSubDirectories_ManyWithHidden', 5, tmpResult.count);
|
---|
761 | assertEqualsString('testListSubDirectories_ManyWithHidden', TEST_PATH + '\unittests\testdir\dir_archived', tmpResult[0]);
|
---|
762 | assertEqualsString('testListSubDirectories_ManyWithHidden', TEST_PATH + '\unittests\testdir\dir_hidden', tmpResult[1]);
|
---|
763 | assertEqualsString('testListSubDirectories_ManyWithHidden', TEST_PATH + '\unittests\testdir\dir_readonly', tmpResult[2]);
|
---|
764 | assertEqualsString('testListSubDirectories_ManyWithHidden', TEST_PATH + '\unittests\testdir\dir_system', tmpResult[3]);
|
---|
765 | assertEqualsString('testListSubDirectories_ManyWithHidden', TEST_PATH + '\unittests\testdir\subdir1', tmpResult[4]);
|
---|
766 |
|
---|
767 | tmpResult.Destroy;
|
---|
768 | end;
|
---|
769 |
|
---|
770 |
|
---|
771 | // ----------------------------------------------------------
|
---|
772 |
|
---|
773 |
|
---|
774 | Procedure testListFilesInDirectoryRecursiveWithTermination;
|
---|
775 | var
|
---|
776 | tmpResult : TStringList;
|
---|
777 | begin
|
---|
778 | tmpResult := TStringList.Create;
|
---|
779 |
|
---|
780 | ListFilesInDirectoryRecursiveWithTermination(TEST_PATH + '\unittests\testdir', '*.ex1;ex2;file_in_*', false, false, tmpResult, nil, false);
|
---|
781 |
|
---|
782 | assertEqualsInt('testListFilesInDirectoryRecursiveWithTermination', 5, tmpResult.count);
|
---|
783 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination 0', 'file1.ex1', tmpResult[0]);
|
---|
784 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination 1', 'file2.ex1', tmpResult[1]);
|
---|
785 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination 2', 'file_in_archived', tmpResult[2]);
|
---|
786 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination 3', 'file_in_readonly', tmpResult[3]);
|
---|
787 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination 4', 'file1.ex1', tmpResult[4]);
|
---|
788 |
|
---|
789 | tmpResult.Destroy;
|
---|
790 | end;
|
---|
791 |
|
---|
792 |
|
---|
793 | Procedure testListFilesInDirectoryRecursiveWithTermination_WithHidden;
|
---|
794 | var
|
---|
795 | tmpResult : TStringList;
|
---|
796 | begin
|
---|
797 | tmpResult := TStringList.Create;
|
---|
798 |
|
---|
799 | ListFilesInDirectoryRecursiveWithTermination(TEST_PATH + '\unittests\testdir', '*.ex1;ex2;file_in_*', false, true, tmpResult, nil, false);
|
---|
800 |
|
---|
801 | assertEqualsInt('testListFilesInDirectoryRecursiveWithTermination_WithHidden', 7, tmpResult.count);
|
---|
802 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithHidden 0', 'file1.ex1', tmpResult[0]);
|
---|
803 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithHidden 1', 'file2.ex1', tmpResult[1]);
|
---|
804 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithHidden 2', 'file_in_archived', tmpResult[2]);
|
---|
805 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithHidden 5', 'file_in_hidden', tmpResult[3]);
|
---|
806 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithHidden 8', 'file_in_readonly', tmpResult[4]);
|
---|
807 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithHidden 11', 'file_in_system', tmpResult[5]);
|
---|
808 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithHidden 14', 'file1.ex1', tmpResult[6]);
|
---|
809 |
|
---|
810 | tmpResult.Destroy;
|
---|
811 | end;
|
---|
812 |
|
---|
813 |
|
---|
814 | Procedure testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden;
|
---|
815 | var
|
---|
816 | tmpResult : TStringList;
|
---|
817 | begin
|
---|
818 | tmpResult := TStringList.Create;
|
---|
819 |
|
---|
820 | ListFilesInDirectoryRecursiveWithTermination(TEST_PATH + '\unittests\testdir', '*.ex1;ex2;file_in_*', true, true, tmpResult, nil, false);
|
---|
821 |
|
---|
822 | assertEqualsInt('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden', 7, tmpResult.count);
|
---|
823 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden 0', TEST_PATH + '\unittests\testdir\' + 'file1.ex1', tmpResult[0]);
|
---|
824 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden 1', TEST_PATH + '\unittests\testdir\' + 'file2.ex1', tmpResult[1]);
|
---|
825 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden 2', TEST_PATH + '\unittests\testdir\dir_archived\' + 'file_in_archived', tmpResult[2]);
|
---|
826 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden 5', TEST_PATH + '\unittests\testdir\dir_hidden\' + 'file_in_hidden', tmpResult[3]);
|
---|
827 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden 8', TEST_PATH + '\unittests\testdir\dir_readonly\' + 'file_in_readonly', tmpResult[4]);
|
---|
828 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden 11', TEST_PATH + '\unittests\testdir\dir_system\' + 'file_in_system', tmpResult[5]);
|
---|
829 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden 14', TEST_PATH + '\unittests\testdir\subdir1\' + 'file1.ex1', tmpResult[6]);
|
---|
830 |
|
---|
831 | tmpResult.Destroy;
|
---|
832 | end;
|
---|
833 |
|
---|
834 |
|
---|
835 | Procedure testListFilesInDirectoryRecursiveWithTermination_WithDirectoryInResult;
|
---|
836 | var
|
---|
837 | tmpResult : TStringList;
|
---|
838 | begin
|
---|
839 | tmpResult := TStringList.Create;
|
---|
840 |
|
---|
841 | ListFilesInDirectoryRecursiveWithTermination(TEST_PATH + '\unittests\testdir', '*.ex1;ex2', true, false, tmpResult, nil, false);
|
---|
842 |
|
---|
843 | assertEqualsInt('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult', 3, tmpResult.count);
|
---|
844 | assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult', TEST_PATH + '\unittests\testdir' + '\file1.ex1', tmpResult[0]);
|
---|
845 | assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult', TEST_PATH + '\unittests\testdir' + '\file2.ex1', tmpResult[1]);
|
---|
846 | assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult', TEST_PATH + '\unittests\testdir' + '\subdir1\file1.ex1', tmpResult[2]);
|
---|
847 |
|
---|
848 | tmpResult.Destroy;
|
---|
849 | end;
|
---|
850 |
|
---|
851 |
|
---|
852 | Procedure testListFilesInDirectoryRecursiveWithTermination_1WithDirectoryInResultWithHidden;
|
---|
853 | var
|
---|
854 | tmpResult : TStringList;
|
---|
855 | begin
|
---|
856 | tmpResult := TStringList.Create;
|
---|
857 |
|
---|
858 | ListFilesInDirectoryRecursiveWithTermination(TEST_PATH + '\unittests\testdir', '*.ex1;ex2', true, true, tmpResult, nil, false);
|
---|
859 |
|
---|
860 | assertEqualsInt('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResultWithHidden', 3, tmpResult.count);
|
---|
861 | assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResultWithHidden', TEST_PATH + '\unittests\testdir' + '\file1.ex1', tmpResult[0]);
|
---|
862 | assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResultWithHidden', TEST_PATH + '\unittests\testdir' + '\file2.ex1', tmpResult[1]);
|
---|
863 | assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResultWithHidden', TEST_PATH + '\unittests\testdir' + '\subdir1\file1.ex1', tmpResult[2]);
|
---|
864 |
|
---|
865 | tmpResult.Destroy;
|
---|
866 | end;
|
---|
867 |
|
---|
868 |
|
---|
869 | // ----------------------------------------------------------
|
---|
870 |
|
---|
871 |
|
---|
872 | Procedure testParentDir_Empty;
|
---|
873 | var
|
---|
874 | tmpResult : String;
|
---|
875 | begin
|
---|
876 | tmpResult := ParentDir('');
|
---|
877 |
|
---|
878 | assertEqualsString('testParentDir_Empty', '', tmpResult);
|
---|
879 | end;
|
---|
880 |
|
---|
881 |
|
---|
882 | Procedure testParentDir_Root;
|
---|
883 | var
|
---|
884 | tmpResult : String;
|
---|
885 | begin
|
---|
886 | tmpResult := ParentDir('C:\');
|
---|
887 |
|
---|
888 | assertEqualsString('testParentDir_Root', '', tmpResult);
|
---|
889 | end;
|
---|
890 |
|
---|
891 |
|
---|
892 | Procedure testParentDir_UnixRoot;
|
---|
893 | var
|
---|
894 | tmpResult : String;
|
---|
895 | begin
|
---|
896 | tmpResult := ParentDir('\');
|
---|
897 |
|
---|
898 | assertEqualsString('testParentDir_UnixRoot', '', tmpResult);
|
---|
899 | end;
|
---|
900 |
|
---|
901 |
|
---|
902 | Procedure testParentDir;
|
---|
903 | var
|
---|
904 | tmpResult : String;
|
---|
905 | begin
|
---|
906 | tmpResult := ParentDir('\abc\def');
|
---|
907 |
|
---|
908 | assertEqualsString('testParentDir', '\abc', tmpResult);
|
---|
909 | end;
|
---|
910 |
|
---|
911 |
|
---|
912 | Procedure testParentDir_OnlyOne;
|
---|
913 | var
|
---|
914 | tmpResult : String;
|
---|
915 | begin
|
---|
916 | tmpResult := ParentDir('\abc');
|
---|
917 |
|
---|
918 | assertEqualsString('testParentDir_OnlyOne', '', tmpResult);
|
---|
919 | end;
|
---|
920 |
|
---|
921 |
|
---|
922 | Procedure testParentDir_SlashAtEnd;
|
---|
923 | var
|
---|
924 | tmpResult : String;
|
---|
925 | begin
|
---|
926 | tmpResult := ParentDir('\abc\def\');
|
---|
927 |
|
---|
928 | assertEqualsString('testParentDir_SlashAtEnd', '\abc', tmpResult);
|
---|
929 | end;
|
---|
930 |
|
---|
931 |
|
---|
932 | Procedure testParentDir_NoSlashAtStart;
|
---|
933 | var
|
---|
934 | tmpResult : String;
|
---|
935 | begin
|
---|
936 | tmpResult := ParentDir('abc\def\');
|
---|
937 |
|
---|
938 | assertEqualsString('testParentDir_NoSlashAtStart', 'abc', tmpResult);
|
---|
939 | end;
|
---|
940 |
|
---|
941 |
|
---|
942 | Procedure testParentDir_NoSlash;
|
---|
943 | var
|
---|
944 | tmpResult : String;
|
---|
945 | begin
|
---|
946 | tmpResult := ParentDir('abc');
|
---|
947 |
|
---|
948 | assertEqualsString('testParentDir_NoSlash', '', tmpResult);
|
---|
949 | end;
|
---|
950 |
|
---|
951 |
|
---|
952 | Procedure testParentDir_GoToRootDrive;
|
---|
953 | var
|
---|
954 | tmpResult : String;
|
---|
955 | begin
|
---|
956 | tmpResult := ParentDir('c:\abc');
|
---|
957 |
|
---|
958 | assertEqualsString('testParentDir_GoToRootDrive', 'c:', tmpResult);
|
---|
959 | end;
|
---|
960 |
|
---|
961 |
|
---|
962 | // ----------------------------------------------------------
|
---|
963 |
|
---|
964 |
|
---|
965 | Procedure testMakeDirs_Empty;
|
---|
966 | var
|
---|
967 | tmpResult : String;
|
---|
968 | begin
|
---|
969 | tmpResult := MakeDirs('');
|
---|
970 |
|
---|
971 | assertEqualsString('testMakeDirs_Empty', '', tmpResult);
|
---|
972 | end;
|
---|
973 |
|
---|
974 |
|
---|
975 | Procedure testMakeDirs_Slash;
|
---|
976 | var
|
---|
977 | tmpResult : String;
|
---|
978 | begin
|
---|
979 | tmpResult := MakeDirs('\');
|
---|
980 |
|
---|
981 | assertEqualsString('testMakeDirs_Slash', '', tmpResult);
|
---|
982 | end;
|
---|
983 |
|
---|
984 |
|
---|
985 | Procedure testMakeDirs_Simple;
|
---|
986 | var
|
---|
987 | tmpResult : String;
|
---|
988 | begin
|
---|
989 | RmDir(TEST_PATH + '\unittests\testdir\makedirs');
|
---|
990 |
|
---|
991 | tmpResult := MakeDirs(TEST_PATH + '\unittests\testdir' + '\makedirs');
|
---|
992 |
|
---|
993 | RmDir(TEST_PATH + '\unittests\testdir\makedirs');
|
---|
994 |
|
---|
995 | assertEqualsString('testMakeDirs_Simple', TEST_PATH + '\unittests\testdir\makedirs', tmpResult);
|
---|
996 | end;
|
---|
997 |
|
---|
998 |
|
---|
999 | Procedure testMakeDirs_Complex;
|
---|
1000 | var
|
---|
1001 | tmpResult : String;
|
---|
1002 | begin
|
---|
1003 | RmDir(TEST_PATH + '\unittests\testdir\makedirs\subdir\test');
|
---|
1004 | RmDir(TEST_PATH + '\unittests\testdir\makedirs\subdir');
|
---|
1005 | RmDir(TEST_PATH + '\unittests\testdir\makedirs');
|
---|
1006 |
|
---|
1007 | tmpResult := MakeDirs(TEST_PATH + '\unittests\testdir' + '\makedirs\subdir\test');
|
---|
1008 |
|
---|
1009 | RmDir(TEST_PATH + '\unittests\testdir\makedirs\subdir\test');
|
---|
1010 | RmDir(TEST_PATH + '\unittests\testdir\makedirs\subdir');
|
---|
1011 | RmDir(TEST_PATH + '\unittests\testdir\makedirs');
|
---|
1012 |
|
---|
1013 | assertEqualsString('testMakeDirs_Simple', TEST_PATH + '\unittests\testdir\makedirs\subdir\test', tmpResult);
|
---|
1014 | end;
|
---|
1015 |
|
---|
1016 |
|
---|
1017 | // ----------------------------------------------------------
|
---|
1018 |
|
---|
1019 |
|
---|
1020 | Procedure testDirectoryExists_Empty;
|
---|
1021 | var
|
---|
1022 | tmpResult : Boolean;
|
---|
1023 | begin
|
---|
1024 | tmpResult := DirectoryExists('');
|
---|
1025 |
|
---|
1026 | assertTrue('testDirectoryExists_Empty', tmpResult);
|
---|
1027 | end;
|
---|
1028 |
|
---|
1029 |
|
---|
1030 | Procedure testDirectoryExists_DriveOnlyLowercase;
|
---|
1031 | var
|
---|
1032 | tmpResult : Boolean;
|
---|
1033 | begin
|
---|
1034 | tmpResult := DirectoryExists('c:');
|
---|
1035 |
|
---|
1036 | assertTrue('testDirectoryExists_DriveOnlyLowercase', tmpResult);
|
---|
1037 | end;
|
---|
1038 |
|
---|
1039 |
|
---|
1040 | Procedure testDirectoryExists_DriveOnlyUppercase;
|
---|
1041 | var
|
---|
1042 | tmpResult : Boolean;
|
---|
1043 | begin
|
---|
1044 | tmpResult := DirectoryExists('C:');
|
---|
1045 |
|
---|
1046 | assertTrue('testDirectoryExists_DriveOnlyUppercase', tmpResult);
|
---|
1047 | end;
|
---|
1048 |
|
---|
1049 |
|
---|
1050 | Procedure testDirectoryExists_DriveOnlySlashAtEnd;
|
---|
1051 | var
|
---|
1052 | tmpResult : Boolean;
|
---|
1053 | begin
|
---|
1054 | tmpResult := DirectoryExists('C:\');
|
---|
1055 |
|
---|
1056 | assertTrue('testDirectoryExists_DriveOnlySlashAtEnd', tmpResult);
|
---|
1057 | end;
|
---|
1058 |
|
---|
1059 |
|
---|
1060 | Procedure testDirectoryExists_DriveAndPath;
|
---|
1061 | var
|
---|
1062 | tmpResult : Boolean;
|
---|
1063 | begin
|
---|
1064 | tmpResult := DirectoryExists('C:\os2\bitmap');
|
---|
1065 |
|
---|
1066 | assertTrue('testDirectoryExists_DriveAndPath', tmpResult);
|
---|
1067 | end;
|
---|
1068 |
|
---|
1069 |
|
---|
1070 | Procedure testDirectoryExists_DriveAndPathSlashAtEnd;
|
---|
1071 | var
|
---|
1072 | tmpResult : Boolean;
|
---|
1073 | begin
|
---|
1074 | tmpResult := DirectoryExists('C:\os2\bitmap\');
|
---|
1075 |
|
---|
1076 | assertTrue('testDirectoryExists_DriveAndPathSlashAtEnd', tmpResult);
|
---|
1077 | end;
|
---|
1078 |
|
---|
1079 |
|
---|
1080 | Procedure testDirectoryExists_InvalidDrive;
|
---|
1081 | var
|
---|
1082 | tmpResult : Boolean;
|
---|
1083 | begin
|
---|
1084 | tmpResult := DirectoryExists('y:');
|
---|
1085 |
|
---|
1086 | assertFalse('testDirectoryExists_InvalidDrive', tmpResult);
|
---|
1087 | end;
|
---|
1088 |
|
---|
1089 |
|
---|
1090 | Procedure testDirectoryExists_InvalidDriveAndPath;
|
---|
1091 | var
|
---|
1092 | tmpResult : Boolean;
|
---|
1093 | begin
|
---|
1094 | tmpResult := DirectoryExists('y:\test');
|
---|
1095 |
|
---|
1096 | assertFalse('testDirectoryExists_InvalidDriveAndPath', tmpResult);
|
---|
1097 | end;
|
---|
1098 |
|
---|
1099 |
|
---|
1100 | Procedure testDirectoryExists_NotExistent;
|
---|
1101 | var
|
---|
1102 | tmpResult : Boolean;
|
---|
1103 | begin
|
---|
1104 | tmpResult := DirectoryExists('C:\os2\bit\');
|
---|
1105 |
|
---|
1106 | assertFalse('testDirectoryExists_NotExistent', tmpResult);
|
---|
1107 | end;
|
---|
1108 |
|
---|
1109 |
|
---|
1110 | Procedure testDirectoryExists_Archived;
|
---|
1111 | var
|
---|
1112 | tmpResult : Boolean;
|
---|
1113 | begin
|
---|
1114 | tmpResult := DirectoryExists(TEST_PATH + '\unittests\testdir\dir_archived');
|
---|
1115 |
|
---|
1116 | assertTrue('testDirectoryExists_Archived', tmpResult);
|
---|
1117 | end;
|
---|
1118 |
|
---|
1119 |
|
---|
1120 | Procedure testDirectoryExists_Hidden;
|
---|
1121 | var
|
---|
1122 | tmpResult : Boolean;
|
---|
1123 | begin
|
---|
1124 | tmpResult := DirectoryExists(TEST_PATH + '\unittests\testdir\dir_hidden');
|
---|
1125 |
|
---|
1126 | assertTrue('testDirectoryExists_Hidden', tmpResult);
|
---|
1127 | end;
|
---|
1128 |
|
---|
1129 |
|
---|
1130 | Procedure testDirectoryExists_Readonly;
|
---|
1131 | var
|
---|
1132 | tmpResult : Boolean;
|
---|
1133 | begin
|
---|
1134 | tmpResult := DirectoryExists(TEST_PATH + '\unittests\testdir\dir_readonly');
|
---|
1135 |
|
---|
1136 | assertTrue('testDirectoryExists_Readonly', tmpResult);
|
---|
1137 | end;
|
---|
1138 |
|
---|
1139 |
|
---|
1140 | Procedure testDirectoryExists_System;
|
---|
1141 | var
|
---|
1142 | tmpResult : Boolean;
|
---|
1143 | begin
|
---|
1144 | tmpResult := DirectoryExists(TEST_PATH + '\unittests\testdir\dir_system');
|
---|
1145 |
|
---|
1146 | assertTrue('testDirectoryExists_System', tmpResult);
|
---|
1147 | end;
|
---|
1148 |
|
---|
1149 |
|
---|
1150 | // ----------------------------------------------------------
|
---|
1151 |
|
---|
1152 |
|
---|
1153 | Procedure testDriveLetterToDriveNumber;
|
---|
1154 | var
|
---|
1155 | tmpResult : longint;
|
---|
1156 | begin
|
---|
1157 | tmpResult := DriveLetterToDriveNumber('A');
|
---|
1158 |
|
---|
1159 | assertEqualsInt('testDriveLetterToDriveNumber', 1, tmpResult);
|
---|
1160 | end;
|
---|
1161 |
|
---|
1162 |
|
---|
1163 | Procedure testDriveLetterToDriveNumber_LowerCase;
|
---|
1164 | var
|
---|
1165 | tmpResult : longint;
|
---|
1166 | begin
|
---|
1167 | tmpResult := DriveLetterToDriveNumber('a');
|
---|
1168 |
|
---|
1169 | assertEqualsInt('testDriveLetterToDriveNumber_LowerCase', 1, tmpResult);
|
---|
1170 | end;
|
---|
1171 |
|
---|
1172 |
|
---|
1173 | Procedure testDriveLetterToDriveNumber_Unknown;
|
---|
1174 | var
|
---|
1175 | tmpResult : longint;
|
---|
1176 | begin
|
---|
1177 | tmpResult := DriveLetterToDriveNumber('');
|
---|
1178 |
|
---|
1179 | assertEqualsInt('testDriveLetterToDriveNumber_Unknown', 0, tmpResult);
|
---|
1180 | end;
|
---|
1181 |
|
---|
1182 |
|
---|
1183 | // ----------------------------------------------------------
|
---|
1184 |
|
---|
1185 |
|
---|
1186 | Procedure testDriveNumberToDriveLetter;
|
---|
1187 | begin
|
---|
1188 | assertEqualsString('testDriveNumberToDriveLetter 1', 'A', DriveNumberToDriveLetter(1));
|
---|
1189 | assertEqualsString('testDriveNumberToDriveLetter 2', 'B', DriveNumberToDriveLetter(2));
|
---|
1190 | end;
|
---|
1191 |
|
---|
1192 |
|
---|
1193 | // ----------------------------------------------------------
|
---|
1194 |
|
---|
1195 |
|
---|
1196 | Procedure testGetBootDriveLetter;
|
---|
1197 | var
|
---|
1198 | tmpResult : char;
|
---|
1199 | begin
|
---|
1200 | tmpResult := GetBootDriveLetter;
|
---|
1201 |
|
---|
1202 | assertEqualsString('testGetBootDriveLetter', 'C', tmpResult);
|
---|
1203 | end;
|
---|
1204 |
|
---|
1205 |
|
---|
1206 | // ----------------------------------------------------------
|
---|
1207 |
|
---|
1208 |
|
---|
1209 | Procedure testFileIsReadOnly_False;
|
---|
1210 | var
|
---|
1211 | tmpResult : boolean;
|
---|
1212 | begin
|
---|
1213 | tmpResult := FileIsReadOnly(GetBootDriveLetter + ':\config.sys');
|
---|
1214 |
|
---|
1215 | assertFalse('testFileIsReadOnly_False', tmpResult);
|
---|
1216 | end;
|
---|
1217 |
|
---|
1218 |
|
---|
1219 | Procedure testFileIsReadOnly_True;
|
---|
1220 | var
|
---|
1221 | tmpResult : boolean;
|
---|
1222 | begin
|
---|
1223 | tmpResult := FileIsReadOnly(GetBootDriveLetter + ':\os2ldr');
|
---|
1224 |
|
---|
1225 | assertTrue('testFileIsReadOnly_True', tmpResult);
|
---|
1226 | end;
|
---|
1227 |
|
---|
1228 |
|
---|
1229 | // ----------------------------------------------------------
|
---|
1230 |
|
---|
1231 |
|
---|
1232 | Function getFileUtilsUnitTests : TList;
|
---|
1233 | Begin
|
---|
1234 | result := TList.Create;
|
---|
1235 |
|
---|
1236 | result.add(@testAddDirectorySeparator_Empty);
|
---|
1237 | result.add(@testAddDirectorySeparator_SingleChar);
|
---|
1238 | result.add(@testAddDirectorySeparator_ManyChars);
|
---|
1239 | result.add(@testAddDirectorySeparator_SlashAtEnd);
|
---|
1240 |
|
---|
1241 | result.add(@testAddDirectorySeparatorIfNotEmpty_Empty);
|
---|
1242 | result.add(@testAddDirectorySeparatorIfNotEmpty_SingleChar);
|
---|
1243 | result.add(@testAddDirectorySeparatorIfNotEmpty_ManyChars);
|
---|
1244 | result.add(@testAddDirectorySeparatorIfNotEmpty_SlashAtEnd);
|
---|
1245 |
|
---|
1246 | result.add(@testRemoveRightDirectorySeparator_Empty);
|
---|
1247 | result.add(@testRemoveRightDirectorySeparator_WithoutSlash);
|
---|
1248 | result.add(@testRemoveRightDirectorySeparator_WithSlash);
|
---|
1249 |
|
---|
1250 | result.add(@testExpandPath_BothEmpty);
|
---|
1251 | result.add(@testExpandPath_PathEmpty);
|
---|
1252 | result.add(@testExpandPath_PathEmptyDirEndsWithSlash);
|
---|
1253 | result.add(@testExpandPath_AbsolutePath);
|
---|
1254 | result.add(@testExpandPath_DriveWithSlash);
|
---|
1255 | result.add(@testExpandPath_DriveWithoutSlash);
|
---|
1256 | result.add(@testExpandPath_RootPathForDrive);
|
---|
1257 | result.add(@testExpandPath_RootDirForDrive);
|
---|
1258 | result.add(@testExpandPath_RootPathWithoutDrive);
|
---|
1259 | result.add(@testExpandPath_RootDirWithoutDrive);
|
---|
1260 | result.add(@testExpandPath_AppendWithSlash);
|
---|
1261 | result.add(@testExpandPath_AppendWithoutSlash);
|
---|
1262 | result.add(@testExpandPath_AppendWithSlashAtEnd);
|
---|
1263 | result.add(@testExpandPath_WithDot);
|
---|
1264 | result.add(@testExpandPath_WithDotAtEnd);
|
---|
1265 | result.add(@testExpandPath_WithDots);
|
---|
1266 | result.add(@testExpandPath_WithDotsAtEnd);
|
---|
1267 | result.add(@testExpandPath_WithDotsInFront);
|
---|
1268 | result.add(@testExpandPath_WithDotsInFrontReachingRoot);
|
---|
1269 | result.add(@testExpandPath_WithDotsInFrontReachingDrive);
|
---|
1270 | result.add(@testExpandPath_WithDotsInFrontLeavingRoot);
|
---|
1271 | result.add(@testExpandPath_WithDotsInFrontLeavingDrive);
|
---|
1272 |
|
---|
1273 | result.add(@testGetLogFilesDir);
|
---|
1274 |
|
---|
1275 | result.add(@testSearchPath_Found);
|
---|
1276 | result.add(@testSearchPath_FoundMixedCase);
|
---|
1277 | result.add(@testSearchPath_NotFound);
|
---|
1278 | result.add(@testSearchPath_NotExistingEnvironment);
|
---|
1279 |
|
---|
1280 | result.add(@testSearchHelpPaths_FoundBookshelf);
|
---|
1281 | result.add(@testSearchHelpPaths_FoundHelp);
|
---|
1282 | // result.add(@testSearchHelpPaths_DontSearchInAppDir);
|
---|
1283 | result.add(@testSearchHelpPaths_FoundInAppDir);
|
---|
1284 | result.add(@testSearchHelpPaths_NotFoundInAppDir);
|
---|
1285 |
|
---|
1286 | result.add(@testFindDefaultLanguageHelpFile);
|
---|
1287 | result.add(@testFindDefaultLanguageHelpFile_it);
|
---|
1288 | result.add(@testFindDefaultLanguageHelpFile_it_UpperCase);
|
---|
1289 |
|
---|
1290 | result.add(@testGetDirsInPath_Unknown);
|
---|
1291 | result.add(@testGetDirsInPath_Help);
|
---|
1292 |
|
---|
1293 | result.add(@testListFilesInDirectory_NoFiles);
|
---|
1294 | result.add(@testListFilesInDirectory_EmptyFilter);
|
---|
1295 | result.add(@testListFilesInDirectory_OneFile);
|
---|
1296 | result.add(@testListFilesInDirectory_ManyFiles);
|
---|
1297 | result.add(@testListFilesInDirectory_ManyFilter);
|
---|
1298 | result.add(@testListFilesInDirectoryWithDirectoryInResult_NoFiles);
|
---|
1299 | result.add(@testListFilesInDirectoryWithDirectoryInResult_EmptyFilter);
|
---|
1300 | result.add(@testListFilesInDirectoryWithDirectoryInResult_OneFile);
|
---|
1301 | result.add(@testListFilesInDirectoryWithDirectoryInResult_ManyFiles);
|
---|
1302 | result.add(@testListFilesInDirectoryWithDirectoryInResult_ManyFilter);
|
---|
1303 |
|
---|
1304 | result.add(@testListSubDirectories_None);
|
---|
1305 | result.add(@testListSubDirectories_NoneWithHidden);
|
---|
1306 | result.add(@testListSubDirectories_Many);
|
---|
1307 | result.add(@testListSubDirectories_ManyWithHidden);
|
---|
1308 |
|
---|
1309 | result.add(@testListFilesInDirectoryRecursiveWithTermination);
|
---|
1310 | result.add(@testListFilesInDirectoryRecursiveWithTermination_WithHidden);
|
---|
1311 | result.add(@testListFilesInDirectoryRecursiveWithTermination_WithDirAndHidden);
|
---|
1312 | result.add(@testListFilesInDirectoryRecursiveWithTermination_WithDirectoryInResult);
|
---|
1313 | result.add(@testListFilesInDirectoryRecursiveWithTermination_1WithDirectoryInResultWithHidden);
|
---|
1314 |
|
---|
1315 | result.add(@testParentDir_Empty);
|
---|
1316 | result.add(@testParentDir_Root);
|
---|
1317 | result.add(@testParentDir_UnixRoot);
|
---|
1318 | result.add(@testParentDir);
|
---|
1319 | result.add(@testParentDir_OnlyOne);
|
---|
1320 | result.add(@testParentDir_SlashAtEnd);
|
---|
1321 | result.add(@testParentDir_NoSlashAtStart);
|
---|
1322 | result.add(@testParentDir_NoSlash);
|
---|
1323 | result.add(@testParentDir_GoToRootDrive);
|
---|
1324 |
|
---|
1325 | result.add(@testMakeDirs_Empty);
|
---|
1326 | result.add(@testMakeDirs_Slash);
|
---|
1327 | result.add(@testMakeDirs_Simple);
|
---|
1328 | result.add(@testMakeDirs_Complex);
|
---|
1329 |
|
---|
1330 | result.add(@testDirectoryExists_Empty);
|
---|
1331 | result.add(@testDirectoryExists_DriveOnlyLowercase);
|
---|
1332 | result.add(@testDirectoryExists_DriveOnlyUppercase);
|
---|
1333 | result.add(@testDirectoryExists_DriveOnlySlashAtEnd);
|
---|
1334 | result.add(@testDirectoryExists_DriveAndPath);
|
---|
1335 | result.add(@testDirectoryExists_DriveAndPathSlashAtEnd);
|
---|
1336 | result.add(@testDirectoryExists_InvalidDrive);
|
---|
1337 | result.add(@testDirectoryExists_InvalidDriveAndPath);
|
---|
1338 | result.add(@testDirectoryExists_NotExistent);
|
---|
1339 |
|
---|
1340 | result.add(@testDriveLetterToDriveNumber);
|
---|
1341 | result.add(@testDriveLetterToDriveNumber_LowerCase);
|
---|
1342 | result.add(@testDriveLetterToDriveNumber_Unknown);
|
---|
1343 |
|
---|
1344 | result.add(@testDriveNumberToDriveLetter);
|
---|
1345 |
|
---|
1346 | result.add(@testGetBootDriveLetter);
|
---|
1347 |
|
---|
1348 | result.add(@testFileIsReadOnly_False);
|
---|
1349 | result.add(@testFileIsReadOnly_True);
|
---|
1350 |
|
---|
1351 | end;
|
---|
1352 |
|
---|
1353 | End.
|
---|