Update contrib.
1 // Copyright (c) 2000-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.
14 // Test traversal of directories and locating files in directories
19 #include <e32std_private.h>
20 #define __E32TEST_EXTENSION__
27 RTest test( _L("T_ROFSDIR") );
29 _LIT( KTestFile1, "root.txt" );
30 _LIT( KTestFile2, "Dir1\\level1.txt" );
31 _LIT( KTestFile3, "Dir1\\Dir2\\level2.txt" );
32 _LIT( KTestFile4, "Dir1\\Dir2\\Dir3\\level3.txt" );
33 _LIT( KTestFile5, "Dir1\\Dir2\\Dir3\\Dir4\\level4.txt" );
34 _LIT( KTestFile6, "Dir1\\Dir2\\Dir3\\Dir4\\Dir5\\level5.txt" );
35 _LIT( KTestFile7, "Dir1\\Dir2\\Dir3\\Dir4\\Dir5\\Dir6\\level6.txt" );
36 _LIT( KTestFile8, "Dir1\\Dir2\\Dir3\\Dir4\\Dir5\\Dir6\\Dir7\\level7.txt" );
37 _LIT( KTestFile9, "DeepDir1\\DeepDir2\\DeepDir3\\DeepDir4\\DeepDir5\\DeepDir6\\DeepDir7\\DeepDir8\\DeepDir9\\DeepDir10\\DeepDir11\\DeepDir12\\DeepDir13\\DeepDir14\\file.txt" );
38 _LIT( KTestFile10, "Parent\\parfile.txt" );
39 _LIT( KTestFile11, "Parent\\SubDir1A\\subfileA.txt" );
40 _LIT( KTestFile12, "Parent\\SubDir1B\\subfileB.txt" );
41 _LIT( KTestFile13, "Parent\\SubDir1C\\subfileC.txt" );
42 _LIT( KTestFile14, "Parent\\SubDir1D\\subfileD.txt" );
43 _LIT( KTestFile15, "Parent\\SubDir1E\\subfileE.txt" );
44 _LIT( KTestFile16, "Parent\\SubDir1F\\SubSubA\\subsub_a.txt" );
45 _LIT( KTestFile17, "Parent\\SubDir1F\\SubSubB\\subsub_b.txt" );
46 _LIT( KTestFile18, "Parent\\SubDir1F\\SubSubC\\subsub_c.txt" );
47 _LIT( KTestFile19, "Parent\\SubDir1F\\SubSubD\\subsub_d.txt" );
48 _LIT( KTestFile20, "Mixed\\par1.txt" );
49 _LIT( KTestFile21, "Mixed\\SubDir1\\sub1.txt" );
50 _LIT( KTestFile22, "Mixed\\SubDir2\\sub2.txt" );
51 _LIT( KTestFile23, "Mixed\\SubDir3\\sub3.txt" );
52 _LIT( KTestFile24, "Mixed\\SubDir4\\sub4.txt" );
53 _LIT( KTestFile25, "Mixed\\SubDir5\\sub5.txt" );
54 _LIT( KTestFile26, "Mixed\\SubDir6\\sub6.txt" );
55 _LIT( KTestFile27, "Mixed\\SubDir7\\sub7.txt" );
56 _LIT( KTestFile28, "Mixed\\SubDir8\\sub8.txt" );
57 _LIT( KTestFile29, "Mixed\\par2.txt" );
58 _LIT( KTestFile30, "Mixed\\par3.txt" );
59 _LIT( KTestFile31, "Mixed\\par4.txt" );
60 _LIT( KTestFile32, "Mixed\\par5.txt" );
61 _LIT( KTestFile33, "Mixed\\par6.txt" );
62 _LIT( KTestFile34, "Mixed\\par7.txt" );
63 _LIT( KTestFile35, "Mixed\\par8.txt" );
64 // required to test extension
65 _LIT( KTestFile36, "ext.txt" );
66 _LIT( KTestFile37, "Dir1\\ext.txt" );
67 _LIT( KTestFile38, "Dir1\\level1_ext.txt" );
68 //required to test the unique files
69 //(Note: These file names depend on the mount ids. Hence change in mount order will affect the test)
70 _LIT( KTestFile39, "Exattrib\\test1.txt[02-00]" );
71 _LIT( KTestFile40, "Exattrib\\test1.txt[03-00]");
72 _LIT( KTestFile41, "Exattrib\\test2.txt[03-00]" );
73 _LIT( KTestFile42, "Exattrib\\test3-1.txt[02-00]");
74 _LIT( KTestFile43, "Exattrib\\test5-1.txt[x-y][03-00]");
76 const TInt KRootDirEntryCount = 17;
78 _LIT( KRootFile, "root.txt" );
79 _LIT( KRootFileExt, "ext.txt" );
80 _LIT( KRootDir1, "Dir1" );
81 _LIT( KRootDeepDir1, "DeepDir1" );
82 _LIT( KRootDirParent, "Parent" );
83 _LIT( KRootDirMixed, "Mixed" );
84 _LIT( KRootDirReadTest, "ReadTest" );
85 _LIT( KRootDirAttrib, "Attrib" );
86 _LIT( KRootDirExattrib, "Exattrib" );
87 _LIT( KRootDirResource, "Resource" );
88 _LIT( KRootImg, "Img" );
89 _LIT( KRootSys, "sys" );
90 _LIT( KRootSystem, "system" );
91 _LIT( KRootTest, "Test" );
92 _LIT( KRootDirMultiple, "Multiple" );
93 _LIT( KRootAutoexec, "autoexec.bat" );
95 _LIT( KRootDirScripts, "scripts" );
98 _LIT( KSubDirOnlyBase, "Parent\\SubDir1F\\" );
99 _LIT( KSubSubPattern, "SubSub%c" );
100 const TInt KSubDirOnlyCount = 4;
102 _LIT( KFilesOnlyBase, "Parent\\SubDir1F\\SubSubA\\" );
103 _LIT( KSubSubFilePattern, "subsub_%c.txt" );
104 const TInt KFilesOnlyCount = 1;
106 _LIT( KMixedDirBase, "Mixed\\" );
107 _LIT( KMixedDirPattern, "SubDir%d" );
108 _LIT( KMixedFilePattern, "par%d.txt" );
109 const TInt KMixedSubDirCount = 8;
110 const TInt KMixedSubFileCount = 8;
113 const TInt KMultipleDirEntryCount=14;
114 _LIT( KMultipleFile1, "new1.txt" );
115 _LIT( KMultipleFile2, "new2.txt" );
116 _LIT( KMultipleFile3, "new3.txt" );
117 _LIT( KMultipleFile4, "replaceme1.txt" );
118 _LIT( KMultipleFile5, "replaceme2.txt" );
119 _LIT( KMultipleFile6, "replaceme3.txt" );
120 _LIT( KMultipleFile7, "replaceme4.txt" );
121 _LIT( KMultipleFile8, "rom.txt" );
122 _LIT( KMultipleFile9, "romreplace.txt" );
123 // required to test multiple rofs
124 _LIT( KMultipleFile10, "multirofs.txt" );
125 // files on user data fat partition
126 _LIT( KMultipleFile11, "new4.txt" );
127 _LIT( KMultipleFile12, "replaceme5.txt" );
128 _LIT( KMultipleFile13, "romreplacefat.txt" );
129 _LIT( KMultipleFile14, "t_file.cpp" );
131 const TInt KExattribDirEntryCount = 11;
133 _LIT( KExattribFile1, "test1.txt[02-00]" );
134 _LIT( KExattribFile2, "test1.txt[03-00]" );
135 _LIT( KExattribFile3, "test2.txt[03-00]" );
136 _LIT( KExattribFile4, "test3-1.txt[02-00]" );
137 _LIT( KExattribFile5, "test4-2.txt[03-00]" );
138 _LIT( KExattribFile6, "test5-1.txt[x-y][03-00]" );
139 _LIT( KExattribFile7, "test5-2.txt[x-y]" );
140 _LIT( KExattribFile8, "test8-1.txt[04-00]" );
141 _LIT( KExattribFile9, "test6-1.txt[04-00]" );
142 _LIT( KExattribFile10, "test7-1.txt[03-00]" );
143 _LIT( KExattribFile11, "test7-1.txt[04-00]" );
145 _LIT( KDriveBase, " :\\" );
146 _LIT( KDriveMultiple, "Multiple\\" );
147 _LIT( KDriveExattrib, "Exattrib\\" );
148 _LIT( KWildCard, "*" );
159 LOCAL_C void TestOpenFilesL(TInt aDriveToTest, TBool aExtension, TBool aMultipleRofs)
161 // Tests that we can open files in various directories on the drive
170 const TDesC* const fileArray[43] =
172 &KTestFile1, &KTestFile2, &KTestFile3, &KTestFile4, &KTestFile5,
173 &KTestFile6, &KTestFile7, &KTestFile8, &KTestFile9, &KTestFile10,
174 &KTestFile11, &KTestFile12, &KTestFile13, &KTestFile14, &KTestFile15,
175 &KTestFile16, &KTestFile17, &KTestFile18, &KTestFile19, &KTestFile20,
176 &KTestFile21, &KTestFile22, &KTestFile23, &KTestFile24, &KTestFile25,
177 &KTestFile26, &KTestFile27, &KTestFile28, &KTestFile29, &KTestFile30,
178 &KTestFile31, &KTestFile32, &KTestFile33, &KTestFile34, &KTestFile35,
179 &KTestFile36, &KTestFile37, &KTestFile38, &KTestFile39, &KTestFile40,
180 &KTestFile41, &KTestFile42, &KTestFile43
183 test.Next( _L("Test opening files in directories") );
184 TFileName name(KDriveBase);
185 name[0] = TText('A' + aDriveToTest);
187 for( TInt i = 0; i < index; i++ )
189 name.SetLength( 3 ); // trim back to drive specifier
190 if(aExtension && (i==1))
191 name.Append( *fileArray[i+36] );
193 name.Append( *fileArray[i] );
194 test.Printf( _L("Opening file %S\n"), &name );
196 TInt r = file.Open( TheFs, name, EFileRead );
203 LOCAL_C void TestScanDirL(TInt aDriveToTest, TEntrySet aEntrySet)
205 // Scan the root directory file
208 const TDesC* const rootEntriesExt[ KRootDirEntryCount ] =
210 &KRootFileExt, &KRootFile, &KRootDir1, &KRootDeepDir1,
211 &KRootDirParent, &KRootDirMixed, &KRootDirReadTest, &KRootDirAttrib, &KRootDirExattrib,
212 &KRootDirResource, &KRootImg, &KRootSys, &KRootSystem, &KRootTest, &KRootDirMultiple,
217 const TDesC* const rootEntries[ KRootDirEntryCount-1 ] =
219 &KRootFile, &KRootDir1, &KRootDeepDir1,
220 &KRootDirParent, &KRootDirMixed, &KRootDirReadTest, &KRootDirAttrib, &KRootDirExattrib,
221 &KRootDirResource, &KRootImg, &KRootSys, &KRootSystem, &KRootTest, &KRootDirMultiple,
226 const TDesC* const multipleEntries[ KMultipleDirEntryCount ] =
228 &KMultipleFile1, &KMultipleFile2, &KMultipleFile3, &KMultipleFile4, &KMultipleFile5,
229 &KMultipleFile6, &KMultipleFile7, &KMultipleFile8, &KMultipleFile9, &KMultipleFile10,
230 &KMultipleFile11, &KMultipleFile12, &KMultipleFile13, &KMultipleFile14
233 const TDesC* const exattribEntries[ KExattribDirEntryCount ] =
235 &KExattribFile1, &KExattribFile2, &KExattribFile3, &KExattribFile4,
236 &KExattribFile5, &KExattribFile6, &KExattribFile7, &KExattribFile8,
237 &KExattribFile9, &KExattribFile10, &KExattribFile11
240 const TDesC* const *entries = NULL;
242 TBool seen[KRootDirEntryCount];
243 memclr(seen, KRootDirEntryCount*sizeof(TBool));
244 TFileName name(KDriveBase);
245 name[0] = TText('A' + aDriveToTest);
250 DirCount=KRootDirEntryCount-1;
252 test.Next( _L("Scanning root directory") );
255 DirCount=KRootDirEntryCount;
256 entries=rootEntriesExt;
257 test.Next( _L("Scanning root extension directory") );
260 DirCount=KMultipleDirEntryCount;
261 entries=multipleEntries;
262 name.Append(KDriveMultiple);
263 test.Next( _L("Scanning multiple directory") );
266 DirCount=KExattribDirEntryCount;
267 entries=exattribEntries;
268 name.Append(KDriveExattrib);
269 test.Next( _L("Scanning Exattrib directory") );
276 TInt r = TheFs.GetDir( name, KEntryAttMaskSupported, ESortNone, dir );
279 TInt actualCount = dir->Count();
280 for(TInt i = 0; i < actualCount; i++)
282 const TEntry& e = dir->operator[](i);
283 TFileName lowerName(e.iName);
284 lowerName.LowerCase();
285 TBool found = EFalse;
286 // try to find the name in our list
287 for(TInt j = 0; j < DirCount && !found; j++)
289 TFileName expectedLower(*entries[j]);
290 expectedLower.LowerCase();
291 // Check the directory name is that expected.
292 found = lowerName == expectedLower;
297 test.Printf( _L("ERROR: saw entry %S twice\n"), &e.iName );
308 test.Printf( _L("ERROR: entry %S unknown\n"), &e.iName );
312 // All the entries are those expected but are there enough matching entries.
313 // Allow the autoexe.bat to not be present so the test can pass when run
314 // when not part of an auto test rom.
316 if (aEntrySet == ERoot || aEntrySet == ERootExtension)
317 {// The "scripts" directory is not present on all roms.
320 test_Value(actualCount, actualCount >= DirCount-tolerance);
326 LOCAL_C void TestSubDirsOnlyL(TInt aDriveToTest)
328 // Tests that scanning a directory containing only subdirectories
329 // only returns entries marked as directories
332 test.Next( _L("Testing scan of dir containing only subdirs") );
335 TFileName name(KDriveBase);
336 name[0] = TText('A' + aDriveToTest);
337 name.Append( KSubDirOnlyBase );
338 name.Append( KWildCard );
340 TInt r = TheFs.GetDir( name, KEntryAttMaskSupported, ESortNone, dir );
343 TEST_FOR_MATCH( dir->Count(), KSubDirOnlyCount );
345 TBuf<32> subEntryName;
346 for( TInt i = 0; i < KSubDirOnlyCount; i++ )
348 const TEntry& e = dir->operator[](i);
349 subEntryName.Format( KSubSubPattern, 'A' + i );
350 test.Printf( _L("Found entry %S\n"), &e.iName );
351 test( e.iName == subEntryName );
358 LOCAL_C void TestFilesOnlyL(TInt aDriveToTest)
360 // Tests that scanning a directory containing only files
361 // does not return any entries marked as files
364 test.Next( _L("Testing scan of dir containing only files") );
367 TFileName name(KDriveBase);
368 name[0] = TText('A' + aDriveToTest);
369 name.Append( KFilesOnlyBase );
370 name.Append( KWildCard );
372 TInt r = TheFs.GetDir( name, KEntryAttMaskSupported, ESortNone, dir );
375 TEST_FOR_MATCH( dir->Count(), KFilesOnlyCount );
377 TBuf<32> subEntryName;
378 for( TInt i = 0; i < KFilesOnlyCount; i++ )
380 const TEntry& e = dir->operator[](i);
381 subEntryName.Format( KSubSubFilePattern, 'a' + i );
382 test.Printf( _L("Found entry %S\n"), &e.iName );
383 test( e.iName == subEntryName );
390 LOCAL_C void TestMaskDirsL(TInt aDriveToTest)
392 // Test scanning a directory with masking to return only directories
395 test.Next( _L("Testing scan of dir masking out files") );
398 TFileName name(KDriveBase);
399 name[0] = TText('A' + aDriveToTest);
400 name.Append( KMixedDirBase );
401 name.Append( KWildCard );
403 TInt r = TheFs.GetDir( name, KEntryAttMatchExclusive | KEntryAttDir, ESortNone, dir );
406 TEST_FOR_MATCH( dir->Count(), KMixedSubDirCount );
408 TBuf<32> subEntryName;
409 for( TInt i = 0; i < KMixedSubDirCount; i++ )
411 const TEntry& e = dir->operator[](i);
412 subEntryName.Format( KMixedDirPattern, i+1 );
413 test.Printf( _L("Found entry %S\n"), &e.iName );
414 test( e.iName == subEntryName );
420 LOCAL_C void TestMaskFilesL(TInt aDriveToTest)
422 // Test scanning a directory with masking to return only files
425 test.Next( _L("Testing scan of dir masking out directories") );
428 TFileName name(KDriveBase);
429 name[0] = TText('A' + aDriveToTest);
430 name.Append( KMixedDirBase );
431 name.Append( KWildCard );
433 TInt r = TheFs.GetDir( name, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir );
436 TEST_FOR_MATCH( dir->Count(), KMixedSubFileCount );
438 TBuf<32> subEntryName;
439 for( TInt i = 0; i < KMixedSubFileCount; i++ )
441 const TEntry& e = dir->operator[](i);
442 subEntryName.Format( KMixedFilePattern, i+1 );
443 test.Printf( _L("Found entry %S\n"), &e.iName );
444 test( e.iName == subEntryName );
450 LOCAL_C void TestGetDirL(TInt aDriveToTest)
452 // Test UID scanning of a directory
455 test.Next( _L("Testing scan of dir with UID bitmask") );
457 TFileName name(KDriveBase);
458 name[0] = TText('A' + aDriveToTest);
459 name.Append( KRootDirResource );
460 name.Append(_L("\\"));
462 const TUid KUidInterfaceImplementationCollectionInfo = {0x101F747D};
464 TUidType rscUidType(KNullUid,KUidInterfaceImplementationCollectionInfo,KNullUid);
467 TInt r = TheFs.GetDir(name, rscUidType, ESortByUid, dir);
469 TInt count = dir->Count();
473 TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
474 r = TheFs.GetDir(name, uidType2, ESortByUid, dir);
476 count = dir->Count();
483 //************************
486 void DoTestL(TInt aDriveToTest)
489 test.Start( _L("Testing ROFS directory structure") );
491 test.Printf( _L("Looking for ROFS extension..\n"));
492 TBool extension = EFalse;
493 TFileName name(KDriveBase);
494 name[0] = TText('A' + aDriveToTest);
496 name.SetLength( 3 ); // trim back to drive specifier
497 name.Append( KTestFile36 );
500 test.Printf( _L("Attempt to open file %S.."), &name );
501 TInt r = file.Open( TheFs, name, EFileRead );
506 test.Printf( _L("ROFS extension found.\n"));
508 else if(r==KErrNotFound)
510 test.Printf( _L("Not found, ROFS extension not present.\n"));
513 test.Printf( _L("Looking for multiple ROFS..\n"));
514 TBool multipleRofs = EFalse;
515 name.SetLength( 3 ); // trim back to drive specifier
516 name.Append( KMultipleFile10 );
518 test.Printf( _L("Attempt to open file %S.."), &name );
519 r = file.Open( TheFs, name, EFileRead );
524 test.Printf( _L("Multiple ROFS found. %S is present.\n"), &name);
526 else if(r==KErrNotFound)
528 test.Printf( _L("No multiple ROFS found. %S is not present.\n"), &name);
531 TestOpenFilesL(aDriveToTest,extension,multipleRofs);
532 TestScanDirL(aDriveToTest, extension?ERootExtension:ERoot);
533 TestSubDirsOnlyL(aDriveToTest);
534 TestFilesOnlyL(aDriveToTest);
535 TestMaskDirsL(aDriveToTest);
536 TestMaskFilesL(aDriveToTest);
537 TestGetDirL(aDriveToTest);
539 // Test dir works for muliple rofs
542 TestScanDirL(aDriveToTest, EMultiple);
543 TestScanDirL(aDriveToTest, EExattrib);