source: trunk/NewView/unittests/FileUtilsUnitTests.pas@ 97

Last change on this file since 97 was 97, checked in by RBRi, 18 years ago

file util fix for the last refactoring

  • Property svn:eol-style set to native
File size: 27.9 KB
Line 
1Unit FileUtilsUnitTests;
2
3Interface
4
5uses
6 Classes,
7 TestAssert,
8 FileUtilsUnit;
9
10
11 FUNCTION getFileUtilsUnitTests : TList;
12
13
14Implementation
15
16 Procedure testAddDirectorySeparator_Empty;
17 var
18 tmpResult : String;
19 begin
20 tmpResult := AddDirectorySeparator('');
21
22 assertEqualsString('testAddDirectorySeparator_Empty', '\', tmpResult);
23 end;
24
25 Procedure testAddDirectorySeparator_SingleChar;
26 var
27 tmpResult : String;
28 begin
29 tmpResult := AddDirectorySeparator('x');
30
31 assertEqualsString('testAddDirectorySeparator_SingleChar', 'x\', tmpResult);
32 end;
33
34 Procedure testAddDirectorySeparator_ManyChars;
35 var
36 tmpResult : String;
37 begin
38 tmpResult := AddDirectorySeparator('xyz dkdj ');
39
40 assertEqualsString('testAddDirectorySeparator_ManyChars', 'xyz dkdj \', tmpResult);
41 end;
42
43
44 Procedure testAddDirectorySeparator_SlashAtEnd;
45 var
46 tmpResult : String;
47 begin
48 tmpResult := AddDirectorySeparator('xy\');
49
50 assertEqualsString('testAddDirectorySeparator_SlashAtEnd', 'xy\', tmpResult);
51 end;
52
53
54 // ----------------------------------------------------------
55
56
57 Procedure testAddDirectorySeparatorIfNotEmpty_Empty;
58 var
59 tmpResult : String;
60 begin
61 tmpResult := AddDirectorySeparatorIfNotEmpty('');
62
63 assertEqualsString('testAddDirectorySeparatorIfNotEmpty_Empty', '', tmpResult);
64 end;
65
66 Procedure testAddDirectorySeparatorIfNotEmpty_SingleChar;
67 var
68 tmpResult : String;
69 begin
70 tmpResult := AddDirectorySeparatorIfNotEmpty('x');
71
72 assertEqualsString('testAddDirectorySeparatorIfNotEmpty_SingleChar', 'x\', tmpResult);
73 end;
74
75 Procedure testAddDirectorySeparatorIfNotEmpty_ManyChars;
76 var
77 tmpResult : String;
78 begin
79 tmpResult := AddDirectorySeparatorIfNotEmpty('xyz dkdj ');
80
81 assertEqualsString('testAddDirectorySeparatorIfNotEmpty_ManyChars', 'xyz dkdj \', tmpResult);
82 end;
83
84
85 Procedure testAddDirectorySeparatorIfNotEmpty_SlashAtEnd;
86 var
87 tmpResult : String;
88 begin
89 tmpResult := AddDirectorySeparatorIfNotEmpty('xy\');
90
91 assertEqualsString('testAddDirectorySeparatorIfNotEmpty_SlashAtEnd', 'xy\', tmpResult);
92 end;
93
94
95 // ----------------------------------------------------------
96
97
98 Procedure testRemoveRightDirectorySeparator_Empty;
99 var
100 tmpResult : String;
101 begin
102 tmpResult := RemoveRightDirectorySeparator('');
103
104 assertEqualsString('testRemoveRightDirectorySeparator_Empty', '', tmpResult);
105 end;
106
107
108 Procedure testRemoveRightDirectorySeparator_WithoutSlash;
109 var
110 tmpResult : String;
111 begin
112 tmpResult := RemoveRightDirectorySeparator('abc');
113
114 assertEqualsString('testRemoveRightDirectorySeparator_WithoutSlash', 'abc', tmpResult);
115 end;
116
117
118 Procedure testRemoveRightDirectorySeparator_WithSlash;
119 var
120 tmpResult : String;
121 begin
122 tmpResult := RemoveRightDirectorySeparator('abc\');
123
124 assertEqualsString('testRemoveRightDirectorySeparator_WithSlash', 'abc', tmpResult);
125 end;
126
127
128 // ----------------------------------------------------------
129
130 Procedure testExpandPath_BothEmpty;
131 var
132 tmpResult : String;
133 begin
134 tmpResult := ExpandPath('', '');
135
136 assertEqualsString('testExpandPath_BothEmpty', '', tmpResult);
137 end;
138
139
140 Procedure testExpandPath_PathEmpty;
141 var
142 tmpResult : String;
143 begin
144 tmpResult := ExpandPath('\abc\def', '');
145
146 assertEqualsString('testExpandPath_PathEmpty', '\abc\def', tmpResult);
147 end;
148
149
150 Procedure testExpandPath_PathEmptyDirEndsWithSlash;
151 var
152 tmpResult : String;
153 begin
154 tmpResult := ExpandPath('\abc\def\', '');
155
156 assertEqualsString('testExpandPath_PathEmpty', '\abc\def', tmpResult);
157 end;
158
159
160 Procedure testExpandPath_AbsolutePath;
161 var
162 tmpResult : String;
163 begin
164 tmpResult := ExpandPath('\abc\def', 'c:\test');
165
166 assertEqualsString('testExpandPath_AbsolutePath', 'c:\test', tmpResult);
167 end;
168
169
170 Procedure testExpandPath_DriveWithSlash;
171 var
172 tmpResult : String;
173 begin
174 tmpResult := ExpandPath('\abc\def', 'c:\');
175
176 assertEqualsString('testExpandPath_DriveWithSlash', 'c:\', tmpResult);
177 end;
178
179
180 Procedure testExpandPath_DriveWithoutSlash;
181 var
182 tmpResult : String;
183 begin
184 tmpResult := ExpandPath('\abc\def', 'c:');
185
186 assertEqualsString('testExpandPath_DriveWithoutSlash', 'c:\', tmpResult);
187 end;
188
189
190 Procedure testExpandPath_RootPathForDrive;
191 var
192 tmpResult : String;
193 begin
194 tmpResult := ExpandPath('d:\abc\def', '\');
195
196 assertEqualsString('testExpandPath_RootPathForDrive', 'd:\', tmpResult);
197 end;
198
199
200 Procedure testExpandPath_RootDirForDrive;
201 var
202 tmpResult : String;
203 begin
204 tmpResult := ExpandPath('d:\abc\def', '\xy');
205
206 assertEqualsString('testExpandPath_RootDirForDrive', 'd:\xy', tmpResult);
207 end;
208
209
210 Procedure testExpandPath_RootPathWithoutDrive;
211 var
212 tmpResult : String;
213 begin
214 tmpResult := ExpandPath('abc\def', '\');
215
216 assertEqualsString('testExpandPath_RootPathWithoutDrive', '\', tmpResult);
217 end;
218
219
220 Procedure testExpandPath_RootDirWithoutDrive;
221 var
222 tmpResult : String;
223 begin
224 tmpResult := ExpandPath('abc\def', '\xyz');
225
226 assertEqualsString('testExpandPath_RootDirWithoutDrive', '\xyz', tmpResult);
227 end;
228
229
230 Procedure testExpandPath_AppendWithSlash;
231 var
232 tmpResult : String;
233 begin
234 tmpResult := ExpandPath('abc\def\', 'xyz');
235
236 assertEqualsString('testExpandPath_AppendWithSlash', 'abc\def\xyz', tmpResult);
237 end;
238
239
240 Procedure testExpandPath_AppendWithoutSlash;
241 var
242 tmpResult : String;
243 begin
244 tmpResult := ExpandPath('abc\def', 'xyz');
245
246 assertEqualsString('testExpandPath_AppendWithoutSlash', 'abc\def\xyz', tmpResult);
247 end;
248
249
250 Procedure testExpandPath_AppendWithSlashAtEnd;
251 var
252 tmpResult : String;
253 begin
254 tmpResult := ExpandPath('abc\def', 'xyz\');
255
256 assertEqualsString('testExpandPath_AppendWithSlashAtEnd', 'abc\def\xyz', tmpResult);
257 end;
258
259
260 Procedure testExpandPath_WithDot;
261 var
262 tmpResult : String;
263 begin
264 tmpResult := ExpandPath('abc\def', 'xyz\.\abc');
265
266 assertEqualsString('testExpandPath_WithDot', 'abc\def\xyz\abc', tmpResult);
267 end;
268
269
270 Procedure testExpandPath_WithDotAtEnd;
271 var
272 tmpResult : String;
273 begin
274 tmpResult := ExpandPath('abc\def', 'xyz\.');
275
276 assertEqualsString('testExpandPath_WithDotAtEnd', 'abc\def\xyz', tmpResult);
277 end;
278
279
280 Procedure testExpandPath_WithDots;
281 var
282 tmpResult : String;
283 begin
284 tmpResult := ExpandPath('abc\def', 'xyz\..\abc');
285
286 assertEqualsString('testExpandPath_WithDots', 'abc\def\abc', tmpResult);
287 end;
288
289
290 Procedure testExpandPath_WithDotsAtEnd;
291 var
292 tmpResult : String;
293 begin
294 tmpResult := ExpandPath('abc\def', 'xyz\..');
295
296 assertEqualsString('testExpandPath_WithDotsAtEnd', 'abc\def', tmpResult);
297 end;
298
299
300 Procedure testExpandPath_WithDotsInFront;
301 var
302 tmpResult : String;
303 begin
304 tmpResult := ExpandPath('abc\def', '..\xyz');
305
306 assertEqualsString('testExpandPath_WithDotsInFront', 'abc\xyz', tmpResult);
307 end;
308
309
310 Procedure testExpandPath_WithDotsInFrontReachingRoot;
311 var
312 tmpResult : String;
313 begin
314 tmpResult := ExpandPath('abc\def', '..\..\xyz');
315
316 assertEqualsString('testExpandPath_WithDotsInFrontReachingRoot', '\xyz', tmpResult);
317 end;
318
319
320 Procedure testExpandPath_WithDotsInFrontReachingDrive;
321 var
322 tmpResult : String;
323 begin
324 tmpResult := ExpandPath('c:\abc\def', '..\..\xyz');
325
326 assertEqualsString('testExpandPath_WithDotsInFront', 'c:\xyz', tmpResult);
327 end;
328
329
330 Procedure testExpandPath_WithDotsInFrontLeavingRoot;
331 var
332 tmpResult : String;
333 begin
334 tmpResult := ExpandPath('abc\def', '..\..\..\xyz');
335
336 assertEqualsString('testExpandPath_WithDotsInFrontLeavingRoot', '\xyz', tmpResult);
337 end;
338
339
340 Procedure testExpandPath_WithDotsInFrontLeavingDrive;
341 var
342 tmpResult : String;
343 begin
344 tmpResult := ExpandPath('c:\abc\def', '..\..\..\xyz');
345
346 assertEqualsString('testExpandPath_WithDotsInFrontLeavingDrive', 'c:\xyz', tmpResult);
347 end;
348
349
350 // ----------------------------------------------------------
351
352
353 Procedure testGetLogFilesDir;
354 var
355 tmpResult : String;
356 begin
357 tmpResult := GetLogFilesDir;
358
359 assertEqualsString('testGetLogFilesDir', 'C:\var\log\', tmpResult);
360 end;
361
362
363 // ----------------------------------------------------------
364
365 Procedure testSearchPath_Found;
366 var
367 tmpResult : Boolean;
368 tmpResultFilename : String;
369 begin
370 tmpResult := SearchPath('BOOKSHELF', 'CMDREF.INF', tmpResultFilename);
371
372 assertTrue('testSearchPath_Found', tmpResult);
373 assertEqualsString('testSearchPath_Found', 'C:\OS2\BOOK\CMDREF.INF', tmpResultFilename);
374 end;
375
376
377 Procedure testSearchPath_FoundMixedCase;
378 var
379 tmpResult : Boolean;
380 tmpResultFilename : String;
381 begin
382 tmpResult := SearchPath('BOOKSHELF', 'cMdRef.iNf', tmpResultFilename);
383
384 assertTrue('testSearchPath_FoundMixedCase', tmpResult);
385 assertEqualsString('testSearchPath_FoundMixedCase', 'C:\OS2\BOOK\cMdRef.iNf', tmpResultFilename);
386 end;
387
388
389 Procedure testSearchPath_NotFound;
390 var
391 tmpResult : Boolean;
392 tmpResultFilename : String;
393 begin
394 tmpResult := SearchPath('BOOKSHELF', 'RBRi.INF', tmpResultFilename);
395
396 assertFalse('testSearchPath_NotFound', tmpResult);
397 assertEqualsString('testSearchPath_NotFound', '', tmpResultFilename);
398 end;
399
400
401 Procedure testSearchPath_NotExistingEnvironment;
402 var
403 tmpResult : Boolean;
404 tmpResultFilename : String;
405 begin
406 tmpResult := SearchPath('BUECHER', 'RBRi.INF', tmpResultFilename);
407
408 assertFalse('testSearchPath_NotExistingEnvironment', tmpResult);
409 assertEqualsString('testSearchPath_NotExistingEnvironment', '', tmpResultFilename);
410 end;
411
412 // ----------------------------------------------------------
413
414 Procedure testSearchHelpPaths_FoundBookshelf;
415 var
416 tmpResult : Boolean;
417 tmpResultFilename : String;
418 begin
419 tmpResult := SearchHelpPaths('CMDREF.INF', tmpResultFilename, false);
420
421 assertTrue('testSearchHelpPaths_FoundBookshelf', tmpResult);
422 assertEqualsString('testSearchHelpPaths_FoundBookshelf', 'C:\OS2\BOOK\CMDREF.INF', tmpResultFilename);
423 end;
424
425
426 Procedure testSearchHelpPaths_FoundHelp;
427 var
428 tmpResult : Boolean;
429 tmpResultFilename : String;
430 begin
431 tmpResult := SearchHelpPaths('WPHELP.HLP', tmpResultFilename, false);
432
433 assertTrue('testSearchHelpPaths_FoundHelp', tmpResult);
434 assertEqualsString('testSearchHelpPaths_FoundHelp', 'C:\OS2\HELP\WPHELP.HLP', tmpResultFilename);
435 end;
436
437{ . is part of the helppath
438 Procedure testSearchHelpPaths_DontSearchInAppDir;
439 var
440 tmpResult : Boolean;
441 tmpResultFilename : String;
442 begin
443 tmpResult := SearchHelpPaths('NewViewTests.EXE', tmpResultFilename, False);
444
445 assertFalse('testSearchHelpPaths_DontSearchInAppDir', tmpResult);
446 assertEqualsString('testSearchHelpPaths_DontSearchInAppDir', '', tmpResultFilename);
447 end;
448}
449
450 Procedure testSearchHelpPaths_FoundInAppDir;
451 var
452 tmpResult : Boolean;
453 tmpResultFilename : String;
454 begin
455 tmpResult := SearchHelpPaths('NewViewTests.EXE', tmpResultFilename, True);
456
457 assertTrue('testSearchHelpPaths_FoundInAppDir', tmpResult);
458 assertEqualsString('testSearchHelpPaths_FoundInAppDir', 'P:\newview_dev\build\unittest\NewViewTests.EXE', tmpResultFilename);
459 end;
460
461
462 Procedure testSearchHelpPaths_NotFoundInAppDir;
463 var
464 tmpResult : Boolean;
465 tmpResultFilename : String;
466 begin
467 tmpResult := SearchHelpPaths('NewView.EXE', tmpResultFilename, True);
468
469 assertFalse('testSearchHelpPaths_NotFoundInAppDir', tmpResult);
470 assertEqualsString('testSearchHelpPaths_NotFoundInAppDir', '', tmpResultFilename);
471 end;
472
473 // ----------------------------------------------------------
474
475 Procedure testFindDefaultLanguageHelpFile;
476 var
477 tmpResult : String;
478 begin
479 tmpResult := FindDefaultLanguageHelpFile('NewView', '');
480
481 assertEqualsString('testFindDefaultLanguageHelpFile', 'C:\ecs\help\NewView.hlp', tmpResult);
482 end;
483
484 Procedure testFindDefaultLanguageHelpFile_it;
485 var
486 tmpResult : String;
487 begin
488 tmpResult := FindDefaultLanguageHelpFile('NewView', 'it');
489
490 assertEqualsString('testFindDefaultLanguageHelpFile_it', 'C:\ecs\help\NewView_it.hlp', tmpResult);
491 end;
492
493 Procedure testFindDefaultLanguageHelpFile_it_UpperCase;
494 var
495 tmpResult : String;
496 begin
497 tmpResult := FindDefaultLanguageHelpFile('NewView', 'IT');
498
499 assertEqualsString('testFindDefaultLanguageHelpFile_it_UpperCase', 'C:\ecs\help\NewView_IT.hlp', tmpResult);
500 end;
501
502
503 // ----------------------------------------------------------
504
505
506 Procedure testGetDirsInPath_Unknown;
507 var
508 tmpResult : TStringList;
509 begin
510 tmpResult := TStringList.Create;
511 tmpResult.Add('Tester');
512
513 GetDirsInPath('Unknown', tmpResult);
514
515 assertEqualsInt('testGetDirsInPath_Unknown', 0, tmpResult.count);
516
517 tmpResult.Destroy;
518 end;
519
520
521 Procedure testGetDirsInPath_Help;
522 var
523 tmpResult : TStringList;
524 begin
525 tmpResult := TStringList.Create;
526 tmpResult.Add('Tester');
527
528 GetDirsInPath('HELP', tmpResult);
529
530 assertEqualsInt('testGetDirsInPath_Help', 15, tmpResult.count);
531 assertEqualsString('testGetDirsInPath_Help', 'D:\progs\watcom\BINP\HELP', tmpResult[0]);
532 assertEqualsString('testGetDirsInPath_Help', 'd:\progs\SIBYL\BIN', tmpResult[14]);
533
534 tmpResult.Destroy;
535 end;
536
537 // ----------------------------------------------------------
538
539 Procedure testListFilesInDirectory_NoFiles;
540 var
541 tmpResult : TStringList;
542 begin
543 tmpResult := TStringList.Create;
544
545 ListFilesInDirectory('P:\newview_dev', '*.jonas', false, tmpResult);
546
547 assertEqualsInt('testListFilesInDirectory_NoFiles', 0, tmpResult.count);
548 end;
549
550
551 Procedure testListFilesInDirectory_EmptyFilter;
552 var
553 tmpResult : TStringList;
554 begin
555 tmpResult := TStringList.Create;
556
557 ListFilesInDirectory('P:\newview_dev', '', false, tmpResult);
558
559 assertEqualsInt('testListFilesInDirectory_EmptyFilter', 0, tmpResult.count);
560
561 tmpResult.Destroy;
562 end;
563
564
565 Procedure testListFilesInDirectory_OneFile;
566 var
567 tmpResult : TStringList;
568 begin
569 tmpResult := TStringList.Create;
570
571 ListFilesInDirectory('P:\newview_dev', '*.txt', false, tmpResult);
572
573 assertEqualsInt('testListFilesInDirectory_OneFile', 1, tmpResult.count);
574 assertEqualsString('testListFilesInDirectory_OneFile', '__readme.txt', tmpResult[0]);
575
576 tmpResult.Destroy;
577 end;
578
579
580 Procedure testListFilesInDirectory_ManyFiles;
581 var
582 tmpResult : TStringList;
583 begin
584 tmpResult := TStringList.Create;
585
586 ListFilesInDirectory('P:\newview_dev', '*.*', false, tmpResult);
587
588 assertEqualsInt('testListFilesInDirectory_ManyFiles', 3, tmpResult.count);
589 assertEqualsString('testListFilesInDirectory_ManyFiles', 'env.cmd', tmpResult[0]);
590 assertEqualsString('testListFilesInDirectory_ManyFiles', 'med.cmd', tmpResult[1]);
591 assertEqualsString('testListFilesInDirectory_ManyFiles', '__readme.txt', tmpResult[2]);
592
593 tmpResult.Destroy;
594 end;
595
596
597 Procedure testListFilesInDirectory_ManyFilter;
598 var
599 tmpResult : TStringList;
600 begin
601 tmpResult := TStringList.Create;
602
603 ListFilesInDirectory('P:\newview_dev', '*.txt;*v.cmd', false, tmpResult);
604
605 assertEqualsInt('testListFilesInDirectory_ManyFilter', 2, tmpResult.count);
606 assertEqualsString('testListFilesInDirectory_ManyFilter', '__readme.txt', tmpResult[0]);
607 assertEqualsString('testListFilesInDirectory_ManyFilter', 'env.cmd', tmpResult[1]);
608
609 tmpResult.Destroy;
610 end;
611
612
613 // ----------------------------------------------------------
614
615
616 Procedure testListFilesInDirectoryWithDirectoryInResult_NoFiles;
617 var
618 tmpResult : TStringList;
619 begin
620 tmpResult := TStringList.Create;
621
622 ListFilesInDirectory('P:\newview_dev', '*.jonas', true, tmpResult);
623
624 assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_NoFiles', 0, tmpResult.count);
625 end;
626
627
628 Procedure testListFilesInDirectoryWithDirectoryInResult_EmptyFilter;
629 var
630 tmpResult : TStringList;
631 begin
632 tmpResult := TStringList.Create;
633
634 ListFilesInDirectory('P:\newview_dev', '', true, tmpResult);
635
636 assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_EmptyFilter', 0, tmpResult.count);
637
638 tmpResult.Destroy;
639 end;
640
641
642 Procedure testListFilesInDirectoryWithDirectoryInResult_OneFile;
643 var
644 tmpResult : TStringList;
645 begin
646 tmpResult := TStringList.Create;
647
648 ListFilesInDirectory('P:\newview_dev', '*.txt', true, tmpResult);
649
650 assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_OneFile', 1, tmpResult.count);
651 assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_OneFile', 'P:\newview_dev\__readme.txt', tmpResult[0]);
652
653 tmpResult.Destroy;
654 end;
655
656
657 Procedure testListFilesInDirectoryWithDirectoryInResult_ManyFiles;
658 var
659 tmpResult : TStringList;
660 begin
661 tmpResult := TStringList.Create;
662
663 ListFilesInDirectory('P:\newview_dev', '*.*', true, tmpResult);
664
665 assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', 3, tmpResult.count);
666 assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', 'P:\newview_dev\env.cmd', tmpResult[0]);
667 assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', 'P:\newview_dev\med.cmd', tmpResult[1]);
668 assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFiles', 'P:\newview_dev\__readme.txt', tmpResult[2]);
669
670 tmpResult.Destroy;
671 end;
672
673
674 Procedure testListFilesInDirectoryWithDirectoryInResult_ManyFilter;
675 var
676 tmpResult : TStringList;
677 begin
678 tmpResult := TStringList.Create;
679
680 ListFilesInDirectory('P:\newview_dev', '*.txt;*v.cmd', true, tmpResult);
681
682 assertEqualsInt('testListFilesInDirectoryWithDirectoryInResult_ManyFilter', 2, tmpResult.count);
683 assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFilter', 'P:\newview_dev\__readme.txt', tmpResult[0]);
684 assertEqualsString('testListFilesInDirectoryWithDirectoryInResult_ManyFilter', 'P:\newview_dev\env.cmd', tmpResult[1]);
685
686 tmpResult.Destroy;
687 end;
688
689 // ----------------------------------------------------------
690
691 Procedure testListSubDirectories_None;
692 var
693 tmpResult : TStringList;
694 begin
695 tmpResult := TStringList.Create;
696
697 ListSubDirectories('P:\newview_dev\dll', tmpResult);
698
699 assertEqualsInt('testListSubDirectories_None', 0, tmpResult.count);
700
701 tmpResult.Destroy;
702 end;
703
704
705 Procedure testListSubDirectories_Many;
706 var
707 tmpResult : TStringList;
708 begin
709 tmpResult := TStringList.Create;
710
711 ListSubDirectories('P:\newview_dev\i18n', tmpResult);
712
713 assertEqualsInt('testListSubDirectories_Many', 14, tmpResult.count);
714 assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\.svn', tmpResult[0]);
715 assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\cz', tmpResult[1]);
716 assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\de', tmpResult[2]);
717 assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\eo', tmpResult[3]);
718
719 tmpResult.Destroy;
720 end;
721
722
723 // ----------------------------------------------------------
724
725
726 Procedure testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult;
727 var
728 tmpResult : TStringList;
729 begin
730 tmpResult := TStringList.Create;
731
732 ListFilesInDirectoryRecursiveWithTermination('P:\newview_dev\i18n', '*.ipf;*.lng', true, tmpResult, nil, false);
733
734 assertEqualsInt('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult', 16, tmpResult.count);
735 assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult', 'P:\newview_dev\i18n\NewView.ipf', tmpResult[0]);
736 assertEqualsString('testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult', 'P:\newview_dev\i18n\sv\newview_sv.lng', tmpResult[15]);
737
738 tmpResult.Destroy;
739 end;
740
741
742 // ----------------------------------------------------------
743
744
745 Procedure testListFilesInDirectoryRecursiveWithTermination;
746 var
747 tmpResult : TStringList;
748 begin
749 tmpResult := TStringList.Create;
750
751 ListFilesInDirectoryRecursiveWithTermination('P:\newview_dev\i18n', '*.ipf;*.lng', false, tmpResult, nil, false);
752
753 assertEqualsInt('testListFilesInDirectoryRecursiveWithTermination', 16, tmpResult.count);
754 assertEqualsString('testListFilesInDirectoryRecursiveWithTermination', 'NewView.ipf', tmpResult[0]);
755 assertEqualsString('testListFilesInDirectoryRecursiveWithTermination', 'newview_sv.lng', tmpResult[15]);
756
757 tmpResult.Destroy;
758 end;
759
760
761 // ----------------------------------------------------------
762
763
764 Procedure testParentDir_Empty;
765 var
766 tmpResult : String;
767 begin
768 tmpResult := ParentDir('');
769
770 assertEqualsString('testParentDir_Empty', '', tmpResult);
771 end;
772
773
774 Procedure testParentDir_Root;
775 var
776 tmpResult : String;
777 begin
778 tmpResult := ParentDir('C:\');
779
780 assertEqualsString('testParentDir_Root', '', tmpResult);
781 end;
782
783
784 Procedure testParentDir_UnixRoot;
785 var
786 tmpResult : String;
787 begin
788 tmpResult := ParentDir('\');
789
790 assertEqualsString('testParentDir_UnixRoot', '', tmpResult);
791 end;
792
793
794 Procedure testParentDir;
795 var
796 tmpResult : String;
797 begin
798 tmpResult := ParentDir('\abc\def');
799
800 assertEqualsString('testParentDir', '\abc', tmpResult);
801 end;
802
803
804 Procedure testParentDir_OnlyOne;
805 var
806 tmpResult : String;
807 begin
808 tmpResult := ParentDir('\abc');
809
810 assertEqualsString('testParentDir_OnlyOne', '', tmpResult);
811 end;
812
813
814 Procedure testParentDir_SlashAtEnd;
815 var
816 tmpResult : String;
817 begin
818 tmpResult := ParentDir('\abc\def\');
819
820 assertEqualsString('testParentDir_SlashAtEnd', '\abc', tmpResult);
821 end;
822
823
824 Procedure testParentDir_NoSlashAtStart;
825 var
826 tmpResult : String;
827 begin
828 tmpResult := ParentDir('abc\def\');
829
830 assertEqualsString('testParentDir_NoSlashAtStart', 'abc', tmpResult);
831 end;
832
833
834 Procedure testParentDir_NoSlash;
835 var
836 tmpResult : String;
837 begin
838 tmpResult := ParentDir('abc');
839
840 assertEqualsString('testParentDir_NoSlash', '', tmpResult);
841 end;
842
843
844 Procedure testParentDir_GoToRootDrive;
845 var
846 tmpResult : String;
847 begin
848 tmpResult := ParentDir('c:\abc');
849
850 assertEqualsString('testParentDir_GoToRootDrive', 'c:', tmpResult);
851 end;
852
853
854 // ----------------------------------------------------------
855
856
857 Procedure testDirectoryExists_Empty;
858 var
859 tmpResult : Boolean;
860 begin
861 tmpResult := DirectoryExists('');
862
863 assertTrue('testDirectoryExists_Empty', tmpResult);
864 end;
865
866
867 Procedure testDirectoryExists_DriveOnlyLowercase;
868 var
869 tmpResult : Boolean;
870 begin
871 tmpResult := DirectoryExists('c:');
872
873 assertTrue('testDirectoryExists_DriveOnlyLowercase', tmpResult);
874 end;
875
876
877 Procedure testDirectoryExists_DriveOnlyUppercase;
878 var
879 tmpResult : Boolean;
880 begin
881 tmpResult := DirectoryExists('C:');
882
883 assertTrue('testDirectoryExists_DriveOnlyUppercase', tmpResult);
884 end;
885
886
887 Procedure testDirectoryExists_DriveOnlySlashAtEnd;
888 var
889 tmpResult : Boolean;
890 begin
891 tmpResult := DirectoryExists('C:\');
892
893 assertTrue('testDirectoryExists_DriveOnlySlashAtEnd', tmpResult);
894 end;
895
896
897 Procedure testDirectoryExists_DriveAndPath;
898 var
899 tmpResult : Boolean;
900 begin
901 tmpResult := DirectoryExists('C:\os2\bitmap');
902
903 assertTrue('testDirectoryExists_DriveAndPath', tmpResult);
904 end;
905
906
907 Procedure testDirectoryExists_DriveAndPathSlashAtEnd;
908 var
909 tmpResult : Boolean;
910 begin
911 tmpResult := DirectoryExists('C:\os2\bitmap\');
912
913 assertTrue('testDirectoryExists_DriveAndPathSlashAtEnd', tmpResult);
914 end;
915
916
917 Procedure testDirectoryExists_InvalidDrive;
918 var
919 tmpResult : Boolean;
920 begin
921 tmpResult := DirectoryExists('y:');
922
923 assertFalse('testDirectoryExists_InvalidDrive', tmpResult);
924 end;
925
926
927 Procedure testDirectoryExists_InvalidDriveAndPath;
928 var
929 tmpResult : Boolean;
930 begin
931 tmpResult := DirectoryExists('y:\test');
932
933 assertFalse('testDirectoryExists_InvalidDriveAndPath', tmpResult);
934 end;
935
936
937 Procedure testDirectoryExists_NotExistent;
938 var
939 tmpResult : Boolean;
940 begin
941 tmpResult := DirectoryExists('C:\os2\bit\');
942
943 assertFalse('testDirectoryExists_NotExistent', tmpResult);
944 end;
945
946
947
948 // ----------------------------------------------------------
949
950
951 Function getFileUtilsUnitTests : TList;
952 Begin
953 result := TList.Create;
954
955 result.add(@testAddDirectorySeparator_Empty);
956 result.add(@testAddDirectorySeparator_SingleChar);
957 result.add(@testAddDirectorySeparator_ManyChars);
958 result.add(@testAddDirectorySeparator_SlashAtEnd);
959
960 result.add(@testAddDirectorySeparatorIfNotEmpty_Empty);
961 result.add(@testAddDirectorySeparatorIfNotEmpty_SingleChar);
962 result.add(@testAddDirectorySeparatorIfNotEmpty_ManyChars);
963 result.add(@testAddDirectorySeparatorIfNotEmpty_SlashAtEnd);
964
965 result.add(@testRemoveRightDirectorySeparator_Empty);
966 result.add(@testRemoveRightDirectorySeparator_WithoutSlash);
967 result.add(@testRemoveRightDirectorySeparator_WithSlash);
968
969 result.add(@testExpandPath_BothEmpty);
970 result.add(@testExpandPath_PathEmpty);
971 result.add(@testExpandPath_PathEmptyDirEndsWithSlash);
972 result.add(@testExpandPath_AbsolutePath);
973 result.add(@testExpandPath_DriveWithSlash);
974 result.add(@testExpandPath_DriveWithoutSlash);
975 result.add(@testExpandPath_RootPathForDrive);
976 result.add(@testExpandPath_RootDirForDrive);
977 result.add(@testExpandPath_RootPathWithoutDrive);
978 result.add(@testExpandPath_RootDirWithoutDrive);
979 result.add(@testExpandPath_AppendWithSlash);
980 result.add(@testExpandPath_AppendWithoutSlash);
981 result.add(@testExpandPath_AppendWithSlashAtEnd);
982 result.add(@testExpandPath_WithDot);
983 result.add(@testExpandPath_WithDotAtEnd);
984 result.add(@testExpandPath_WithDots);
985 result.add(@testExpandPath_WithDotsAtEnd);
986 result.add(@testExpandPath_WithDotsInFront);
987 result.add(@testExpandPath_WithDotsInFrontReachingRoot);
988 result.add(@testExpandPath_WithDotsInFrontReachingDrive);
989 result.add(@testExpandPath_WithDotsInFrontLeavingRoot);
990 result.add(@testExpandPath_WithDotsInFrontLeavingDrive);
991
992 result.add(@testGetLogFilesDir);
993
994 result.add(@testSearchPath_Found);
995 result.add(@testSearchPath_FoundMixedCase);
996 result.add(@testSearchPath_NotFound);
997 result.add(@testSearchPath_NotExistingEnvironment);
998
999 result.add(@testSearchHelpPaths_FoundBookshelf);
1000 result.add(@testSearchHelpPaths_FoundHelp);
1001// result.add(@testSearchHelpPaths_DontSearchInAppDir);
1002 result.add(@testSearchHelpPaths_FoundInAppDir);
1003 result.add(@testSearchHelpPaths_NotFoundInAppDir);
1004
1005 result.add(@testFindDefaultLanguageHelpFile);
1006 result.add(@testFindDefaultLanguageHelpFile_it);
1007 result.add(@testFindDefaultLanguageHelpFile_it_UpperCase);
1008
1009 result.add(@testGetDirsInPath_Unknown);
1010 result.add(@testGetDirsInPath_Help);
1011
1012 result.add(@testListFilesInDirectory_NoFiles);
1013 result.add(@testListFilesInDirectory_EmptyFilter);
1014 result.add(@testListFilesInDirectory_OneFile);
1015 result.add(@testListFilesInDirectory_ManyFiles);
1016 result.add(@testListFilesInDirectory_ManyFilter);
1017 result.add(@testListFilesInDirectoryWithDirectoryInResult_NoFiles);
1018 result.add(@testListFilesInDirectoryWithDirectoryInResult_EmptyFilter);
1019 result.add(@testListFilesInDirectoryWithDirectoryInResult_OneFile);
1020 result.add(@testListFilesInDirectoryWithDirectoryInResult_ManyFiles);
1021 result.add(@testListFilesInDirectoryWithDirectoryInResult_ManyFilter);
1022
1023 result.add(@testListSubDirectories_None);
1024 result.add(@testListSubDirectories_Many);
1025
1026 result.add(@testListFilesInDirectoryRecursiveWithTermination);
1027 result.add(@testListFilesInDirectoryRecursiveWithTerminationWithDirectoryInResult);
1028
1029 result.add(@testParentDir_Empty);
1030 result.add(@testParentDir_Root);
1031 result.add(@testParentDir_UnixRoot);
1032 result.add(@testParentDir);
1033 result.add(@testParentDir_OnlyOne);
1034 result.add(@testParentDir_SlashAtEnd);
1035 result.add(@testParentDir_NoSlashAtStart);
1036 result.add(@testParentDir_NoSlash);
1037 result.add(@testParentDir_GoToRootDrive);
1038
1039 result.add(@testDirectoryExists_Empty);
1040 result.add(@testDirectoryExists_DriveOnlyLowercase);
1041 result.add(@testDirectoryExists_DriveOnlyUppercase);
1042 result.add(@testDirectoryExists_DriveOnlySlashAtEnd);
1043 result.add(@testDirectoryExists_DriveAndPath);
1044 result.add(@testDirectoryExists_DriveAndPathSlashAtEnd);
1045 result.add(@testDirectoryExists_InvalidDrive);
1046 result.add(@testDirectoryExists_InvalidDriveAndPath);
1047 result.add(@testDirectoryExists_NotExistent);
1048 end;
1049
1050End.
Note: See TracBrowser for help on using the repository browser.