os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_RDirData.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_RDirData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,582 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 +@test
    1.24 +@internalComponent
    1.25 +v
    1.26 +This contains CT_RDirData
    1.27 +*/
    1.28 +
    1.29 +//	User includes
    1.30 +#include "T_RDirData.h"
    1.31 +#include "T_SfSrvServer.h"
    1.32 +#include "FileserverUtil.h"
    1.33 +
    1.34 +
    1.35 +
    1.36 +/*@{*/
    1.37 +///	Parameters
    1.38 +_LIT(KPath,										"path");
    1.39 +_LIT(KTUidType,									"uidtype");
    1.40 +_LIT(KRFsObjectName,							"rfsObject");
    1.41 +_LIT(KAsync,									"async");
    1.42 +_LIT(KArrayObjectName,							"arrayObject");
    1.43 +_LIT(KEntryObjectName,							"entryObject");
    1.44 +_LIT(KEntryAttMask,								"attmask");
    1.45 +_LIT(KParamExpectedFileName,					"filename%d");
    1.46 +_LIT(KReadArray,								"readarray");
    1.47 +_LIT(KCompareFiles,								"compare");
    1.48 +
    1.49 +
    1.50 +///Commands
    1.51 +_LIT(KCmdNew,									"new");
    1.52 +_LIT(KCmdDestructor,							"~");
    1.53 +_LIT(KCmdOpen,									"Open");
    1.54 +_LIT(KCmdRead,									"Read");
    1.55 +_LIT(KCmdClose,									"Close");
    1.56 +
    1.57 +//Constants
    1.58 +const TInt	KBufferLength		= 64;
    1.59 +
    1.60 +CT_RDirData* CT_RDirData::NewL()
    1.61 +/**
    1.62 +* Two phase constructor
    1.63 +*/
    1.64 +	{
    1.65 +	CT_RDirData* ret = new (ELeave) CT_RDirData();
    1.66 +	CleanupStack::PushL(ret);
    1.67 +	ret->ConstructL();
    1.68 +	CleanupStack::Pop(ret);
    1.69 +	return ret;
    1.70 +	}
    1.71 +
    1.72 +
    1.73 +
    1.74 +CT_RDirData::CT_RDirData()
    1.75 +:	iRDir(NULL)
    1.76 +,	iRead(NULL)
    1.77 +,	iReadBlock(NULL)
    1.78 +,	iEntry(NULL)
    1.79 +,	iExpectedNames(NULL)
    1.80 +,	iObjName(NULL)
    1.81 +,	iCompare(NULL)
    1.82 +/**
    1.83 +* Protected constructor. First phase construction
    1.84 +*/
    1.85 +	{
    1.86 +	}
    1.87 +
    1.88 +
    1.89 +void CT_RDirData::ConstructL()
    1.90 +/**
    1.91 +* Protected constructor. Second phase construction
    1.92 +*/
    1.93 +	{
    1.94 +	iRead = CActiveCallback::NewL( *this );
    1.95 +	iReadBlock = CActiveCallback::NewL( *this );
    1.96 +	iExpectedNames = new(ELeave) RPointerArray<TPath>();
    1.97 +	}
    1.98 +
    1.99 +
   1.100 +CT_RDirData::~CT_RDirData()
   1.101 +/**
   1.102 +* Destructor.
   1.103 +*/
   1.104 +	{
   1.105 +	DoCleanup();
   1.106 +	}
   1.107 +
   1.108 +
   1.109 +TAny* CT_RDirData::GetObject()
   1.110 +	{
   1.111 +	return iRDir;
   1.112 +	}
   1.113 +
   1.114 +
   1.115 +TBool CT_RDirData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   1.116 +/**
   1.117 +* Process a command read from the ini file
   1.118 +*
   1.119 +* @param aCommand	the command to process
   1.120 +* @param aSection		the entry in the ini file requiring the command to be processed
   1.121 +*
   1.122 +* @return ETrue if the command is processed
   1.123 +*/
   1.124 +	{
   1.125 +	TBool ret = ETrue;
   1.126 +
   1.127 +	if (aCommand == KCmdNew)
   1.128 +		{
   1.129 +		DoCmdNew();
   1.130 +		}
   1.131 +	else if (aCommand == KCmdOpen)
   1.132 +		{
   1.133 +		DoCmdOpenL(aSection);
   1.134 +		}
   1.135 +	else if (aCommand == KCmdRead)
   1.136 +		{
   1.137 +		DoCmdReadL(aSection, aAsyncErrorIndex);
   1.138 +		}
   1.139 +	else if (aCommand == KCmdClose)
   1.140 +		{
   1.141 +		DoCmdClose();
   1.142 +		}
   1.143 +	else if (aCommand == KCmdDestructor)
   1.144 +		{
   1.145 +		DoCmdDestructor();
   1.146 +		}
   1.147 +	else
   1.148 +		{
   1.149 +		ret = EFalse;
   1.150 +		}
   1.151 +	return ret;
   1.152 +	}
   1.153 +
   1.154 +void CT_RDirData::DoCleanup()
   1.155 +	{
   1.156 +	INFO_PRINTF1(_L("Deleting current RDir"));
   1.157 +	delete iEntry;
   1.158 +	iEntry = NULL;
   1.159 +	delete iRDir;
   1.160 +	iRDir = NULL;
   1.161 +
   1.162 +	delete iRead;
   1.163 +	iRead = NULL;
   1.164 +	delete iReadBlock;
   1.165 +	iReadBlock = NULL;
   1.166 +	iExpectedNames->ResetAndDestroy();	
   1.167 +	}
   1.168 +
   1.169 +void CT_RDirData::DoCmdNew()
   1.170 +	{
   1.171 +	INFO_PRINTF1(_L("Create new RDirs class instance"));
   1.172 +
   1.173 +	delete iRDir;
   1.174 +	iRDir = NULL;
   1.175 +
   1.176 +	TRAPD(err, iRDir = new (ELeave) RDir());
   1.177 +	if ( err != KErrNone )
   1.178 +		{
   1.179 +		ERR_PRINTF2(_L("new error %d"), err);
   1.180 +		SetError( err );
   1.181 +		}
   1.182 +	}
   1.183 +	
   1.184 +void CT_RDirData::DoCmdClose()
   1.185 +/** 
   1.186 +*	Close RDir handle 
   1.187 +*/
   1.188 +	{
   1.189 +	INFO_PRINTF1(_L("Closing RDir"));
   1.190 +	iRDir->Close();
   1.191 +	}
   1.192 +
   1.193 +void CT_RDirData::DoCmdDestructor()
   1.194 +/** 
   1.195 +*	Destroy RDir the object 
   1.196 +*/
   1.197 +	{
   1.198 +	INFO_PRINTF1(_L("Destroying the RDir object"));
   1.199 +	DoCleanup();
   1.200 +	}
   1.201 +	
   1.202 +void CT_RDirData::DoCmdOpenL(const TDesC& aSection)
   1.203 +	{		
   1.204 +	INFO_PRINTF1(_L("Opening directory!"));
   1.205 +	
   1.206 +	TBool	dataOk = ETrue;
   1.207 +		
   1.208 +	TPtrC	rfsObjectName;
   1.209 +	RFs*    rfsObject = NULL;
   1.210 +	if(GET_MANDATORY_STRING_PARAMETER(KRFsObjectName(), aSection, rfsObjectName))
   1.211 +	    {
   1.212 +	    rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
   1.213 +	    }
   1.214 +	else
   1.215 +		{
   1.216 +		dataOk = EFalse;
   1.217 +		}
   1.218 +	    
   1.219 +	TPtrC path;
   1.220 +	if(!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path))
   1.221 +		{
   1.222 +		dataOk = EFalse;
   1.223 +		}
   1.224 +	
   1.225 +	TUidType	uidType = KNullUid;
   1.226 +	TInt		intUIDType;
   1.227 +	TBool		isUidType = EFalse;
   1.228 +
   1.229 +	TUint		attMask = KEntryAttNormal;
   1.230 +	INFO_PRINTF2(_L("section name - %S"),&aSection);
   1.231 +	
   1.232 +	if(!FileserverUtil::GetAttMask(*this, aSection, KEntryAttMask(), attMask))
   1.233 +		{
   1.234 +		if (GET_MANDATORY_INT_PARAMETER(KTUidType(), aSection, intUIDType))
   1.235 +			{
   1.236 +    		TUid id = TUid::Uid(intUIDType);
   1.237 +	   		uidType = TUidType(id);
   1.238 +	   		INFO_PRINTF2(_L("UID type set to %d"), uidType[0].iUid);
   1.239 +	   		isUidType = ETrue;
   1.240 +			}
   1.241 +		else
   1.242 +			{
   1.243 +			dataOk = EFalse;
   1.244 +			ERR_PRINTF2(_L("attmask or %S must be declared !!!"), &KTUidType);
   1.245 +			}
   1.246 +		}
   1.247 +		
   1.248 +	if (dataOk)	
   1.249 +		{
   1.250 +		TInt 	err = KErrNone;
   1.251 +		
   1.252 +		if (isUidType)
   1.253 +			{
   1.254 +			err = iRDir->Open(*rfsObject, path, uidType);
   1.255 +			}
   1.256 +		else
   1.257 +			{
   1.258 +			err = iRDir->Open(*rfsObject, path, attMask);
   1.259 +			}
   1.260 +				
   1.261 +		if (err != KErrNone)
   1.262 +			{
   1.263 +			INFO_PRINTF2(_L("Open() error: %d"), err);
   1.264 +			SetError(err);
   1.265 +			}
   1.266 +		else
   1.267 +			{
   1.268 +			INFO_PRINTF1(_L("Directory has been opened!"));
   1.269 +			}
   1.270 +		}
   1.271 +	}
   1.272 +	
   1.273 +void CT_RDirData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   1.274 +	{
   1.275 +	INFO_PRINTF1(_L("Reading directory!"));
   1.276 +	
   1.277 +	TBool 	async 		= EFalse;
   1.278 +	TBool	readArray	= EFalse;
   1.279 +	TBool	compare		= EFalse;
   1.280 +	
   1.281 +	GET_OPTIONAL_BOOL_PARAMETER(KAsync(), aSection, async);
   1.282 +	
   1.283 +	if(GET_OPTIONAL_BOOL_PARAMETER(KReadArray(),aSection,readArray))
   1.284 +		{
   1.285 +		ReadExpectedNamesL( aSection);
   1.286 +		}
   1.287 +		
   1.288 +	if(GET_OPTIONAL_BOOL_PARAMETER(KCompareFiles(),aSection,compare))
   1.289 +		{
   1.290 +		iCompare = compare;
   1.291 +		}
   1.292 +
   1.293 +	TPtrC entryArrayName;
   1.294 +	if (GET_OPTIONAL_STRING_PARAMETER(KArrayObjectName(), aSection, entryArrayName))
   1.295 +		{
   1.296 +		TEntryArray* entryArray = new(ELeave) TEntryArray();
   1.297 +		CleanupStack::PushL(entryArray);
   1.298 +		
   1.299 +		CT_EntryArrayData* entryArrayWrapper = 
   1.300 +			static_cast<CT_EntryArrayData*> (GetDataWrapperL(entryArrayName));
   1.301 +		if (entryArrayWrapper)
   1.302 +			{
   1.303 +			entryArrayWrapper->SetObjectL(entryArray);
   1.304 +			}
   1.305 +		else
   1.306 +			{
   1.307 +			ERR_PRINTF2(_L("Not initialized %S"), &entryArrayName);
   1.308 +			SetBlockResult(EFail);
   1.309 +			}
   1.310 +		CleanupStack::Pop(entryArray);
   1.311 +			
   1.312 +		if (async)
   1.313 +			{
   1.314 +			iObjName = entryArrayName;
   1.315 +			iRDir->Read(*entryArray, iReadBlock->iStatus);
   1.316 +			iReadBlock->Activate(aAsyncErrorIndex);
   1.317 +			IncOutstanding();
   1.318 +			}
   1.319 +		else
   1.320 +			{
   1.321 +			TInt err = iRDir->Read(*entryArray);
   1.322 +			
   1.323 +			if((err == KErrNone) || (err == KErrEof))
   1.324 +				{
   1.325 +				INFO_PRINTF1(_L("Read function completed successfully"));
   1.326 +				SetError(err);
   1.327 +				if(compare)
   1.328 +					{
   1.329 +					CompareEntryArray(entryArray);
   1.330 +					}
   1.331 +				}
   1.332 +			else
   1.333 +				{
   1.334 +				ERR_PRINTF2(_L("Read function failed with error: %d"), err);
   1.335 +				SetError(err);	
   1.336 +				}
   1.337 +			}
   1.338 +		}
   1.339 +	else
   1.340 +		{
   1.341 +		TPtrC entryName;
   1.342 +		if (GET_MANDATORY_STRING_PARAMETER(KEntryObjectName(), aSection, entryName))
   1.343 +			{
   1.344 +			TEntry* entry = new(ELeave) TEntry();
   1.345 +			CleanupStack::PushL(entry);
   1.346 +			
   1.347 +			CT_EntryData* entryWrapper = 
   1.348 +				static_cast<CT_EntryData*> (GetDataWrapperL(entryName));
   1.349 +			
   1.350 +			if (entryWrapper)
   1.351 +				{
   1.352 +				entryWrapper->SetObjectL(entry);
   1.353 +				}
   1.354 +			else
   1.355 +				{
   1.356 +				ERR_PRINTF2(_L("Not initialized %S"), &entryName);
   1.357 +				SetBlockResult(EFail);
   1.358 +				}
   1.359 +			
   1.360 +			CleanupStack::Pop(entry);
   1.361 +			
   1.362 +			if (async)
   1.363 +				{
   1.364 +				iObjName = entryName;
   1.365 +				delete iEntry;
   1.366 +				iEntry = NULL;
   1.367 +				iEntry = new(ELeave) TPckg<TEntry>(*entry);
   1.368 +				iRDir->Read(*iEntry, iRead->iStatus);
   1.369 +				iRead->Activate(aAsyncErrorIndex);
   1.370 +				IncOutstanding();
   1.371 +				}
   1.372 +			else
   1.373 +				{
   1.374 +				TInt err = iRDir->Read(*entry);
   1.375 +			
   1.376 +				if((err == KErrNone) || (err == KErrEof))
   1.377 +					{
   1.378 +					INFO_PRINTF1(_L("Read function completed successfully"));
   1.379 +					SetError(err);
   1.380 +					if(compare)
   1.381 +						{
   1.382 +						CompareEntryData(entry);
   1.383 +						}
   1.384 +					}
   1.385 +				else
   1.386 +					{
   1.387 +					ERR_PRINTF2(_L("Read function failed with error: %d"), err);
   1.388 +					SetError(err);	
   1.389 +					}
   1.390 +				}
   1.391 +			}
   1.392 +		}
   1.393 +	}
   1.394 +	
   1.395 +		
   1.396 +void CT_RDirData::ReadExpectedNamesL( const TDesC& aSection )
   1.397 +/**
   1.398 +*	Read list of expected file names from ili file
   1.399 +*/
   1.400 +	{
   1.401 +	iExpectedNames->ResetAndDestroy();
   1.402 +
   1.403 +	TBool moreData = EFalse;
   1.404 +	TInt index = 0;
   1.405 +	do
   1.406 +		{
   1.407 +		TBuf<KBufferLength> tempStore;
   1.408 +		tempStore.Format(KParamExpectedFileName(), ++index);
   1.409 +		TPtrC fileName;
   1.410 +		moreData = GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName);
   1.411 +		if (moreData)
   1.412 +			{
   1.413 +			TPath* path = new(ELeave) TPath(fileName);
   1.414 +			CleanupStack::PushL(path);
   1.415 +			iExpectedNames->AppendL(path);
   1.416 +			CleanupStack::Pop();
   1.417 +			}
   1.418 +		}
   1.419 +	while (moreData);
   1.420 +	}
   1.421 +
   1.422 +
   1.423 +void CT_RDirData::CompareEntryArray(TEntryArray* aEntryArray)
   1.424 +/**
   1.425 +*	Compare TEntryArray entryes with list of expected files
   1.426 +*/
   1.427 +	{
   1.428 +	if(aEntryArray->Count() == iExpectedNames->Count())
   1.429 +		{
   1.430 +		for(TInt i = 0; i < aEntryArray->Count(); i++)
   1.431 +			{
   1.432 +			TBool eof = EFalse;
   1.433 +			for(TInt k = 0; !eof && (k < iExpectedNames->Count()); k++)
   1.434 +				{
   1.435 +				TEntry* tmpEntry = new(ELeave) TEntry();
   1.436 +				*tmpEntry = aEntryArray->operator[](i);
   1.437 +				if(*(iExpectedNames->operator[](k)) == tmpEntry->iName)
   1.438 +					{
   1.439 +					TPath* name = iExpectedNames->operator[](k);
   1.440 +					INFO_PRINTF3( _L( "Entry name = expected name, %S = %S"), &tmpEntry->iName, name);
   1.441 +					
   1.442 +					iExpectedNames->Remove(k);
   1.443 +					delete name;
   1.444 +					eof = ETrue;	
   1.445 +					}
   1.446 +					
   1.447 +				delete tmpEntry;
   1.448 +				}
   1.449 +			}
   1.450 +		if(iExpectedNames->Count() > 0)
   1.451 +			{
   1.452 +			ERR_PRINTF1(_L("TEntryArray members are not equal to expected"));
   1.453 +			SetBlockResult(EFail);
   1.454 +			}
   1.455 +		else
   1.456 +			{
   1.457 +			INFO_PRINTF1( _L( "TEntryArray members are equal to expected"));
   1.458 +			}
   1.459 +		}
   1.460 +	else if(aEntryArray->Count() > iExpectedNames->Count())
   1.461 +		{
   1.462 +		ERR_PRINTF1(_L("Found unexpecded file(s)"));
   1.463 +		SetBlockResult(EFail);
   1.464 +		}
   1.465 +	else if(aEntryArray->Count() < iExpectedNames->Count())
   1.466 +		{
   1.467 +		ERR_PRINTF1(_L("List of expected files more than amount of real files"));
   1.468 +		SetBlockResult(EFail);
   1.469 +		}
   1.470 +	}
   1.471 +	
   1.472 +void CT_RDirData::CompareEntryData(TEntry* aEntry)
   1.473 +/**
   1.474 +*	Compare TEntry with entry in list of expected files
   1.475 +*/
   1.476 +	{
   1.477 +	TBool eof = EFalse;	
   1.478 +	TBool fileCompare = EFalse;
   1.479 +	for(TInt i = 0; !eof && (i < iExpectedNames->Count()); i++)
   1.480 +		{
   1.481 +		if(*(iExpectedNames->operator[](i)) == aEntry->iName)
   1.482 +			{
   1.483 +			TPath* name = iExpectedNames->operator[](i);
   1.484 +			fileCompare = ETrue;
   1.485 +				
   1.486 +			iExpectedNames->Remove(i);
   1.487 +			delete name;
   1.488 +			eof = ETrue;
   1.489 +			}
   1.490 +		}
   1.491 +	if(!fileCompare)
   1.492 +		{
   1.493 +		ERR_PRINTF2(_L("Unexpected file - %S"),&aEntry->iName);
   1.494 +		SetBlockResult(EFail);
   1.495 +		}
   1.496 +	}
   1.497 +	
   1.498 +
   1.499 +void CT_RDirData::RunL(CActive* aActive, TInt aIndex)
   1.500 +	{	
   1.501 +	INFO_PRINTF1(_L("RunL Called!"));
   1.502 +	
   1.503 +	if ((aActive == iReadBlock) || (aActive == iRead))
   1.504 +		{
   1.505 +
   1.506 +		TInt err = aActive->iStatus.Int();
   1.507 +		if (err == KErrNone)
   1.508 +			{
   1.509 +			TEntry	&actualEntry = iEntry->operator()();
   1.510 +			INFO_PRINTF2(_L("Asynchronous Read function completed successfully, %S"),&(actualEntry.iName));
   1.511 +			}
   1.512 +		else if (err == KErrEof)
   1.513 +			{
   1.514 +			INFO_PRINTF1(_L("Asynchronous Read function reached the end and returned expectedly KErrEof"));
   1.515 +			SetAsyncError(aIndex, err);
   1.516 +			}
   1.517 +		else
   1.518 +			{
   1.519 +			ERR_PRINTF2(_L("RunL Error: %d"), err);
   1.520 +			SetAsyncError(aIndex, err);
   1.521 +			}
   1.522 +		
   1.523 +
   1.524 +		if(iCompare && ((err == KErrNone) || (err == KErrEof)))
   1.525 +			{
   1.526 +			if(aActive == iReadBlock)
   1.527 +				{
   1.528 +				TEntryArray *entryArray = static_cast<TEntryArray*>(GetDataObjectL(iObjName));
   1.529 +				if (entryArray)
   1.530 +					{
   1.531 +					CompareEntryArray(entryArray);
   1.532 +					}
   1.533 +				else
   1.534 +					{
   1.535 +					SetBlockResult(EFail);
   1.536 +					ERR_PRINTF2(_L("Empty Object: %S"), &iObjName);
   1.537 +					}
   1.538 +				}
   1.539 +			else if(aActive == iRead)
   1.540 +				{
   1.541 +				TEntry* entry = static_cast<TEntry*>(GetDataObjectL(iObjName));
   1.542 +				if (entry)
   1.543 +					{
   1.544 +					CompareEntryData(entry);
   1.545 +					}
   1.546 +				else
   1.547 +					{
   1.548 +					SetBlockResult(EFail);
   1.549 +					ERR_PRINTF2(_L("Empty Object: %S"), &iObjName);
   1.550 +					}
   1.551 +				}
   1.552 +			}
   1.553 +
   1.554 +		delete iEntry;
   1.555 +		iEntry = NULL;
   1.556 +		
   1.557 +		DecOutstanding();
   1.558 +		}
   1.559 +	else
   1.560 +		{
   1.561 + 		ERR_PRINTF1( _L("Stray RunL signal") );
   1.562 + 		SetBlockResult( EFail );
   1.563 +		}
   1.564 +	}
   1.565 +	
   1.566 +void CT_RDirData::DoCancel(CActive* aActive, TInt aIndex)
   1.567 +	{
   1.568 +	INFO_PRINTF1(_L("DoCancel Called!"));
   1.569 +	
   1.570 +	if ( aActive == iRead )
   1.571 +		{	
   1.572 +		TInt err = aActive->iStatus.Int();
   1.573 +		if(err != KErrNone )
   1.574 +			{
   1.575 +			ERR_PRINTF2(_L("DoCancel Error: %d"), err);
   1.576 +			SetAsyncError(aIndex, err);
   1.577 +			}
   1.578 +		DecOutstanding();
   1.579 +		}
   1.580 +	else
   1.581 +		{
   1.582 + 		ERR_PRINTF1( _L("Stray RunL signal") );
   1.583 + 		SetBlockResult( EFail );
   1.584 +		}	
   1.585 +	}