sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\ext\t_ext1.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: #include "f32_test_utils.h" sl@0: sl@0: using namespace F32_Test_Utils; sl@0: sl@0: sl@0: GLDEF_D RTest test(_L("T_EXT1")); sl@0: sl@0: _LIT(KExtensionLog,"T_LOGEXT"); sl@0: _LIT(KExtensionLogName,"Logger"); sl@0: _LIT(KExtensionEmpty,"T_EMPTYEXT"); sl@0: _LIT(KExtensionEmptyName,"Empty"); sl@0: _LIT(KExtensionBit,"T_BITEXT"); sl@0: _LIT(KExtensionBitName,"Bitchange"); sl@0: _LIT(KExtensionRubbish,"T_RUBBISH"); sl@0: _LIT(dir1,"\\dir1\\"); sl@0: _LIT(file1Name,"\\dir1\\file1.doc"); sl@0: _LIT8(toWrite,"abcdefghijklmnop"); sl@0: sl@0: void TestSecondaryExtensions() sl@0: // sl@0: // a secondary extension is one that is added to a drive with an existing file system sl@0: // therefore a mount is successful with or without the extension sl@0: // sl@0: { sl@0: test.Next(_L("TestSecondaryExtensions()")); sl@0: TInt drive; sl@0: TInt err=RFs::CharToDrive(gDriveToTest,drive); sl@0: test(err==KErrNone); sl@0: sl@0: TPckgBuf drvSyncBuf; sl@0: err = TheFs.QueryVolumeInfoExt(drive, EIsDriveSync, drvSyncBuf); sl@0: test(err==KErrNone); sl@0: const TBool bDrvSync = drvSyncBuf(); sl@0: sl@0: sl@0: TFullName fsName; sl@0: TInt r=TheFs.FileSystemName(fsName,drive); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("fsName=%S\n"),&fsName); sl@0: sl@0: #if defined(__WINS__) sl@0: if(drive==EDriveC) sl@0: { sl@0: // check that the extension cannot be mounted since not supported by the file system sl@0: r=TheFs.AddExtension(KExtensionLog); sl@0: test(r==KErrNone); sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNotSupported); sl@0: r=TheFs.RemoveExtension(KExtensionLogName); sl@0: test(r==KErrNone); sl@0: return; sl@0: } sl@0: #endif sl@0: sl@0: test.Next(_L("RFs::AddExtension()")); sl@0: r=TheFs.AddExtension(KExtensionLog); sl@0: RDebug::Print(_L("addext=%d"),r); sl@0: test(r==KErrNone); sl@0: r=TheFs.AddExtension(KExtensionLog); sl@0: test(r==KErrAlreadyExists); sl@0: r=TheFs.AddExtension(KExtensionRubbish); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.AddExtension(KExtensionEmpty); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("RFs::MountExtension()")); sl@0: #if !defined(__WINS__) sl@0: // check that the extension cannot be mounted on file system that does not support extensions sl@0: r=TheFs.MountExtension(KExtensionLogName,EDriveZ); sl@0: test(r==KErrNotSupported); sl@0: #endif sl@0: // test mounting on drive with no file system sl@0: r=TheFs.DismountFileSystem(fsName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNotReady); sl@0: r=TheFs.MountFileSystem(fsName,drive,bDrvSync); sl@0: test(r==KErrNone); sl@0: // test with a resource open sl@0: _LIT(KFileName,"testing.doc"); sl@0: RFile file; sl@0: r=file.Replace(TheFs,KFileName,EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrInUse); sl@0: file.Close(); sl@0: r=TheFs.Delete(KFileName); sl@0: test(r==KErrNone); sl@0: // test with a format open sl@0: TBuf<4> driveBuf=_L("?:\\"); sl@0: driveBuf[0]=(TText)(drive+'A'); sl@0: RFormat format; sl@0: TInt count; sl@0: r=format.Open(TheFs,driveBuf,EHighDensity,count); sl@0: test(r==KErrNone); sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrInUse); sl@0: format.Close(); sl@0: // get the extension name sl@0: TFullName extName; sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNotFound); sl@0: // now load the extension sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionLogName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: // try remounting the same extension sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrAlreadyExists); sl@0: // mount a second extension sl@0: r=TheFs.MountExtension(KExtensionEmptyName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionLogName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNone && extName==KExtensionEmptyName); sl@0: sl@0: // force a remount on a removable media and check that extensions both exist sl@0: test.Printf(_L("Test forcing remount\n")); sl@0: TDriveInfo info; sl@0: r=TheFs.Drive(info,drive); sl@0: if(info.iDriveAtt&KDriveAttRemovable) sl@0: { sl@0: const TInt KMediaRemountForceMediaChange = 0x00000001; sl@0: sl@0: sl@0: TRequestStatus changeStatus; sl@0: TheFs.NotifyChange(ENotifyAll, changeStatus); sl@0: sl@0: test.Printf(_L("Remounting the drive\n"), r); sl@0: r = TheFs.RemountDrive(drive, NULL, (TUint) KMediaRemountForceMediaChange); sl@0: test(r == KErrNotReady || r == KErrNone); sl@0: sl@0: do sl@0: { sl@0: test.Printf(_L("Waiting for media change...\n")); sl@0: User::WaitForRequest(changeStatus); sl@0: sl@0: r=TheFs.Drive(info,drive); sl@0: test.Printf(_L("Drive() returned %d\n"), r); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll, changeStatus); sl@0: } sl@0: while (r == KErrNotReady); sl@0: TheFs.NotifyChangeCancel(changeStatus); sl@0: sl@0: User::After(1000000); //-- don't know why we need this, otherwise for WINS mediadriver returns -18 sl@0: sl@0: sl@0: sl@0: /* sl@0: //-- strange, but this variant caused Media Driver to always return -18 sl@0: //-- and the media have become inaccessible forever (on H2). sl@0: //-- funny enough, but turning ON heavy logging from the drivers (PBUS & KLOCDRV) helped the problem sl@0: sl@0: test.Printf(_L("Force media change\n")); sl@0: RLocalDrive d; sl@0: TBool flag=EFalse; sl@0: r=d.Connect(1,flag); sl@0: test(r==KErrNone); sl@0: d.ForceMediaChange(); sl@0: d.Close(); sl@0: //#if defined(__WINS__) sl@0: // ??? seems to work, find out why sl@0: //User::After(500000); sl@0: User::After(2000000); sl@0: //#endif sl@0: */ sl@0: } sl@0: sl@0: sl@0: sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionLogName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNone && extName==KExtensionEmptyName); sl@0: sl@0: test.Printf(_L("Accessing media...\n")); sl@0: // and now do some file system operations sl@0: TBuf8<16> readBuf; sl@0: r=TheFs.MkDir(dir1); sl@0: sl@0: test.Printf(_L("res=%d\n"), r); sl@0: sl@0: sl@0: test(r==KErrNone||r==KErrAlreadyExists); sl@0: RFile file1; sl@0: r=file1.Replace(TheFs,file1Name,EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: r=file1.Write(toWrite); sl@0: test(r==KErrNone); sl@0: r=file1.Read(0,readBuf); sl@0: test(readBuf==toWrite); sl@0: r=file1.SetSize(0); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: r=TheFs.Delete(file1Name); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(dir1); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("RFs::DismountExtension()")); sl@0: // test with a resource open sl@0: r=file.Replace(TheFs,KFileName,EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: r=TheFs.DismountExtension(KExtensionLogName,drive); sl@0: test(r==KErrInUse); sl@0: file.Close(); sl@0: r=TheFs.Delete(KFileName); sl@0: test(r==KErrNone); sl@0: // test with a format open sl@0: r=format.Open(TheFs,driveBuf,EHighDensity,count); sl@0: test(r==KErrNone); sl@0: r=TheFs.DismountExtension(KExtensionLogName,drive); sl@0: test(r==KErrInUse); sl@0: format.Close(); sl@0: // now dismount an extension sl@0: r=TheFs.DismountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionEmptyName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: // try to dismount an extension that is not mounted sl@0: r=TheFs.DismountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionEmptyName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: // dismount the remaining extension sl@0: r=TheFs.DismountExtension(KExtensionEmptyName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: sl@0: test.Next(_L("RFs::RemoveExtension()")); sl@0: r=TheFs.RemoveExtension(KExtensionLogName); sl@0: test(r==KErrNone); sl@0: r=TheFs.RemoveExtension(KExtensionEmptyName); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: void TestPrimaryExtensions() sl@0: // sl@0: // a primary extension is one that is added to a drive before a file system is mounted sl@0: // must be present for the mount to be successful (eg. FTL) sl@0: // sl@0: { sl@0: test.Next(_L("TestPrimaryExtensions()")); sl@0: TInt drive; sl@0: TInt err=RFs::CharToDrive(gDriveToTest,drive); sl@0: test(err==KErrNone); sl@0: sl@0: #if defined(__WINS__) sl@0: if(drive==EDriveC) sl@0: return; sl@0: #endif sl@0: sl@0: TPckgBuf drvSyncBuf; sl@0: err = TheFs.QueryVolumeInfoExt(drive, EIsDriveSync, drvSyncBuf); sl@0: test(err==KErrNone); sl@0: const TBool bDrvSync = drvSyncBuf(); sl@0: sl@0: // don't test on ram drive since accesses memory directly sl@0: TDriveInfo info; sl@0: TInt r=TheFs.Drive(info,drive); sl@0: if(info.iMediaAtt&KMediaAttVariableSize) sl@0: return; sl@0: sl@0: TFullName fsName; sl@0: r=TheFs.FileSystemName(fsName,drive); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("fsName=%S\n"),&fsName); sl@0: sl@0: test.Next(_L("RFs::AddExtension()")); sl@0: r=TheFs.AddExtension(KExtensionLog); sl@0: test(r==KErrNone); sl@0: r=TheFs.AddExtension(KExtensionEmpty); sl@0: test(r==KErrNone); sl@0: r=TheFs.AddExtension(KExtensionBit); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("RFs::MountFileSystem()")); sl@0: // test with file system that already exists sl@0: r=TheFs.MountFileSystem(fsName,KExtensionBitName,drive,bDrvSync); sl@0: test(r==KErrAccessDenied); sl@0: // unmount drive and mount primary extension along with file system sl@0: r=TheFs.DismountFileSystem(fsName,drive); sl@0: test(r==KErrNone); sl@0: sl@0: //-- !! N.B this extension mangles data read/written ftom/to the media, for some file systems it is OK and mounting succeeds sl@0: //-- for others - this will result in KErrCorrupt sl@0: r=TheFs.MountFileSystem(fsName,KExtensionBitName,drive,bDrvSync); sl@0: test(r==KErrNone||r==KErrCorrupt); sl@0: sl@0: // and now format sl@0: Format(drive); sl@0: TFullName extName; sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionBitName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: sl@0: // and now do some file system operations sl@0: TBuf8<16> readBuf; sl@0: r=TheFs.MkDir(dir1); sl@0: test(r==KErrNone||r==KErrAlreadyExists); sl@0: RFile file1; sl@0: r=file1.Replace(TheFs,file1Name,EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: r=file1.Write(toWrite); sl@0: test(r==KErrNone); sl@0: r=file1.Read(0,readBuf); sl@0: test(readBuf==toWrite); sl@0: r=file1.SetSize(0); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: r=TheFs.Delete(file1Name); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(dir1); sl@0: test(r==KErrNone); sl@0: sl@0: // add a secondary extension sl@0: test.Printf(_L("RFs::MountExtension()")); sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionBitName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNone && extName==KExtensionLogName); sl@0: // try to add the same extension sl@0: r=TheFs.MountExtension(KExtensionBitName,drive); sl@0: test(r==KErrAlreadyExists); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionBitName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNone && extName==KExtensionLogName); sl@0: // try to add a third extension sl@0: r=TheFs.MountExtension(KExtensionEmptyName,drive); sl@0: test(r==KErrAccessDenied); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionBitName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNone && extName==KExtensionLogName); sl@0: sl@0: // and now do some file system operations sl@0: r=TheFs.MkDir(dir1); sl@0: test(r==KErrNone||r==KErrAlreadyExists); sl@0: r=file1.Replace(TheFs,file1Name,EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: r=file1.Write(toWrite); sl@0: test(r==KErrNone); sl@0: r=file1.Read(0,readBuf); sl@0: test(readBuf==toWrite); sl@0: r=file1.SetSize(0); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: r=TheFs.Delete(file1Name); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(dir1); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("RFs::DismountExtension()")); sl@0: // test that can't dismount a primary extension via this method sl@0: r=TheFs.DismountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionBitName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.DismountExtension(KExtensionBitName,drive); sl@0: test(r==KErrAccessDenied); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionBitName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: sl@0: test.Printf(_L("RFs::DismountFileSystem()")); sl@0: r=TheFs.MountExtension(KExtensionLogName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNone && extName==KExtensionBitName); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNone && extName==KExtensionLogName); sl@0: // and now dismount sl@0: r=TheFs.DismountFileSystem(fsName,drive); sl@0: test(r==KErrNone); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNotReady); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotReady); sl@0: // remount the file system sl@0: r=TheFs.MountFileSystem(fsName,drive,bDrvSync); sl@0: test(r==KErrNone||r==KErrCorrupt); sl@0: r=TheFs.ExtensionName(extName,drive,0); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.ExtensionName(extName,drive,1); sl@0: test(r==KErrNotFound); sl@0: Format(drive); sl@0: sl@0: test.Next(_L("RFs::RemoveExtension()")); sl@0: r=TheFs.RemoveExtension(KExtensionLogName); sl@0: test(r==KErrNone); sl@0: r=TheFs.RemoveExtension(KExtensionEmptyName); sl@0: test(r==KErrNone); sl@0: r=TheFs.RemoveExtension(KExtensionBitName); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: GLDEF_C void CallTestsL() sl@0: // sl@0: // Do tests relative to the session path sl@0: // sl@0: { sl@0: //-- set up console output sl@0: F32_Test_Utils::SetConsole(test.Console()); sl@0: sl@0: TInt drive; sl@0: TInt err=RFs::CharToDrive(gDriveToTest,drive); sl@0: test.Start(_L("Starting Test - T_EXT1")); sl@0: test(err==KErrNone); sl@0: sl@0: PrintDrvInfo(TheFs, drive); sl@0: sl@0: //Do not run this test on the NAND drive, as sl@0: //this has the FTL mounted as a primary extension sl@0: //which causes the test to fail sl@0: #if defined(__WINS__) sl@0: if (drive==EDriveU) sl@0: return; sl@0: #else sl@0: TDriveInfo driveInfo; sl@0: TheFs.Drive(driveInfo,drive); sl@0: if (driveInfo.iType == EMediaNANDFlash) sl@0: { sl@0: return; sl@0: } sl@0: #endif sl@0: TestSecondaryExtensions(); sl@0: sl@0: //-- the t_bitext extension mangles data from the media, which may make FS mounting fail because of "corrupted" data. sl@0: //-- Then this step formats the media, automounter doesn't support it straightforward way sl@0: if(!Is_Lffs(TheFs, drive) && !Is_Automounter(TheFs, drive)) sl@0: { sl@0: TestPrimaryExtensions(); sl@0: } sl@0: sl@0: test.End(); sl@0: test.Close(); sl@0: }