sl@0: // Copyright (c) 2007-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\server\t_swapfilesystem.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: _LIT(KTestString,"t_swapfilesystem"); sl@0: sl@0: LOCAL_D RTest test(KTestString); sl@0: sl@0: LOCAL_D RFs TheFs; sl@0: sl@0: LOCAL_D TChar gDriveToTest; sl@0: sl@0: _LIT(KFsNameComposite,"Composite"); sl@0: _LIT(KFsNameFat, "Fat"); sl@0: sl@0: //--------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_SWAPFSYS-0602 sl@0: //! @SYMTestCaseDesc Swap current file system with current file system sl@0: //! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test sl@0: //! @SYMTestPriority Medium sl@0: //! @SYMTestActions 1. Get name of the file system currently mounted on the drive sl@0: //! 2. Swap current file system with the same one sl@0: //! @SYMTestExpectedResults 1. Error code KErrAlreadyExists if Composite file is sl@0: //! current file system sl@0: //! 2. Error code KErrNotSupported if the drive is Z as on this drive, sl@0: //! only composite file system can be swapped only once sl@0: //! 3. Error codes KErrNone, KErrNotSupported or KErrInUse, otherwise. sl@0: //--------------------------------------------------------------------------------------------- sl@0: sl@0: LOCAL_C TInt TestSwapFSCurrent(TChar aDriveLetter) sl@0: // sl@0: // If no file system is mounted / error in getting file system name, skip the test sl@0: // sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt driveNumber; sl@0: TFileName curFSName; sl@0: TFileName newFSName; sl@0: sl@0: test.Next(_L("\nSwap current file system with same file system")); sl@0: sl@0: test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter)); sl@0: sl@0: err = TheFs.CharToDrive(aDriveLetter, driveNumber); sl@0: if(KErrNone != err) sl@0: { sl@0: test.Printf(_L("\nInvalid drive")); sl@0: test(EFalse); sl@0: } sl@0: sl@0: // Find current file system name sl@0: err = TheFs.FileSystemName(curFSName,driveNumber); sl@0: if(KErrNone != err) sl@0: { sl@0: test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name.")); sl@0: return (err); sl@0: } sl@0: sl@0: test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr()); sl@0: sl@0: newFSName = curFSName; sl@0: sl@0: test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr()); sl@0: sl@0: err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber); sl@0: sl@0: test.Printf(_L("\nError code is %d"),err); sl@0: sl@0: if(curFSName.CompareF(KFsNameComposite) == 0) sl@0: { sl@0: // This is unique case: sl@0: // Swap Composite (current) with Composite (new) sl@0: test(KErrAlreadyExists == err); sl@0: } sl@0: else if(driveNumber == EDriveZ) sl@0: { sl@0: // This is another such case: sl@0: // On Z Drive, only Swap with Composite is allowed sl@0: test(KErrNotSupported == err); sl@0: } sl@0: else sl@0: { sl@0: // Other / generic cases sl@0: test(KErrNone == err || sl@0: KErrNotSupported == err || sl@0: KErrInUse == err ); sl@0: } sl@0: sl@0: test.Printf(_L("\nCurrent test is completed.")); sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: //--------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_SWAPFSYS-0603 sl@0: //! @SYMTestCaseDesc Swap current file system with FAT file system sl@0: //! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test sl@0: //! @SYMTestPriority Medium sl@0: //! @SYMTestActions 1. Get name of the file system currently mounted on the drive sl@0: //! 2. Swap the current file system with FAT file system sl@0: //! @SYMTestExpectedResults 1. Error code KErrNotSupported on drive Z sl@0: //! 2. Error codes KErrNone, KErrNotSupported or KErrInUse, otherwise sl@0: //--------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestSwapFSFat(TChar aDriveLetter) sl@0: // sl@0: // It is always assumed that FAT is always available!! sl@0: // If no file system is mounted / error in getting file system name, skip the test sl@0: // sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt driveNumber; sl@0: TFileName curFSName; sl@0: TFileName newFSName; sl@0: sl@0: test.Next(_L("\nSwap current file system with FAT File System")); sl@0: sl@0: test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter)); sl@0: err = TheFs.CharToDrive(aDriveLetter, driveNumber); sl@0: if(KErrNone != err) sl@0: { sl@0: test.Printf(_L("\nInvalid drive")); sl@0: test(EFalse); sl@0: } sl@0: sl@0: // Find current file system name sl@0: err = TheFs.FileSystemName(curFSName,driveNumber); sl@0: if(KErrNone != err) sl@0: { sl@0: test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name.")); sl@0: return (err); sl@0: } sl@0: sl@0: test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr()); sl@0: sl@0: newFSName = KFsNameFat; sl@0: sl@0: test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr()); sl@0: sl@0: err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber); sl@0: sl@0: test.Printf(_L("\nError code is %d"),err); sl@0: sl@0: if(driveNumber == EDriveZ) sl@0: { sl@0: // This is unique case: sl@0: // On Z Drive, only Swap with Composite is allowed sl@0: test(KErrNotSupported == err); sl@0: } sl@0: else sl@0: { sl@0: // Other / generic cases sl@0: test(KErrNone == err || sl@0: KErrNotSupported == err || sl@0: KErrInUse == err ); sl@0: } sl@0: sl@0: test.Printf(_L("\nCurrent test is completed.")); sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_SWAPFSYS-0604 sl@0: //! @SYMTestCaseDesc Swap current file system with Composite File System sl@0: //! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test sl@0: //! @SYMTestPriority Medium sl@0: //! @SYMTestActions 1. Add Composite file system to the file server sl@0: //! to know its availability sl@0: //! 2. Get the current file system name mounted on the test drive sl@0: //! 3. Swap the current file system with Composite file system sl@0: //! @SYMTestExpectedResults 1. KErrNotFound is composite file system is not available sl@0: //! 2. Error codes KErrAlreadyExists, KErrInUse or KErrNone, on drive Z sl@0: //! 3. Error codes KErrNotSupported, KErrAlreadyExists or KErrInUse, sl@0: //! on other drives sl@0: //--------------------------------------------------------------------------------------------- sl@0: LOCAL_C TInt TestSwapFSComposite(TChar aDriveLetter) sl@0: // sl@0: // If no file system is mounted / error in getting file system name, skip the test sl@0: // sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt driveNumber; sl@0: TFileName curFSName; sl@0: TFileName newFSName; sl@0: TBool compFSAvailable = EFalse; sl@0: sl@0: test.Next(_L("\nSwap current file system with Composite File System")); sl@0: sl@0: test.Printf(_L("\nTest is run on drive is %c"),TUint(aDriveLetter)); sl@0: err = TheFs.CharToDrive(aDriveLetter, driveNumber); sl@0: if(KErrNone != err) sl@0: { sl@0: test.Printf(_L("\nInvalid drive")); sl@0: test(EFalse); sl@0: } sl@0: sl@0: err = TheFs.AddFileSystem(_L("ecomp.fsy")); sl@0: sl@0: if (KErrNone == err || KErrAlreadyExists == err) sl@0: { sl@0: compFSAvailable = ETrue; sl@0: } sl@0: sl@0: // Find current file system name sl@0: err = TheFs.FileSystemName(curFSName,driveNumber); sl@0: if(KErrNone != err) sl@0: { sl@0: test.Printf(_L("\nFile System NOT mounted. Quiting current test")); sl@0: return (err); sl@0: } sl@0: sl@0: test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr()); sl@0: sl@0: newFSName = KFsNameComposite; sl@0: sl@0: test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr()); sl@0: sl@0: err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber); sl@0: sl@0: test.Printf(_L("\nError code is %d"),err); sl@0: sl@0: if(compFSAvailable) sl@0: { sl@0: //Composite is available!! sl@0: if(driveNumber == EDriveZ) sl@0: { sl@0: test(KErrAlreadyExists == err || sl@0: KErrInUse == err || sl@0: KErrNone == err ); sl@0: } sl@0: else sl@0: { sl@0: test(KErrNotSupported == err || sl@0: KErrAlreadyExists == err || sl@0: KErrInUse == err ); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: //Composote NOT available!! sl@0: test(KErrNotFound == err); sl@0: } sl@0: sl@0: test.Printf(_L("\nCurrent test is completed.")); sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void ParseCommandArguments() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: TBuf<0x100> cmd; sl@0: User::CommandLine(cmd); sl@0: TLex lex(cmd); sl@0: TPtrC token=lex.NextToken(); sl@0: TFileName thisfile=RProcess().FileName(); sl@0: if (token.MatchF(thisfile)==0) sl@0: { sl@0: token.Set(lex.NextToken()); sl@0: } sl@0: test.Printf(_L("CLP=%S"),&token); sl@0: sl@0: if(token.Length()!=0) sl@0: { sl@0: gDriveToTest=token[0]; sl@0: gDriveToTest.UpperCase(); sl@0: } sl@0: else sl@0: gDriveToTest='C'; sl@0: } sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: TInt err; sl@0: sl@0: test.Title(); sl@0: sl@0: err = TheFs.Connect(); sl@0: sl@0: test(KErrNone == err); sl@0: sl@0: ParseCommandArguments(); sl@0: sl@0: #if defined(__WINS__) sl@0: // The emulator z: drive maps onto the PCs local file system sl@0: // and swapping / unmounting it is not allowed. sl@0: // Hence, skip the test on emulated Z: drive. sl@0: if (gDriveToTest != 'Z') sl@0: { sl@0: TestSwapFSCurrent(gDriveToTest); sl@0: TestSwapFSFat(gDriveToTest); sl@0: TestSwapFSComposite(gDriveToTest); sl@0: } sl@0: #else sl@0: TestSwapFSCurrent(gDriveToTest); sl@0: TestSwapFSFat(gDriveToTest); sl@0: TestSwapFSComposite(gDriveToTest); sl@0: #endif sl@0: sl@0: TheFs.Close(); sl@0: sl@0: test.Printf(_L("t_swapfilesystem completed successfully")); sl@0: sl@0: test.Close(); sl@0: sl@0: return KErrNone; sl@0: }