os/kernelhwsrv/kerneltest/f32test/server/t_fatcharsetconv_aux.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_fatcharsetconv_aux.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,882 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\server\T_Fatcharsetconv_Aux.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <f32dbg.h>
    1.22 +#include "T_fatcharsetconv_Aux.h"
    1.23 +
    1.24 +CFileMan* gFileMan = NULL;
    1.25 +RPointerArray<RFile>* gFileHandles = NULL;
    1.26 +TTestLogFailureData gLogFailureData;
    1.27 +RRawDisk TheDisk;
    1.28 +TFatBootSector gBootSector;
    1.29 +TBool gIOTesting;
    1.30 +TBool gAutoTest; // is BTB test
    1.31 +
    1.32 +RFs TheFs;
    1.33 +RFile TheFile;
    1.34 +RDir TheDir;
    1.35 +
    1.36 +TFileName gSessionPath;
    1.37 +TInt gAllocFailOff=KAllocFailureOff;
    1.38 +TInt gAllocFailOn=KAllocFailureOff;
    1.39 +TChar gDriveToTest;
    1.40 +TFileName gFileName;
    1.41 +
    1.42 +TTCType	gTCType;
    1.43 +TUint	gTCId;
    1.44 +
    1.45 +GLDEF_C void Format(TInt aDrive)
    1.46 +//
    1.47 +// Format current drive
    1.48 +//
    1.49 +	{
    1.50 +	test.Next(_L("Format"));
    1.51 +	TBuf<4> driveBuf=_L("?:\\");
    1.52 +	driveBuf[0]=(TText)(aDrive+'A');
    1.53 +	RFormat format;
    1.54 +	TInt count;
    1.55 +	TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
    1.56 +	test(r==KErrNone);
    1.57 +	while(count)
    1.58 +		{
    1.59 +		TInt r=format.Next(count);
    1.60 +		test(r==KErrNone);
    1.61 +		}
    1.62 +	format.Close();
    1.63 +	}
    1.64 +
    1.65 +void MakeDir(const TDesC& aDirName)
    1.66 +//
    1.67 +// Make a directory
    1.68 +//
    1.69 +	{
    1.70 +	TInt r=TheFs.MkDirAll(aDirName);
    1.71 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.72 +	}
    1.73 +
    1.74 +
    1.75 +void ReportCheckDiskFailure(TInt aRet)
    1.76 +//
    1.77 +// Report the failure of checkdisk
    1.78 +//
    1.79 +	{
    1.80 +	test.Printf(_L("CHECKDISK FAILED: "));
    1.81 +	switch(aRet)
    1.82 +		{
    1.83 +	case 1:	test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
    1.84 +	case 2:	test.Printf(_L("Two files are linked to the same cluster\n")); break;
    1.85 +	case 3:	test.Printf(_L("Unallocated cluster contains a value != 0\n"));	break;
    1.86 +	case 4:	test.Printf(_L("Size of file != number of clusters in chain\n")); break;
    1.87 +	default: test.Printf(_L("Undefined Error value %d\n"),aRet);
    1.88 +		}
    1.89 +	test(EFalse);
    1.90 +	}
    1.91 +
    1.92 +void CreateTestDirectory(const TDesC& aSessionPath)
    1.93 +//
    1.94 +// Create directory for test
    1.95 +//
    1.96 +	{
    1.97 +	TParsePtrC path(aSessionPath);
    1.98 +	test(path.DrivePresent()==EFalse);
    1.99 +	TInt r=TheFs.SetSessionPath(aSessionPath);
   1.100 +	test(r==KErrNone);
   1.101 +	r=TheFs.SessionPath(gSessionPath);
   1.102 +	test(r==KErrNone);
   1.103 +	r=TheFs.MkDirAll(gSessionPath);
   1.104 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.105 +	}
   1.106 +
   1.107 +TInt CurrentDrive(TChar aDriveChar)
   1.108 +//
   1.109 +// Return the current drive number
   1.110 +//
   1.111 +	{
   1.112 +	TInt driveNum;
   1.113 +	TInt r = TheFs.CharToDrive(aDriveChar,driveNum);
   1.114 +	test(r==KErrNone);
   1.115 +	gDriveToTest = gSessionPath[0] = (TText)aDriveChar;
   1.116 +	return(driveNum);
   1.117 +	}
   1.118 +
   1.119 +TInt CurrentDrive()
   1.120 +//
   1.121 +// Return the current drive number
   1.122 +//
   1.123 +	{
   1.124 +	TInt driveNum;
   1.125 +	TInt r = TheFs.CharToDrive(gSessionPath[0],driveNum);
   1.126 +	test(r==KErrNone);
   1.127 +	return(driveNum);
   1.128 +	}
   1.129 +
   1.130 +void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
   1.131 +//
   1.132 +// Make a file and write uid and data
   1.133 +//
   1.134 +	{
   1.135 +	RFile file;
   1.136 +	TInt r=file.Replace(TheFs,aFileName,0);
   1.137 +	test(r==KErrNone || r==KErrPathNotFound);
   1.138 +	if (r==KErrPathNotFound)
   1.139 +		{
   1.140 +		r=TheFs.MkDirAll(aFileName);
   1.141 +		test(r==KErrNone);
   1.142 +		r=file.Replace(TheFs,aFileName,0);
   1.143 +		test(r==KErrNone);
   1.144 +		}
   1.145 +	TCheckedUid checkedUid(aUidType);
   1.146 +	TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
   1.147 +	r=file.Write(uidData);
   1.148 +	test(r==KErrNone);
   1.149 +	r=file.Write(aFileContents);
   1.150 +	test(r==KErrNone);
   1.151 +	file.Close();
   1.152 +	}
   1.153 +
   1.154 +void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents)
   1.155 +//
   1.156 +// Make a file and write something in it
   1.157 +//
   1.158 +	{
   1.159 +	RFile file;
   1.160 +	TInt r=file.Replace(TheFs,aFileName,0);
   1.161 +	if(r!=KErrNone && r!=KErrPathNotFound)
   1.162 +		{
   1.163 +		test.Printf(_L("ERROR: r=%d"),r);
   1.164 +		test(EFalse);
   1.165 +		}
   1.166 +	test(r==KErrNone || r==KErrPathNotFound);
   1.167 +	if (r==KErrPathNotFound)
   1.168 +		{
   1.169 +		r=TheFs.MkDirAll(aFileName);
   1.170 +		test(r==KErrNone);
   1.171 +		r=file.Replace(TheFs,aFileName,0);
   1.172 +		test(r==KErrNone);
   1.173 +		}
   1.174 +	r=file.Write(aFileContents);
   1.175 +	test(r==KErrNone);
   1.176 +	file.Close();
   1.177 +	}
   1.178 +
   1.179 +void MakeFile(const TDesC& aFileName,TInt anAttributes)
   1.180 +//
   1.181 +// Make a file and write something in it
   1.182 +//
   1.183 +	{
   1.184 +	RFile file;
   1.185 +	TInt r=file.Replace(TheFs,aFileName,0);
   1.186 +	test(r==KErrNone || r==KErrPathNotFound);
   1.187 +	if (r==KErrPathNotFound)
   1.188 +		{
   1.189 +		r=TheFs.MkDirAll(aFileName);
   1.190 +		test(r==KErrNone);
   1.191 +		r=file.Replace(TheFs,aFileName,0);
   1.192 +		test(r==KErrNone);
   1.193 +		}
   1.194 +	file.Close();
   1.195 +	r=TheFs.SetAtt(aFileName,anAttributes,0);
   1.196 +	test(r==KErrNone);
   1.197 +	}
   1.198 +
   1.199 +void MakeFile(const TDesC& aFileName)
   1.200 +//
   1.201 +// Make a file
   1.202 +//
   1.203 +	{
   1.204 +	MakeFile(aFileName,_L8(""));
   1.205 +	}
   1.206 +
   1.207 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   1.208 +void QuickFormat()
   1.209 +    {
   1.210 +    FormatFatDrive(TheFs, CurrentDrive(), ETrue);
   1.211 +    }
   1.212 +
   1.213 +void ReadBootSector(TFatBootSector& aBootSector)
   1.214 +	{
   1.215 +    TInt r = ReadBootSector(TheFs, CurrentDrive(), KBootSectorNum<<KDefaultSectorLog2, aBootSector);
   1.216 +    test(r==KErrNone);
   1.217 +
   1.218 +    if(!aBootSector.IsValid())
   1.219 +        {
   1.220 +        test.Printf(_L("Wrong bootsector! Dump:\n"));
   1.221 +        aBootSector.PrintDebugInfo();
   1.222 +        test(0);
   1.223 +        }
   1.224 +	}
   1.225 +
   1.226 +void GetBootInfo()
   1.227 +	{
   1.228 +	QuickFormat();
   1.229 +	ReadBootSector(gBootSector);
   1.230 +	}
   1.231 +#endif
   1.232 +
   1.233 +void CheckIfIOTesting(TTestSwitches& aSwitches)
   1.234 +	{
   1.235 +	if( ((aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows) && !(aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows))
   1.236 +	  ||((aSwitches.iVerOnSymbian || aSwitches.iVerOnWindows) && !(aSwitches.iExeOnSymbian || aSwitches.iExeOnWindows))
   1.237 +	  )
   1.238 +		{
   1.239 +		gIOTesting = ETrue;
   1.240 +		}
   1.241 +	}
   1.242 +
   1.243 +void CheckDisk()
   1.244 +	{
   1.245 +	TInt r=TheFs.CheckDisk(gSessionPath);
   1.246 +	if (r!=KErrNone && r!=KErrNotSupported)
   1.247 +		ReportCheckDiskFailure(r);
   1.248 +	r = TheFs.ScanDrive(gSessionPath);
   1.249 +	if (r!=KErrNone && r!=KErrNotSupported && r!=KErrInUse)
   1.250 +		ReportCheckDiskFailure(r);
   1.251 +	}
   1.252 +
   1.253 +void InitLogData()
   1.254 +	{
   1.255 +	gLogFailureData.iExeOsName = KNone;
   1.256 +	gLogFailureData.iVerOsName = KNone;
   1.257 +	gLogFailureData.iExeDrive  = 'A';
   1.258 +	gLogFailureData.iVerDrive  = 'A';
   1.259 +	}
   1.260 +
   1.261 +void ClearTCLogData()
   1.262 +	{
   1.263 +	gLogFailureData.iTCTypeName.SetLength(0);
   1.264 +	gLogFailureData.iTCFailureOn.SetLength(0);
   1.265 +	gLogFailureData.iTCId = 0;
   1.266 +	gLogFailureData.iTCUniquePath.SetLength(0);
   1.267 +	gLogFailureData.iAPIName.SetLength(0);
   1.268 +	gLogFailureData.iLineNum = 0;
   1.269 +	// gLogFailureData.iFileName.SetLength(0);
   1.270 +	}
   1.271 +
   1.272 +/*
   1.273 + * Search test cases by the index of the array of test case group, overloaded version for basic unitary cases.
   1.274 + * @param 	aIdx		the test case index in search
   1.275 + * @param	aBasicUnitaryTestCaseGroup		the input test group, should always be gBasicUnitaryTestCases[]
   1.276 + * @param	aTestCaseFound		contains params of the test case found by the test case Id.
   1.277 + * @return	KErrNone	if only one test case on the id is found
   1.278 + * 			KErrNotFound	if no test case is found
   1.279 + */
   1.280 +TInt SearchTestCaseByArrayIdx(TUint aIdx, const TTestCaseUnitaryBasic aBasicUnitaryTestCaseGroup[],
   1.281 +					 TTestParamAll& aTestCaseFound, TBool aIsWithDLL=EFalse)
   1.282 +	{
   1.283 +	if (aBasicUnitaryTestCaseGroup[aIdx].iBasic.iTestCaseID != 0)
   1.284 +		{
   1.285 +		aTestCaseFound.iTestCaseID 	= aBasicUnitaryTestCaseGroup[aIdx].iBasic.iTestCaseID;
   1.286 +		aTestCaseFound.iAPI 		= aBasicUnitaryTestCaseGroup[aIdx].iBasic.iAPI;
   1.287 +
   1.288 +		aTestCaseFound.iSrcDrvChar	= aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iDrvChar;
   1.289 +		aTestCaseFound.iSrcCmdPath.Copy(aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmdPath);
   1.290 +		aTestCaseFound.iSrcPrsPath.Copy(aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsPath);
   1.291 +		aTestCaseFound.iSrcPrsFiles = aBasicUnitaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsFiles;
   1.292 +
   1.293 +		aTestCaseFound.iIsWithDLL = aIsWithDLL;
   1.294 +
   1.295 +		// To make every test case uniquely indentified for interOP
   1.296 +		// update the test case id  and its path correspondingly
   1.297 +		TBuf<15> tempName = _L("_");
   1.298 +		if(aTestCaseFound.iIsWithDLL)
   1.299 +			tempName.Append(_L("DLL"));
   1.300 +		else
   1.301 +			tempName.Append(_L("NDLL"));
   1.302 +
   1.303 +		TInt idx = aTestCaseFound.iSrcCmdPath.Find(_L("\\Src\\"));
   1.304 +		aTestCaseFound.iSrcCmdPath.Insert(idx, tempName);
   1.305 +		aTestCaseFound.iSrcPrsPath.Insert(idx, tempName);
   1.306 +		}
   1.307 +	else
   1.308 +		return KErrNotFound;
   1.309 +
   1.310 +	return KErrNone;
   1.311 +	}
   1.312 +/*
   1.313 + * Search test cases by the index of the array of test case group, overloaded version for basic binary cases.
   1.314 + * @param 	aIdx		the test case index in search
   1.315 + * @param	aBasicUnitaryTestCaseGroup		the input test group, should always be gBasicBinaryTestCases[]
   1.316 + * @param	aTestCaseFound		contains params of the test case found by the test case Id.
   1.317 + * @return	KErrNone	if only one test case on the id is found
   1.318 + * 			KErrNotFound	if no test case is found
   1.319 + */
   1.320 +TInt SearchTestCaseByArrayIdx(TUint aIdx, const TTestCaseBinaryBasic aBasicBinaryTestCaseGroup[],
   1.321 +					TTestParamAll& aTestCaseFound, TBool aIsWithDLL=EFalse)
   1.322 +	{
   1.323 +	if (aBasicBinaryTestCaseGroup[aIdx].iBasic.iTestCaseID != 0)
   1.324 +		{
   1.325 +		aTestCaseFound.iTestCaseID 	= aBasicBinaryTestCaseGroup[aIdx].iBasic.iTestCaseID;
   1.326 +		aTestCaseFound.iAPI 		= aBasicBinaryTestCaseGroup[aIdx].iBasic.iAPI;
   1.327 +	
   1.328 +		aTestCaseFound.iSrcDrvChar	= aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iDrvChar;
   1.329 +		aTestCaseFound.iSrcCmdPath.Copy(aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iCmdPath);
   1.330 +		aTestCaseFound.iSrcPrsPath.Copy(aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsPath);
   1.331 +		aTestCaseFound.iSrcPrsFiles = aBasicBinaryTestCaseGroup[aIdx].iSrcPrsBasic.iPrsFiles;
   1.332 +
   1.333 +		aTestCaseFound.iTrgDrvChar	= aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iDrvChar;
   1.334 +		aTestCaseFound.iTrgCmdPath.Copy(aBasicBinaryTestCaseGroup[aIdx].iTrgPrsBasic.iCmdPath);
   1.335 +
   1.336 +		aTestCaseFound.iIsWithDLL = aIsWithDLL;
   1.337 +		// To make every test case uniquely indentified for interOP
   1.338 +		// update the test case id  and its path correspondingly
   1.339 +		TBuf<15> tempBuf;
   1.340 +		TInt idx = aTestCaseFound.iSrcCmdPath.Find(_L("\\T_FCSC\\")) + 8 /* Len of \\T_FCSC\\ */;
   1.341 +		TInt i = 0;
   1.342 +		while(aTestCaseFound.iSrcCmdPath[idx] != '\\')
   1.343 +			{
   1.344 +			tempBuf.SetLength(i+1);
   1.345 +			tempBuf[i++] = aTestCaseFound.iSrcCmdPath[idx++]; 
   1.346 +			}
   1.347 +		tempBuf.Append(_L("_"));
   1.348 +		if(aTestCaseFound.iIsWithDLL)
   1.349 +			tempBuf.Append(_L("DLL"));
   1.350 +		else
   1.351 +			tempBuf.Append(_L("NDLL"));
   1.352 +		
   1.353 +		TInt len = 0;
   1.354 +		idx = aTestCaseFound.iSrcCmdPath.Find(_L("\\T_FCSC\\")) + 8;
   1.355 +		while(aTestCaseFound.iSrcCmdPath[idx] != '\\')
   1.356 +			{
   1.357 +			len++;
   1.358 +			aTestCaseFound.iSrcCmdPath[idx++]; 
   1.359 +			}
   1.360 +		aTestCaseFound.iSrcCmdPath.Replace(idx-len, len, tempBuf);
   1.361 +
   1.362 +		len =0;
   1.363 +		idx = aTestCaseFound.iSrcPrsPath.Find(_L("\\T_FCSC\\")) + 8;
   1.364 +		while(aTestCaseFound.iSrcPrsPath[idx] != '\\')
   1.365 +			{
   1.366 +			len++;
   1.367 +			aTestCaseFound.iSrcCmdPath[idx++]; 
   1.368 +			}
   1.369 +		aTestCaseFound.iSrcPrsPath.Replace(idx-len, len, tempBuf);
   1.370 +
   1.371 +		len =0;
   1.372 +		idx = aTestCaseFound.iTrgCmdPath.Find(_L("\\T_FCSC\\")) + 8;
   1.373 +		while(aTestCaseFound.iTrgCmdPath[idx] != '\\')
   1.374 +			{
   1.375 +			len++;
   1.376 +			aTestCaseFound.iTrgCmdPath[idx++]; 
   1.377 +			}
   1.378 +		aTestCaseFound.iTrgCmdPath.Replace(idx-len, len, tempBuf);
   1.379 +		}
   1.380 +	else
   1.381 +		{
   1.382 +		return KErrNotFound;
   1.383 +		}
   1.384 +	return KErrNone;
   1.385 +	}
   1.386 +
   1.387 +void Help()
   1.388 +	{
   1.389 +	RDebug::Print(_L("t_fatcharsetconv [-x {s,w}] [-d {dt}][-v {sw}]"));
   1.390 +	RDebug::Print(_L("\t-x :	for executing tests"));
   1.391 +	RDebug::Print(_L("\t\t	s or S for execution on Symbian"));
   1.392 +	RDebug::Print(_L("\t\t	w or W for execution on Windows"));
   1.393 +	RDebug::Print(_L("\t-d:		drive to test for execution/verification"));
   1.394 +	RDebug::Print(_L("\t\t	This test runs on FAT or Win32 file systems only"));
   1.395 +	RDebug::Print(_L("\t\t	d or D for test drive on Symbian (FAT file system)"));
   1.396 +	RDebug::Print(_L("\t\t	Any FAT/Win32 file system drive on emulator i.e. T, X etc"));
   1.397 +	RDebug::Print(_L("\t-v :	for validating tests"));
   1.398 +	RDebug::Print(_L("\t\t	s or S for verification on symbian"));
   1.399 +	RDebug::Print(_L("\t\t	w or W for verification on Windows"));
   1.400 +	}
   1.401 +
   1.402 +void ClearSwitches(TTestSwitches& aSwitches)
   1.403 +	{
   1.404 +	// clear the switches
   1.405 +	aSwitches.iExeOnSymbian = EFalse;
   1.406 +	aSwitches.iVerOnSymbian = EFalse;
   1.407 +	aSwitches.iExeOnWindows = EFalse;
   1.408 +	aSwitches.iVerOnWindows = EFalse;
   1.409 +	aSwitches.iExeDriveChar =' ';
   1.410 +	aSwitches.iVerDriveChar =' ';
   1.411 +	aSwitches.iExeDriveNum =0;
   1.412 +	aSwitches.iVerDriveNum =0;
   1.413 +	aSwitches.iMountedFSName.SetLength(0);
   1.414 +	}
   1.415 +
   1.416 +
   1.417 +void ParseCommandArguments(TTestSwitches& aSwitches)
   1.418 +	{
   1.419 +	TBuf<256> cmd;
   1.420 +	User::CommandLine(cmd);
   1.421 +	RDebug::Print(_L("Command Line : %S"), &cmd);
   1.422 +	TChar testDrive = 'C';
   1.423 +		
   1.424 +	InitLogData();
   1.425 +	ClearSwitches(aSwitches);
   1.426 +
   1.427 +	TFileName currentFile=RProcess().FileName();
   1.428 +	TLex lex(cmd);
   1.429 +	TPtrC token=lex.NextToken();
   1.430 +	if (token.MatchF(currentFile)==0)
   1.431 +		{
   1.432 +		token.Set(lex.NextToken());
   1.433 +		}
   1.434 +	if (token.Length()==0)
   1.435 +		{
   1.436 +		testDrive = 'C'; // default drives
   1.437 +		gAutoTest = ETrue;
   1.438 +		}
   1.439 +	else if((token[0] >='A' && token[0]<='Z') || (token[0] >='a' && token[0]<='z'))
   1.440 +		{
   1.441 +		testDrive = token[0];
   1.442 +		gAutoTest = ETrue;
   1.443 +		}
   1.444 +	else
   1.445 +		{
   1.446 +		while (!lex.Eos())
   1.447 +			{
   1.448 +			if (token.Length()==0)
   1.449 +				{
   1.450 +				continue;	// ignore trailing whitespace
   1.451 +				}
   1.452 +			if (token==_L("-x") || token==_L("-X"))
   1.453 +				{
   1.454 +				token.Set(lex.NextToken());
   1.455 +				if((token==_L("s")) || (token==_L("S")))
   1.456 +					{
   1.457 +					aSwitches.iExeOnSymbian = ETrue;
   1.458 +					gLogFailureData.iExeOsName = KSymbian;
   1.459 +					}
   1.460 +				else if((token==_L("w")) || (token==_L("W")))
   1.461 +					{
   1.462 +					aSwitches.iExeOnWindows = ETrue;
   1.463 +					gLogFailureData.iExeOsName = KWindows;
   1.464 +					}
   1.465 +				token.Set(lex.NextToken());
   1.466 +				continue;
   1.467 +				}
   1.468 +			if (token==_L("-d") || token==_L("-D"))
   1.469 +				{
   1.470 +				token.Set(lex.NextToken());
   1.471 +				testDrive = token[0];
   1.472 +				token.Set(lex.NextToken());
   1.473 +				continue;
   1.474 +				}
   1.475 +			if (token==_L("-v") || token==_L("-V"))
   1.476 +				{
   1.477 +				token.Set(lex.NextToken());
   1.478 +				if((token==_L("s")) || (token==_L("S")))
   1.479 +					{
   1.480 +					aSwitches.iVerOnSymbian = ETrue;
   1.481 +					gLogFailureData.iVerOsName = KSymbian;
   1.482 +					}
   1.483 +				else if((token==_L("w")) || (token==_L("W")))
   1.484 +					{
   1.485 +					aSwitches.iVerOnWindows = ETrue;
   1.486 +					gLogFailureData.iVerOsName = KWindows;
   1.487 +					}
   1.488 +				token.Set(lex.NextToken());
   1.489 +				continue;
   1.490 +				}
   1.491 +			RDebug::Print(_L("Unknown option %S"), &token);
   1.492 +			Help();
   1.493 +			return;
   1.494 +			}
   1.495 +		}
   1.496 +
   1.497 +	CheckIfIOTesting(aSwitches);
   1.498 +
   1.499 +	if(gIOTesting)
   1.500 +		{
   1.501 +		gAutoTest = EFalse;
   1.502 +		}
   1.503 +	else
   1.504 +		{
   1.505 +		gAutoTest = ETrue;
   1.506 +		}
   1.507 +
   1.508 +	testDrive.UpperCase();
   1.509 +	if (gAutoTest)
   1.510 +		{
   1.511 +#if defined (__WINS__)
   1.512 +		//execution phase
   1.513 +		aSwitches.iExeOnWindows = ETrue;
   1.514 +		aSwitches.iExeDriveChar = testDrive;
   1.515 +		aSwitches.iExeDriveNum = CurrentDrive(aSwitches.iExeDriveChar);
   1.516 +		gLogFailureData.iExeDrive = aSwitches.iExeDriveChar;
   1.517 +		gLogFailureData.iExeOsName = KWindows;
   1.518 +		//verification phase
   1.519 +		aSwitches.iVerOnWindows = ETrue;
   1.520 +		aSwitches.iVerDriveChar = testDrive;
   1.521 +		aSwitches.iVerDriveNum = CurrentDrive(aSwitches.iVerDriveChar);
   1.522 +		gLogFailureData.iVerDrive = aSwitches.iVerDriveChar;
   1.523 +		gLogFailureData.iVerOsName = KWindows;
   1.524 +#else	
   1.525 +		//execution phase
   1.526 +		aSwitches.iExeOnSymbian = ETrue;
   1.527 +		aSwitches.iExeDriveChar = testDrive;
   1.528 +		aSwitches.iExeDriveNum = CurrentDrive(aSwitches.iExeDriveChar);
   1.529 +		gLogFailureData.iExeDrive = aSwitches.iExeDriveChar;
   1.530 +		gLogFailureData.iExeOsName = KSymbian;
   1.531 +		//verification phase	
   1.532 +		aSwitches.iVerOnSymbian = ETrue;
   1.533 +		aSwitches.iVerDriveChar = testDrive;
   1.534 +		aSwitches.iVerDriveNum = CurrentDrive(aSwitches.iVerDriveChar);
   1.535 +		gLogFailureData.iVerDrive = aSwitches.iVerDriveChar;
   1.536 +		gLogFailureData.iVerOsName = KSymbian;
   1.537 +#endif
   1.538 +		}
   1.539 +
   1.540 +	if(aSwitches.iExeOnWindows || aSwitches.iExeOnSymbian)
   1.541 +		{
   1.542 +		aSwitches.iExeDriveChar = testDrive;
   1.543 +		aSwitches.iExeDriveNum = CurrentDrive(aSwitches.iExeDriveChar);
   1.544 +		gLogFailureData.iExeDrive = aSwitches.iExeDriveChar;
   1.545 +		}
   1.546 +	if(aSwitches.iVerOnWindows || aSwitches.iVerOnSymbian)
   1.547 +		{
   1.548 +		aSwitches.iVerDriveChar = testDrive;
   1.549 +		aSwitches.iVerDriveNum = CurrentDrive(aSwitches.iVerDriveChar);
   1.550 +		gLogFailureData.iVerDrive = aSwitches.iVerDriveChar;
   1.551 +		}
   1.552 +	}
   1.553 +
   1.554 +void InitialiseL()
   1.555 +	{
   1.556 +	gFileMan=CFileMan::NewL(TheFs);
   1.557 +	}
   1.558 +
   1.559 +void RmDir(const TDesC& aDirName)
   1.560 +	{
   1.561 +	TFileName filename_dir = aDirName;
   1.562 +	TInt r = 0;
   1.563 +	r = TheFs.SetAtt(filename_dir, 0, KEntryAttReadOnly);
   1.564 +	test(r==KErrNone);
   1.565 +	r=gFileMan->RmDir(filename_dir);
   1.566 +	test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound || r==KErrInUse);
   1.567 +	}
   1.568 +
   1.569 +// Cleanup test variables
   1.570 +void Cleanup()
   1.571 +	{
   1.572 +	delete gFileMan;
   1.573 +	}
   1.574 +
   1.575 +/**
   1.576 +    Parsing Dir Data Block
   1.577 +    @param  aDataBlock		data block in TInt[] for parsing	
   1.578 +    @param  aDirDataArray	returning dir data array after parsing
   1.579 +
   1.580 +    @panic 					if data setup error
   1.581 +*/
   1.582 +void ParsingDirDataBlock(const TInt aDataBlock[], RArray<TInt>& aDirDataArray)
   1.583 +	{
   1.584 +	TInt err = KErrNone;
   1.585 +	aDirDataArray.Reset();
   1.586 +
   1.587 +	if (aDataBlock[0] == EOB)
   1.588 +		{
   1.589 +		return;
   1.590 +		}
   1.591 +
   1.592 +	TInt i = 1;
   1.593 +	FOREVER
   1.594 +		{
   1.595 +		TInt lastItem = aDataBlock[i-1];
   1.596 +		TInt currentItem = aDataBlock[i];
   1.597 +		
   1.598 +		// check currentItem
   1.599 +		if (currentItem == EOB)
   1.600 +			{
   1.601 +			if (lastItem == CON || lastItem > LAST)
   1.602 +			//check last
   1.603 +				{
   1.604 +				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.605 +				test(EFalse);
   1.606 +				}
   1.607 +			else
   1.608 +			// passed, insert last, break
   1.609 +				{
   1.610 +				err = aDirDataArray.InsertInOrder(lastItem);
   1.611 +				if (err != KErrNone && err != KErrAlreadyExists)
   1.612 +					{
   1.613 +					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.614 +					test(EFalse);
   1.615 +					}
   1.616 +				break;
   1.617 +				}
   1.618 +			}
   1.619 +		else if (currentItem == CON)
   1.620 +		// if current == CON
   1.621 +			{
   1.622 +			if (lastItem == CON || lastItem >= LAST)
   1.623 +			// check last item
   1.624 +				{
   1.625 +				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.626 +				test(EFalse);
   1.627 +				}
   1.628 +			else // last < LAST, last != CON
   1.629 +				{
   1.630 +				// check next item
   1.631 +				TInt nextItem = aDataBlock[i+1];
   1.632 +				if (nextItem <= 0 || nextItem > LAST || lastItem >= nextItem)
   1.633 +					{
   1.634 +					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.635 +					test(EFalse);
   1.636 +					}
   1.637 +				else
   1.638 +					{
   1.639 +					// all valid
   1.640 +					for (TInt j = lastItem; j < nextItem; j++)
   1.641 +						{
   1.642 +						err = aDirDataArray.InsertInOrder(j);
   1.643 +						if (err != KErrNone && err != KErrAlreadyExists)
   1.644 +							{
   1.645 +							test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.646 +							test(EFalse);
   1.647 +							}
   1.648 +						}
   1.649 +					}
   1.650 +				}
   1.651 +			i++;
   1.652 +			}
   1.653 +		else if (0 <= currentItem && currentItem <= LAST)
   1.654 +		// if current == normal item
   1.655 +			{
   1.656 +			if (lastItem == CON)
   1.657 +				{
   1.658 +				i++;
   1.659 +				continue;
   1.660 +				}
   1.661 +			else if (lastItem >= LAST)
   1.662 +			// check last item
   1.663 +				{
   1.664 +				test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.665 +				test(EFalse);
   1.666 +				}
   1.667 +			else
   1.668 +			// passed, insert last
   1.669 +				{
   1.670 +				err = aDirDataArray.InsertInOrder(lastItem);
   1.671 +				if (err != KErrNone && err != KErrAlreadyExists)
   1.672 +					{
   1.673 +					test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.674 +					test(EFalse);
   1.675 +					}
   1.676 +				}
   1.677 +			i++;
   1.678 +			}
   1.679 +			else	// invalid input
   1.680 +			{
   1.681 +			test.Printf(_L("ERROR<SetupDir>: wrong dir data setup! err=%d\n"), err);
   1.682 +			test(EFalse);
   1.683 +			}
   1.684 +		}
   1.685 +	}
   1.686 +
   1.687 +/**
   1.688 +    Setup dir structure for testing and verifying functional results
   1.689 +    @param	datastr			data structure to setup directory
   1.690 +    @param  iOperation   	Operation to be performed 
   1.691 +    @param  SrcDrive		Source drive
   1.692 +    @param	Targetdrive		Target drive input
   1.693 +    @panic					if data structure definition is incorrect
   1.694 +*/
   1.695 +void SetupDirFiles(const TDesC& aPath, const TDirSetupFiles& aDirFiles)
   1.696 +	{
   1.697 +	TFileName path = aPath;
   1.698 +	if (path.Length() == 0)
   1.699 +		{
   1.700 +		test.Printf(_L("ERROR<SetupDirFiles()>: Zero length src path!\n"));
   1.701 +		test(EFalse);
   1.702 +		}
   1.703 +	
   1.704 +	MakeDir(path);
   1.705 +	
   1.706 +	RArray<TInt> addBlockDataArray;
   1.707 +	RArray<TInt> deductBlockDataArray;
   1.708 +	
   1.709 +	ParsingDirDataBlock(aDirFiles.iAddingBlock, addBlockDataArray);
   1.710 +	ParsingDirDataBlock(aDirFiles.iDeductBlock, deductBlockDataArray);
   1.711 +	
   1.712 +	if (addBlockDataArray.Count() == 0)
   1.713 +	// empty dir setup
   1.714 +		{
   1.715 +		return;
   1.716 +		}
   1.717 +	for (TInt i = 0; i < deductBlockDataArray.Count(); ++i)
   1.718 +		{
   1.719 +		TInt idxToDelete = addBlockDataArray.FindInOrder(deductBlockDataArray[i]);
   1.720 +		if (idxToDelete >= 0)
   1.721 +			{
   1.722 +			addBlockDataArray.Remove(idxToDelete);
   1.723 +			}
   1.724 +		else if (idxToDelete == KErrNotFound)
   1.725 +			{
   1.726 +			continue;
   1.727 +			}
   1.728 +		else
   1.729 +			{
   1.730 +			test.Printf(_L("ERROR<<SetupDir>>: wrong dir data setup! err=%d\n"), idxToDelete);
   1.731 +			test(EFalse);
   1.732 +			}
   1.733 +		}
   1.734 +	if (addBlockDataArray.Count() > 0)
   1.735 +		{
   1.736 +		for (TInt i = 0; i < addBlockDataArray.Count(); ++i)
   1.737 +			{
   1.738 +			TInt idx = addBlockDataArray[i];
   1.739 +			path = aPath;
   1.740 +			path += gDirPatterns[idx];
   1.741 +			if (path[path.Length() - 1] == '\\')
   1.742 +				{
   1.743 +				MakeDir(path);
   1.744 +				}
   1.745 +			else
   1.746 +				{
   1.747 +				MakeFile(path, _L8("blahblah"));
   1.748 +				}
   1.749 +			}
   1.750 +		}
   1.751 +	
   1.752 +	addBlockDataArray.Reset();
   1.753 +	deductBlockDataArray.Reset();
   1.754 +	}
   1.755 +
   1.756 +void LogTestFailureData(TTCType tcType, TFileName failedOn, 
   1.757 +					TUint tcId, TFileName tcUniquePath, TInt line)
   1.758 +	{
   1.759 +	if(tcType == EUnitaryTest)
   1.760 +		gLogFailureData.iTCTypeName = KUnitary;
   1.761 +	else if(tcType == EBinaryTest)
   1.762 +		gLogFailureData.iTCTypeName = KBinary;
   1.763 +	gLogFailureData.iTCFailureOn = failedOn;
   1.764 +	gLogFailureData.iTCId = tcId;
   1.765 +	gLogFailureData.iTCUniquePath.Copy(tcUniquePath);
   1.766 +	gLogFailureData.iLineNum = line;
   1.767 +	gLogFailureData.iFileName.Copy(gFileName);
   1.768 +
   1.769 +	RFile file;
   1.770 +	TBuf8<256>	tempBuf;
   1.771 +
   1.772 +	TFileName logFileName;
   1.773 +	if(gIOTesting)
   1.774 +		{
   1.775 +		if(failedOn == KExecution)
   1.776 +			{
   1.777 +			logFileName.Append(KExeLogFileName);
   1.778 +			}
   1.779 +		else
   1.780 +			{
   1.781 +			logFileName.Append(KVerLogFileName);
   1.782 +			}
   1.783 +		}
   1.784 +	else
   1.785 +		{
   1.786 +		logFileName.Append(KLogFileName);
   1.787 +		}
   1.788 +
   1.789 +	logFileName.Append(KUnderScore);
   1.790 +	logFileName.Append(gDriveToTest);
   1.791 +	logFileName.Append(KExtension);
   1.792 +
   1.793 +	TInt r = file.Create(TheFs, logFileName, EFileRead|EFileWrite);
   1.794 +	test(r == KErrNone || r == KErrAlreadyExists);
   1.795 +
   1.796 +	if (r == KErrNone)
   1.797 +		{
   1.798 +		tempBuf.Append(KLogFileHeader);
   1.799 +		file.Write(tempBuf);
   1.800 +		}
   1.801 +
   1.802 +	if (r == KErrAlreadyExists)
   1.803 +		{
   1.804 +		r = file.Open(TheFs, logFileName, EFileRead|EFileWrite);
   1.805 +		test(r == KErrNone);
   1.806 +		TInt start = 0;
   1.807 +		r=file.Seek(ESeekEnd,start);
   1.808 +		test(r == KErrNone);
   1.809 +		}
   1.810 +	
   1.811 +	tempBuf.SetLength(0);
   1.812 +	tempBuf.Append(KNewLine);
   1.813 +	if(gIOTesting)
   1.814 +		tempBuf.Append(KYes);
   1.815 +	else
   1.816 +		tempBuf.Append(KNo);
   1.817 +	tempBuf.Append(KComma);
   1.818 +	file.Write(tempBuf);
   1.819 +
   1.820 +	tempBuf.SetLength(0);
   1.821 +	tempBuf.Append(gLogFailureData.iTCTypeName);
   1.822 +	tempBuf.Append(KComma);
   1.823 +	file.Write(tempBuf);
   1.824 +
   1.825 +	tempBuf.SetLength(0);
   1.826 +	tempBuf.Append(gLogFailureData.iTCFailureOn);
   1.827 +	tempBuf.Append(KComma);
   1.828 +	file.Write(tempBuf);
   1.829 +
   1.830 +	tempBuf.SetLength(0);
   1.831 +	tempBuf.AppendNum(gLogFailureData.iTCId);
   1.832 +	tempBuf.Append(KComma);
   1.833 +	file.Write(tempBuf);
   1.834 +		
   1.835 +	tempBuf.SetLength(0);
   1.836 +	tempBuf.Append(gLogFailureData.iTCUniquePath);
   1.837 +	tempBuf.Append(KComma);
   1.838 +	file.Write(tempBuf);
   1.839 +			
   1.840 +	tempBuf.SetLength(0);
   1.841 +	tempBuf.Append(gLogFailureData.iFSName);
   1.842 +	tempBuf.Append(KComma);
   1.843 +	file.Write(tempBuf);
   1.844 +	
   1.845 +	tempBuf.SetLength(0);
   1.846 +	tempBuf.Append(gLogFailureData.iExeOsName);
   1.847 +	tempBuf.Append(KComma);
   1.848 +	file.Write(tempBuf);
   1.849 +
   1.850 +	tempBuf.SetLength(0);
   1.851 +	tempBuf.Append(gLogFailureData.iExeDrive);
   1.852 +	tempBuf.Append(KComma);
   1.853 +	file.Write(tempBuf);
   1.854 +	
   1.855 +	tempBuf.SetLength(0);
   1.856 +	tempBuf.Append(gLogFailureData.iVerOsName);
   1.857 +	tempBuf.Append(KComma);
   1.858 +	file.Write(tempBuf);
   1.859 +			
   1.860 +	tempBuf.SetLength(0);
   1.861 +	tempBuf.Append(gLogFailureData.iVerDrive);
   1.862 +	tempBuf.Append(KComma);
   1.863 +	file.Write(tempBuf);
   1.864 +			
   1.865 +	tempBuf.SetLength(0);
   1.866 +	tempBuf.Append(gLogFailureData.iAPIName);
   1.867 +	tempBuf.Append(KComma);
   1.868 +	file.Write(tempBuf);
   1.869 +	
   1.870 +	tempBuf.SetLength(0);
   1.871 +	tempBuf.AppendNum(gLogFailureData.iLineNum);
   1.872 +	tempBuf.Append(KComma);
   1.873 +	file.Write(tempBuf);
   1.874 +	
   1.875 +	tempBuf.SetLength(0);
   1.876 +	tempBuf.Append(gLogFailureData.iFuncName);
   1.877 +	tempBuf.Append(KComma);
   1.878 +	file.Write(tempBuf);
   1.879 +
   1.880 +	tempBuf.SetLength(0);
   1.881 +	tempBuf.Append(gLogFailureData.iFileName);
   1.882 +	file.Write(tempBuf);
   1.883 +
   1.884 +	file.Close();
   1.885 +	}