os/kernelhwsrv/kerneltest/f32test/server/t_fatcharsetconv_aux.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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_Aux.cpp
    15 // 
    16 //
    17 
    18 #include <f32dbg.h>
    19 #include "T_fatcharsetconv_Aux.h"
    20 
    21 CFileMan* gFileMan = NULL;
    22 RPointerArray<RFile>* gFileHandles = NULL;
    23 TTestLogFailureData gLogFailureData;
    24 RRawDisk TheDisk;
    25 TFatBootSector gBootSector;
    26 TBool gIOTesting;
    27 TBool gAutoTest; // is BTB test
    28 
    29 RFs TheFs;
    30 RFile TheFile;
    31 RDir TheDir;
    32 
    33 TFileName gSessionPath;
    34 TInt gAllocFailOff=KAllocFailureOff;
    35 TInt gAllocFailOn=KAllocFailureOff;
    36 TChar gDriveToTest;
    37 TFileName gFileName;
    38 
    39 TTCType	gTCType;
    40 TUint	gTCId;
    41 
    42 GLDEF_C void Format(TInt aDrive)
    43 //
    44 // Format current drive
    45 //
    46 	{
    47 	test.Next(_L("Format"));
    48 	TBuf<4> driveBuf=_L("?:\\");
    49 	driveBuf[0]=(TText)(aDrive+'A');
    50 	RFormat format;
    51 	TInt count;
    52 	TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
    53 	test(r==KErrNone);
    54 	while(count)
    55 		{
    56 		TInt r=format.Next(count);
    57 		test(r==KErrNone);
    58 		}
    59 	format.Close();
    60 	}
    61 
    62 void MakeDir(const TDesC& aDirName)
    63 //
    64 // Make a directory
    65 //
    66 	{
    67 	TInt r=TheFs.MkDirAll(aDirName);
    68 	test(r==KErrNone || r==KErrAlreadyExists);
    69 	}
    70 
    71 
    72 void ReportCheckDiskFailure(TInt aRet)
    73 //
    74 // Report the failure of checkdisk
    75 //
    76 	{
    77 	test.Printf(_L("CHECKDISK FAILED: "));
    78 	switch(aRet)
    79 		{
    80 	case 1:	test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
    81 	case 2:	test.Printf(_L("Two files are linked to the same cluster\n")); break;
    82 	case 3:	test.Printf(_L("Unallocated cluster contains a value != 0\n"));	break;
    83 	case 4:	test.Printf(_L("Size of file != number of clusters in chain\n")); break;
    84 	default: test.Printf(_L("Undefined Error value %d\n"),aRet);
    85 		}
    86 	test(EFalse);
    87 	}
    88 
    89 void CreateTestDirectory(const TDesC& aSessionPath)
    90 //
    91 // Create directory for test
    92 //
    93 	{
    94 	TParsePtrC path(aSessionPath);
    95 	test(path.DrivePresent()==EFalse);
    96 	TInt r=TheFs.SetSessionPath(aSessionPath);
    97 	test(r==KErrNone);
    98 	r=TheFs.SessionPath(gSessionPath);
    99 	test(r==KErrNone);
   100 	r=TheFs.MkDirAll(gSessionPath);
   101 	test(r==KErrNone || r==KErrAlreadyExists);
   102 	}
   103 
   104 TInt CurrentDrive(TChar aDriveChar)
   105 //
   106 // Return the current drive number
   107 //
   108 	{
   109 	TInt driveNum;
   110 	TInt r = TheFs.CharToDrive(aDriveChar,driveNum);
   111 	test(r==KErrNone);
   112 	gDriveToTest = gSessionPath[0] = (TText)aDriveChar;
   113 	return(driveNum);
   114 	}
   115 
   116 TInt CurrentDrive()
   117 //
   118 // Return the current drive number
   119 //
   120 	{
   121 	TInt driveNum;
   122 	TInt r = TheFs.CharToDrive(gSessionPath[0],driveNum);
   123 	test(r==KErrNone);
   124 	return(driveNum);
   125 	}
   126 
   127 void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
   128 //
   129 // Make a file and write uid and data
   130 //
   131 	{
   132 	RFile file;
   133 	TInt r=file.Replace(TheFs,aFileName,0);
   134 	test(r==KErrNone || r==KErrPathNotFound);
   135 	if (r==KErrPathNotFound)
   136 		{
   137 		r=TheFs.MkDirAll(aFileName);
   138 		test(r==KErrNone);
   139 		r=file.Replace(TheFs,aFileName,0);
   140 		test(r==KErrNone);
   141 		}
   142 	TCheckedUid checkedUid(aUidType);
   143 	TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
   144 	r=file.Write(uidData);
   145 	test(r==KErrNone);
   146 	r=file.Write(aFileContents);
   147 	test(r==KErrNone);
   148 	file.Close();
   149 	}
   150 
   151 void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents)
   152 //
   153 // Make a file and write something in it
   154 //
   155 	{
   156 	RFile file;
   157 	TInt r=file.Replace(TheFs,aFileName,0);
   158 	if(r!=KErrNone && r!=KErrPathNotFound)
   159 		{
   160 		test.Printf(_L("ERROR: r=%d"),r);
   161 		test(EFalse);
   162 		}
   163 	test(r==KErrNone || r==KErrPathNotFound);
   164 	if (r==KErrPathNotFound)
   165 		{
   166 		r=TheFs.MkDirAll(aFileName);
   167 		test(r==KErrNone);
   168 		r=file.Replace(TheFs,aFileName,0);
   169 		test(r==KErrNone);
   170 		}
   171 	r=file.Write(aFileContents);
   172 	test(r==KErrNone);
   173 	file.Close();
   174 	}
   175 
   176 void MakeFile(const TDesC& aFileName,TInt anAttributes)
   177 //
   178 // Make a file and write something in it
   179 //
   180 	{
   181 	RFile file;
   182 	TInt r=file.Replace(TheFs,aFileName,0);
   183 	test(r==KErrNone || r==KErrPathNotFound);
   184 	if (r==KErrPathNotFound)
   185 		{
   186 		r=TheFs.MkDirAll(aFileName);
   187 		test(r==KErrNone);
   188 		r=file.Replace(TheFs,aFileName,0);
   189 		test(r==KErrNone);
   190 		}
   191 	file.Close();
   192 	r=TheFs.SetAtt(aFileName,anAttributes,0);
   193 	test(r==KErrNone);
   194 	}
   195 
   196 void MakeFile(const TDesC& aFileName)
   197 //
   198 // Make a file
   199 //
   200 	{
   201 	MakeFile(aFileName,_L8(""));
   202 	}
   203 
   204 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   205 void QuickFormat()
   206     {
   207     FormatFatDrive(TheFs, CurrentDrive(), ETrue);
   208     }
   209 
   210 void ReadBootSector(TFatBootSector& aBootSector)
   211 	{
   212     TInt r = ReadBootSector(TheFs, CurrentDrive(), KBootSectorNum<<KDefaultSectorLog2, aBootSector);
   213     test(r==KErrNone);
   214 
   215     if(!aBootSector.IsValid())
   216         {
   217         test.Printf(_L("Wrong bootsector! Dump:\n"));
   218         aBootSector.PrintDebugInfo();
   219         test(0);
   220         }
   221 	}
   222 
   223 void GetBootInfo()
   224 	{
   225 	QuickFormat();
   226 	ReadBootSector(gBootSector);
   227 	}
   228 #endif
   229 
   230 void CheckIfIOTesting(TTestSwitches& aSwitches)
   231 	{
   232 	if( ((aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows) && !(aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows))
   233 	  ||((aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows) && !(aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows))
   234 	  )
   235 		{
   236 		gIOTesting = ETrue;
   237 		}
   238 	}
   239 
   240 void CheckDisk()
   241 	{
   242 	TInt r=TheFs.CheckDisk(gSessionPath);
   243 	if (r!=KErrNone && r!=KErrNotSupported)
   244 		ReportCheckDiskFailure(r);
   245 	r = TheFs.ScanDrive(gSessionPath);
   246 	if (r!=KErrNone && r!=KErrNotSupported && r!=KErrInUse)
   247 		ReportCheckDiskFailure(r);
   248 	}
   249 
   250 void InitLogData()
   251 	{
   252 	gLogFailureData.iExeOsName = KNone;
   253 	gLogFailureData.iVerOsName = KNone;
   254 	gLogFailureData.iExeDrive  = 'A';
   255 	gLogFailureData.iVerDrive  = 'A';
   256 	}
   257 
   258 void ClearTCLogData()
   259 	{
   260 	gLogFailureData.iTCTypeName.SetLength(0);
   261 	gLogFailureData.iTCFailureOn.SetLength(0);
   262 	gLogFailureData.iTCId = 0;
   263 	gLogFailureData.iTCUniquePath.SetLength(0);
   264 	gLogFailureData.iAPIName.SetLength(0);
   265 	gLogFailureData.iLineNum = 0;
   266 	// gLogFailureData.iFileName.SetLength(0);
   267 	}
   268 
   269 /*
   270  * Search test cases by the index of the array of test case group, overloaded version for basic unitary cases.
   271  * @param 	aIdx		the test case index in search
   272  * @param	aBasicUnitaryTestCaseGroup		the input test group, should always be gBasicUnitaryTestCases[]
   273  * @param	aTestCaseFound		contains params of the test case found by the test case Id.
   274  * @return	KErrNone	if only one test case on the id is found
   275  * 			KErrNotFound	if no test case is found
   276  */
   277 TInt SearchTestCaseByArrayIdx(TUint aIdx, const TTestCaseUnitaryBasic aBasicUnitaryTestCaseGroup[],
   278 					 TTestParamAll& aTestCaseFound, TBool aIsWithDLL=EFalse)
   279 	{
   280 	if (aBasicUnitaryTestCaseGroup[aIdx].iBasic.iTestCaseID != 0)
   281 		{
   282 		aTestCaseFound.iTestCaseID 	= aBasicUnitaryTestCaseGroup[aIdx].iBasic.iTestCaseID;
   283 		aTestCaseFound.iAPI 		= aBasicUnitaryTestCaseGroup[aIdx].iBasic.iAPI;
   284 
   285 		aTestCaseFound.iSrcDrvChar	= aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iDrvChar;
   286 		aTestCaseFound.iSrcCmdPath.Copy(aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmdPath);
   287 		aTestCaseFound.iSrcPrsPath.Copy(aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsPath);
   288 		aTestCaseFound.iSrcPrsFiles = aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsFiles;
   289 
   290 		aTestCaseFound.iIsWithDLL = aIsWithDLL;
   291 
   292 		// To make every test case uniquely indentified for interOP
   293 		// update the test case id  and its path correspondingly
   294 		TBuf<15> tempName = _L("_");
   295 		if(aTestCaseFound.iIsWithDLL)
   296 			tempName.Append(_L("DLL"));
   297 		else
   298 			tempName.Append(_L("NDLL"));
   299 
   300 		TInt idx = aTestCaseFound.iSrcCmdPath.Find(_L("\\Src\\"));
   301 		aTestCaseFound.iSrcCmdPath.Insert(idx, tempName);
   302 		aTestCaseFound.iSrcPrsPath.Insert(idx, tempName);
   303 		}
   304 	else
   305 		return KErrNotFound;
   306 
   307 	return KErrNone;
   308 	}
   309 /*
   310  * Search test cases by the index of the array of test case group, overloaded version for basic binary cases.
   311  * @param 	aIdx		the test case index in search
   312  * @param	aBasicUnitaryTestCaseGroup		the input test group, should always be gBasicBinaryTestCases[]
   313  * @param	aTestCaseFound		contains params of the test case found by the test case Id.
   314  * @return	KErrNone	if only one test case on the id is found
   315  * 			KErrNotFound	if no test case is found
   316  */
   317 TInt SearchTestCaseByArrayIdx(TUint aIdx, const TTestCaseBinaryBasic aBasicBinaryTestCaseGroup[],
   318 					TTestParamAll& aTestCaseFound, TBool aIsWithDLL=EFalse)
   319 	{
   320 	if (aBasicBinaryTestCaseGroup[aIdx].iBasic.iTestCaseID != 0)
   321 		{
   322 		aTestCaseFound.iTestCaseID 	= aBasicBinaryTestCaseGroup[aIdx].iBasic.iTestCaseID;
   323 		aTestCaseFound.iAPI 		= aBasicBinaryTestCaseGroup[aIdx].iBasic.iAPI;
   324 	
   325 		aTestCaseFound.iSrcDrvChar	= aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iDrvChar;
   326 		aTestCaseFound.iSrcCmdPath.Copy(aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmdPath);
   327 		aTestCaseFound.iSrcPrsPath.Copy(aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsPath);
   328 		aTestCaseFound.iSrcPrsFiles = aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsFiles;
   329 
   330 		aTestCaseFound.iTrgDrvChar	= aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iDrvChar;
   331 		aTestCaseFound.iTrgCmdPath.Copy(aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iCmdPath);
   332 
   333 		aTestCaseFound.iIsWithDLL = aIsWithDLL;
   334 		// To make every test case uniquely indentified for interOP
   335 		// update the test case id  and its path correspondingly
   336 		TBuf<15> tempBuf;
   337 		TInt idx = aTestCaseFound.iSrcCmdPath.Find(_L("\\T_FCSC\\")) + 8 /* Len of \\T_FCSC\\ */;
   338 		TInt i = 0;
   339 		while(aTestCaseFound.iSrcCmdPath[idx] != '\\')
   340 			{
   341 			tempBuf.SetLength(i+1);
   342 			tempBuf[i++] = aTestCaseFound.iSrcCmdPath[idx++]; 
   343 			}
   344 		tempBuf.Append(_L("_"));
   345 		if(aTestCaseFound.iIsWithDLL)
   346 			tempBuf.Append(_L("DLL"));
   347 		else
   348 			tempBuf.Append(_L("NDLL"));
   349 		
   350 		TInt len = 0;
   351 		idx = aTestCaseFound.iSrcCmdPath.Find(_L("\\T_FCSC\\")) + 8;
   352 		while(aTestCaseFound.iSrcCmdPath[idx] != '\\')
   353 			{
   354 			len++;
   355 			aTestCaseFound.iSrcCmdPath[idx++]; 
   356 			}
   357 		aTestCaseFound.iSrcCmdPath.Replace(idx-len, len, tempBuf);
   358 
   359 		len =0;
   360 		idx = aTestCaseFound.iSrcPrsPath.Find(_L("\\T_FCSC\\")) + 8;
   361 		while(aTestCaseFound.iSrcPrsPath[idx] != '\\')
   362 			{
   363 			len++;
   364 			aTestCaseFound.iSrcCmdPath[idx++]; 
   365 			}
   366 		aTestCaseFound.iSrcPrsPath.Replace(idx-len, len, tempBuf);
   367 
   368 		len =0;
   369 		idx = aTestCaseFound.iTrgCmdPath.Find(_L("\\T_FCSC\\")) + 8;
   370 		while(aTestCaseFound.iTrgCmdPath[idx] != '\\')
   371 			{
   372 			len++;
   373 			aTestCaseFound.iTrgCmdPath[idx++]; 
   374 			}
   375 		aTestCaseFound.iTrgCmdPath.Replace(idx-len, len, tempBuf);
   376 		}
   377 	else
   378 		{
   379 		return KErrNotFound;
   380 		}
   381 	return KErrNone;
   382 	}
   383 
   384 void Help()
   385 	{
   386 	RDebug::Print(_L("t_fatcharsetconv [-x {s,w}] [-d {dt}][-v {sw}]"));
   387 	RDebug::Print(_L("\t-x :	for executing tests"));
   388 	RDebug::Print(_L("\t\t	s or S for execution on Symbian"));
   389 	RDebug::Print(_L("\t\t	w or W for execution on Windows"));
   390 	RDebug::Print(_L("\t-d:		drive to test for execution/verification"));
   391 	RDebug::Print(_L("\t\t	This test runs on FAT or Win32 file systems only"));
   392 	RDebug::Print(_L("\t\t	d or D for test drive on Symbian (FAT file system)"));
   393 	RDebug::Print(_L("\t\t	Any FAT/Win32 file system drive on emulator i.e. T, X etc"));
   394 	RDebug::Print(_L("\t-v :	for validating tests"));
   395 	RDebug::Print(_L("\t\t	s or S for verification on symbian"));
   396 	RDebug::Print(_L("\t\t	w or W for verification on Windows"));
   397 	}
   398 
   399 void ClearSwitches(TTestSwitches& aSwitches)
   400 	{
   401 	// clear the switches
   402 	aSwitches.iExeOnSymbian = EFalse;
   403 	aSwitches.iVerOnSymbian = EFalse;
   404 	aSwitches.iExeOnWindows = EFalse;
   405 	aSwitches.iVerOnWindows = EFalse;
   406 	aSwitches.iExeDriveChar =' ';
   407 	aSwitches.iVerDriveChar =' ';
   408 	aSwitches.iExeDriveNum =0;
   409 	aSwitches.iVerDriveNum =0;
   410 	aSwitches.iMountedFSName.SetLength(0);
   411 	}
   412 
   413 
   414 void ParseCommandArguments(TTestSwitches& aSwitches)
   415 	{
   416 	TBuf<256> cmd;
   417 	User::CommandLine(cmd);
   418 	RDebug::Print(_L("Command Line : %S"), &cmd);
   419 	TChar testDrive = 'C';
   420 		
   421 	InitLogData();
   422 	ClearSwitches(aSwitches);
   423 
   424 	TFileName currentFile=RProcess().FileName();
   425 	TLex lex(cmd);
   426 	TPtrC token=lex.NextToken();
   427 	if (token.MatchF(currentFile)==0)
   428 		{
   429 		token.Set(lex.NextToken());
   430 		}
   431 	if (token.Length()==0)
   432 		{
   433 		testDrive = 'C'; // default drives
   434 		gAutoTest = ETrue;
   435 		}
   436 	else if((token[0] >='A' && token[0]<='Z') || (token[0] >='a' && token[0]<='z'))
   437 		{
   438 		testDrive = token[0];
   439 		gAutoTest = ETrue;
   440 		}
   441 	else
   442 		{
   443 		while (!lex.Eos())
   444 			{
   445 			if (token.Length()==0)
   446 				{
   447 				continue;	// ignore trailing whitespace
   448 				}
   449 			if (token==_L("-x") || token==_L("-X"))
   450 				{
   451 				token.Set(lex.NextToken());
   452 				if((token==_L("s")) || (token==_L("S")))
   453 					{
   454 					aSwitches.iExeOnSymbian = ETrue;
   455 					gLogFailureData.iExeOsName = KSymbian;
   456 					}
   457 				else if((token==_L("w")) || (token==_L("W")))
   458 					{
   459 					aSwitches.iExeOnWindows = ETrue;
   460 					gLogFailureData.iExeOsName = KWindows;
   461 					}
   462 				token.Set(lex.NextToken());
   463 				continue;
   464 				}
   465 			if (token==_L("-d") || token==_L("-D"))
   466 				{
   467 				token.Set(lex.NextToken());
   468 				testDrive = token[0];
   469 				token.Set(lex.NextToken());
   470 				continue;
   471 				}
   472 			if (token==_L("-v") || token==_L("-V"))
   473 				{
   474 				token.Set(lex.NextToken());
   475 				if((token==_L("s")) || (token==_L("S")))
   476 					{
   477 					aSwitches.iVerOnSymbian = ETrue;
   478 					gLogFailureData.iVerOsName = KSymbian;
   479 					}
   480 				else if((token==_L("w")) || (token==_L("W")))
   481 					{
   482 					aSwitches.iVerOnWindows = ETrue;
   483 					gLogFailureData.iVerOsName = KWindows;
   484 					}
   485 				token.Set(lex.NextToken());
   486 				continue;
   487 				}
   488 			RDebug::Print(_L("Unknown option %S"), &token);
   489 			Help();
   490 			return;
   491 			}
   492 		}
   493 
   494 	CheckIfIOTesting(aSwitches);
   495 
   496 	if(gIOTesting)
   497 		{
   498 		gAutoTest = EFalse;
   499 		}
   500 	else
   501 		{
   502 		gAutoTest = ETrue;
   503 		}
   504 
   505 	testDrive.UpperCase();
   506 	if (gAutoTest)
   507 		{
   508 #if defined (__WINS__)
   509 		//execution phase
   510 		aSwitches.iExeOnWindows = ETrue;
   511 		aSwitches.iExeDriveChar = testDrive;
   512 		aSwitches.iExeDriveNum = CurrentDrive(aSwitches.iExeDriveChar);
   513 		gLogFailureData.iExeDrive = aSwitches.iExeDriveChar;
   514 		gLogFailureData.iExeOsName = KWindows;
   515 		//verification phase
   516 		aSwitches.iVerOnWindows = ETrue;
   517 		aSwitches.iVerDriveChar = testDrive;
   518 		aSwitches.iVerDriveNum = CurrentDrive(aSwitches.iVerDriveChar);
   519 		gLogFailureData.iVerDrive = aSwitches.iVerDriveChar;
   520 		gLogFailureData.iVerOsName = KWindows;
   521 #else	
   522 		//execution phase
   523 		aSwitches.iExeOnSymbian = ETrue;
   524 		aSwitches.iExeDriveChar = testDrive;
   525 		aSwitches.iExeDriveNum = CurrentDrive(aSwitches.iExeDriveChar);
   526 		gLogFailureData.iExeDrive = aSwitches.iExeDriveChar;
   527 		gLogFailureData.iExeOsName = KSymbian;
   528 		//verification phase	
   529 		aSwitches.iVerOnSymbian = ETrue;
   530 		aSwitches.iVerDriveChar = testDrive;
   531 		aSwitches.iVerDriveNum = CurrentDrive(aSwitches.iVerDriveChar);
   532 		gLogFailureData.iVerDrive = aSwitches.iVerDriveChar;
   533 		gLogFailureData.iVerOsName = KSymbian;
   534 #endif
   535 		}
   536 
   537 	if(aSwitches.iExeOnWindows || aSwitches.iExeOnSymbian)
   538 		{
   539 		aSwitches.iExeDriveChar = testDrive;
   540 		aSwitches.iExeDriveNum = CurrentDrive(aSwitches.iExeDriveChar);
   541 		gLogFailureData.iExeDrive = aSwitches.iExeDriveChar;
   542 		}
   543 	if(aSwitches.iVerOnWindows || aSwitches.iVerOnSymbian)
   544 		{
   545 		aSwitches.iVerDriveChar = testDrive;
   546 		aSwitches.iVerDriveNum = CurrentDrive(aSwitches.iVerDriveChar);
   547 		gLogFailureData.iVerDrive = aSwitches.iVerDriveChar;
   548 		}
   549 	}
   550 
   551 void InitialiseL()
   552 	{
   553 	gFileMan=CFileMan::NewL(TheFs);
   554 	}
   555 
   556 void RmDir(const TDesC& aDirName)
   557 	{
   558 	TFileName filename_dir = aDirName;
   559 	TInt r = 0;
   560 	r = TheFs.SetAtt(filename_dir, 0, KEntryAttReadOnly);
   561 	test(r==KErrNone);
   562 	r=gFileMan->RmDir(filename_dir);
   563 	test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound || r==KErrInUse);
   564 	}
   565 
   566 // Cleanup test variables
   567 void Cleanup()
   568 	{
   569 	delete gFileMan;
   570 	}
   571 
   572 /**
   573     Parsing Dir Data Block
   574     @param  aDataBlock		data block in TInt[] for parsing	
   575     @param  aDirDataArray	returning dir data array after parsing
   576 
   577     @panic 					if data setup error
   578 */
   579 void ParsingDirDataBlock(const TInt aDataBlock[], RArray<TInt>& aDirDataArray)
   580 	{
   581 	TInt err = KErrNone;
   582 	aDirDataArray.Reset();
   583 
   584 	if (aDataBlock[0] == EOB)
   585 		{
   586 		return;
   587 		}
   588 
   589 	TInt i = 1;
   590 	FOREVER
   591 		{
   592 		TInt lastItem = aDataBlock[i-1];
   593 		TInt currentItem = aDataBlock[i];
   594 		
   595 		// check currentItem
   596 		if (currentItem == EOB)
   597 			{
   598 			if (lastItem == CON || lastItem > LAST)
   599 			//check last
   600 				{
   601 				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   602 				test(EFalse);
   603 				}
   604 			else
   605 			// passed, insert last, break
   606 				{
   607 				err = aDirDataArray.InsertInOrder(lastItem);
   608 				if (err != KErrNone && err != KErrAlreadyExists)
   609 					{
   610 					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   611 					test(EFalse);
   612 					}
   613 				break;
   614 				}
   615 			}
   616 		else if (currentItem == CON)
   617 		// if current == CON
   618 			{
   619 			if (lastItem == CON || lastItem >= LAST)
   620 			// check last item
   621 				{
   622 				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   623 				test(EFalse);
   624 				}
   625 			else // last < LAST, last != CON
   626 				{
   627 				// check next item
   628 				TInt nextItem = aDataBlock[i+1];
   629 				if (nextItem <= 0 || nextItem > LAST || lastItem >= nextItem)
   630 					{
   631 					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   632 					test(EFalse);
   633 					}
   634 				else
   635 					{
   636 					// all valid
   637 					for (TInt j = lastItem; j < nextItem; j++)
   638 						{
   639 						err = aDirDataArray.InsertInOrder(j);
   640 						if (err != KErrNone && err != KErrAlreadyExists)
   641 							{
   642 							test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   643 							test(EFalse);
   644 							}
   645 						}
   646 					}
   647 				}
   648 			i++;
   649 			}
   650 		else if (0 <= currentItem && currentItem <= LAST)
   651 		// if current == normal item
   652 			{
   653 			if (lastItem == CON)
   654 				{
   655 				i++;
   656 				continue;
   657 				}
   658 			else if (lastItem >= LAST)
   659 			// check last item
   660 				{
   661 				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   662 				test(EFalse);
   663 				}
   664 			else
   665 			// passed, insert last
   666 				{
   667 				err = aDirDataArray.InsertInOrder(lastItem);
   668 				if (err != KErrNone && err != KErrAlreadyExists)
   669 					{
   670 					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   671 					test(EFalse);
   672 					}
   673 				}
   674 			i++;
   675 			}
   676 			else	// invalid input
   677 			{
   678 			test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   679 			test(EFalse);
   680 			}
   681 		}
   682 	}
   683 
   684 /**
   685     Setup dir structure for testing and verifying functional results
   686     @param	datastr			data structure to setup directory
   687     @param  iOperation   	Operation to be performed 
   688     @param  SrcDrive		Source drive
   689     @param	Targetdrive		Target drive input
   690     @panic					if data structure definition is incorrect
   691 */
   692 void SetupDirFiles(const TDesC& aPath, const TDirSetupFiles& aDirFiles)
   693 	{
   694 	TFileName path = aPath;
   695 	if (path.Length() == 0)
   696 		{
   697 		test.Printf(_L("ERROR<SetupDirFiles()>: Zero length src path!\n"));
   698 		test(EFalse);
   699 		}
   700 	
   701 	MakeDir(path);
   702 	
   703 	RArray<TInt> addBlockDataArray;
   704 	RArray<TInt> deductBlockDataArray;
   705 	
   706 	ParsingDirDataBlock(aDirFiles.iAddingBlock, addBlockDataArray);
   707 	ParsingDirDataBlock(aDirFiles.iDeductBlock, deductBlockDataArray);
   708 	
   709 	if (addBlockDataArray.Count() == 0)
   710 	// empty dir setup
   711 		{
   712 		return;
   713 		}
   714 	for (TInt i = 0; i < deductBlockDataArray.Count(); ++i)
   715 		{
   716 		TInt idxToDelete = addBlockDataArray.FindInOrder(deductBlockDataArray[i]);
   717 		if (idxToDelete >= 0)
   718 			{
   719 			addBlockDataArray.Remove(idxToDelete);
   720 			}
   721 		else if (idxToDelete == KErrNotFound)
   722 			{
   723 			continue;
   724 			}
   725 		else
   726 			{
   727 			test.Printf(_L("ERROR<<SetupDir>>: wrong dir data setup! err=%d\n"), idxToDelete);
   728 			test(EFalse);
   729 			}
   730 		}
   731 	if (addBlockDataArray.Count() > 0)
   732 		{
   733 		for (TInt i = 0; i < addBlockDataArray.Count(); ++i)
   734 			{
   735 			TInt idx = addBlockDataArray[i];
   736 			path = aPath;
   737 			path += gDirPatterns[idx];
   738 			if (path[path.Length() - 1] == '\\')
   739 				{
   740 				MakeDir(path);
   741 				}
   742 			else
   743 				{
   744 				MakeFile(path, _L8("blahblah"));
   745 				}
   746 			}
   747 		}
   748 	
   749 	addBlockDataArray.Reset();
   750 	deductBlockDataArray.Reset();
   751 	}
   752 
   753 void LogTestFailureData(TTCType tcType, TFileName failedOn, 
   754 					TUint tcId, TFileName tcUniquePath, TInt line)
   755 	{
   756 	if(tcType == EUnitaryTest)
   757 		gLogFailureData.iTCTypeName = KUnitary;
   758 	else if(tcType == EBinaryTest)
   759 		gLogFailureData.iTCTypeName = KBinary;
   760 	gLogFailureData.iTCFailureOn = failedOn;
   761 	gLogFailureData.iTCId = tcId;
   762 	gLogFailureData.iTCUniquePath.Copy(tcUniquePath);
   763 	gLogFailureData.iLineNum = line;
   764 	gLogFailureData.iFileName.Copy(gFileName);
   765 
   766 	RFile file;
   767 	TBuf8<256>	tempBuf;
   768 
   769 	TFileName logFileName;
   770 	if(gIOTesting)
   771 		{
   772 		if(failedOn == KExecution)
   773 			{
   774 			logFileName.Append(KExeLogFileName);
   775 			}
   776 		else
   777 			{
   778 			logFileName.Append(KVerLogFileName);
   779 			}
   780 		}
   781 	else
   782 		{
   783 		logFileName.Append(KLogFileName);
   784 		}
   785 
   786 	logFileName.Append(KUnderScore);
   787 	logFileName.Append(gDriveToTest);
   788 	logFileName.Append(KExtension);
   789 
   790 	TInt r = file.Create(TheFs, logFileName, EFileRead|EFileWrite);
   791 	test(r == KErrNone || r == KErrAlreadyExists);
   792 
   793 	if (r == KErrNone)
   794 		{
   795 		tempBuf.Append(KLogFileHeader);
   796 		file.Write(tempBuf);
   797 		}
   798 
   799 	if (r == KErrAlreadyExists)
   800 		{
   801 		r = file.Open(TheFs, logFileName, EFileRead|EFileWrite);
   802 		test(r == KErrNone);
   803 		TInt start = 0;
   804 		r=file.Seek(ESeekEnd,start);
   805 		test(r == KErrNone);
   806 		}
   807 	
   808 	tempBuf.SetLength(0);
   809 	tempBuf.Append(KNewLine);
   810 	if(gIOTesting)
   811 		tempBuf.Append(KYes);
   812 	else
   813 		tempBuf.Append(KNo);
   814 	tempBuf.Append(KComma);
   815 	file.Write(tempBuf);
   816 
   817 	tempBuf.SetLength(0);
   818 	tempBuf.Append(gLogFailureData.iTCTypeName);
   819 	tempBuf.Append(KComma);
   820 	file.Write(tempBuf);
   821 
   822 	tempBuf.SetLength(0);
   823 	tempBuf.Append(gLogFailureData.iTCFailureOn);
   824 	tempBuf.Append(KComma);
   825 	file.Write(tempBuf);
   826 
   827 	tempBuf.SetLength(0);
   828 	tempBuf.AppendNum(gLogFailureData.iTCId);
   829 	tempBuf.Append(KComma);
   830 	file.Write(tempBuf);
   831 		
   832 	tempBuf.SetLength(0);
   833 	tempBuf.Append(gLogFailureData.iTCUniquePath);
   834 	tempBuf.Append(KComma);
   835 	file.Write(tempBuf);
   836 			
   837 	tempBuf.SetLength(0);
   838 	tempBuf.Append(gLogFailureData.iFSName);
   839 	tempBuf.Append(KComma);
   840 	file.Write(tempBuf);
   841 	
   842 	tempBuf.SetLength(0);
   843 	tempBuf.Append(gLogFailureData.iExeOsName);
   844 	tempBuf.Append(KComma);
   845 	file.Write(tempBuf);
   846 
   847 	tempBuf.SetLength(0);
   848 	tempBuf.Append(gLogFailureData.iExeDrive);
   849 	tempBuf.Append(KComma);
   850 	file.Write(tempBuf);
   851 	
   852 	tempBuf.SetLength(0);
   853 	tempBuf.Append(gLogFailureData.iVerOsName);
   854 	tempBuf.Append(KComma);
   855 	file.Write(tempBuf);
   856 			
   857 	tempBuf.SetLength(0);
   858 	tempBuf.Append(gLogFailureData.iVerDrive);
   859 	tempBuf.Append(KComma);
   860 	file.Write(tempBuf);
   861 			
   862 	tempBuf.SetLength(0);
   863 	tempBuf.Append(gLogFailureData.iAPIName);
   864 	tempBuf.Append(KComma);
   865 	file.Write(tempBuf);
   866 	
   867 	tempBuf.SetLength(0);
   868 	tempBuf.AppendNum(gLogFailureData.iLineNum);
   869 	tempBuf.Append(KComma);
   870 	file.Write(tempBuf);
   871 	
   872 	tempBuf.SetLength(0);
   873 	tempBuf.Append(gLogFailureData.iFuncName);
   874 	tempBuf.Append(KComma);
   875 	file.Write(tempBuf);
   876 
   877 	tempBuf.SetLength(0);
   878 	tempBuf.Append(gLogFailureData.iFileName);
   879 	file.Write(tempBuf);
   880 
   881 	file.Close();
   882 	}