First public contribution.
1 // Copyright (c) 2002-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 // f32test\ext\t_ext1.cpp
22 #include "f32_test_utils.h"
24 using namespace F32_Test_Utils;
27 GLDEF_D RTest test(_L("T_EXT1"));
29 _LIT(KExtensionLog,"T_LOGEXT");
30 _LIT(KExtensionLogName,"Logger");
31 _LIT(KExtensionEmpty,"T_EMPTYEXT");
32 _LIT(KExtensionEmptyName,"Empty");
33 _LIT(KExtensionBit,"T_BITEXT");
34 _LIT(KExtensionBitName,"Bitchange");
35 _LIT(KExtensionRubbish,"T_RUBBISH");
36 _LIT(dir1,"\\dir1\\");
37 _LIT(file1Name,"\\dir1\\file1.doc");
38 _LIT8(toWrite,"abcdefghijklmnop");
40 void TestSecondaryExtensions()
42 // a secondary extension is one that is added to a drive with an existing file system
43 // therefore a mount is successful with or without the extension
46 test.Next(_L("TestSecondaryExtensions()"));
48 TInt err=RFs::CharToDrive(gDriveToTest,drive);
51 TPckgBuf<TBool> drvSyncBuf;
52 err = TheFs.QueryVolumeInfoExt(drive, EIsDriveSync, drvSyncBuf);
54 const TBool bDrvSync = drvSyncBuf();
58 TInt r=TheFs.FileSystemName(fsName,drive);
60 test.Printf(_L("fsName=%S\n"),&fsName);
65 // check that the extension cannot be mounted since not supported by the file system
66 r=TheFs.AddExtension(KExtensionLog);
68 r=TheFs.MountExtension(KExtensionLogName,drive);
69 test(r==KErrNotSupported);
70 r=TheFs.RemoveExtension(KExtensionLogName);
76 test.Next(_L("RFs::AddExtension()"));
77 r=TheFs.AddExtension(KExtensionLog);
78 RDebug::Print(_L("addext=%d"),r);
80 r=TheFs.AddExtension(KExtensionLog);
81 test(r==KErrAlreadyExists);
82 r=TheFs.AddExtension(KExtensionRubbish);
83 test(r==KErrNotFound);
84 r=TheFs.AddExtension(KExtensionEmpty);
87 test.Next(_L("RFs::MountExtension()"));
88 #if !defined(__WINS__)
89 // check that the extension cannot be mounted on file system that does not support extensions
90 r=TheFs.MountExtension(KExtensionLogName,EDriveZ);
91 test(r==KErrNotSupported);
93 // test mounting on drive with no file system
94 r=TheFs.DismountFileSystem(fsName,drive);
96 r=TheFs.MountExtension(KExtensionLogName,drive);
97 test(r==KErrNotReady);
98 r=TheFs.MountFileSystem(fsName,drive,bDrvSync);
100 // test with a resource open
101 _LIT(KFileName,"testing.doc");
103 r=file.Replace(TheFs,KFileName,EFileShareExclusive);
105 r=TheFs.MountExtension(KExtensionLogName,drive);
108 r=TheFs.Delete(KFileName);
110 // test with a format open
111 TBuf<4> driveBuf=_L("?:\\");
112 driveBuf[0]=(TText)(drive+'A');
115 r=format.Open(TheFs,driveBuf,EHighDensity,count);
117 r=TheFs.MountExtension(KExtensionLogName,drive);
120 // get the extension name
122 r=TheFs.ExtensionName(extName,drive,0);
123 test(r==KErrNotFound);
124 // now load the extension
125 r=TheFs.MountExtension(KExtensionLogName,drive);
127 r=TheFs.ExtensionName(extName,drive,0);
128 test(r==KErrNone && extName==KExtensionLogName);
129 r=TheFs.ExtensionName(extName,drive,1);
130 test(r==KErrNotFound);
131 // try remounting the same extension
132 r=TheFs.MountExtension(KExtensionLogName,drive);
133 test(r==KErrAlreadyExists);
134 // mount a second extension
135 r=TheFs.MountExtension(KExtensionEmptyName,drive);
137 r=TheFs.ExtensionName(extName,drive,0);
138 test(r==KErrNone && extName==KExtensionLogName);
139 r=TheFs.ExtensionName(extName,drive,1);
140 test(r==KErrNone && extName==KExtensionEmptyName);
142 // force a remount on a removable media and check that extensions both exist
143 test.Printf(_L("Test forcing remount\n"));
145 r=TheFs.Drive(info,drive);
146 if(info.iDriveAtt&KDriveAttRemovable)
148 const TInt KMediaRemountForceMediaChange = 0x00000001;
151 TRequestStatus changeStatus;
152 TheFs.NotifyChange(ENotifyAll, changeStatus);
154 test.Printf(_L("Remounting the drive\n"), r);
155 r = TheFs.RemountDrive(drive, NULL, (TUint) KMediaRemountForceMediaChange);
156 test(r == KErrNotReady || r == KErrNone);
160 test.Printf(_L("Waiting for media change...\n"));
161 User::WaitForRequest(changeStatus);
163 r=TheFs.Drive(info,drive);
164 test.Printf(_L("Drive() returned %d\n"), r);
166 TheFs.NotifyChange(ENotifyAll, changeStatus);
168 while (r == KErrNotReady);
169 TheFs.NotifyChangeCancel(changeStatus);
171 User::After(1000000); //-- don't know why we need this, otherwise for WINS mediadriver returns -18
176 //-- strange, but this variant caused Media Driver to always return -18
177 //-- and the media have become inaccessible forever (on H2).
178 //-- funny enough, but turning ON heavy logging from the drivers (PBUS & KLOCDRV) helped the problem
180 test.Printf(_L("Force media change\n"));
185 d.ForceMediaChange();
187 //#if defined(__WINS__)
188 // ??? seems to work, find out why
189 //User::After(500000);
190 User::After(2000000);
197 r=TheFs.ExtensionName(extName,drive,0);
198 test(r==KErrNone && extName==KExtensionLogName);
199 r=TheFs.ExtensionName(extName,drive,1);
200 test(r==KErrNone && extName==KExtensionEmptyName);
202 test.Printf(_L("Accessing media...\n"));
203 // and now do some file system operations
207 test.Printf(_L("res=%d\n"), r);
210 test(r==KErrNone||r==KErrAlreadyExists);
212 r=file1.Replace(TheFs,file1Name,EFileShareExclusive);
214 r=file1.Write(toWrite);
216 r=file1.Read(0,readBuf);
217 test(readBuf==toWrite);
221 r=TheFs.Delete(file1Name);
226 test.Next(_L("RFs::DismountExtension()"));
227 // test with a resource open
228 r=file.Replace(TheFs,KFileName,EFileShareExclusive);
230 r=TheFs.DismountExtension(KExtensionLogName,drive);
233 r=TheFs.Delete(KFileName);
235 // test with a format open
236 r=format.Open(TheFs,driveBuf,EHighDensity,count);
238 r=TheFs.DismountExtension(KExtensionLogName,drive);
241 // now dismount an extension
242 r=TheFs.DismountExtension(KExtensionLogName,drive);
244 r=TheFs.ExtensionName(extName,drive,0);
245 test(r==KErrNone && extName==KExtensionEmptyName);
246 r=TheFs.ExtensionName(extName,drive,1);
247 test(r==KErrNotFound);
248 // try to dismount an extension that is not mounted
249 r=TheFs.DismountExtension(KExtensionLogName,drive);
250 test(r==KErrNotFound);
251 r=TheFs.ExtensionName(extName,drive,0);
252 test(r==KErrNone && extName==KExtensionEmptyName);
253 r=TheFs.ExtensionName(extName,drive,1);
254 test(r==KErrNotFound);
255 // dismount the remaining extension
256 r=TheFs.DismountExtension(KExtensionEmptyName,drive);
258 r=TheFs.ExtensionName(extName,drive,0);
259 test(r==KErrNotFound);
260 r=TheFs.ExtensionName(extName,drive,1);
261 test(r==KErrNotFound);
263 test.Next(_L("RFs::RemoveExtension()"));
264 r=TheFs.RemoveExtension(KExtensionLogName);
266 r=TheFs.RemoveExtension(KExtensionEmptyName);
270 void TestPrimaryExtensions()
272 // a primary extension is one that is added to a drive before a file system is mounted
273 // must be present for the mount to be successful (eg. FTL)
276 test.Next(_L("TestPrimaryExtensions()"));
278 TInt err=RFs::CharToDrive(gDriveToTest,drive);
281 #if defined(__WINS__)
286 TPckgBuf<TBool> drvSyncBuf;
287 err = TheFs.QueryVolumeInfoExt(drive, EIsDriveSync, drvSyncBuf);
289 const TBool bDrvSync = drvSyncBuf();
291 // don't test on ram drive since accesses memory directly
293 TInt r=TheFs.Drive(info,drive);
294 if(info.iMediaAtt&KMediaAttVariableSize)
298 r=TheFs.FileSystemName(fsName,drive);
300 test.Printf(_L("fsName=%S\n"),&fsName);
302 test.Next(_L("RFs::AddExtension()"));
303 r=TheFs.AddExtension(KExtensionLog);
305 r=TheFs.AddExtension(KExtensionEmpty);
307 r=TheFs.AddExtension(KExtensionBit);
310 test.Next(_L("RFs::MountFileSystem()"));
311 // test with file system that already exists
312 r=TheFs.MountFileSystem(fsName,KExtensionBitName,drive,bDrvSync);
313 test(r==KErrAccessDenied);
314 // unmount drive and mount primary extension along with file system
315 r=TheFs.DismountFileSystem(fsName,drive);
318 //-- !! N.B this extension mangles data read/written ftom/to the media, for some file systems it is OK and mounting succeeds
319 //-- for others - this will result in KErrCorrupt
320 r=TheFs.MountFileSystem(fsName,KExtensionBitName,drive,bDrvSync);
321 test(r==KErrNone||r==KErrCorrupt);
326 r=TheFs.ExtensionName(extName,drive,0);
327 test(r==KErrNone && extName==KExtensionBitName);
328 r=TheFs.ExtensionName(extName,drive,1);
329 test(r==KErrNotFound);
331 // and now do some file system operations
334 test(r==KErrNone||r==KErrAlreadyExists);
336 r=file1.Replace(TheFs,file1Name,EFileShareExclusive);
338 r=file1.Write(toWrite);
340 r=file1.Read(0,readBuf);
341 test(readBuf==toWrite);
345 r=TheFs.Delete(file1Name);
350 // add a secondary extension
351 test.Printf(_L("RFs::MountExtension()"));
352 r=TheFs.MountExtension(KExtensionLogName,drive);
354 r=TheFs.ExtensionName(extName,drive,0);
355 test(r==KErrNone && extName==KExtensionBitName);
356 r=TheFs.ExtensionName(extName,drive,1);
357 test(r==KErrNone && extName==KExtensionLogName);
358 // try to add the same extension
359 r=TheFs.MountExtension(KExtensionBitName,drive);
360 test(r==KErrAlreadyExists);
361 r=TheFs.ExtensionName(extName,drive,0);
362 test(r==KErrNone && extName==KExtensionBitName);
363 r=TheFs.ExtensionName(extName,drive,1);
364 test(r==KErrNone && extName==KExtensionLogName);
365 // try to add a third extension
366 r=TheFs.MountExtension(KExtensionEmptyName,drive);
367 test(r==KErrAccessDenied);
368 r=TheFs.ExtensionName(extName,drive,0);
369 test(r==KErrNone && extName==KExtensionBitName);
370 r=TheFs.ExtensionName(extName,drive,1);
371 test(r==KErrNone && extName==KExtensionLogName);
373 // and now do some file system operations
375 test(r==KErrNone||r==KErrAlreadyExists);
376 r=file1.Replace(TheFs,file1Name,EFileShareExclusive);
378 r=file1.Write(toWrite);
380 r=file1.Read(0,readBuf);
381 test(readBuf==toWrite);
385 r=TheFs.Delete(file1Name);
390 test.Printf(_L("RFs::DismountExtension()"));
391 // test that can't dismount a primary extension via this method
392 r=TheFs.DismountExtension(KExtensionLogName,drive);
394 r=TheFs.ExtensionName(extName,drive,0);
395 test(r==KErrNone && extName==KExtensionBitName);
396 r=TheFs.ExtensionName(extName,drive,1);
397 test(r==KErrNotFound);
398 r=TheFs.DismountExtension(KExtensionBitName,drive);
399 test(r==KErrAccessDenied);
400 r=TheFs.ExtensionName(extName,drive,0);
401 test(r==KErrNone && extName==KExtensionBitName);
402 r=TheFs.ExtensionName(extName,drive,1);
403 test(r==KErrNotFound);
405 test.Printf(_L("RFs::DismountFileSystem()"));
406 r=TheFs.MountExtension(KExtensionLogName,drive);
408 r=TheFs.ExtensionName(extName,drive,0);
409 test(r==KErrNone && extName==KExtensionBitName);
410 r=TheFs.ExtensionName(extName,drive,1);
411 test(r==KErrNone && extName==KExtensionLogName);
413 r=TheFs.DismountFileSystem(fsName,drive);
415 r=TheFs.ExtensionName(extName,drive,0);
416 test(r==KErrNotReady);
417 r=TheFs.ExtensionName(extName,drive,1);
418 test(r==KErrNotReady);
419 // remount the file system
420 r=TheFs.MountFileSystem(fsName,drive,bDrvSync);
421 test(r==KErrNone||r==KErrCorrupt);
422 r=TheFs.ExtensionName(extName,drive,0);
423 test(r==KErrNotFound);
424 r=TheFs.ExtensionName(extName,drive,1);
425 test(r==KErrNotFound);
428 test.Next(_L("RFs::RemoveExtension()"));
429 r=TheFs.RemoveExtension(KExtensionLogName);
431 r=TheFs.RemoveExtension(KExtensionEmptyName);
433 r=TheFs.RemoveExtension(KExtensionBitName);
438 GLDEF_C void CallTestsL()
440 // Do tests relative to the session path
443 //-- set up console output
444 F32_Test_Utils::SetConsole(test.Console());
447 TInt err=RFs::CharToDrive(gDriveToTest,drive);
448 test.Start(_L("Starting Test - T_EXT1"));
451 PrintDrvInfo(TheFs, drive);
453 //Do not run this test on the NAND drive, as
454 //this has the FTL mounted as a primary extension
455 //which causes the test to fail
456 #if defined(__WINS__)
460 TDriveInfo driveInfo;
461 TheFs.Drive(driveInfo,drive);
462 if (driveInfo.iType == EMediaNANDFlash)
467 TestSecondaryExtensions();
469 //-- the t_bitext extension mangles data from the media, which may make FS mounting fail because of "corrupted" data.
470 //-- Then this step formats the media, automounter doesn't support it straightforward way
471 if(!Is_Lffs(TheFs, drive) && !Is_Automounter(TheFs, drive))
473 TestPrimaryExtensions();