First public contribution.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 GLDEF_D RTest test(_L("T_SCAN"));
22 LOCAL_C void BuildTestDir()
24 // Build up a test directory structure
30 // File1 File2 Left File3 Right Empty(Directory)
32 // Dir2 Dir3 File4 File5
34 // File6 Dir4----Hidden---HiddenFile
42 MakeDir(_L("\\F32-TST\\SCANTEST\\Empty\\"));
44 MakeFile(_L("\\F32-TST\\SCANTEST\\File1"));
45 MakeFile(_L("\\F32-TST\\SCANTEST\\File2"));
46 MakeFile(_L("\\F32-TST\\SCANTEST\\File3"));
48 MakeFile(_L("\\F32-TST\\SCANTEST\\Right\\File4"));
49 MakeFile(_L("\\F32-TST\\SCANTEST\\Right\\File5"));
51 MakeFile(_L("\\F32-TST\\SCANTEST\\Left\\Dir2\\File6"));
52 MakeFile(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\File7"));
54 MakeFile(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\File8"));
55 MakeFile(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\HiddenFile"));
56 MakeFile(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\System\\File9"));
59 r=TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden"), KEntryAttHidden, 0);
61 r=TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\HiddenFile"), KEntryAttHidden, 0);
63 r=TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\System"), KEntryAttSystem, 0);
73 test.Next(_L("Create scanner"));
74 CDirScan* scanner=CDirScan::NewL(TheFs);
76 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\"),dirName);
77 scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName);
80 test.Next(_L("Scan top level directory"));
81 scanner->NextL(entryList);
82 TInt count=entryList->Count();
84 TEntry entry=(*entryList)[0];
85 test(entry.iName==_L("Empty"));
86 entry=(*entryList)[1];
87 test(entry.iName==_L("File1"));
88 entry=(*entryList)[2];
89 test(entry.iName==_L("File2"));
90 entry=(*entryList)[3];
91 test(entry.iName==_L("File3"));
92 entry=(*entryList)[4];
93 test(entry.iName==_L("Left"));
94 entry=(*entryList)[5];
95 test(entry.iName==_L("Right"));
98 test.Next(_L("Reset scanner"));
99 scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName);
101 test.Next(_L("Scan ascending: ScanTest directory"));
102 scanner->NextL(entryList);
103 count=entryList->Count();
105 entry=(*entryList)[0];
106 test(entry.iName==_L("Empty"));
107 entry=(*entryList)[1];
108 test(entry.iName==_L("File1"));
109 entry=(*entryList)[2];
110 test(entry.iName==_L("File2"));
111 entry=(*entryList)[3];
112 test(entry.iName==_L("File3"));
113 entry=(*entryList)[4];
114 test(entry.iName==_L("Left"));
115 entry=(*entryList)[5];
116 test(entry.iName==_L("Right"));
119 test.Next(_L("Check next directory: Empty"));
120 scanner->NextL(entryList);
121 count=entryList->Count();
125 test.Next(_L("Check next directory: Left"));
126 scanner->NextL(entryList);
127 count=entryList->Count();
129 entry=(*entryList)[0];
130 test(entry.iName==_L("Dir2"));
131 entry=(*entryList)[1];
132 test(entry.iName==_L("Dir3"));
135 test.Next(_L("Check next directory: Left\\Dir2"));
136 scanner->NextL(entryList);
137 count=entryList->Count();
139 entry=(*entryList)[0];
140 //test(entry.iName==_L("File6"));
143 test.Next(_L("Check next directory: Left\\Dir3"));
144 scanner->NextL(entryList);
145 count=entryList->Count();
147 entry=(*entryList)[0];
148 test(entry.iName==_L("Dir4"));
151 test.Next(_L("Check next directory: Left\\Dir3\\Dir4"));
152 scanner->NextL(entryList);
153 count=entryList->Count();
155 entry=(*entryList)[0];
156 test(entry.iName==_L("File7"));
159 test.Next(_L("Check next directory: Right"));
160 scanner->NextL(entryList);
161 count=entryList->Count();
163 entry=(*entryList)[0];
164 test(entry.iName==_L("File4"));
165 entry=(*entryList)[1];
166 test(entry.iName==_L("File5"));
169 test.Next(_L("End of scan"));
170 scanner->NextL(entryList);
171 test(entryList==NULL);
178 // Scan subset of test directory structure and test abs/rel paths
182 test.Next(_L("Scan descending: ScanTest\\Left "));
183 CDirScan* scanner=CDirScan::NewL(TheFs);
185 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\"),dirName);
186 scanner->SetScanDataL(dirName.FullName(),KEntryAttNormal,ESortByName|EDescending);
188 test.Next(_L("Check next directory: Left"));
190 scanner->NextL(entryList);
191 TInt count=entryList->Count();
193 test(scanner->AbbreviatedPath()==_L("\\"));
194 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\"),dirName);
195 test(scanner->FullPath()==dirName.FullName());
198 test.Next(_L("Check next directory: Left\\Dir3"));
199 scanner->NextL(entryList);
200 count=entryList->Count();
202 test(scanner->AbbreviatedPath()==_L("\\Dir3\\"));
203 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\Dir3\\"),dirName);
204 test(scanner->FullPath()==dirName.FullName());
207 test.Next(_L("Check next directory: Left\\Dir3\\Dir4"));
208 scanner->NextL(entryList);
209 count=entryList->Count();
211 test((*entryList)[0].iName==_L("File7"));
212 test(scanner->AbbreviatedPath()==_L("\\Dir3\\Dir4\\"));
213 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\Dir3\\Dir4\\"),dirName);
214 test(scanner->FullPath()==dirName.FullName());
217 test.Next(_L("Check next directory: Left\\Dir2"));
218 scanner->NextL(entryList);
219 count=entryList->Count();
221 test((*entryList)[0].iName==_L("File6"));
222 test(scanner->AbbreviatedPath()==_L("\\Dir2\\"));
223 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\Dir2\\"),dirName);
224 test(scanner->FullPath()==dirName.FullName());
231 // Print directory structure
235 test.Next(_L("List directory structure"));
236 TheFs.SetAllocFailure(gAllocFailOff);
237 TFileName sessionPath;
238 TInt r=TheFs.SessionPath(sessionPath);
240 r=TheFs.SetSessionPath(_L("N:\\"));
245 CDirScan* scanner=CDirScan::NewL(fs.iObj);
247 TheFs.Parse(sessionPath,dirName);
248 scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName);
252 scanner->NextL(entryList);
255 TInt count=entryList->Count();
258 TEntry data=(*entryList)[count];
259 TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
260 test.Printf(_L("%S%S\n"),&path,&data.iName);
266 r=TheFs.SetSessionPath(sessionPath);
268 TheFs.SetAllocFailure(gAllocFailOn);
273 // Scan for a matching filename
277 test.Start(_L("Scan for a matching filename"));
278 MakeFile(_L("\\F32-TST\\SCANTEST\\MaTCHteST.EXTENSION"));
279 MakeFile(_L("\\F32-TST\\SCANTEST\\MATCH.EXT"));
280 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\ANOTherteST.EXTENSION"));
281 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\APPDLL.DLL"));
282 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\TEST.EXTENSION"));
283 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\DIR4\\MaTCHteST.EXTENSION"));
286 CDirScan* scanner=CDirScan::NewL(TheFs);
289 test.Next(_L("Scan for MAT??.EXT")); // can't test for MAT*.EXT because shortname of MaTCHteST.EXTENSION
290 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\MAT??.EXT"),dirName); // is MATCHT~1.EXT !!!
291 scanner->SetScanDataL(dirName.FullName(),KEntryAttNormal,ESortByName);
292 scanner->NextL(entryList);
293 test((TInt)entryList);
294 test(entryList->Count()==1);
295 test((*entryList)[0].iName.MatchF(_L("MATCH.EXT"))!=KErrNotFound);
296 test(scanner->AbbreviatedPath()==_L("\\"));
297 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\"),dirName);
298 test(scanner->FullPath()==dirName.FullName());
302 scanner->NextL(entryList);
305 test(entryList->Count()==0);
309 test.Next(_L("Scan for *.EXTENSION"));
310 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\*.EXTENSION"),dirName);
311 scanner->SetScanDataL(dirName.FullName(),KEntryAttNormal,ESortByName);
312 scanner->NextL(entryList);
313 test((TInt)entryList);
314 test(entryList->Count()==1);
315 test((*entryList)[0].iName.MatchF(_L("MATCHTEST.EXTENSION"))!=KErrNotFound);
316 test(scanner->AbbreviatedPath()==_L("\\"));
317 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\"),dirName);
318 test(scanner->FullPath()==dirName.FullName());
321 scanner->NextL(entryList);
322 test((TInt)entryList);
323 } while (entryList->Count()==0);
324 test(entryList->Count()==2);
325 test((*entryList)[0].iName.MatchF(_L("ANOTHERTEST.EXTENSION"))!=KErrNotFound);
326 test((*entryList)[1].iName.MatchF(_L("test.EXTENSION"))!=KErrNotFound);
327 test(scanner->AbbreviatedPath().MatchF(_L("\\LEFT\\DIR3\\"))!=KErrNotFound);
328 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\"),dirName);
329 test(scanner->FullPath().MatchF(dirName.FullName())!=KErrNotFound);
332 scanner->NextL(entryList);
333 test((TInt)entryList);
334 } while (entryList->Count()==0);
335 test(entryList->Count()==1);
336 test((*entryList)[0].iName.MatchF(_L("MATCHTEST.EXTENSION"))!=KErrNotFound);
337 test(scanner->AbbreviatedPath().MatchF(_L("\\LEFT\\DIR3\\DIR4\\"))!=KErrNotFound);
338 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\DIR4\\"),dirName);
339 test(scanner->FullPath().MatchF(dirName.FullName())!=KErrNotFound);
343 scanner->NextL(entryList);
346 test(entryList->Count()==0);
350 test.Next(_L("Scan for APPDLL.DLL"));
351 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\APPDLL.DLL"),dirName);
352 scanner->SetScanDataL(dirName.FullName(),KEntryAttNormal,ESortByName);
355 scanner->NextL(entryList);
356 if (entryList->Count()!=0)
358 test((TInt)entryList);
361 test(entryList->Count()==1);
362 test((*entryList)[0].iName==_L("APPDLL.DLL"));
363 test(scanner->AbbreviatedPath().MatchF(_L("\\LEFT\\DIR3\\"))!=KErrNotFound);
364 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\"),dirName);
365 test(scanner->FullPath().MatchF(dirName.FullName())!=KErrNotFound);
369 scanner->NextL(entryList);
372 test(entryList->Count()==0);
385 test.Next(_L("List Z: directory structure"));
386 CDirScan* scanner=CDirScan::NewLC(TheFs);
387 TPtrC romPath(_L("Z:\\"));
389 TInt r=TheFs.Parse(romPath,dirName);
391 scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName);
395 scanner->NextL(entryList);
398 TInt count=entryList->Count();
401 TEntry data=(*entryList)[count];
402 TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
403 test.Printf(_L("%S%S\n"),&path,&data.iName);
408 CleanupStack::PopAndDestroy();
413 // Scan up a directory tree
417 test.Next(_L("Test ascending scan"));
418 MakeFile(_L("\\F32-TST\\SCANTEST\\MaTCHteST.EXTENSION"));
419 MakeFile(_L("\\F32-TST\\SCANTEST\\MATCH.EXT"));
420 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\ANOTherteST.EXTENSION"));
421 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\APPDLL.DLL"));
422 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\TEST.EXTENSION"));
423 MakeFile(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\DIR4\\MaTCHteST.EXTENSION"));
426 CDirScan* scanner=CDirScan::NewL(TheFs);
429 test.Next(_L("Scan for MAT*.EXT"));
430 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\"),dirName);
431 // TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\DIR4\\MaTCHteST.EXTENSION"),dirName);
432 // scanner->SetScanDataL(dirName.FullName(),KEntryAttNormal,ESortByName,CDirScan::EScanUpTree);
433 scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName,CDirScan::EScanUpTree);
437 scanner->NextL(entryList);
440 TInt count=entryList->Count();
443 TEntry entry=(*entryList)[count];
444 test.Printf(_L("entry.iName = %S\n"),&entry.iName);
445 // test(entry.iName==_L("MATCH.EXT"));
456 // Test scanning hidden directories
461 CDirScan* scanner=CDirScan::NewL(TheFs);
464 test.Next(_L("Scan in hidden directories for files"));
465 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\*"),dirName);
466 scanner->SetScanDataL(dirName.FullName(),KEntryAttHidden,ESortByName,CDirScan::EScanDownTree);
471 scanner->NextL(entryList);
474 TInt count=entryList->Count();
477 TEntry entry=(*entryList)[count];
478 test.Printf(_L("entry.iName = %S\n"),&entry.iName);
479 if (entry.IsHidden())
481 if (entry.iName==_L("File8"))
486 test(hiddenCount==2);
488 test.Next(_L("Scan for system and hidden directories and files"));
489 TheFs.Parse(_L("\\F32-TST\\SCANTEST\\LEFT\\DIR3\\*"),dirName);
490 scanner->SetScanDataL(dirName.FullName(),KEntryAttSystem|KEntryAttHidden|KEntryAttDir,ESortByName,CDirScan::EScanDownTree);
495 scanner->NextL(entryList);
498 TInt count=entryList->Count();
501 TEntry entry=(*entryList)[count];
502 test.Printf(_L("entry.iName = %S\n"),&entry.iName);
503 if (entry.IsHidden())
505 if (entry.iName==_L("File8"))
507 if (entry.IsSystem())
509 if (entry.iName==_L("File9"))
514 test(hiddenCount==5);
519 GLDEF_C void CallTestsL()
525 CreateTestDirectory(_L("\\F32-TST\\SCANTEST\\"));
526 DeleteTestDirectory();
533 DeleteTestDirectory();
535 DeleteTestDirectory();
539 DeleteTestDirectory();