os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DirScanData.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_DirScanData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,480 @@
     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_DirScanData
    1.27 +*/
    1.28 +
    1.29 +//	User includes
    1.30 +#include "T_DirScanData.h"
    1.31 +#include "T_SfSrvServer.h"
    1.32 +
    1.33 +/*@{*/
    1.34 +///	Parameters
    1.35 +_LIT(KAttMask,							"attmask" );
    1.36 +_LIT(KRfsObject,						"rfsObject");
    1.37 +_LIT(KDirObject,						"dirObject");
    1.38 +_LIT(KExpected,							"expected");
    1.39 +_LIT(KPath,								"path");
    1.40 +_LIT(KEntrySortKey,						"sortkey");
    1.41 +_LIT(KScanDirection,					"scandirection");
    1.42 +
    1.43 +///Commands
    1.44 +_LIT(KCmdNewL,							"NewL");
    1.45 +_LIT(KCmdNewLC,							"NewLC");
    1.46 +_LIT(KCmdSetScanDataL,					"SetScanDataL");
    1.47 +_LIT(KCmdFullPath,						"FullPath");
    1.48 +_LIT(KCmdAbbreviatedPath,				"AbbreviatedPath");
    1.49 +_LIT(KCmdNextL,							"NextL");
    1.50 +_LIT(KCmdDestructor,					"~");
    1.51 +
    1.52 +//	Sort key
    1.53 +_LIT(KESortNone,						"ESortNone");
    1.54 +_LIT(KESortByName,						"ESortByName");
    1.55 +_LIT(KESortByExt,						"ESortByExt");
    1.56 +_LIT(KESortBySize,						"ESortBySize");
    1.57 +_LIT(KESortByDate,						"ESortByDate");
    1.58 +_LIT(KESortByUid,						"ESortByUid");
    1.59 +_LIT(KEDirsAnyOrder,					"EDirsAnyOrder");
    1.60 +_LIT(KEDirsFirst,						"EDirsFirst");
    1.61 +_LIT(KEDirsLast,						"EDirsLast");
    1.62 +_LIT(KEAscending,						"EAscending");
    1.63 +_LIT(KEDescending,						"EDescending");
    1.64 +_LIT(KEDirDescending,					"EDirDescending");
    1.65 +
    1.66 +// Scan directions
    1.67 +_LIT(KEScanUpTree,	 					"EScanUpTree");
    1.68 +_LIT(KEScanDownTree,	 				"EScanDownTree");
    1.69 +
    1.70 +
    1.71 +CT_DirScanData* CT_DirScanData::NewL()
    1.72 +/**
    1.73 +* Two phase constructor
    1.74 +*/
    1.75 +	{
    1.76 +	CT_DirScanData* ret = new (ELeave) CT_DirScanData();
    1.77 +	CleanupStack::PushL(ret);
    1.78 +	ret->ConstructL();
    1.79 +	CleanupStack::Pop(ret);
    1.80 +	return ret;
    1.81 +	}
    1.82 +	
    1.83 +
    1.84 +CT_DirScanData::CT_DirScanData()
    1.85 +:	iDirScan(NULL)
    1.86 +/**
    1.87 +* Protected constructor. First phase construction
    1.88 +*/
    1.89 +	{
    1.90 +	}
    1.91 +
    1.92 +
    1.93 +void CT_DirScanData::ConstructL()
    1.94 +/**
    1.95 +* Protected constructor. Second phase construction
    1.96 +*/
    1.97 +	{
    1.98 +	}
    1.99 +
   1.100 +
   1.101 +CT_DirScanData::~CT_DirScanData()
   1.102 +/**
   1.103 +* Destructor.
   1.104 +*/
   1.105 +	{
   1.106 +	DoCleanup();
   1.107 +	}
   1.108 +
   1.109 +
   1.110 +TAny* CT_DirScanData::GetObject()
   1.111 +	{
   1.112 +	return iDirScan;
   1.113 +	}
   1.114 +
   1.115 +
   1.116 +TBool	CT_DirScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   1.117 +/**
   1.118 +* Process a command read from the ini file
   1.119 +*
   1.120 +* @param aCommand	the command to process
   1.121 +* @param aSection	the section in the ini file requiring the command to be processed
   1.122 +*
   1.123 +* @return ETrue if the command is processed
   1.124 +*/
   1.125 +	{
   1.126 +	TBool	retVal = ETrue;
   1.127 +
   1.128 +	if (aCommand == KCmdNewL)
   1.129 +		{
   1.130 +		DoCmdNewL(aSection);
   1.131 +		}
   1.132 +	else if (aCommand == KCmdDestructor)
   1.133 +		{
   1.134 +		DoCleanup();
   1.135 +		}
   1.136 +	else if (aCommand == KCmdNewLC)
   1.137 +		{
   1.138 +		DoCmdNewLC(aSection);
   1.139 +		}
   1.140 +	else if (aCommand == KCmdSetScanDataL)
   1.141 +		{
   1.142 +		DoCmdSetScanDataL(aSection);
   1.143 +		}
   1.144 +	else if (aCommand == KCmdNextL)
   1.145 +		{
   1.146 +		DoCmdNextL(aSection);
   1.147 +		}
   1.148 +	else if (aCommand == KCmdAbbreviatedPath)
   1.149 +		{
   1.150 +		DoCmdAbbreviatedPath(aSection);
   1.151 +		}
   1.152 +	else if (aCommand == KCmdFullPath)
   1.153 +		{
   1.154 +		DoCmdFullPath(aSection);
   1.155 +		}
   1.156 +	else
   1.157 +		{
   1.158 +		retVal = EFalse;
   1.159 +		}
   1.160 +	return retVal;
   1.161 +	}
   1.162 +
   1.163 +void CT_DirScanData::DoCleanup()
   1.164 +	{
   1.165 +	INFO_PRINTF1(_L("Doing cleanup!"));
   1.166 +	
   1.167 +	if (iDirScan)
   1.168 +		{
   1.169 +		delete iDirScan;
   1.170 +		iDirScan = NULL;
   1.171 +		}
   1.172 +	}
   1.173 +		
   1.174 +void CT_DirScanData::DoCmdNewL(const TDesC& aSection)
   1.175 +	{
   1.176 +	INFO_PRINTF1(_L("Constructing CDirScan object!"));
   1.177 +	
   1.178 +	RFs*	rfsObject = NULL;
   1.179 +	TPtrC	rfsObjectName;
   1.180 +	if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
   1.181 +		{
   1.182 +		rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
   1.183 +		}
   1.184 +	
   1.185 +	DoCleanup();
   1.186 +	TRAPD (error, iDirScan = CDirScan::NewL(*rfsObject));
   1.187 +	if (error == KErrNone)
   1.188 +		{
   1.189 +		INFO_PRINTF1(_L("CDirScan object has been created with NewL constructor!"));			
   1.190 +		}
   1.191 +	else
   1.192 +		{
   1.193 +		ERR_PRINTF2(_L("CDirScan object is not created with NewL constructor! Error code: %d"), error);
   1.194 +		SetError(error);
   1.195 +		}
   1.196 +	}
   1.197 +	
   1.198 +void CT_DirScanData::DoCmdNewLC(const TDesC& aSection)
   1.199 +	{
   1.200 +	INFO_PRINTF1(_L("Constructing CDirScan object!"));
   1.201 +	
   1.202 +	RFs*	rfsObject = NULL;
   1.203 +	TPtrC	rfsObjectName;
   1.204 +	if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
   1.205 +		{
   1.206 +		rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
   1.207 +		}
   1.208 +	
   1.209 +	DoCleanup();
   1.210 +	TRAPD (error, iDirScan = CDirScan::NewLC(*rfsObject); CleanupStack::Pop(iDirScan) );
   1.211 +	if (error == KErrNone)
   1.212 +		{
   1.213 +		INFO_PRINTF1(_L("CDirScan object has been created with NewLC constructor!"));
   1.214 +		}
   1.215 +	else
   1.216 +		{
   1.217 +		ERR_PRINTF2(_L("CDirScan object is not created with NewLC constructor! Error code: %d"), error);
   1.218 +		SetError(error);
   1.219 +		}
   1.220 +	}
   1.221 +
   1.222 +void CT_DirScanData::DoCmdSetScanDataL(const TDesC& aSection)
   1.223 +	{
   1.224 +	INFO_PRINTF1(_L("Setting data scanning!"));
   1.225 +	
   1.226 +	TBool	dataOk = ETrue;
   1.227 +	
   1.228 +	TPtrC	path;
   1.229 +	if (!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path))
   1.230 +		{
   1.231 +		dataOk = EFalse;
   1.232 +		}
   1.233 +
   1.234 +	TUint	attMask = KEntryAttHidden;
   1.235 +	if ( !FileserverUtil::GetAttMask(*this, aSection, KAttMask(), attMask))
   1.236 +        {
   1.237 +       	dataOk = EFalse;
   1.238 +       	}
   1.239 +
   1.240 +	TPtrC	entrySortKey;
   1.241 +	TUint	sortKey = ESortNone;
   1.242 +	
   1.243 +	if (GET_OPTIONAL_STRING_PARAMETER(KEntrySortKey(), aSection, entrySortKey))
   1.244 +		{
   1.245 +		if ( !ConvertToSortKey(entrySortKey, sortKey) )
   1.246 +			{
   1.247 +			TInt	intTemp;
   1.248 +			if ( GET_MANDATORY_INT_PARAMETER(KEntrySortKey(), aSection, intTemp) )
   1.249 +				{
   1.250 +				sortKey=intTemp;
   1.251 +				}
   1.252 +			else
   1.253 +				{
   1.254 +				dataOk = EFalse;
   1.255 +				}
   1.256 +			}
   1.257 +		}
   1.258 +		
   1.259 +	TPtrC						entryScanDirection;
   1.260 +	CDirScan::TScanDirection	scanDirection = CDirScan::EScanDownTree;
   1.261 +	
   1.262 +	if (GET_OPTIONAL_STRING_PARAMETER(KScanDirection(), aSection, entryScanDirection))
   1.263 +		{
   1.264 +		if ( !ConvertToScanDirection(entryScanDirection, scanDirection))
   1.265 +            {
   1.266 +           	dataOk = EFalse;
   1.267 +           	}
   1.268 +		}
   1.269 +		
   1.270 +	
   1.271 +	if (dataOk)
   1.272 +		{
   1.273 +		TRAPD (err, iDirScan->SetScanDataL(path, attMask, sortKey, scanDirection));
   1.274 +		if(err == KErrNone)
   1.275 +			{
   1.276 +			INFO_PRINTF1(_L("SetScanDataL complete!"));
   1.277 +			}
   1.278 +		else
   1.279 +			{
   1.280 +			ERR_PRINTF2(_L("SetScanDataL() Error: %d"), err);
   1.281 +			SetError(err);
   1.282 +			}
   1.283 +		}
   1.284 +	}	
   1.285 +
   1.286 +void CT_DirScanData::DoCmdNextL(const TDesC& aSection)
   1.287 +	{
   1.288 +	INFO_PRINTF1(_L("Scanning next directory entries!"));
   1.289 +	
   1.290 +	CDir*		dirObject = NULL;
   1.291 +	CT_DirData* dirWrapperObject = NULL;
   1.292 +	TPtrC		dirObjectName;
   1.293 +	
   1.294 +	if (GET_MANDATORY_STRING_PARAMETER(KDirObject, aSection, dirObjectName))
   1.295 +		{
   1.296 +		dirWrapperObject = static_cast<CT_DirData*>(GetDataWrapperL(dirObjectName));
   1.297 +		}
   1.298 +	TRAPD (err, iDirScan->NextL(dirObject));
   1.299 +	if (err == KErrNone)
   1.300 +		{
   1.301 +		if (dirObject == NULL)
   1.302 +			{
   1.303 +			INFO_PRINTF1(_L("CDir instance is NULL, there is no directory left to go."));
   1.304 +			}
   1.305 +		else
   1.306 +			{
   1.307 +			INFO_PRINTF1(_L("Scanning the next directory entry completed successfully!"));
   1.308 +			}
   1.309 +		}
   1.310 +	else
   1.311 +		{
   1.312 +		ERR_PRINTF2(_L("Can't scan the next directory entry in the structure Error code: %d"), err);
   1.313 +		SetError(err);
   1.314 +		}
   1.315 +		
   1.316 +	if (dirObject)
   1.317 +		{
   1.318 +		if(dirWrapperObject)
   1.319 +			{
   1.320 +			dirWrapperObject->SetObjectL(dirObject);
   1.321 +			}
   1.322 +		else
   1.323 +		    {
   1.324 +		    delete dirObject;
   1.325 +		    dirObject = NULL;			        
   1.326 +		    }
   1.327 +		}	
   1.328 +	}
   1.329 +	
   1.330 +void CT_DirScanData::DoCmdAbbreviatedPath(const TDesC& aSection)
   1.331 +	{
   1.332 +	INFO_PRINTF1(_L("Getting directory abbreviated path!"));
   1.333 +	
   1.334 +	TPtrC	expected;
   1.335 +	if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
   1.336 +		{
   1.337 +		TPtrC	abbPath;
   1.338 +		abbPath.Set(iDirScan->AbbreviatedPath());
   1.339 +		
   1.340 +		if (abbPath != expected)
   1.341 +			{
   1.342 +			ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &abbPath, &expected);
   1.343 +			SetBlockResult(EFail);
   1.344 +			}
   1.345 +		else 
   1.346 +			{
   1.347 +			INFO_PRINTF2(_L("Result (%S) match with expected result!"), &abbPath);
   1.348 +			}
   1.349 +		}
   1.350 +	}
   1.351 +
   1.352 +void CT_DirScanData::DoCmdFullPath(const TDesC& aSection)
   1.353 +	{
   1.354 +	INFO_PRINTF1(_L("Getting directory full path!"));
   1.355 +	
   1.356 +	TPtrC	expected;
   1.357 +	if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
   1.358 +		{
   1.359 +		TPtrC	fullPath;
   1.360 +		fullPath.Set(iDirScan->FullPath());
   1.361 +		
   1.362 +		if (fullPath != expected)
   1.363 +			{
   1.364 +			ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &fullPath, &expected);
   1.365 +			SetBlockResult(EFail);
   1.366 +			}
   1.367 +		else 
   1.368 +			{
   1.369 +			INFO_PRINTF2(_L("Result (%S) match with expected result!"), &fullPath);
   1.370 +			}
   1.371 +		}
   1.372 +	}
   1.373 +	
   1.374 +	
   1.375 +TBool CT_DirScanData::ConvertToSortKey(const TDesC& aSortKeyStr, TUint& aSortKey)
   1.376 +	{
   1.377 +	TBool ret = ETrue;
   1.378 +
   1.379 +	if (aSortKeyStr == KESortNone)
   1.380 +		{
   1.381 +		aSortKey = ESortNone;
   1.382 +		}
   1.383 +	else if (aSortKeyStr == KESortByName)
   1.384 +		{
   1.385 +		aSortKey = ESortByName;
   1.386 +		}
   1.387 +	else if (aSortKeyStr == KESortByExt)
   1.388 +		{
   1.389 +		aSortKey = ESortByExt;
   1.390 +		}
   1.391 +	else if (aSortKeyStr == KESortBySize)
   1.392 +		{
   1.393 +		aSortKey = ESortBySize;
   1.394 +		}
   1.395 +	else if (aSortKeyStr == KESortByDate)
   1.396 +		{
   1.397 +		aSortKey = ESortByDate;
   1.398 +		}
   1.399 +	else if (aSortKeyStr == KESortByUid)
   1.400 +		{
   1.401 +		aSortKey = ESortByUid;
   1.402 +		}
   1.403 +	else if (aSortKeyStr == KEDirsAnyOrder)
   1.404 +		{
   1.405 +		aSortKey = EDirsAnyOrder;
   1.406 +		}
   1.407 +	else if (aSortKeyStr == KEDirsFirst)
   1.408 +		{
   1.409 +		aSortKey = EDirsFirst;
   1.410 +		}
   1.411 +	else if (aSortKeyStr == KEDirsLast)
   1.412 +		{
   1.413 +		aSortKey = EDirsLast;
   1.414 +		}
   1.415 +	else if (aSortKeyStr == KEAscending)
   1.416 +		{
   1.417 +		aSortKey = EAscending;
   1.418 +		}
   1.419 +	else if (aSortKeyStr == KEDescending)
   1.420 +		{
   1.421 +		aSortKey = EDescending;
   1.422 +		}
   1.423 +	else if (aSortKeyStr == KEDirDescending)
   1.424 +		{
   1.425 +		aSortKey = EDirDescending;
   1.426 +		}
   1.427 +	else if (aSortKeyStr.Match((_L("*|*"))) != KErrNotFound)
   1.428 +		{
   1.429 +		TUint tmpSortKey;
   1.430 +
   1.431 +		TInt location = aSortKeyStr.Match(_L("*|*"));
   1.432 +		//Converting Left part of the data
   1.433 +		TPtrC left = aSortKeyStr.Left(location);
   1.434 +		if (ConvertToSortKey(left, tmpSortKey))
   1.435 +			{
   1.436 +			aSortKey = tmpSortKey;
   1.437 +			}
   1.438 +		else
   1.439 +			{
   1.440 +			ret = EFalse;
   1.441 +			}
   1.442 +
   1.443 +		//Converting right data can be with another "|"
   1.444 +		TPtrC right = aSortKeyStr.Mid(location + 1);
   1.445 +
   1.446 +		if (ConvertToSortKey(right, tmpSortKey))
   1.447 +			{
   1.448 +			aSortKey = aSortKey | tmpSortKey;
   1.449 +			}
   1.450 +		else
   1.451 +			{
   1.452 +			ret = EFalse;
   1.453 +			}
   1.454 +		}
   1.455 +	else
   1.456 +		{
   1.457 +		ret = EFalse;
   1.458 +		}
   1.459 +
   1.460 +	return ret;
   1.461 +	}
   1.462 +
   1.463 +
   1.464 +	
   1.465 +TBool CT_DirScanData::ConvertToScanDirection(const TDesC& aScanDirectionStr, CDirScan::TScanDirection& aScanDirection)
   1.466 +	{
   1.467 +	TBool ret = ETrue;
   1.468 +
   1.469 +	if (aScanDirectionStr == KEScanUpTree)
   1.470 +		{
   1.471 +		aScanDirection = CDirScan::EScanUpTree;
   1.472 +		}
   1.473 +	else if (aScanDirectionStr == KEScanDownTree)
   1.474 +		{
   1.475 +		aScanDirection = CDirScan::EScanDownTree;
   1.476 +		}
   1.477 +	else
   1.478 +		{
   1.479 +		ret = EFalse;
   1.480 +		}
   1.481 +
   1.482 +	return ret;
   1.483 +	}