kerneltest/f32test/server/t_swapfsys.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32test\server\t_swapfilesystem.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <e32test.h>
       
    20 
       
    21 _LIT(KTestString,"t_swapfilesystem");
       
    22 
       
    23 LOCAL_D RTest test(KTestString);
       
    24 
       
    25 LOCAL_D RFs TheFs;
       
    26 
       
    27 LOCAL_D TChar gDriveToTest;
       
    28 
       
    29 _LIT(KFsNameComposite,"Composite");
       
    30 _LIT(KFsNameFat,      "Fat");
       
    31 
       
    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 //---------------------------------------------------------------------------------------------
       
    45 
       
    46 LOCAL_C TInt TestSwapFSCurrent(TChar aDriveLetter)
       
    47 // 
       
    48 // If no file system is mounted / error in getting file system name, skip the test
       
    49 // 
       
    50 	{
       
    51 	TInt 		err = KErrNone;
       
    52 	TInt 		driveNumber;
       
    53 	TFileName 	curFSName;
       
    54 	TFileName 	newFSName;
       
    55 	
       
    56 	test.Next(_L("\nSwap current file system with same file system"));
       
    57 	
       
    58 	test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter));
       
    59 	
       
    60 	err = TheFs.CharToDrive(aDriveLetter, driveNumber);
       
    61 	if(KErrNone != err)
       
    62 		{
       
    63 		test.Printf(_L("\nInvalid drive"));
       
    64 		test(EFalse);
       
    65 		}
       
    66 	
       
    67 	// Find current file system name
       
    68 	err = TheFs.FileSystemName(curFSName,driveNumber);
       
    69 	if(KErrNone != err)
       
    70 		{
       
    71 		test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name."));
       
    72 		return (err);
       
    73 		}
       
    74 	
       
    75 	test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
       
    76 	
       
    77 	newFSName = curFSName;
       
    78 	
       
    79 	test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
       
    80 	
       
    81 	err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
       
    82 	
       
    83 	test.Printf(_L("\nError code is %d"),err);
       
    84 	
       
    85 	if(curFSName.CompareF(KFsNameComposite) == 0)
       
    86 		{
       
    87 		// This is unique case: 
       
    88 		// Swap Composite (current) with Composite (new)
       
    89 		test(KErrAlreadyExists == err);
       
    90 		}
       
    91 	else if(driveNumber == EDriveZ)
       
    92 		{
       
    93 		// This is another such case: 
       
    94 		// On Z Drive, only Swap with Composite is allowed
       
    95 		test(KErrNotSupported  == err);
       
    96 		}
       
    97 	else
       
    98 		{
       
    99 		// Other / generic cases
       
   100 		test(KErrNone          == err || 
       
   101 			 KErrNotSupported  == err ||
       
   102 		     KErrInUse         == err   );
       
   103 		}
       
   104 	
       
   105 	test.Printf(_L("\nCurrent test is completed."));
       
   106 	
       
   107 	return (KErrNone);
       
   108 	}
       
   109 
       
   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)
       
   121 // 
       
   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
       
   124 // 
       
   125 	{
       
   126 	TInt 		err = KErrNone;
       
   127 	TInt 		driveNumber;
       
   128 	TFileName 	curFSName;
       
   129 	TFileName 	newFSName;
       
   130 	
       
   131 	test.Next(_L("\nSwap current file system with FAT File System"));
       
   132 	
       
   133 	test.Printf(_L("\nTest is run on drive %c"),TUint(aDriveLetter));
       
   134 	err = TheFs.CharToDrive(aDriveLetter, driveNumber);
       
   135 	if(KErrNone != err)
       
   136 		{
       
   137 		test.Printf(_L("\nInvalid drive"));
       
   138 		test(EFalse);
       
   139 		}
       
   140 	
       
   141 	// Find current file system name
       
   142 	err = TheFs.FileSystemName(curFSName,driveNumber);
       
   143 	if(KErrNone != err)
       
   144 		{
       
   145 		test.Printf(_L("\nSkipping current test as File System is NOT mounted / error in getting the name."));
       
   146 		return (err);
       
   147 		}
       
   148 	
       
   149 	test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
       
   150 	
       
   151 	newFSName = KFsNameFat;
       
   152 	
       
   153 	test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
       
   154 	
       
   155 	err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
       
   156 	
       
   157 	test.Printf(_L("\nError code is %d"),err);
       
   158 	
       
   159 	if(driveNumber == EDriveZ)
       
   160 		{
       
   161 		// This is unique case: 
       
   162 		// On Z Drive, only Swap with Composite is allowed
       
   163 		test(KErrNotSupported  == err);
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		// Other / generic cases
       
   168 		test(KErrNone          == err || 
       
   169 			 KErrNotSupported  == err ||
       
   170 		     KErrInUse         == err   );		
       
   171 		}
       
   172 	
       
   173 	test.Printf(_L("\nCurrent test is completed."));
       
   174 	
       
   175 	return (KErrNone);
       
   176 	}
       
   177 
       
   178 
       
   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, 
       
   191 //!                            on other drives
       
   192 //---------------------------------------------------------------------------------------------
       
   193 LOCAL_C TInt TestSwapFSComposite(TChar aDriveLetter)
       
   194 // 
       
   195 // If no file system is mounted / error in getting file system name, skip the test
       
   196 // 
       
   197 	{
       
   198 	TInt 		err = KErrNone;
       
   199 	TInt 		driveNumber;
       
   200 	TFileName 	curFSName;
       
   201 	TFileName 	newFSName;
       
   202 	TBool		compFSAvailable = EFalse;
       
   203 	
       
   204 	test.Next(_L("\nSwap current file system with Composite File System"));
       
   205 	
       
   206 	test.Printf(_L("\nTest is run on drive is %c"),TUint(aDriveLetter));
       
   207 	err = TheFs.CharToDrive(aDriveLetter, driveNumber);
       
   208 	if(KErrNone != err)
       
   209 		{
       
   210 		test.Printf(_L("\nInvalid drive"));
       
   211 		test(EFalse);
       
   212 		}
       
   213 	
       
   214 	err = TheFs.AddFileSystem(_L("ecomp.fsy"));
       
   215 	
       
   216 	if (KErrNone == err || KErrAlreadyExists == err)
       
   217 		{
       
   218 		compFSAvailable = ETrue;
       
   219 		}
       
   220 	
       
   221 	// Find current file system name
       
   222 	err = TheFs.FileSystemName(curFSName,driveNumber);
       
   223 	if(KErrNone != err)
       
   224 		{
       
   225 		test.Printf(_L("\nFile System NOT mounted. Quiting current test"));
       
   226 		return (err);
       
   227 		}
       
   228 	
       
   229 	test.Printf(_L("\nName of the file system currently mounted on this drive is %s"),curFSName.Ptr());
       
   230 	
       
   231 	newFSName = KFsNameComposite;
       
   232 	
       
   233 	test.Printf(_L("\nName of the file system to be mounted on this drive is %s"),newFSName.Ptr());
       
   234 	
       
   235 	err = TheFs.SwapFileSystem(curFSName,newFSName,driveNumber);
       
   236 	
       
   237 	test.Printf(_L("\nError code is %d"),err);
       
   238 	
       
   239 	if(compFSAvailable)
       
   240 		{
       
   241 		//Composite is available!!
       
   242 		if(driveNumber == EDriveZ)
       
   243 			{
       
   244 			test(KErrAlreadyExists == err ||
       
   245 				 KErrInUse         == err ||
       
   246 				 KErrNone		   == err   );
       
   247 			}
       
   248 		else
       
   249 			{
       
   250 			test(KErrNotSupported  == err ||
       
   251 			 	 KErrAlreadyExists == err ||
       
   252 			     KErrInUse         == err   );			
       
   253 			}
       
   254 		}
       
   255 	else
       
   256 		{
       
   257 			//Composote NOT available!!
       
   258 			test(KErrNotFound == err);		
       
   259 		}
       
   260 	
       
   261 	test.Printf(_L("\nCurrent test is completed."));
       
   262 	
       
   263 	return (KErrNone);	
       
   264 	}
       
   265 
       
   266 LOCAL_C void ParseCommandArguments()
       
   267 //
       
   268 //
       
   269 //
       
   270 	{
       
   271 	TBuf<0x100> cmd;
       
   272 	User::CommandLine(cmd);
       
   273 	TLex lex(cmd);
       
   274 	TPtrC token=lex.NextToken();
       
   275 	TFileName thisfile=RProcess().FileName();
       
   276 	if (token.MatchF(thisfile)==0)
       
   277 		{
       
   278 		token.Set(lex.NextToken());
       
   279 		}
       
   280 	test.Printf(_L("CLP=%S"),&token);
       
   281 
       
   282 	if(token.Length()!=0)		
       
   283 		{
       
   284 		gDriveToTest=token[0];
       
   285 		gDriveToTest.UpperCase();
       
   286 		}
       
   287 	else						
       
   288 		gDriveToTest='C';
       
   289 	}
       
   290 
       
   291 
       
   292 GLDEF_C TInt E32Main()
       
   293 //
       
   294 // 
       
   295 //
       
   296 	{
       
   297 	TInt err;
       
   298 	
       
   299 	test.Title();
       
   300 	
       
   301 	err = TheFs.Connect();
       
   302 	
       
   303 	test(KErrNone == err);
       
   304 	
       
   305 	ParseCommandArguments();
       
   306 	
       
   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')
       
   312 		{
       
   313 		TestSwapFSCurrent(gDriveToTest);
       
   314 		TestSwapFSFat(gDriveToTest);
       
   315 		TestSwapFSComposite(gDriveToTest);
       
   316 		}
       
   317 #else
       
   318 	TestSwapFSCurrent(gDriveToTest);
       
   319 	TestSwapFSFat(gDriveToTest);
       
   320 	TestSwapFSComposite(gDriveToTest);
       
   321 #endif
       
   322 	
       
   323 	TheFs.Close();
       
   324 	
       
   325 	test.Printf(_L("t_swapfilesystem completed successfully"));
       
   326 	
       
   327 	test.Close();
       
   328 	
       
   329 	return KErrNone;
       
   330 	}