Update contrib.
1 // Copyright (c) 2007-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\server\t_swapfilesystem.cpp
21 _LIT(KTestString,"t_swapfilesystem");
23 LOCAL_D RTest test(KTestString);
27 LOCAL_D TChar gDriveToTest;
29 _LIT(KFsNameComposite,"Composite");
30 _LIT(KFsNameFat, "Fat");
32 //---------------------------------------------------------------------------------------------
33 //! @SYMTestCaseID PBASE-T_SWAPFSYS-0602
34 //! @SYMTestCaseDesc Swap current file system with current file system
35 //! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test
36 //! @SYMTestPriority Medium
37 //! @SYMTestActions 1. Get name of the file system currently mounted on the drive
38 //! 2. Swap current file system with the same one
39 //! @SYMTestExpectedResults 1. Error code KErrAlreadyExists if Composite file is
40 //! current file system
41 //! 2. Error code KErrNotSupported if the drive is Z as on this drive,
42 //! only composite file system can be swapped only once
43 //! 3. Error codes KErrNone, KErrNotSupported or KErrInUse, otherwise.
44 //---------------------------------------------------------------------------------------------
46 LOCAL_C TInt TestSwapFSCurrent(TChar aDriveLetter)
48 // If no file system is mounted / error in getting file system name, skip the test
56 test.Next(_L("\nSwap current file system with same file system"));
58 test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter));
60 err = TheFs.CharToDrive(aDriveLetter, driveNumber);
63 test.Printf(_L("\nInvalid drive"));
67 // Find current file system name
68 err = TheFs.FileSystemName(curFSName,driveNumber);
71 test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name."));
75 test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
77 newFSName = curFSName;
79 test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
81 err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
83 test.Printf(_L("\nError code is %d"),err);
85 if(curFSName.CompareF(KFsNameComposite) == 0)
87 // This is unique case:
88 // Swap Composite (current) with Composite (new)
89 test(KErrAlreadyExists == err);
91 else if(driveNumber == EDriveZ)
93 // This is another such case:
94 // On Z Drive, only Swap with Composite is allowed
95 test(KErrNotSupported == err);
99 // Other / generic cases
100 test(KErrNone == err ||
101 KErrNotSupported == err ||
105 test.Printf(_L("\nCurrent test is completed."));
110 //---------------------------------------------------------------------------------------------
111 //! @SYMTestCaseID PBASE-T_SWAPFSYS-0603
112 //! @SYMTestCaseDesc Swap current file system with FAT file system
113 //! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test
114 //! @SYMTestPriority Medium
115 //! @SYMTestActions 1. Get name of the file system currently mounted on the drive
116 //! 2. Swap the current file system with FAT file system
117 //! @SYMTestExpectedResults 1. Error code KErrNotSupported on drive Z
118 //! 2. Error codes KErrNone, KErrNotSupported or KErrInUse, otherwise
119 //---------------------------------------------------------------------------------------------
120 LOCAL_C TInt TestSwapFSFat(TChar aDriveLetter)
122 // It is always assumed that FAT is always available!!
123 // If no file system is mounted / error in getting file system name, skip the test
131 test.Next(_L("\nSwap current file system with FAT File System"));
133 test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter));
134 err = TheFs.CharToDrive(aDriveLetter, driveNumber);
137 test.Printf(_L("\nInvalid drive"));
141 // Find current file system name
142 err = TheFs.FileSystemName(curFSName,driveNumber);
145 test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name."));
149 test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
151 newFSName = KFsNameFat;
153 test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
155 err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
157 test.Printf(_L("\nError code is %d"),err);
159 if(driveNumber == EDriveZ)
161 // This is unique case:
162 // On Z Drive, only Swap with Composite is allowed
163 test(KErrNotSupported == err);
167 // Other / generic cases
168 test(KErrNone == err ||
169 KErrNotSupported == err ||
173 test.Printf(_L("\nCurrent test is completed."));
179 //---------------------------------------------------------------------------------------------
180 //! @SYMTestCaseID PBASE-T_SWAPFSYS-0604
181 //! @SYMTestCaseDesc Swap current file system with Composite File System
182 //! @SYMDEF DEF101639 RFs::SwapFileSystem is not tested by f32test
183 //! @SYMTestPriority Medium
184 //! @SYMTestActions 1. Add Composite file system to the file server
185 //! to know its availability
186 //! 2. Get the current file system name mounted on the test drive
187 //! 3. Swap the current file system with Composite file system
188 //! @SYMTestExpectedResults 1. KErrNotFound is composite file system is not available
189 //! 2. Error codes KErrAlreadyExists, KErrInUse or KErrNone, on drive Z
190 //! 3. Error codes KErrNotSupported, KErrAlreadyExists or KErrInUse,
192 //---------------------------------------------------------------------------------------------
193 LOCAL_C TInt TestSwapFSComposite(TChar aDriveLetter)
195 // If no file system is mounted / error in getting file system name, skip the test
202 TBool compFSAvailable = EFalse;
204 test.Next(_L("\nSwap current file system with Composite File System"));
206 test.Printf(_L("\nTest is run on drive is %c"),TUint(aDriveLetter));
207 err = TheFs.CharToDrive(aDriveLetter, driveNumber);
210 test.Printf(_L("\nInvalid drive"));
214 err = TheFs.AddFileSystem(_L("ecomp.fsy"));
216 if (KErrNone == err || KErrAlreadyExists == err)
218 compFSAvailable = ETrue;
221 // Find current file system name
222 err = TheFs.FileSystemName(curFSName,driveNumber);
225 test.Printf(_L("\nFile System NOT mounted. Quiting current test"));
229 test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
231 newFSName = KFsNameComposite;
233 test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
235 err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
237 test.Printf(_L("\nError code is %d"),err);
241 //Composite is available!!
242 if(driveNumber == EDriveZ)
244 test(KErrAlreadyExists == err ||
250 test(KErrNotSupported == err ||
251 KErrAlreadyExists == err ||
257 //Composote NOT available!!
258 test(KErrNotFound == err);
261 test.Printf(_L("\nCurrent test is completed."));
266 LOCAL_C void ParseCommandArguments()
272 User::CommandLine(cmd);
274 TPtrC token=lex.NextToken();
275 TFileName thisfile=RProcess().FileName();
276 if (token.MatchF(thisfile)==0)
278 token.Set(lex.NextToken());
280 test.Printf(_L("CLP=%S"),&token);
282 if(token.Length()!=0)
284 gDriveToTest=token[0];
285 gDriveToTest.UpperCase();
292 GLDEF_C TInt E32Main()
301 err = TheFs.Connect();
303 test(KErrNone == err);
305 ParseCommandArguments();
307 #if defined(__WINS__)
308 // The emulator z: drive maps onto the PCs local file system
309 // and swapping / unmounting it is not allowed.
310 // Hence, skip the test on emulated Z: drive.
311 if (gDriveToTest != 'Z')
313 TestSwapFSCurrent(gDriveToTest);
314 TestSwapFSFat(gDriveToTest);
315 TestSwapFSComposite(gDriveToTest);
318 TestSwapFSCurrent(gDriveToTest);
319 TestSwapFSFat(gDriveToTest);
320 TestSwapFSComposite(gDriveToTest);
325 test.Printf(_L("t_swapfilesystem completed successfully"));