os/kernelhwsrv/kerneltest/f32test/server/t_fatcharsetconv_main.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-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_FatCharSetConv_Main.cpp
    15 // 
    16 //
    17 
    18 #define __E32TEST_EXTENSION__
    19 
    20 #include <e32test.h>
    21 #include <e32svr.h>
    22 //#include <hal.h>
    23 #include <f32fsys.h>
    24 #include <f32dbg.h>
    25 #include "t_server.h"
    26 #include "t_chlffs.h"
    27 #include "fat_utils.h"
    28 #include "T_Fatcharsetconv_Cases.h"
    29 
    30 
    31 RTest test(_L("T_FatCharSetConv"));
    32 
    33 using namespace Fat_Test_Utils;
    34 
    35 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
    36 
    37 template <class C>
    38 TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
    39 	{
    40     TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
    41     TInt r = fs.ControlIo(drv, fkn, ptrC);
    42     return r;
    43 	}
    44 
    45 /*
    46  * Presetting module, presets initial source, target and comparing direcotries.
    47  * @param	aParam	test param that contains all information about a test case
    48  */
    49 void DataGenerationL(const TTestParamAll& aParam)
    50 	{
    51 	// Setup source files
    52 	RBuf path;
    53 	path.CreateL(aParam.iSrcPrsPath);
    54 	
    55 	path[0] = (TUint16)*aParam.iSrcDrvChar;
    56 	if(path[0] == (TUint8)gDriveToTest)
    57 		{
    58 		SetupDirFiles(path, aParam.iSrcPrsFiles);
    59 		}
    60 	
    61 	if (aParam.iAPI == EGetShortName || aParam.iAPI == EGetShortNameWithDLL || aParam.iAPI == EGetShortNameWithoutDLL || aParam.iAPI == ERFsReplace || aParam.iAPI == ERFsRename ||aParam.iAPI == ERenameFile )
    62 		{
    63 		path[0] = (TUint16)*aParam.iTrgDrvChar;
    64 		}
    65 	path.Close();
    66 	CheckDisk();
    67 	}
    68 
    69 /*
    70  * Test execution module
    71  * @param	aParam	test param that contains all information about a test case
    72  * @panic	USER:84	if return codes do not match the expected values. 	
    73  */
    74 void DataExecutionL(const TTestParamAll& aParam, const TTCType aTCType)
    75 	{
    76 	RBuf srcCmdFile;
    77 	srcCmdFile.CreateL(aParam.iSrcCmdPath);
    78 	RBuf trgCmdFile;
    79 	trgCmdFile.CreateL(aParam.iTrgCmdPath);
    80 	RBuf srcCmd;
    81 	srcCmd.CreateL(aParam.iSrcPrsPath);
    82 	
    83 	if (srcCmdFile.Length() > 0)
    84 		{
    85 		srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
    86 		}
    87 	else
    88 		{
    89 		// srcCmdFile= gSessionPath;
    90 		srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
    91 		}
    92 	if (srcCmd.Length() > 0)
    93 		{
    94 		srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
    95 		}
    96 	else
    97 		{
    98 		// srcCmd= gSessionPath;
    99 		srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
   100 		}
   101 
   102 	// logging for failure
   103 	gTCType = aTCType;
   104 	RBuf failedOnBuf;
   105 	failedOnBuf.CreateL(KExecution());
   106 	gTCId = aParam.iTestCaseID;
   107 	RBuf tcUniquePath;
   108 	tcUniquePath.CreateL(aParam.iSrcPrsPath);
   109 
   110 	TInt r = KErrNone;
   111 
   112 	switch(aParam.iAPI)
   113 		{
   114 		case EGetShortName:
   115 		case EGetShortNameWithDLL:
   116 		case EGetShortNameWithoutDLL:
   117 			{
   118 			__UHEAP_MARK;
   119 			if(aParam.iAPI == EGetShortName )
   120 				gLogFailureData.iAPIName = KGetShortName;
   121 			else if(aParam.iAPI == EGetShortNameWithDLL )
   122 				gLogFailureData.iAPIName = KGetShortNameWithDLL;
   123 			else if(aParam.iAPI == EGetShortNameWithoutDLL )
   124 				gLogFailureData.iAPIName = KGetShortNameWithoutDLL;
   125 
   126 				if (trgCmdFile.Length() > 0)
   127 					{
   128 					trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   129 					}
   130 				else
   131 					{
   132 					//trgCmdFile= gSessionPath;
   133 					trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   134 					}
   135 
   136 			TBuf<0x10> shortName;
   137 			r=TheFs.GetShortName(srcCmdFile,shortName);
   138 			testAndLog(r==KErrNone);
   139 			srcCmd.ReAllocL(srcCmd.Length() + shortName.Length());
   140 			srcCmd+= shortName;
   141 			testAndLog(srcCmd==trgCmdFile);
   142 			__UHEAP_MARKEND;
   143 			}
   144 			break;
   145 		case ELongShortConversion:
   146 			{
   147 			__UHEAP_MARK;
   148 			gLogFailureData.iAPIName = KLongShortConversion;
   149 			if (trgCmdFile.Length() > 0)
   150 				{
   151 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   152 				}
   153 			else
   154 				{
   155 				//trgCmdFile= gSessionPath;
   156 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   157 				}
   158 
   159 			RBuf lgnFullPath;
   160 			RBuf shnFullPath;
   161 			TFileName longName;
   162 			TBuf<0x10> shortName;
   163 	
   164 			r = TheFs.GetShortName(srcCmdFile, shortName);
   165 			testAndLog(r==KErrNone);
   166 	
   167 			shnFullPath.CreateL(srcCmd);
   168 			shnFullPath.ReAllocL(srcCmd.Length() + shortName.Length());
   169 			shnFullPath.Append(shortName);
   170 			r = shnFullPath.Compare(trgCmdFile);
   171 			testAndLog(r==KErrNone);
   172 
   173 			r = TheFs.GetLongName(shnFullPath, longName);
   174 			testAndLog(r==KErrNone);
   175 			
   176 			lgnFullPath.CreateL(srcCmd);
   177 			lgnFullPath.ReAllocL(srcCmd.Length() + longName.Length());
   178 			lgnFullPath.Append(longName);
   179 			r = lgnFullPath.Compare(srcCmdFile);
   180 			testAndLog(r==KErrNone);
   181 			
   182 			lgnFullPath.Close();
   183 			shnFullPath.Close();
   184 			__UHEAP_MARKEND;
   185 			}
   186 			break;
   187 		case ECreateFile:
   188 			{
   189 			__UHEAP_MARK;
   190 			gLogFailureData.iAPIName  = KCreateFile;
   191 			r = TheFile.Create(TheFs,srcCmdFile,EFileWrite);
   192 			testAndLog(r==KErrNone);
   193 			TheFile.Close();
   194 			__UHEAP_MARKEND;
   195 			}
   196 			break;
   197 		case EIsValidName:
   198 			{
   199 			__UHEAP_MARK;
   200 			gLogFailureData.iAPIName = KIsValidName;
   201 			TText badChar;
   202 			r=TheFs.IsValidName(srcCmdFile,badChar);
   203 			testAndLog(r==(TInt)ETrue);
   204 			r=TheFs.IsValidName(srcCmdFile);
   205 			testAndLog(r==(TInt)ETrue);
   206 			__UHEAP_MARKEND;
   207 			}
   208 			break;
   209 		case EMkDir:
   210 			{
   211 			__UHEAP_MARK;
   212 			gLogFailureData.iAPIName = KMkDir;
   213 			r=TheFs.MkDir(srcCmdFile);
   214 			testAndLog(r==KErrNone);
   215 			__UHEAP_MARKEND;
   216 			}
   217 			break;		
   218 		case EMkDirAll:
   219 			{
   220 			__UHEAP_MARK;
   221 			gLogFailureData.iAPIName = KMkDirAll;
   222 			r=TheFs.MkDirAll(srcCmdFile);
   223 			testAndLog(r==KErrNone);
   224 			__UHEAP_MARKEND;
   225 			}
   226 			break;		
   227 		case ERenameFile:
   228 			{
   229 			__UHEAP_MARK;
   230 			gLogFailureData.iAPIName = KRenameFile;
   231 			if (trgCmdFile.Length() > 0)
   232 				{
   233 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   234 				}
   235 			else
   236 				{
   237 				//trgCmdFile= gSessionPath;
   238 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   239 				}
   240 				
   241 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   242 			testAndLog(r == KErrNone);
   243 			r=TheFile.Rename(trgCmdFile);
   244 			testAndLog(r==KErrNone);
   245 			TheFile.Close();
   246 			__UHEAP_MARKEND;
   247 			}
   248 			break;
   249 		case EReadFileSection:
   250 			{
   251 			__UHEAP_MARK;
   252 			gLogFailureData.iAPIName = KReadFileSection;
   253 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   254 			testAndLog(r == KErrNone);
   255 			
   256 			TInt numWrite = 15;
   257 			TBuf8<50> writeBuf = _L8("I am going to write some junk for testing purpose");
   258 			TheFile.Write(writeBuf, numWrite);
   259    			r=TheFile.Flush();
   260    			testAndLog(r==KErrNone);
   261   			TheFile.Close();
   262 			__UHEAP_MARKEND;
   263 			}
   264 			break;
   265 		case EDeleteFile:
   266 			{
   267 			__UHEAP_MARK;
   268 			gLogFailureData.iAPIName = KDeleteFile;
   269 			r=TheFs.Delete(srcCmdFile);
   270 			testAndLog(r==KErrNone);
   271 			__UHEAP_MARKEND;
   272 			}
   273 			break;
   274 		case EOpenDir:
   275 			{
   276 			__UHEAP_MARK;
   277 			gLogFailureData.iAPIName = KOpenDir;
   278 			r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
   279 			testAndLog(r==KErrNone);
   280 			TheDir.Close();
   281 			__UHEAP_MARKEND;
   282 			}
   283 			break;
   284 		case EReadDir:
   285 			{
   286 			__UHEAP_MARK;
   287 			gLogFailureData.iAPIName = KReadDir;
   288 			r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
   289 			testAndLog(r==KErrNone);
   290 			TheDir.Close();
   291 			__UHEAP_MARKEND;
   292 			}
   293 			break;
   294 		case ERemoveDir:
   295 			{
   296 			__UHEAP_MARK;
   297 			gLogFailureData.iAPIName = KRemoveDir;
   298 			r=TheFs.RmDir(srcCmdFile);
   299 			testAndLog(r==KErrNone);
   300 			__UHEAP_MARKEND;
   301 			}
   302 			break;		
   303 		case EIsFileInRom:
   304 			{
   305 			__UHEAP_MARK;
   306 			gLogFailureData.iAPIName = KIsFileInRom;
   307 			// The tested files are created on non-rom drives, which should not be found 
   308 			//	on rom drives
   309 			TUint8* ptr=TheFs.IsFileInRom(srcCmdFile);
   310 			testAndLog(ptr==NULL);
   311 			__UHEAP_MARKEND;
   312 			}
   313 			break;
   314 		case EReplaceFile:
   315 			{
   316 			__UHEAP_MARK;
   317 			gLogFailureData.iAPIName = KReplaceFile;
   318 			r=TheFile.Replace(TheFs, srcCmdFile ,EFileWrite);
   319 			testAndLog(r==KErrNone);
   320 			TheFile.Close();
   321 			__UHEAP_MARKEND;
   322 			}
   323 			break;
   324 		case EOperateOnFileNames:
   325 			{
   326 			__UHEAP_MARK;
   327 			gLogFailureData.iAPIName = KOperateOnFileNames;
   328 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead);
   329 			testAndLog(r == KErrNone);
   330 			TheFile.Close();
   331 			__UHEAP_MARKEND;
   332 			}
   333 			break;
   334 		case EFileModify:
   335 			{
   336 			__UHEAP_MARK;
   337 			gLogFailureData.iAPIName = KFileModify;
   338 			TTime time;
   339 			r=TheFs.Modified(srcCmdFile,time);
   340 			testAndLog(r==KErrNone);
   341 			__UHEAP_MARKEND;
   342 			}
   343 			break;
   344 		case EFileAttributes:
   345 			{
   346 			__UHEAP_MARK;
   347 			gLogFailureData.iAPIName = KFileAttributes;
   348 			TUint att;
   349 			r=TheFs.Att(srcCmdFile,att);
   350 			testAndLog(r==KErrNone);
   351 			__UHEAP_MARKEND;
   352 			}
   353 			break;
   354 		case ERFsEntry:
   355 			{
   356 			__UHEAP_MARK;
   357 			gLogFailureData.iAPIName = KRFsEntry;
   358 			TEntry entryDetail;
   359 			r=TheFs.Entry(srcCmdFile, entryDetail);
   360 			testAndLog(r==KErrNone);
   361 			__UHEAP_MARKEND;
   362 			}
   363 			break;
   364 		case ERFsReplace:
   365 			{
   366 			__UHEAP_MARK;	
   367 			gLogFailureData.iAPIName = KRFsReplace;
   368 			if (trgCmdFile.Length() > 0)
   369 				{
   370 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   371 				}
   372 			else
   373 				{
   374 				//trgCmdFile= gSessionPath;
   375 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   376 				}
   377 			r=TheFs.Replace(srcCmdFile,trgCmdFile);
   378 			testAndLog(r==KErrNone);
   379 			__UHEAP_MARKEND;
   380 			}
   381 			break;
   382 		case ERFsRename:
   383 			{
   384 			__UHEAP_MARK;
   385 			gLogFailureData.iAPIName = KRFsRename;
   386 			if (trgCmdFile.Length() > 0)
   387 				{
   388 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   389 				}
   390 			else
   391 				{
   392 				//trgCmdFile= gSessionPath;
   393 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   394 				} 
   395 			r=TheFs.Rename(srcCmdFile,trgCmdFile);
   396 			testAndLog(r==KErrNone);
   397 			__UHEAP_MARKEND;
   398 			}	
   399 			break;
   400 		case EGetDir:	
   401 			{
   402 			__UHEAP_MARK;
   403 			gLogFailureData.iAPIName = KGetDir;
   404 			CDir *anEntryList;
   405 			r=TheFs.GetDir(srcCmdFile,KEntryAttNormal,ESortByName,anEntryList);
   406 			testAndLog(r==KErrNone);
   407 			delete anEntryList;
   408 			__UHEAP_MARKEND;
   409 			}
   410 			break;
   411 		case EFileTemp:
   412 			{
   413 			__UHEAP_MARK;
   414 			gLogFailureData.iAPIName = KFileTemp;
   415 			TFileName tempFileName;
   416 			r=TheFile.Temp(TheFs,srcCmdFile,tempFileName,EFileWrite);
   417 			testAndLog(r == KErrNone);
   418 			TheFile.Close();
   419 			__UHEAP_MARKEND;
   420 			}
   421 			break;
   422 		case EReadFromFile:
   423 			{
   424 			__UHEAP_MARK;
   425 			gLogFailureData.iAPIName = KReadFromFile;
   426 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   427 			testAndLog(r == KErrNone);
   428 			
   429 			TBuf8<200> writeBuf = _L8("I am going to write something to the file and then read from the specified position to test an overload of RFIle::Read");
   430 			TInt numWrite = 50;
   431    			TheFile.Write(writeBuf, numWrite);
   432    			testAndLog(r==KErrNone);
   433 			TheFile.Close();
   434 			__UHEAP_MARKEND;
   435 			}	
   436 		break;
   437 		case EWriteToFile:
   438 			{
   439 			__UHEAP_MARK;						
   440 			gLogFailureData.iAPIName = KWriteToFile;
   441 
   442 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   443 			testAndLog(r == KErrNone);
   444 
   445 			TBuf8<200> writeBuf = _L8("I am going to write something to the file and then read from the specified position to test an overload of RFIle::Read");
   446 			TInt numWrite = 50;
   447    			TheFile.Write(writeBuf, numWrite);
   448    			testAndLog(r==KErrNone);
   449    			r=TheFile.Flush();
   450    			testAndLog(r==KErrNone);
   451 			TheFile.Close();
   452    			__UHEAP_MARKEND;
   453 			}	
   454 			
   455 		break;
   456 	 	default:
   457 		break;
   458 
   459 		}
   460 //	test.Printf(_L("DataExecution::\tTest case %d passed\n"),aParam.iTestCaseID);
   461 
   462 	failedOnBuf.Close();
   463 	tcUniquePath.Close();
   464 
   465 	srcCmdFile.Close();
   466 	trgCmdFile.Close();
   467 	srcCmd.Close();
   468 	CheckDisk();
   469 	}
   470 
   471 void DataVerificationL(const TTestParamAll& aParam, const TTCType aTCType)
   472 	{
   473 	RBuf srcCmdFile;
   474 	srcCmdFile.CreateL(aParam.iSrcCmdPath);
   475 	RBuf trgCmdFile;
   476 	trgCmdFile.CreateL(aParam.iTrgCmdPath);
   477 	RBuf srcCmd;
   478 	srcCmd.CreateL(aParam.iSrcPrsPath);
   479 
   480 	if (srcCmdFile.Length() > 0)
   481 		{
   482 		srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
   483 		}
   484 	else
   485 		{
   486 		//srcCmdFile= gSessionPath;
   487 		srcCmdFile[0] = (TUint16)*aParam.iSrcDrvChar;
   488 		}
   489 		
   490 	if (srcCmd.Length() > 0)
   491 		{
   492 		srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
   493 		}
   494 	else
   495 		{
   496 		//srcCmd= gSessionPath;
   497 		srcCmd[0] = (TUint16)*aParam.iSrcDrvChar;
   498 		}
   499 
   500 	// logging for failure
   501 	gTCType = aTCType;
   502 	RBuf failedOnBuf;
   503 	failedOnBuf.CreateL(KVerification());
   504 	gTCId = aParam.iTestCaseID;
   505 	RBuf tcUniquePath;
   506 	tcUniquePath.CreateL(aParam.iSrcPrsPath);
   507 
   508 	TInt r = KErrNone;
   509 	switch(aParam.iAPI)
   510 		{
   511 		case EGetShortName:
   512 		case EGetShortNameWithDLL:
   513 		case EGetShortNameWithoutDLL:
   514 			{
   515 			__UHEAP_MARK;
   516 			if(aParam.iAPI == EGetShortName )
   517 				gLogFailureData.iAPIName = KGetShortName;
   518 			else if(aParam.iAPI == EGetShortNameWithDLL )
   519 				gLogFailureData.iAPIName = KGetShortNameWithDLL;
   520 			else if(aParam.iAPI == EGetShortNameWithoutDLL )
   521 				gLogFailureData.iAPIName = KGetShortNameWithoutDLL;
   522 
   523 				if (trgCmdFile.Length() > 0)
   524 					{
   525 					trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   526 					}
   527 				else
   528 					{
   529 					//trgCmdFile= gSessionPath;
   530 					trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   531 					}
   532 
   533 			TBuf<0x10> shortName;
   534 			r=TheFs.GetShortName(srcCmdFile,shortName);
   535 			testAndLog(r==KErrNone);
   536 			if(r==KErrNone)
   537 				{
   538 				srcCmd.ReAllocL(srcCmd.Length() + shortName.Length());
   539 				srcCmd+= shortName;
   540 				testAndLog(srcCmd==trgCmdFile);
   541 				}
   542 			__UHEAP_MARKEND;
   543 			}
   544 			break;
   545 		case ELongShortConversion:
   546 			{
   547 			__UHEAP_MARK;
   548 			gLogFailureData.iAPIName = KLongShortConversion;
   549 			if (trgCmdFile.Length() > 0)
   550 				{
   551 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   552 				}
   553 			else
   554 				{
   555 				//trgCmdFile= gSessionPath;
   556 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   557 				}
   558 
   559 			RBuf lgnFullPath;
   560 			RBuf shnFullPath;
   561 			TFileName longName;
   562 			TBuf<0x10> shortName;
   563 	
   564 			r = TheFs.GetShortName(srcCmdFile, shortName);
   565 			testAndLog(r==KErrNone);
   566 	
   567 			if(r==KErrNone)
   568 				{
   569 				shnFullPath.CreateL(srcCmd);
   570 				shnFullPath.ReAllocL(srcCmd.Length() + shortName.Length());
   571 				shnFullPath.Append(shortName);
   572 				r = shnFullPath.Compare(trgCmdFile);
   573 				testAndLog(r==KErrNone);
   574 
   575 				r = TheFs.GetLongName(shnFullPath, longName);
   576 				testAndLog(r==KErrNone);
   577 				
   578 				lgnFullPath.CreateL(srcCmd);
   579 				lgnFullPath.ReAllocL(srcCmd.Length() + longName.Length());
   580 				lgnFullPath.Append(longName);
   581 				r = lgnFullPath.Compare(srcCmdFile);
   582 				testAndLog(r==KErrNone);
   583 
   584 				lgnFullPath.Close();
   585 				shnFullPath.Close();
   586 				}
   587 			__UHEAP_MARKEND;
   588 			}
   589 			break;
   590 		case ECreateFile:
   591 			{
   592 			__UHEAP_MARK;
   593 			gLogFailureData.iAPIName = KCreateFile;
   594 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   595 			testAndLog(r == KErrNone);
   596 			TheFile.Close();
   597 			__UHEAP_MARKEND;
   598 			}
   599 			break;
   600 		case EIsValidName:
   601 			{
   602 			__UHEAP_MARK;
   603 			gLogFailureData.iAPIName = KIsValidName;
   604 			TText badChar;
   605 			r=TheFs.IsValidName(srcCmdFile,badChar);
   606 			testAndLog(r);
   607 			r=TheFs.IsValidName(srcCmdFile);
   608 			testAndLog(r);
   609 			__UHEAP_MARKEND;
   610 			}
   611 			break;
   612 		case EMkDir:
   613 			{
   614 			__UHEAP_MARK;
   615 			gLogFailureData.iAPIName = KMkDir;
   616 			r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
   617 			testAndLog(r==KErrNone);
   618 			TheDir.Close();
   619 			__UHEAP_MARKEND;
   620 			}
   621 			break;
   622 		case EMkDirAll:
   623 			{
   624 			__UHEAP_MARK;
   625 			gLogFailureData.iAPIName = KMkDirAll;
   626 			r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
   627 			testAndLog(r==KErrNone);
   628 			TheDir.Close();
   629 			__UHEAP_MARKEND;
   630 			}
   631 			break;
   632 		case ERenameFile:
   633 			{
   634 			__UHEAP_MARK;
   635 			gLogFailureData.iAPIName = KRenameFile;
   636 			if (trgCmdFile.Length() > 0)
   637 				{
   638 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   639 				}
   640 			else
   641 				{
   642 				//trgCmdFile= gSessionPath;
   643 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   644 				}
   645 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   646 			testAndLog(r == KErrNotFound);
   647 			// r = TheFile.Open(TheFs, trgCmdFile, EFileRead|EFileWrite);
   648 			// testAndLog(r == KErrNone);
   649 			// TheFile.Close();
   650 			__UHEAP_MARKEND;
   651 			}
   652 			break;
   653 		case EReadFileSection:
   654 			{
   655 			__UHEAP_MARK;
   656 			gLogFailureData.iAPIName = KReadFileSection;
   657 			TBool isFileOpen = EFalse;
   658 			r=TheFs.IsFileOpen(srcCmdFile,isFileOpen);
   659 			testAndLog(r==KErrNone);
   660 			if(isFileOpen)
   661 				{
   662 				TheFile.Close();
   663 				}
   664 			else
   665 				{
   666 				TInt numRead = 15;
   667 				TBuf8<50> readBuf;
   668 				r=TheFs.ReadFileSection(srcCmdFile, 0, readBuf, numRead);
   669 				testAndLog(r==KErrNone);
   670 				}
   671 			__UHEAP_MARKEND;
   672 			}
   673 			break;
   674 		case EDeleteFile:
   675 			{
   676 			__UHEAP_MARK;
   677 			gLogFailureData.iAPIName = KDeleteFile;
   678 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   679 			testAndLog(r == KErrNotFound);
   680 			// TheFile.Close();
   681 			__UHEAP_MARKEND;
   682 			}
   683 			break;
   684 		case EOpenDir:
   685 			{
   686 			__UHEAP_MARK;
   687 			gLogFailureData.iAPIName = KOpenDir;
   688 			r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
   689 			testAndLog(r==KErrNone);
   690 			TheDir.Close();
   691 			__UHEAP_MARKEND;
   692 			}
   693 			break;
   694 		case EReadDir:
   695 			{
   696 			__UHEAP_MARK;
   697 			gLogFailureData.iAPIName = KReadDir;
   698 			TEntry entry;
   699 			TInt dirEntryCount = 0;
   700 			r=TheDir.Open(TheFs,srcCmdFile,KEntryAttMaskSupported);
   701 			testAndLog(r==KErrNone);
   702 			FOREVER
   703 				{
   704 				r = TheDir.Read(entry);
   705 				if(r == KErrEof)
   706 					{
   707 					break;
   708 					}
   709 				dirEntryCount++;
   710 				}
   711 			TheDir.Close();
   712 			testAndLog(dirEntryCount == 4);
   713 			__UHEAP_MARKEND;
   714 			}
   715 			break;
   716 		case ERemoveDir:
   717 			{
   718 			__UHEAP_MARK;
   719 			gLogFailureData.iAPIName = KRemoveDir;
   720 			r = TheDir.Open(TheFs, srcCmdFile, KEntryAttMaskSupported);
   721 			testAndLog(r == KErrPathNotFound);
   722 			// TheDir.Close();
   723 			__UHEAP_MARKEND;
   724 			}
   725 			break;
   726 		case EIsFileInRom:
   727 			{
   728 			__UHEAP_MARK;
   729 			gLogFailureData.iAPIName = KIsFileInRom;
   730 			TUint8* ptr=TheFs.IsFileInRom(srcCmdFile);
   731 			// file should not be in ROM
   732 			testAndLog(ptr==NULL)
   733 			__UHEAP_MARKEND;
   734 			}
   735 			break;
   736 		case EReplaceFile:
   737 			{
   738 			__UHEAP_MARK;
   739 			gLogFailureData.iAPIName = KReplaceFile;
   740 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   741 			testAndLog(r == KErrNone);
   742 			TheFile.Close();
   743 			__UHEAP_MARKEND;
   744 			}
   745 			break;
   746 		case EOperateOnFileNames:
   747 			{
   748 			__UHEAP_MARK;
   749 			gLogFailureData.iAPIName = KOperateOnFileNames;
   750 			
   751 			TFileName realFileNameInFS;
   752 			TFileName fullFileName;
   753 			TFileName fileName;
   754 
   755 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead);
   756 			testAndLog(r == KErrNone);
   757 
   758 			if(r==KErrNone)
   759 				{
   760 				r=TheFile.FullName(fullFileName);
   761 				testAndLog(r==KErrNone);
   762 				testAndLog(fullFileName==srcCmdFile);
   763 				
   764 				TInt length = srcCmdFile.Length()-srcCmd.Length();
   765 				
   766 				r=TheFile.Name(fileName);
   767 				testAndLog(r==KErrNone);
   768 				
   769 				TBuf<50> tempFileName;
   770 				tempFileName = srcCmdFile.Right(length);
   771 				testAndLog(fileName==tempFileName);
   772 				testAndLog(length==fileName.Length());
   773 
   774 				r=TheFs.RealName(srcCmdFile,realFileNameInFS);
   775 				testAndLog(r==KErrNone);
   776 				testAndLog(realFileNameInFS==srcCmdFile);
   777 				TheFile.Close();
   778 				}
   779 			__UHEAP_MARKEND;
   780 			}
   781 			break;
   782 		case EFileModify:
   783 			{
   784 			__UHEAP_MARK;
   785 			gLogFailureData.iAPIName = KFileModify;
   786 			TTime tempTime;
   787 			r=TheFs.Modified(srcCmdFile,tempTime);
   788 			testAndLog(r==KErrNone);
   789 			tempTime.HomeTime();
   790 			r=TheFs.SetModified(srcCmdFile,tempTime);
   791 			testAndLog(r==KErrNone);
   792 			__UHEAP_MARKEND;
   793 			}
   794 			break;
   795 		case EFileAttributes:
   796 			{
   797 			__UHEAP_MARK;
   798 			gLogFailureData.iAPIName = KFileAttributes;
   799 			TUint att;
   800 			r=TheFs.Att(srcCmdFile,att);
   801 			testAndLog(r==KErrNone);
   802 			r=TheFs.SetAtt(srcCmdFile,KEntryAttHidden,0);
   803 			testAndLog(r==KErrNone);
   804 			r=TheFs.Att(srcCmdFile,att);
   805 			testAndLog(r==KErrNone);
   806 			__UHEAP_MARKEND;
   807 			}
   808 			break;
   809 		case ERFsEntry:
   810 			{
   811 			__UHEAP_MARK;
   812 			gLogFailureData.iAPIName = KRFsEntry;
   813 			TEntry entryDetail;
   814 			r=TheFs.Entry(srcCmdFile,entryDetail);
   815 			testAndLog(r==KErrNone);
   816 			TTime time;
   817 			time.HomeTime();
   818 			r=TheFs.SetEntry(srcCmdFile, time, KEntryAttHidden, KEntryAttNormal);
   819 			testAndLog(r==KErrNone);
   820 			r=TheFs.Entry(srcCmdFile, entryDetail);
   821 			testAndLog(r==KErrNone);
   822 			__UHEAP_MARKEND;
   823 			}
   824 			break;
   825 		case ERFsReplace:
   826 			{
   827 			__UHEAP_MARK;	
   828 			gLogFailureData.iAPIName = KRFsReplace;
   829 			if (trgCmdFile.Length() > 0)
   830 				{
   831 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   832 				}
   833 			else
   834 				{
   835 				//trgCmdFile= gSessionPath;
   836 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   837 				}
   838 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   839 			testAndLog(r == KErrNotFound);
   840 			// r = TheFile.Open(TheFs, trgCmdFile, EFileRead|EFileWrite);
   841 			// testAndLog(r == KErrNone);
   842 			// TheFile.Close();
   843 			__UHEAP_MARKEND;
   844 			}
   845 			break;
   846 		case ERFsRename:
   847 			{
   848 			__UHEAP_MARK;
   849 			gLogFailureData.iAPIName = KRFsRename;
   850 			if (trgCmdFile.Length() > 0)
   851 				{
   852 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   853 				}
   854 			else
   855 				{
   856 				//trgCmdFile= gSessionPath;
   857 				trgCmdFile[0] = (TUint16)*aParam.iTrgDrvChar;
   858 				} 
   859 			TInt len=srcCmdFile.Length();
   860 			if(srcCmdFile[--len]=='\\')
   861 				{
   862 				r = TheDir.Open(TheFs, srcCmdFile, KEntryAttMaskSupported);
   863 				testAndLog(r == KErrPathNotFound);
   864 				// r = TheDir.Open(TheFs, trgCmdFile, KEntryAttMaskSupported);
   865 				// testAndLog(r == KErrNone);			
   866 				// TheDir.Close();
   867 				}
   868 			else
   869 				{
   870 				r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   871 				testAndLog(r == KErrNotFound);
   872 				// r = TheFile.Open(TheFs, trgCmdFile, EFileRead|EFileWrite);
   873 				// testAndLog(r == KErrNone);
   874 				// TheFile.Close();
   875 				}
   876 			__UHEAP_MARKEND;			
   877 			}
   878 			break;
   879 		case EGetDir:
   880 			{
   881 			__UHEAP_MARK;
   882 			gLogFailureData.iAPIName = KGetDir;
   883 			CDir *anEntryList;
   884 			r=TheFs.GetDir(srcCmdFile,KEntryAttNormal,ESortByName,anEntryList);
   885 			testAndLog(r==KErrNone);
   886 			delete anEntryList;
   887 			__UHEAP_MARKEND;
   888 			}
   889 			break;
   890 		case EFileTemp:
   891 			{
   892 			__UHEAP_MARK;
   893 			gLogFailureData.iAPIName = KFileTemp;
   894 			TFileName tempFileName;
   895 			r=TheFile.Temp(TheFs,srcCmdFile,tempFileName,EFileWrite);
   896 			testAndLog(r == KErrNone);
   897 			TheFile.Close();
   898 			r = TheFile.Create(TheFs, tempFileName, EFileRead|EFileWrite);
   899 			testAndLog(r == KErrAlreadyExists);
   900 			__UHEAP_MARKEND;
   901 			}			
   902 			break;
   903 		case EReadFromFile:
   904 			{
   905 			__UHEAP_MARK;
   906 			gLogFailureData.iAPIName = KReadFromFile;
   907 			
   908 			TInt start=0, readLen=15, readPos=10;
   909 			TBuf8<200> readBuf;
   910 			TInt numWritten = 50;
   911 
   912 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   913 			testAndLog(r == KErrNone);
   914 
   915 			if(r==KErrNone)
   916 				{
   917 				r=TheFile.Seek(ESeekStart,start);
   918 		  		testAndLog(r==KErrNone);
   919 
   920 				readBuf.SetLength(0);
   921 				r=TheFile.Read(readBuf);
   922 				testAndLog(r == KErrNone);
   923 				testAndLog(numWritten == readBuf.Length());
   924 				
   925 				//An overload of RFile::Read(), read specified no.of bytes.
   926 	   			r=TheFile.Seek(ESeekStart,start);
   927 	  			testAndLog(r==KErrNone);
   928 	  			
   929 				readBuf.SetLength(0);
   930 				TheFile.Read(readBuf,readLen);
   931 				testAndLog(r == KErrNone);
   932 				testAndLog(readLen == readBuf.Length());
   933 				
   934 				//An overload of RFile::Read(), read from the specified position.
   935 				readBuf.SetLength(0);
   936 				r=TheFile.Read(readPos,readBuf);
   937 				testAndLog(r == KErrNone);
   938 				testAndLog(numWritten-readPos == readBuf.Length());
   939 				TheFile.Close();
   940 				}
   941 			__UHEAP_MARKEND;
   942 			}	
   943 			break;	
   944 		case EWriteToFile:
   945 			{
   946 			__UHEAP_MARK;
   947 			gLogFailureData.iAPIName = KWriteToFile;
   948 			
   949 			r = TheFile.Open(TheFs, srcCmdFile, EFileRead|EFileWrite);
   950 			testAndLog(r == KErrNone);
   951 
   952 			if(r==KErrNone)
   953 				{
   954 				TInt writeLen=20, writePos=10, start=0, readLen=0;
   955 				TBuf8<200> writeBuf = _L8("I am going to write something to the file and then read from the specified position to test an overload of RFIle::Read");
   956 				TInt numWritten = writeBuf.Length();
   957 				TBuf8<200> readBuf;
   958 				
   959 	   			TheFile.Write(writeBuf);
   960 	   			r=TheFile.Flush();
   961 	   			testAndLog(r==KErrNone);
   962 	   			
   963 	   			r=TheFile.Seek(ESeekStart,start);
   964 	  			testAndLog(r==KErrNone);
   965 	  		
   966 	   			readBuf.SetLength(0);
   967 	   			r=TheFile.Read(readBuf);
   968 	   			testAndLog(r==KErrNone);
   969 	   			readLen = readBuf.Length();
   970 	   			testAndLog(numWritten == readLen);
   971 	   			
   972 	   			r=TheFile.SetSize(0);
   973 	   			testAndLog(r==KErrNone);
   974 	   			
   975 	   			//An overload of RFile::Write(), write specified no.of bytes.
   976 	   			TheFile.Write(writeBuf,writeLen);
   977 	   			r=TheFile.Flush();
   978 	   			testAndLog(r==KErrNone);
   979 	   			
   980 	   			r=TheFile.Seek(ESeekStart,start);
   981 	  			testAndLog(r==KErrNone);
   982 				
   983 				readBuf.SetLength(0);
   984 	   			r=TheFile.Read(readBuf);
   985 	   			testAndLog(r==KErrNone);
   986 	   			readLen = readBuf.Length();
   987 	   			testAndLog(writeLen==readLen);
   988 	   			
   989 				r=TheFile.SetSize(0);
   990 	   			testAndLog(r==KErrNone);
   991 	   			
   992 	   			//An overload of RFile::Write(), write to a particular position.
   993 	   			TBuf8<50> testBuf = _L8("Testing different variants of RFile::Write APIs");   		
   994 	    		TheFile.Write(testBuf);
   995 	    		r=TheFile.Flush();
   996 	   			testAndLog(r==KErrNone);
   997 				
   998 	   			TheFile.Write(writePos,writeBuf);
   999 	   			r=TheFile.Flush();
  1000 	   			testAndLog(r==KErrNone);
  1001 	   			
  1002 	      		r=TheFile.Seek(ESeekStart,start);
  1003 	  			testAndLog(r==KErrNone);
  1004 	  			
  1005 	  			readBuf.SetLength(0);
  1006 	   			r=TheFile.Read(readBuf);
  1007 	   			testAndLog(r==KErrNone);
  1008 	   			readLen = readBuf.Length();
  1009 	   			testAndLog(numWritten + writePos == readLen);
  1010 	   			
  1011 				r=TheFile.SetSize(0);
  1012 	   			testAndLog(r==KErrNone);
  1013 	   			
  1014 	   			//An overload of RFile::Write(), write to a particular position and specified no. of bytes.
  1015 	   			TInt size;
  1016 	    		TheFile.Write(testBuf);
  1017 	    		r=TheFile.Flush();
  1018 	   			testAndLog(r==KErrNone);
  1019 			
  1020 	   			TheFile.Write(writePos,writeBuf,writeLen);
  1021 	   			r=TheFile.Flush();
  1022 	   			testAndLog(r==KErrNone);
  1023 	   			
  1024 	   			r=TheFile.Seek(ESeekStart,start);
  1025 	  			testAndLog(r==KErrNone);
  1026 	  			
  1027 	  			readBuf.SetLength(0);
  1028 	   			r=TheFile.Read(readBuf);
  1029 	   			testAndLog(r==KErrNone);
  1030 	   			
  1031 	   			TInt newSize = testBuf.Length()-(writePos+writeLen);
  1032 	   			if(newSize < testBuf.Length())
  1033 	   				{
  1034 	   				size = testBuf.Length();
  1035 	   				}
  1036 	   			else
  1037 	   				size = newSize;
  1038 	   			readLen = readBuf.Length();
  1039 	   			testAndLog(readLen==size);
  1040 
  1041 	   			r=TheFile.SetSize(0);
  1042 	   			testAndLog(r==KErrNone);
  1043 
  1044 	   			TheFile.Close();
  1045 				}
  1046    			__UHEAP_MARKEND;
  1047 			}
  1048 			break;
  1049 	 	default:
  1050 			break;
  1051 		}
  1052 //	test.Printf(_L("DataVerification::\tTest case %d passed\n"),aParam.iTestCaseID);
  1053 
  1054 	failedOnBuf.Close();
  1055 	tcUniquePath.Close();
  1056 
  1057 	srcCmdFile.Close();
  1058 	trgCmdFile.Close();
  1059 	srcCmd.Close();
  1060 	CheckDisk();
  1061 	}
  1062 	
  1063 void DeletePathAfterTest(const TTestParamAll& aParam)
  1064 	{
  1065 	TFileName path = aParam.iSrcPrsPath;
  1066 	if (path.Length() == 0)
  1067 		{
  1068 		test.Printf(_L("ERROR<SetupDirFiles()>: Zero length src path!\n"));
  1069 		test(EFalse);
  1070 		}
  1071 
  1072 	path[0] = (TUint16)*aParam.iSrcDrvChar;
  1073 	TInt idx = path.Find(_L("Src\\"));
  1074 	path.Delete(idx,path.Length()-idx);
  1075 	RmDir(path);
  1076 	}
  1077 
  1078 
  1079 /*
  1080  * Do all basic binary test cases defined in gBasicUnitaryTestCases[]
  1081  */
  1082 void DoAllBasicUnitaryTestsL(const TTestCaseUnitaryBasic aBasicUnitaryTestCaseGroup[],
  1083 									TTestSwitches& aSwitches, TBool aIsWithDLL)
  1084 	{
  1085 	TTestParamAll* 	nextTestCase = new(ELeave) TTestParamAll();
  1086 	
  1087 	TInt i = 0;
  1088 	
  1089 	// Reset the Test Log Data
  1090 	ClearTCLogData();
  1091 
  1092 	while(SearchTestCaseByArrayIdx(i, aBasicUnitaryTestCaseGroup,
  1093 							*nextTestCase, aIsWithDLL) == KErrNone)
  1094 		{
  1095 		TTime startTime;
  1096 		TTime endTime;
  1097 		startTime.HomeTime();
  1098 		if(aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows)
  1099 			{
  1100 			DataGenerationL(*nextTestCase);
  1101 			DataExecutionL(*nextTestCase, EUnitaryTest);
  1102 			}
  1103 		if(aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows)
  1104 			{
  1105 			DataVerificationL(*nextTestCase, EUnitaryTest);
  1106 			DeletePathAfterTest(*nextTestCase);
  1107 			}
  1108 			
  1109 		CheckDisk();
  1110 		endTime.HomeTime();
  1111 		TTimeIntervalMicroSeconds timeTaken(0);
  1112 		timeTaken = endTime.MicroSecondsFrom(startTime);
  1113 
  1114 //		test.Printf(_L("Test Case Id : %d\n"),(*nextTestCase).iTestCaseID);
  1115 //		TInt time=0;
  1116 //		time=I64LOW(timeTaken.Int64()/1000);
  1117 //		test.Printf(_L("Time Taken by test case %d = %d mS \n"),nextTestCase.iTestCaseID,time);
  1118 		++i;
  1119 		}
  1120 	delete nextTestCase;
  1121 	}
  1122 		
  1123 /*
  1124  * Do all basic binary test cases defined in gBasicBinaryTestCases[]
  1125  */
  1126 void DoAllBasicBinaryTestsL(const TTestCaseBinaryBasic aBasicBinaryTestCaseGroup[],
  1127 							TTestSwitches& aSwitches, TBool aIsWithDLL)
  1128 	{
  1129 	TTestParamAll*	nextTestCase = new(ELeave) TTestParamAll();
  1130 	
  1131 	TInt i = 0;
  1132 	
  1133 	// Reset the Test Log Data
  1134 	ClearTCLogData();
  1135 	
  1136 	while (SearchTestCaseByArrayIdx(i, aBasicBinaryTestCaseGroup,
  1137 							*nextTestCase, aIsWithDLL) == KErrNone)
  1138 		{
  1139 		if (aIsWithDLL)
  1140 			{
  1141 			if(((aBasicBinaryTestCaseGroup[i].iBasic.iAPI==EGetShortNameWithoutDLL)))
  1142 				{
  1143 				++i;
  1144 				continue;
  1145 				}
  1146 			}
  1147 		else
  1148 			{
  1149 			if(((aBasicBinaryTestCaseGroup[i].iBasic.iAPI== EGetShortNameWithDLL) || (aBasicBinaryTestCaseGroup[i].iBasic.iAPI==ELongShortConversion)) )
  1150 				{
  1151 				++i;
  1152 				continue;
  1153 				}
  1154 			}
  1155 		TTime startTime;
  1156 		TTime endTime;
  1157 		startTime.HomeTime();
  1158 
  1159 		if(aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows) 
  1160 			{
  1161 			DataGenerationL(*nextTestCase);
  1162 			DataExecutionL(*nextTestCase, EBinaryTest);
  1163 			}
  1164 		if(aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows)
  1165 			{
  1166 			DataVerificationL(*nextTestCase, EBinaryTest);
  1167 			DeletePathAfterTest(*nextTestCase);
  1168 			}
  1169 
  1170 		endTime.HomeTime();
  1171 		TTimeIntervalMicroSeconds timeTaken(0);
  1172 		timeTaken = endTime.MicroSecondsFrom(startTime);
  1173 
  1174 //		test.Printf(_L("Test Case Id : %d\n"),(*nextTestCase).iTestCaseID);
  1175 //		TInt time2=0;
  1176 //		time2=I64LOW(timeTaken.Int64()/1000);
  1177 //		test.Printf(_L("Time Taken by test id %d = %d mS \n"),nextTestCase.iTestCaseID,time2);
  1178 		++i;
  1179 		}
  1180 
  1181 	delete nextTestCase;
  1182 	}
  1183 
  1184 /*
  1185  * Main testing control unit
  1186  */
  1187 void TestMainWithDLLL(TTestSwitches& aSwitches)
  1188 	{
  1189 	// Enables codepage dll implementation of LocaleUtils functions for this test only
  1190 	TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
  1191 	test(r == KErrNone);
  1192 		
  1193 	test.Printf(_L("Load the Code Page DLL"));
  1194 	r = UserSvr::ChangeLocale(KTestLocale);
  1195 	test(r == KErrNone);
  1196 			
  1197 	test.Next(_L("Test Unitary APIs with only Sync Variant with DLL"));
  1198 	gLogFailureData.iFuncName = KDoAllBasicUnitaryTestsL;
  1199 	DoAllBasicUnitaryTestsL(gBasicUnitaryTestCases, aSwitches, ETrue);
  1200 	
  1201 	test.Next(_L("Test Binary Tests with DLL"));
  1202 	gLogFailureData.iFuncName = KDoAllBasicBinaryTestsL;
  1203 	DoAllBasicBinaryTestsL(gBasicBinaryTestCases, aSwitches, ETrue);
  1204 	
  1205 	// Disables codepage dll implementation of LocaleUtils functions for other base tests
  1206 	r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
  1207 	test(r == KErrNone);
  1208 	}
  1209 	
  1210 void TestMainWithoutDLLL(TTestSwitches& aSwitches)
  1211 	{
  1212 	test.Next(_L("Test Unitary APIs with only Sync Variant without DLL"));
  1213 
  1214 	// Disables codepage dll implementation of LocaleUtils functions
  1215 	TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
  1216 	test(r == KErrNone);
  1217 
  1218 	gLogFailureData.iFuncName = KDoAllBasicUnitaryTestsL;
  1219 	DoAllBasicUnitaryTestsL(gBasicUnitaryTestCases, aSwitches, EFalse);
  1220 	
  1221 	test.Next(_L("Test Binary Tests without DLL"));
  1222 	gLogFailureData.iFuncName = KDoAllBasicBinaryTestsL;
  1223 	DoAllBasicBinaryTestsL(gBasicBinaryTestCases, aSwitches, EFalse);
  1224 	}
  1225 
  1226 void TestCompatibility(const TTestSwitches& aSwitches)
  1227 	{
  1228 	test.Next(_L("test compatibility"));
  1229 
  1230 	// logging for failure
  1231 	gTCType = ESymbianFATSpecific;
  1232 	RBuf failedOnBuf;
  1233 	failedOnBuf.CreateL(gLogFailureData.iFuncName);
  1234 	gTCId = 0;
  1235 	RBuf tcUniquePath;
  1236 	tcUniquePath.CreateL(KNone());
  1237 
  1238 	// original file name in DBCS
  1239 	TFileName fn1 = _L("\\\x798F\x5C71\x96C5\x6CBB");
  1240 	if (aSwitches.iExeOnSymbian)
  1241 		{
  1242 		GetBootInfo();
  1243 		RFile file;
  1244 		TFileName fn = _L("\\ABCD");
  1245 		
  1246 		TInt r=file.Create(TheFs,fn,EFileRead);
  1247 		testAndLog(r==KErrNone);
  1248 		file.Close();
  1249 
  1250 		//	Assume this file is the first entry in the root directory
  1251 		r=TheDisk.Open(TheFs,CurrentDrive());
  1252 		testAndLog(r==KErrNone);
  1253 		
  1254 	    //-- read the 1st dir entry, it should be a DOS entry 
  1255 	    const TInt posEntry1=gBootSector.RootDirStartSector() << KDefaultSectorLog2; //-- dir entry1 position
  1256 	    
  1257 	    TFatDirEntry fatEntry1;
  1258 		TPtr8 ptrEntry1((TUint8*)&fatEntry1,sizeof(TFatDirEntry));
  1259 	    testAndLog(TheDisk.Read(posEntry1, ptrEntry1)==KErrNone); 
  1260 	    testAndLog(!fatEntry1.IsVFatEntry());
  1261 
  1262 	    // Manually modify the short name into unicode characters
  1263 	    // 	Unicode: 	0x(798F 5C71 96C5 6CBB)
  1264 	    //	Shift-JIS: 	0x(959F 8E52 89EB 8EA1)
  1265 
  1266 	    TBuf8<8> unicodeSN = _L8("ABCD1234");
  1267 	    unicodeSN[0] = 0x95;
  1268 	    unicodeSN[1] = 0x9F;
  1269 	    unicodeSN[2] = 0x8E;
  1270 	    unicodeSN[3] = 0x52;
  1271 	    unicodeSN[4] = 0x89;
  1272 	    unicodeSN[5] = 0xEB;
  1273 	    unicodeSN[6] = 0x8E;
  1274 	    unicodeSN[7] = 0xA1;
  1275 	    
  1276 	    fatEntry1.SetName(unicodeSN);
  1277 	    testAndLog(TheDisk.Write(posEntry1, ptrEntry1)==KErrNone);
  1278 	    TheDisk.Close();
  1279 		}
  1280 	if (aSwitches.iVerOnSymbian)
  1281 		{
  1282 		// Access the file without the DLL loaded.
  1283 	    TInt r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
  1284 		testAndLog(r==KErrNone);
  1285 		
  1286 		TEntry entry;
  1287 		r = TheFs.Entry(fn1, entry);
  1288 		testAndLog(r==KErrNotFound);
  1289 		
  1290 	    // Access the file with the DLL loaded.
  1291 	    r = TheFs.ControlIo(CurrentDrive(), KControlIoEnableFatUtilityFunctions);
  1292 		testAndLog(r==KErrNone);
  1293 		r = UserSvr::ChangeLocale(KTestLocale);
  1294 		testAndLog(r==KErrNone);
  1295 
  1296 		r = TheFs.Entry(fn1, entry);
  1297 		testAndLog(r==KErrNone);
  1298 		
  1299 	    r = TheFs.ControlIo(CurrentDrive(), KControlIoDisableFatUtilityFunctions);
  1300 		testAndLog(r==KErrNone);
  1301 		}
  1302 	failedOnBuf.Close();
  1303 	tcUniquePath.Close();
  1304 	}
  1305 
  1306 #endif //defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1307 
  1308 /*
  1309  * Initialise test 
  1310 */
  1311 void CallTestsL(TTestSwitches& aSwitches)
  1312 	{
  1313 	test.Title();
  1314 	test.Start(_L("Starting T_FATCHARSETCONV tests"));
  1315 	(void) aSwitches;
  1316 #ifdef LOG_FAILURE_DATA
  1317 	test.Printf(_L("LOG_FAILURE_DATA: ON\n"));
  1318 #else
  1319 	test.Printf(_L("LOG_FAILURE_DATA: OFF\n"));
  1320 #endif
  1321 
  1322 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1323 	// Test only runs on Fat file systems
  1324 	TheFs.SessionPath(gSessionPath);
  1325 	TInt r = TheFs.FileSystemName(aSwitches.iMountedFSName, CurrentDrive());
  1326 	if (KErrNone == r)
  1327 		{
  1328 		// For automated testing this test should run on FAT file systems only.
  1329 		// For inter-operability testing on FAT and Win32 file systems.
  1330 		// if ((AUTO && FAT) || (IOT && (FAT || Win32))
  1331 		test.Printf(_L("Current File System: \"%S\"\n"), &aSwitches.iMountedFSName);
  1332 		if( (gAutoTest && isFAT(aSwitches.iMountedFSName)) ||
  1333 			(gIOTesting && (isFAT(aSwitches.iMountedFSName) || isWin32(aSwitches.iMountedFSName))))
  1334 			{
  1335 			// Log File System Name
  1336 			gLogFailureData.iFSName = aSwitches.iMountedFSName;
  1337 			
  1338 			// Store current file name
  1339 			TFileName fileName;
  1340 			TInt i=0;
  1341 			while(__FILE__[i]!='\0')
  1342 				{
  1343 				fileName.SetLength(i+1);
  1344 				fileName[i] = __FILE__[i++];
  1345 				}
  1346 			gFileName.Append(fileName);
  1347 			
  1348 			InitialiseL();
  1349 			// Special Cases	- Non-Symbian
  1350 			// Note: this case MUST be run as the first case as it performs formatting!!
  1351 			TestCompatibility(aSwitches);
  1352 			CreateTestDirectory(_L("\\F32-TST\\T_FATCHARSETCONV\\"));
  1353 			//Special Cases	- Only Symbian Specific
  1354 			if(!gIOTesting && aSwitches.iMountedFSName.Compare(KFAT) == 0)
  1355 				{
  1356 				DoSymbianSpecificCases();
  1357 				}
  1358 
  1359 			test.Next(_L("Test without DLL loaded"));
  1360 			if(gAutoTest)
  1361 				{
  1362 				QuickFormat();
  1363 				}
  1364 			TestMainWithoutDLLL(aSwitches);
  1365 							
  1366 			test.Next(_L("Test with DLL loaded"));
  1367 			if(gAutoTest)
  1368 				{
  1369 				QuickFormat();
  1370 				}
  1371 			TestMainWithDLLL(aSwitches);
  1372 			Cleanup();
  1373 			}
  1374 		else
  1375 			{
  1376 			if(gAutoTest)
  1377 				test.Printf(_L("Test only runs on \"FAT\" File Systems !!!\n"));
  1378 			if(gIOTesting)
  1379 				test.Printf(_L("Test only runs on \"FAT\" and \"Win32\" File Systems !!!\n"));
  1380 			}
  1381 		}
  1382 	else
  1383 		{
  1384 		test.Printf(_L("Drive %C: is not ready!\n"), 'A'+CurrentDrive());
  1385 		test(EFalse);
  1386 		}
  1387 #else
  1388 	test.Printf(_L("Test only runs on DEBUG builds, see test logs of debug builds for details.\n"));
  1389 #endif  // _DEBUG) || _DEBUG_RELEASE
  1390 	test.End();
  1391 	}
  1392 
  1393 LOCAL_C void PushLotsL()
  1394 //
  1395 // Expand the cleanup stack
  1396 //
  1397 	{
  1398 	TInt i;
  1399 	for(i=0;i<1000;i++)
  1400 		CleanupStack::PushL((CBase*)NULL);
  1401 	CleanupStack::Pop(1000);
  1402 	}
  1403 
  1404 
  1405 LOCAL_C void DoTests(TInt aDrive, TTestSwitches& aSwitches)
  1406 //
  1407 // Do testing on aDrive
  1408 //
  1409 	{
  1410 	gSessionPath=_L("?:\\F32-TST\\");
  1411 	TChar driveLetter;
  1412 	TInt r=TheFs.DriveToChar(aDrive,driveLetter);
  1413 	test(r==KErrNone);
  1414 	gSessionPath[0]=(TText)driveLetter;
  1415 	r=TheFs.SetSessionPath(gSessionPath);
  1416 	test(r==KErrNone);
  1417 	test.Printf(_L("gSessionPath = \"%S\"\n"), &gSessionPath);
  1418 
  1419 // !!! Disable platform security tests until we get the new APIs
  1420 //	if(User::Capability() & KCapabilityRoot)
  1421 		CheckMountLFFS(TheFs,driveLetter);
  1422 	
  1423 	User::After(1000000);
  1424 
  1425 //	Format(CurrentDrive());
  1426 
  1427 	r=TheFs.MkDirAll(gSessionPath);
  1428 	if(r == KErrCorrupt)
  1429 		{
  1430 		Format(aDrive);
  1431 		r=TheFs.MkDirAll(gSessionPath);
  1432 		test(r==KErrNone);
  1433 		}
  1434 	if (r!=KErrNone && r!=KErrAlreadyExists)
  1435 		{
  1436 		test.Printf(_L("MkDirAll() r %d\n"),r);
  1437 		test(EFalse);
  1438 		}
  1439 	TheFs.ResourceCountMarkStart();
  1440 	TRAP(r,CallTestsL(aSwitches));
  1441 	if (r==KErrNone)
  1442 		TheFs.ResourceCountMarkEnd();
  1443 	else
  1444 		{
  1445 		test.Printf(_L("Error: Leave %d\n"),r);
  1446 		test(EFalse);
  1447 		}
  1448 
  1449 	CheckDisk();
  1450 	TestingLFFS(EFalse);
  1451 	}
  1452 
  1453 	
  1454 GLDEF_C TInt E32Main()
  1455 //
  1456 // Test with drive nearly full
  1457 //
  1458     {
  1459 	CTrapCleanup* cleanup;
  1460 	cleanup=CTrapCleanup::New();
  1461 	TRAPD(r,PushLotsL());
  1462 	__UHEAP_MARK;
  1463 
  1464 	test.Title();
  1465 	test.Start(_L("Starting tests..."));
  1466 
  1467 	gSessionPath=_L("?:\\F32-TST\\");
  1468 	TTestSwitches testSwitches;
  1469 	ParseCommandArguments(testSwitches);
  1470 
  1471 	r=TheFs.Connect();
  1472 	test(r==KErrNone);
  1473 	TheFs.SetAllocFailure(gAllocFailOn);
  1474 
  1475 	TTime timerC;
  1476 	timerC.HomeTime();
  1477 
  1478 	TInt theDrive;
  1479 	r=TheFs.CharToDrive(gDriveToTest,theDrive);
  1480 	test(r==KErrNone);
  1481 	
  1482 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1483 	TPckgBuf<TIOCacheValues> pkgOrgValues;
  1484 	TIOCacheValues& orgValues=pkgOrgValues();
  1485 	r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
  1486 	test(r==KErrNone);
  1487 
  1488 	test.Printf(_L("\n"));
  1489 	test.Printf(_L("Requests on close queue at start=%d\n"),orgValues.iCloseCount);
  1490 	test.Printf(_L("Requests on free queue at start=%d\n"),orgValues.iFreeCount);
  1491 	test.Printf(_L("Requests dynamically allocated at start=%d\n"),orgValues.iAllocated);
  1492 	test.Printf(_L("Requests in total at start=%d\n"),orgValues.iTotalCount);
  1493 #endif
  1494 
  1495 	DoTests(theDrive, testSwitches);
  1496 
  1497 	TTime endTimeC;
  1498 	endTimeC.HomeTime();
  1499 	TTimeIntervalSeconds timeTakenC;
  1500 	r=endTimeC.SecondsFrom(timerC,timeTakenC);
  1501 	test(r==KErrNone);
  1502 
  1503 	test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
  1504 	TheFs.SetAllocFailure(gAllocFailOff);
  1505 	
  1506 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1507 	TPckgBuf<TIOCacheValues> pkgValues;
  1508 	TIOCacheValues& values=pkgValues();
  1509 	r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
  1510 	test(r==KErrNone);
  1511 	
  1512 	test.Printf(_L("Requests on close queue at end=%d\n"),values.iCloseCount);
  1513 	test.Printf(_L("Requests on free queue at end=%d\n"),values.iFreeCount);
  1514 	test.Printf(_L("Requests dynamically allocated at end=%d\n"),values.iAllocated);
  1515 	test.Printf(_L("Requests in total at end=%d\n"),values.iTotalCount);
  1516 	
  1517 	test(orgValues.iCloseCount==values.iCloseCount);
  1518 	test(orgValues.iAllocated == values.iAllocated);
  1519 #endif
  1520 
  1521 	TheFs.Close();
  1522 	test.End();
  1523 	test.Close();
  1524 	__UHEAP_MARKEND;
  1525 	delete cleanup;
  1526 	return(KErrNone);
  1527     }