1 | Unit FileUtilsUnitTests;
|
---|
2 |
|
---|
3 | Interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes,
|
---|
7 | TestAssert,
|
---|
8 | FileUtilsUnit;
|
---|
9 |
|
---|
10 |
|
---|
11 | FUNCTION getFileUtilsUnitTests : TList;
|
---|
12 |
|
---|
13 |
|
---|
14 | Implementation
|
---|
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', tmpResult);
|
---|
546 | ListFilesInDirectory('P:\newview_dev', '*.jonas', tmpResult);
|
---|
547 |
|
---|
548 | assertEqualsInt('testListFilesInDirectory_NoFiles', 0, tmpResult.count);
|
---|
549 | end;
|
---|
550 |
|
---|
551 |
|
---|
552 | Procedure testListFilesInDirectory_EmptyFilter;
|
---|
553 | var
|
---|
554 | tmpResult : TStringList;
|
---|
555 | begin
|
---|
556 | tmpResult := TStringList.Create;
|
---|
557 |
|
---|
558 | ListFilesInDirectory('P:\newview_dev', '', tmpResult);
|
---|
559 |
|
---|
560 | assertEqualsInt('testListFilesInDirectory_EmptyFilter', 0, tmpResult.count);
|
---|
561 |
|
---|
562 | tmpResult.Destroy;
|
---|
563 | end;
|
---|
564 |
|
---|
565 |
|
---|
566 | Procedure testListFilesInDirectory_OneFile;
|
---|
567 | var
|
---|
568 | tmpResult : TStringList;
|
---|
569 | begin
|
---|
570 | tmpResult := TStringList.Create;
|
---|
571 |
|
---|
572 | ListFilesInDirectory('P:\newview_dev', '*.txt', tmpResult);
|
---|
573 |
|
---|
574 | assertEqualsInt('testListFilesInDirectory_OneFile', 1, tmpResult.count);
|
---|
575 | assertEqualsString('testListFilesInDirectory_OneFile', '__readme.txt', tmpResult[0]);
|
---|
576 |
|
---|
577 | tmpResult.Destroy;
|
---|
578 | end;
|
---|
579 |
|
---|
580 |
|
---|
581 | Procedure testListFilesInDirectory_ManyFiles;
|
---|
582 | var
|
---|
583 | tmpResult : TStringList;
|
---|
584 | begin
|
---|
585 | tmpResult := TStringList.Create;
|
---|
586 |
|
---|
587 | ListFilesInDirectory('P:\newview_dev', '*.*', tmpResult);
|
---|
588 |
|
---|
589 | assertEqualsInt('testListFilesInDirectory_ManyFiles', 3, tmpResult.count);
|
---|
590 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'env.cmd', tmpResult[0]);
|
---|
591 | assertEqualsString('testListFilesInDirectory_ManyFiles', 'med.cmd', tmpResult[1]);
|
---|
592 | assertEqualsString('testListFilesInDirectory_ManyFiles', '__readme.txt', tmpResult[2]);
|
---|
593 |
|
---|
594 | tmpResult.Destroy;
|
---|
595 | end;
|
---|
596 |
|
---|
597 |
|
---|
598 | Procedure testListFilesInDirectory_ManyFilter;
|
---|
599 | var
|
---|
600 | tmpResult : TStringList;
|
---|
601 | begin
|
---|
602 | tmpResult := TStringList.Create;
|
---|
603 |
|
---|
604 | ListFilesInDirectory('P:\newview_dev', '*.txt;*v.cmd', tmpResult);
|
---|
605 |
|
---|
606 | assertEqualsInt('testListFilesInDirectory_ManyFilter', 2, tmpResult.count);
|
---|
607 | assertEqualsString('testListFilesInDirectory_ManyFilter', '__readme.txt', tmpResult[0]);
|
---|
608 | assertEqualsString('testListFilesInDirectory_ManyFilter', 'env.cmd', tmpResult[1]);
|
---|
609 |
|
---|
610 | tmpResult.Destroy;
|
---|
611 | end;
|
---|
612 |
|
---|
613 | // ----------------------------------------------------------
|
---|
614 |
|
---|
615 | Procedure testListSubDirectories_None;
|
---|
616 | var
|
---|
617 | tmpResult : TStringList;
|
---|
618 | begin
|
---|
619 | tmpResult := TStringList.Create;
|
---|
620 |
|
---|
621 | ListSubDirectories('P:\newview_dev\dll', tmpResult);
|
---|
622 |
|
---|
623 | assertEqualsInt('testListSubDirectories_None', 0, tmpResult.count);
|
---|
624 |
|
---|
625 | tmpResult.Destroy;
|
---|
626 | end;
|
---|
627 |
|
---|
628 |
|
---|
629 | Procedure testListSubDirectories_Many;
|
---|
630 | var
|
---|
631 | tmpResult : TStringList;
|
---|
632 | begin
|
---|
633 | tmpResult := TStringList.Create;
|
---|
634 |
|
---|
635 | ListSubDirectories('P:\newview_dev\i18n', tmpResult);
|
---|
636 |
|
---|
637 | assertEqualsInt('testListSubDirectories_Many', 14, tmpResult.count);
|
---|
638 | assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\.svn', tmpResult[0]);
|
---|
639 | assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\cz', tmpResult[1]);
|
---|
640 | assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\de', tmpResult[2]);
|
---|
641 | assertEqualsString('testListSubDirectories_Many', 'P:\newview_dev\i18n\eo', tmpResult[3]);
|
---|
642 |
|
---|
643 | tmpResult.Destroy;
|
---|
644 | end;
|
---|
645 |
|
---|
646 |
|
---|
647 | // ----------------------------------------------------------
|
---|
648 |
|
---|
649 |
|
---|
650 | Procedure testListFilesInDirectoryRecursiveWithTermination;
|
---|
651 | var
|
---|
652 | tmpResult : TStringList;
|
---|
653 | begin
|
---|
654 | tmpResult := TStringList.Create;
|
---|
655 |
|
---|
656 | ListFilesInDirectoryRecursiveWithTermination('P:\newview_dev\i18n', '*.ipf;*.lng', tmpResult, nil, false);
|
---|
657 |
|
---|
658 | assertEqualsInt('testListFilesInDirectoryRecursiveWithTermination', 16, tmpResult.count);
|
---|
659 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination', 'NewView.ipf', tmpResult[0]);
|
---|
660 | assertEqualsString('testListFilesInDirectoryRecursiveWithTermination', 'newview_sv.lng', tmpResult[15]);
|
---|
661 |
|
---|
662 | tmpResult.Destroy;
|
---|
663 | end;
|
---|
664 |
|
---|
665 |
|
---|
666 | // ----------------------------------------------------------
|
---|
667 |
|
---|
668 |
|
---|
669 | Procedure testParentDir_Empty;
|
---|
670 | var
|
---|
671 | tmpResult : String;
|
---|
672 | begin
|
---|
673 | tmpResult := ParentDir('');
|
---|
674 |
|
---|
675 | assertEqualsString('testParentDir_Empty', '', tmpResult);
|
---|
676 | end;
|
---|
677 |
|
---|
678 |
|
---|
679 | Procedure testParentDir_Root;
|
---|
680 | var
|
---|
681 | tmpResult : String;
|
---|
682 | begin
|
---|
683 | tmpResult := ParentDir('C:\');
|
---|
684 |
|
---|
685 | assertEqualsString('testParentDir_Root', '', tmpResult);
|
---|
686 | end;
|
---|
687 |
|
---|
688 |
|
---|
689 | Procedure testParentDir_UnixRoot;
|
---|
690 | var
|
---|
691 | tmpResult : String;
|
---|
692 | begin
|
---|
693 | tmpResult := ParentDir('\');
|
---|
694 |
|
---|
695 | assertEqualsString('testParentDir_UnixRoot', '', tmpResult);
|
---|
696 | end;
|
---|
697 |
|
---|
698 |
|
---|
699 | Procedure testParentDir;
|
---|
700 | var
|
---|
701 | tmpResult : String;
|
---|
702 | begin
|
---|
703 | tmpResult := ParentDir('\abc\def');
|
---|
704 |
|
---|
705 | assertEqualsString('testParentDir', '\abc', tmpResult);
|
---|
706 | end;
|
---|
707 |
|
---|
708 |
|
---|
709 | Procedure testParentDir_OnlyOne;
|
---|
710 | var
|
---|
711 | tmpResult : String;
|
---|
712 | begin
|
---|
713 | tmpResult := ParentDir('\abc');
|
---|
714 |
|
---|
715 | assertEqualsString('testParentDir_OnlyOne', '', tmpResult);
|
---|
716 | end;
|
---|
717 |
|
---|
718 |
|
---|
719 | Procedure testParentDir_SlashAtEnd;
|
---|
720 | var
|
---|
721 | tmpResult : String;
|
---|
722 | begin
|
---|
723 | tmpResult := ParentDir('\abc\def\');
|
---|
724 |
|
---|
725 | assertEqualsString('testParentDir_SlashAtEnd', '\abc', tmpResult);
|
---|
726 | end;
|
---|
727 |
|
---|
728 |
|
---|
729 | Procedure testParentDir_NoSlashAtStart;
|
---|
730 | var
|
---|
731 | tmpResult : String;
|
---|
732 | begin
|
---|
733 | tmpResult := ParentDir('abc\def\');
|
---|
734 |
|
---|
735 | assertEqualsString('testParentDir_NoSlashAtStart', 'abc', tmpResult);
|
---|
736 | end;
|
---|
737 |
|
---|
738 |
|
---|
739 | Procedure testParentDir_NoSlash;
|
---|
740 | var
|
---|
741 | tmpResult : String;
|
---|
742 | begin
|
---|
743 | tmpResult := ParentDir('abc');
|
---|
744 |
|
---|
745 | assertEqualsString('testParentDir_NoSlash', '', tmpResult);
|
---|
746 | end;
|
---|
747 |
|
---|
748 |
|
---|
749 | Procedure testParentDir_GoToRootDrive;
|
---|
750 | var
|
---|
751 | tmpResult : String;
|
---|
752 | begin
|
---|
753 | tmpResult := ParentDir('c:\abc');
|
---|
754 |
|
---|
755 | assertEqualsString('testParentDir_GoToRootDrive', 'c:', tmpResult);
|
---|
756 | end;
|
---|
757 |
|
---|
758 |
|
---|
759 | // ----------------------------------------------------------
|
---|
760 |
|
---|
761 |
|
---|
762 | Procedure testDirectoryExists_Empty;
|
---|
763 | var
|
---|
764 | tmpResult : Boolean;
|
---|
765 | begin
|
---|
766 | tmpResult := DirectoryExists('');
|
---|
767 |
|
---|
768 | assertTrue('testDirectoryExists_Empty', tmpResult);
|
---|
769 | end;
|
---|
770 |
|
---|
771 |
|
---|
772 | Procedure testDirectoryExists_DriveOnlyLowercase;
|
---|
773 | var
|
---|
774 | tmpResult : Boolean;
|
---|
775 | begin
|
---|
776 | tmpResult := DirectoryExists('c:');
|
---|
777 |
|
---|
778 | assertTrue('testDirectoryExists_DriveOnlyLowercase', tmpResult);
|
---|
779 | end;
|
---|
780 |
|
---|
781 |
|
---|
782 | Procedure testDirectoryExists_DriveOnlyUppercase;
|
---|
783 | var
|
---|
784 | tmpResult : Boolean;
|
---|
785 | begin
|
---|
786 | tmpResult := DirectoryExists('C:');
|
---|
787 |
|
---|
788 | assertTrue('testDirectoryExists_DriveOnlyUppercase', tmpResult);
|
---|
789 | end;
|
---|
790 |
|
---|
791 |
|
---|
792 | Procedure testDirectoryExists_DriveOnlySlashAtEnd;
|
---|
793 | var
|
---|
794 | tmpResult : Boolean;
|
---|
795 | begin
|
---|
796 | tmpResult := DirectoryExists('C:\');
|
---|
797 |
|
---|
798 | assertTrue('testDirectoryExists_DriveOnlySlashAtEnd', tmpResult);
|
---|
799 | end;
|
---|
800 |
|
---|
801 |
|
---|
802 | Procedure testDirectoryExists_DriveAndPath;
|
---|
803 | var
|
---|
804 | tmpResult : Boolean;
|
---|
805 | begin
|
---|
806 | tmpResult := DirectoryExists('C:\os2\bitmap');
|
---|
807 |
|
---|
808 | assertTrue('testDirectoryExists_DriveAndPath', tmpResult);
|
---|
809 | end;
|
---|
810 |
|
---|
811 |
|
---|
812 | Procedure testDirectoryExists_DriveAndPathSlashAtEnd;
|
---|
813 | var
|
---|
814 | tmpResult : Boolean;
|
---|
815 | begin
|
---|
816 | tmpResult := DirectoryExists('C:\os2\bitmap\');
|
---|
817 |
|
---|
818 | assertTrue('testDirectoryExists_DriveAndPathSlashAtEnd', tmpResult);
|
---|
819 | end;
|
---|
820 |
|
---|
821 |
|
---|
822 | Procedure testDirectoryExists_InvalidDrive;
|
---|
823 | var
|
---|
824 | tmpResult : Boolean;
|
---|
825 | begin
|
---|
826 | tmpResult := DirectoryExists('y:');
|
---|
827 |
|
---|
828 | assertFalse('testDirectoryExists_InvalidDrive', tmpResult);
|
---|
829 | end;
|
---|
830 |
|
---|
831 |
|
---|
832 | Procedure testDirectoryExists_InvalidDriveAndPath;
|
---|
833 | var
|
---|
834 | tmpResult : Boolean;
|
---|
835 | begin
|
---|
836 | tmpResult := DirectoryExists('y:\test');
|
---|
837 |
|
---|
838 | assertFalse('testDirectoryExists_InvalidDriveAndPath', tmpResult);
|
---|
839 | end;
|
---|
840 |
|
---|
841 |
|
---|
842 | Procedure testDirectoryExists_NotExistent;
|
---|
843 | var
|
---|
844 | tmpResult : Boolean;
|
---|
845 | begin
|
---|
846 | tmpResult := DirectoryExists('C:\os2\bit\');
|
---|
847 |
|
---|
848 | assertFalse('testDirectoryExists_NotExistent', tmpResult);
|
---|
849 | end;
|
---|
850 |
|
---|
851 |
|
---|
852 |
|
---|
853 | // ----------------------------------------------------------
|
---|
854 |
|
---|
855 |
|
---|
856 | Function getFileUtilsUnitTests : TList;
|
---|
857 | Begin
|
---|
858 | result := TList.Create;
|
---|
859 |
|
---|
860 | result.add(@testAddDirectorySeparator_Empty);
|
---|
861 | result.add(@testAddDirectorySeparator_SingleChar);
|
---|
862 | result.add(@testAddDirectorySeparator_ManyChars);
|
---|
863 | result.add(@testAddDirectorySeparator_SlashAtEnd);
|
---|
864 |
|
---|
865 | result.add(@testAddDirectorySeparatorIfNotEmpty_Empty);
|
---|
866 | result.add(@testAddDirectorySeparatorIfNotEmpty_SingleChar);
|
---|
867 | result.add(@testAddDirectorySeparatorIfNotEmpty_ManyChars);
|
---|
868 | result.add(@testAddDirectorySeparatorIfNotEmpty_SlashAtEnd);
|
---|
869 |
|
---|
870 | result.add(@testRemoveRightDirectorySeparator_Empty);
|
---|
871 | result.add(@testRemoveRightDirectorySeparator_WithoutSlash);
|
---|
872 | result.add(@testRemoveRightDirectorySeparator_WithSlash);
|
---|
873 |
|
---|
874 | result.add(@testExpandPath_BothEmpty);
|
---|
875 | result.add(@testExpandPath_PathEmpty);
|
---|
876 | result.add(@testExpandPath_PathEmptyDirEndsWithSlash);
|
---|
877 | result.add(@testExpandPath_AbsolutePath);
|
---|
878 | result.add(@testExpandPath_DriveWithSlash);
|
---|
879 | result.add(@testExpandPath_DriveWithoutSlash);
|
---|
880 | result.add(@testExpandPath_RootPathForDrive);
|
---|
881 | result.add(@testExpandPath_RootDirForDrive);
|
---|
882 | result.add(@testExpandPath_RootPathWithoutDrive);
|
---|
883 | result.add(@testExpandPath_RootDirWithoutDrive);
|
---|
884 | result.add(@testExpandPath_AppendWithSlash);
|
---|
885 | result.add(@testExpandPath_AppendWithoutSlash);
|
---|
886 | result.add(@testExpandPath_AppendWithSlashAtEnd);
|
---|
887 | result.add(@testExpandPath_WithDot);
|
---|
888 | result.add(@testExpandPath_WithDotAtEnd);
|
---|
889 | result.add(@testExpandPath_WithDots);
|
---|
890 | result.add(@testExpandPath_WithDotsAtEnd);
|
---|
891 | result.add(@testExpandPath_WithDotsInFront);
|
---|
892 | result.add(@testExpandPath_WithDotsInFrontReachingRoot);
|
---|
893 | result.add(@testExpandPath_WithDotsInFrontReachingDrive);
|
---|
894 | result.add(@testExpandPath_WithDotsInFrontLeavingRoot);
|
---|
895 | result.add(@testExpandPath_WithDotsInFrontLeavingDrive);
|
---|
896 |
|
---|
897 | result.add(@testGetLogFilesDir);
|
---|
898 |
|
---|
899 | result.add(@testSearchPath_Found);
|
---|
900 | result.add(@testSearchPath_FoundMixedCase);
|
---|
901 | result.add(@testSearchPath_NotFound);
|
---|
902 | result.add(@testSearchPath_NotExistingEnvironment);
|
---|
903 |
|
---|
904 | result.add(@testSearchHelpPaths_FoundBookshelf);
|
---|
905 | result.add(@testSearchHelpPaths_FoundHelp);
|
---|
906 | // result.add(@testSearchHelpPaths_DontSearchInAppDir);
|
---|
907 | result.add(@testSearchHelpPaths_FoundInAppDir);
|
---|
908 | result.add(@testSearchHelpPaths_NotFoundInAppDir);
|
---|
909 |
|
---|
910 | result.add(@testFindDefaultLanguageHelpFile);
|
---|
911 | result.add(@testFindDefaultLanguageHelpFile_it);
|
---|
912 | result.add(@testFindDefaultLanguageHelpFile_it_UpperCase);
|
---|
913 |
|
---|
914 | result.add(@testGetDirsInPath_Unknown);
|
---|
915 | result.add(@testGetDirsInPath_Help);
|
---|
916 |
|
---|
917 | result.add(@testListFilesInDirectory_NoFiles);
|
---|
918 | result.add(@testListFilesInDirectory_EmptyFilter);
|
---|
919 | result.add(@testListFilesInDirectory_OneFile);
|
---|
920 | result.add(@testListFilesInDirectory_ManyFiles);
|
---|
921 | result.add(@testListFilesInDirectory_ManyFilter);
|
---|
922 |
|
---|
923 | result.add(@testListSubDirectories_None);
|
---|
924 | result.add(@testListSubDirectories_Many);
|
---|
925 |
|
---|
926 | result.add(@testListFilesInDirectoryRecursiveWithTermination);
|
---|
927 |
|
---|
928 | result.add(@testParentDir_Empty);
|
---|
929 | result.add(@testParentDir_Root);
|
---|
930 | result.add(@testParentDir_UnixRoot);
|
---|
931 | result.add(@testParentDir);
|
---|
932 | result.add(@testParentDir_OnlyOne);
|
---|
933 | result.add(@testParentDir_SlashAtEnd);
|
---|
934 | result.add(@testParentDir_NoSlashAtStart);
|
---|
935 | result.add(@testParentDir_NoSlash);
|
---|
936 | result.add(@testParentDir_GoToRootDrive);
|
---|
937 |
|
---|
938 | result.add(@testDirectoryExists_Empty);
|
---|
939 | result.add(@testDirectoryExists_DriveOnlyLowercase);
|
---|
940 | result.add(@testDirectoryExists_DriveOnlyUppercase);
|
---|
941 | result.add(@testDirectoryExists_DriveOnlySlashAtEnd);
|
---|
942 | result.add(@testDirectoryExists_DriveAndPath);
|
---|
943 | result.add(@testDirectoryExists_DriveAndPathSlashAtEnd);
|
---|
944 | result.add(@testDirectoryExists_InvalidDrive);
|
---|
945 | result.add(@testDirectoryExists_InvalidDriveAndPath);
|
---|
946 | result.add(@testDirectoryExists_NotExistent);
|
---|
947 | end;
|
---|
948 |
|
---|
949 | End.
|
---|