os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_EntryData.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_EntryData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,526 @@
     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 +#include "T_EntryData.h"
    1.23 +#include "T_SfSrvServer.h"
    1.24 +#include "FileserverUtil.h"
    1.25 +
    1.26 +// Commands
    1.27 +_LIT( KCmdAssignmentOperator,	"=" );
    1.28 +_LIT( KCmdIndexOperator,		"[]" );
    1.29 +_LIT( KCmdDelete,				"~" );
    1.30 +_LIT( KCmdIsArchive,			"IsArchive" );
    1.31 +_LIT( KCmdIsDir,				"IsDir" );
    1.32 +_LIT( KCmdIsHidden,				"IsHidden" );
    1.33 +_LIT( KCmdIsReadOnly,			"IsReadOnly" );
    1.34 +_LIT( KCmdIsSystem,				"IsSystem" );
    1.35 +_LIT( KCmdIsTypeValid,			"IsTypeValid" );
    1.36 +_LIT( KCmdIsUidPresent,			"IsUidPresent" );
    1.37 +_LIT( KCmdMostDerivedUid,		"MostDerivedUid" );
    1.38 +_LIT( KCmdNew,					"new" );
    1.39 +_LIT( KCmdSetAttribute,			"SetAttribute" );
    1.40 +
    1.41 +// Parameters
    1.42 +_LIT( KParamAttribute,			"attribute" );
    1.43 +_LIT( KParamObject,				"object" );
    1.44 +_LIT( KExpected,				"expected" );
    1.45 +_LIT( KParamIndex,				"index" );
    1.46 +_LIT( KParamState,				"state" );
    1.47 +_LIT( KValue,					"value" );
    1.48 +
    1.49 +// Attributes
    1.50 +_LIT(KEntryAttNormalStr, 		"KEntryAttNormal");
    1.51 +_LIT(KEntryAttReadOnlyStr, 		"KEntryAttReadOnly");
    1.52 +_LIT(KEntryAttHiddenStr, 		"KEntryAttHidden");
    1.53 +_LIT(KEntryAttSystemStr, 		"KEntryAttSystem");
    1.54 +_LIT(KEntryAttVolumeStr,		"KEntryAttVolume");
    1.55 +_LIT(KEntryAttDirStr, 			"KEntryAttDir");
    1.56 +_LIT(KEntryAttArchiveStr, 		"KEntryAttArchive");
    1.57 +_LIT(KEntryAttXIPStr, 			"KEntryAttXIP");
    1.58 +
    1.59 +
    1.60 +// other string values
    1.61 +#define KTimeFormatSize 		30
    1.62 +
    1.63 +
    1.64 +CT_EntryData* CT_EntryData::NewL( )
    1.65 +/**
    1.66 +* Two phase constructor
    1.67 +*/
    1.68 +	{
    1.69 +	CT_EntryData* ret = new (ELeave) CT_EntryData( );
    1.70 +	CleanupStack::PushL( ret );
    1.71 +	ret->ConstructL();
    1.72 +	CleanupStack::Pop( ret );
    1.73 +	return ret;
    1.74 +	}
    1.75 +
    1.76 +CT_EntryData::CT_EntryData( )
    1.77 +:	iEntry(NULL)
    1.78 +,	iFs(NULL)	
    1.79 +
    1.80 +/**
    1.81 +* Protected constructor. First phase construction
    1.82 +*/
    1.83 +	{
    1.84 +	}
    1.85 +	
    1.86 +void CT_EntryData::ConstructL()
    1.87 +/**
    1.88 +* Protected constructor. Second phase construction
    1.89 +*/
    1.90 +	{
    1.91 +	}
    1.92 +	
    1.93 +CT_EntryData::~CT_EntryData()
    1.94 +/**
    1.95 +* Destructor.
    1.96 +*/
    1.97 +	{
    1.98 +	DoCleanup();
    1.99 +	}
   1.100 +	
   1.101 +void CT_EntryData::DoCleanup()
   1.102 +/** Deltes TEntry class instance */
   1.103 +    {
   1.104 +	INFO_PRINTF1( _L( "Delete TEntry class instance" ) );
   1.105 +	delete iEntry;
   1.106 +	iEntry = NULL;
   1.107 +    }
   1.108 +    
   1.109 +TAny* CT_EntryData::GetObject()
   1.110 +/**
   1.111 +* Return a pointer to the object that the data wraps
   1.112 +*
   1.113 +* @return pointer to the object that the data wraps
   1.114 +*/
   1.115 +	{
   1.116 +	return iEntry;
   1.117 +	}
   1.118 +
   1.119 +void CT_EntryData::SetObjectL( TAny* aAny )
   1.120 +/**
   1.121 +* Set the wrapped data object with new value
   1.122 +*/
   1.123 +	{
   1.124 +	DoCleanup();
   1.125 +	iEntry = static_cast<TEntry*> ( aAny );
   1.126 +	}
   1.127 +
   1.128 +void CT_EntryData::DisownObjectL()
   1.129 +/**
   1.130 +* Clear the wrapped data object pointer w/o de-initialization
   1.131 +*/
   1.132 +	{
   1.133 +	iEntry = NULL;
   1.134 +	}
   1.135 +	
   1.136 +inline TCleanupOperation CT_EntryData::CleanupOperation()
   1.137 +/**
   1.138 +* Return static cleanup function
   1.139 +*/
   1.140 +	{
   1.141 +	return CleanupOperation;
   1.142 +	}
   1.143 +
   1.144 +void CT_EntryData::CleanupOperation( TAny* aAny )
   1.145 +/**
   1.146 +* Static cleanup function
   1.147 +*/
   1.148 +	{
   1.149 +	TEntry* entry = static_cast<TEntry*> ( aAny );
   1.150 +	delete entry;
   1.151 +	}
   1.152 +
   1.153 +TBool CT_EntryData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   1.154 +/**
   1.155 +* Process a command read from the ini file
   1.156 +*
   1.157 +* @param aCommand	the command to process
   1.158 +* @param aSection		the entry in the ini file requiring the command to be processed
   1.159 +*
   1.160 +* @return ETrue if the command is processed
   1.161 +*/
   1.162 +	{
   1.163 +	TBool retVal = ETrue;
   1.164 +	
   1.165 +	if ( aCommand == KCmdAssignmentOperator )
   1.166 +		{
   1.167 +		DoCmdAssignmentOperatorL( aSection );
   1.168 +		}
   1.169 +	else if ( aCommand == KCmdIndexOperator )
   1.170 +		{
   1.171 +		DoCmdIndexOperator( aSection );
   1.172 +		}
   1.173 +	else if ( aCommand == KCmdDelete )
   1.174 +		{
   1.175 +		DoCleanup();
   1.176 +		}
   1.177 +	else if ( aCommand == KCmdIsArchive )
   1.178 +		{
   1.179 +		DoCmdIsArchive( aSection );
   1.180 +		}
   1.181 +	else if ( aCommand == KCmdIsDir )
   1.182 +		{
   1.183 +		DoCmdIsDir( aSection );
   1.184 +		}
   1.185 +	else if ( aCommand == KCmdIsHidden )
   1.186 +		{
   1.187 +		DoCmdIsHidden( aSection );
   1.188 +		}
   1.189 +	else if ( aCommand == KCmdIsReadOnly )
   1.190 +		{
   1.191 +		DoCmdIsReadOnly( aSection );
   1.192 +		}
   1.193 +	else if ( aCommand == KCmdIsSystem )
   1.194 +		{
   1.195 +		DoCmdIsSystem( aSection );
   1.196 +		}
   1.197 +	else if ( aCommand == KCmdIsTypeValid )
   1.198 +		{
   1.199 +		DoCmdIsTypeValid( aSection );
   1.200 +		}
   1.201 +	else if ( aCommand == KCmdIsUidPresent )
   1.202 +		{
   1.203 +		DoCmdIsUidPresent( aSection );
   1.204 +		}
   1.205 +	else if ( aCommand == KCmdMostDerivedUid )
   1.206 +		{
   1.207 +		DoCmdMostDerived( aSection );
   1.208 +		}
   1.209 +	else if ( aCommand == KCmdNew )
   1.210 +		{
   1.211 +		DoCmdNew( aSection );
   1.212 +		}
   1.213 +	else if ( aCommand == KCmdSetAttribute )
   1.214 +		{
   1.215 +		DoCmdSetAttribute( aSection );
   1.216 +		}
   1.217 +	else
   1.218 +	    {
   1.219 +	    retVal = EFalse;    
   1.220 +	    }
   1.221 +	
   1.222 +	return retVal;
   1.223 +	}
   1.224 +
   1.225 +void CT_EntryData::DoCmdNew( const TDesC& aSection )
   1.226 +/** Creates new TEntry class instance */
   1.227 +	{
   1.228 +	DoCleanup();
   1.229 +	
   1.230 +	TPtrC entryObjectName;	
   1.231 +	if( GET_OPTIONAL_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) )
   1.232 +		{
   1.233 +		INFO_PRINTF1( _L( "Create new TEntry(TEntry) class instance." ) );
   1.234 +		
   1.235 +		TEntry* entryObject = NULL;
   1.236 +		TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName));
   1.237 +		if ( err == KErrNone )
   1.238 +			{
   1.239 +			TRAPD( err, iEntry = new (ELeave) TEntry(*entryObject) );
   1.240 +			if ( err != KErrNone )
   1.241 +				{
   1.242 +				ERR_PRINTF2( _L( "new TEntry(TEntry) error %d" ), err );
   1.243 +				SetError( err );
   1.244 +				}
   1.245 +			}
   1.246 +		else
   1.247 +			{
   1.248 +			ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &entryObjectName, err );
   1.249 +			SetBlockResult( EFail );
   1.250 +			}
   1.251 +		}
   1.252 +	else
   1.253 +		{
   1.254 +		INFO_PRINTF1( _L( "Create new TEntry() class instance." ) );
   1.255 +		TRAPD( err, iEntry = new (ELeave) TEntry() );
   1.256 +		if ( err!=KErrNone )
   1.257 +			{
   1.258 +			ERR_PRINTF2( _L( "new TEntry() error %d" ), err );
   1.259 +			SetError( err );
   1.260 +			}
   1.261 +		}
   1.262 +	}
   1.263 +	
   1.264 +void CT_EntryData::DoCmdIndexOperator( const TDesC& aSection )
   1.265 +/** Checks if the given UID is the same as required */
   1.266 +	{
   1.267 +	TInt iniIndex;	
   1.268 +	if ( GET_MANDATORY_INT_PARAMETER( KParamIndex, aSection, iniIndex ) )
   1.269 +		{
   1.270 +		TInt value = (*iEntry)[iniIndex].iUid;
   1.271 +		INFO_PRINTF3( _L( "UID[%d] = %d" ), iniIndex, value );		
   1.272 +		
   1.273 +		TInt iniExpected;
   1.274 +		if ( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, iniExpected ) )
   1.275 +			{			
   1.276 +			if ( value != iniExpected )
   1.277 +				{
   1.278 +				INFO_PRINTF3( _L( "values not the same %d != %d" ), value, iniExpected );
   1.279 +				SetBlockResult( EFail );
   1.280 +				}
   1.281 +			}
   1.282 +		}
   1.283 +	}
   1.284 +	
   1.285 +void CT_EntryData::DoCmdAssignmentOperatorL( const TDesC& aSection )
   1.286 +/** Assigns another TEntry to this TEntry using "=" operator */
   1.287 +	{
   1.288 +	TPtrC entryObjectName;
   1.289 +	if( GET_MANDATORY_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) )
   1.290 +		{
   1.291 +		INFO_PRINTF2( _L( "Assign a %S to this TEntry" ), &entryObjectName );
   1.292 +		
   1.293 +		TEntry* entryObject = NULL;
   1.294 +		TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName));
   1.295 +		if ( err == KErrNone && entryObject)
   1.296 +			{
   1.297 +			*iEntry = iEntry->operator=(*entryObject);
   1.298 +			}
   1.299 +		else
   1.300 +			{
   1.301 +			ERR_PRINTF3( _L( "Object not found or not initialised: %S. Error %d"), &entryObjectName, err );
   1.302 +			SetBlockResult( EFail );
   1.303 +			}
   1.304 +		}
   1.305 +
   1.306 +	if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *iEntry))
   1.307 +		{
   1.308 +		SetBlockResult(EFail);
   1.309 +		}
   1.310 +	}
   1.311 +	
   1.312 +void CT_EntryData::DoCmdIsArchive( const TDesC& aSection )
   1.313 +/** Checks if TEntry has Archive attribute using IsArchive() function */
   1.314 +	{
   1.315 +	INFO_PRINTF1( _L( "IsArchive()" ) );
   1.316 +	TBool result = iEntry->IsArchive();
   1.317 +		
   1.318 +	TBool expected;
   1.319 +	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   1.320 +		{
   1.321 +		if ( !( CompareBool(result, expected) ) )
   1.322 +			{
   1.323 +			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   1.324 +			SetBlockResult(EFail);
   1.325 +			}
   1.326 +		}
   1.327 +	}
   1.328 +	
   1.329 +void CT_EntryData::DoCmdIsDir( const TDesC& aSection )
   1.330 +/** Checks if TEntry has Dir attribute using IsDir() function */
   1.331 +	{
   1.332 +	INFO_PRINTF1( _L( "IsDir()" ) );
   1.333 +	TBool result = iEntry->IsDir();
   1.334 +						
   1.335 +	TBool expected;
   1.336 +	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   1.337 +		{
   1.338 +		if ( !( CompareBool(result, expected) ) )
   1.339 +			{
   1.340 +			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   1.341 +			SetBlockResult(EFail);
   1.342 +			}
   1.343 +		}
   1.344 +	}
   1.345 +	
   1.346 +void CT_EntryData::DoCmdIsHidden( const TDesC& aSection )
   1.347 +/** Checks if TEntry has Hidden attribute using IsHidden() function */
   1.348 +	{
   1.349 +	INFO_PRINTF1( _L( "IsHidden()" ) );
   1.350 +	TBool result = iEntry->IsHidden();
   1.351 +		
   1.352 +	TBool expected;
   1.353 +	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   1.354 +		{
   1.355 +		if ( !( CompareBool(result, expected) ) )
   1.356 +			{
   1.357 +			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   1.358 +			SetBlockResult(EFail);
   1.359 +			}
   1.360 +		}
   1.361 +	}
   1.362 +
   1.363 +void CT_EntryData::DoCmdIsReadOnly( const TDesC& aSection )
   1.364 +/** Checks if TEntry has ReadOnly attribute using IsReadOnly() function */
   1.365 +	{
   1.366 +	INFO_PRINTF1( _L( "IsReadOnly()" ) );
   1.367 +	TBool result = iEntry->IsReadOnly();
   1.368 +		
   1.369 +	TBool expected;
   1.370 +	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   1.371 +		{
   1.372 +		if ( !( CompareBool(result, expected) ) )
   1.373 +			{
   1.374 +			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   1.375 +			SetBlockResult(EFail);
   1.376 +			}
   1.377 +		}
   1.378 +	}
   1.379 +
   1.380 +void CT_EntryData::DoCmdIsSystem( const TDesC& aSection )
   1.381 +/** Checks if TEntry has System attribute using IsSystem() function */
   1.382 +	{
   1.383 +	INFO_PRINTF1( _L( "IsSystem()" ) );
   1.384 +	TBool result = iEntry->IsSystem();
   1.385 +	
   1.386 +	TBool expected;
   1.387 +	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   1.388 +		{
   1.389 +		if ( !( CompareBool(result, expected) ) )
   1.390 +			{
   1.391 +			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   1.392 +			SetBlockResult(EFail);
   1.393 +			}
   1.394 +		}
   1.395 +	}
   1.396 +
   1.397 +void CT_EntryData::DoCmdIsTypeValid( const TDesC& aSection )
   1.398 +/** Checks if TEntry has a valid UID using IsTypeValid() function */
   1.399 +	{
   1.400 +	INFO_PRINTF1( _L( "IsTypeValid()" ) );
   1.401 +	TBool result = iEntry->IsTypeValid();
   1.402 +		
   1.403 +	TBool expected;
   1.404 +	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   1.405 +		{
   1.406 +		if ( !( CompareBool(result, expected) ) )
   1.407 +			{
   1.408 +			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   1.409 +			SetBlockResult(EFail);
   1.410 +			}
   1.411 +		}
   1.412 +	}
   1.413 +	
   1.414 +void CT_EntryData::DoCmdIsUidPresent( const TDesC& aSection )
   1.415 +/** Checks if TEntry has a valid UID using IsTypeValid() function */
   1.416 +	{
   1.417 +	TInt theIntUid;
   1.418 +	TBool expected;
   1.419 +	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) &&
   1.420 +		GET_MANDATORY_INT_PARAMETER( KValue, aSection, theIntUid ) )
   1.421 +		{
   1.422 +		INFO_PRINTF2( _L( "IsUidPresent( Uid(%d) )" ), theIntUid );
   1.423 +		TUid theUid;
   1.424 +		theUid.iUid = theIntUid;
   1.425 +		
   1.426 +		TBool result = iEntry->IsUidPresent( theUid );
   1.427 +		
   1.428 +		if ( !( CompareBool(result, expected) ) )
   1.429 +			{
   1.430 +			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   1.431 +			SetBlockResult(EFail);
   1.432 +			}
   1.433 +		}
   1.434 +	}
   1.435 +
   1.436 +void CT_EntryData::DoCmdMostDerived( const TDesC& aSection )
   1.437 +/** checks if UID with given index is the same as the most derived one by using MostDerived() function */
   1.438 +	{
   1.439 +	TInt id = iEntry->MostDerivedUid().iUid;		
   1.440 +	INFO_PRINTF2( _L( "MostDerivedUid = %d" ), id);
   1.441 +		
   1.442 +	TInt expected;
   1.443 +	if( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, expected ) )
   1.444 +		{		
   1.445 +		if ( expected  != id )
   1.446 +			{
   1.447 +			ERR_PRINTF3( _L( "Error compare UID %d != expected %d" ), id, expected );
   1.448 +			SetBlockResult( EFail );
   1.449 +			}
   1.450 +		}
   1.451 +	}
   1.452 +	
   1.453 +void CT_EntryData::DoCmdSetAttribute( const TDesC& aSection )
   1.454 +/** Sets or resets attributes */
   1.455 +	{
   1.456 +	TPtrC attrName;
   1.457 +	TBool attrState;	
   1.458 +	if( GET_MANDATORY_BOOL_PARAMETER( KParamState, aSection, attrState ) &&
   1.459 +		GET_MANDATORY_STRING_PARAMETER( KParamAttribute, aSection, attrName ) )
   1.460 +		{
   1.461 +		TBool errHappened = EFalse;
   1.462 +		TUint attr;
   1.463 +		if (attrName == KEntryAttNormalStr)
   1.464 +			{
   1.465 +			attr = KEntryAttNormal;
   1.466 +			}
   1.467 +		else if (attrName == KEntryAttReadOnlyStr)
   1.468 +			{
   1.469 +			attr = KEntryAttReadOnly;
   1.470 +			}
   1.471 +		else if (attrName == KEntryAttHiddenStr)
   1.472 +			{
   1.473 +			attr = KEntryAttHidden;
   1.474 +			}
   1.475 +		else if (attrName == KEntryAttSystemStr)
   1.476 +			{
   1.477 +			attr = KEntryAttSystem;
   1.478 +			}
   1.479 +		else if (attrName == KEntryAttVolumeStr)
   1.480 +			{
   1.481 +			attr = KEntryAttVolume;
   1.482 +			}
   1.483 +		else if (attrName == KEntryAttDirStr)
   1.484 +			{
   1.485 +			attr = KEntryAttDir;
   1.486 +			}
   1.487 +		else if (attrName == KEntryAttArchiveStr)
   1.488 +			{
   1.489 +			attr = KEntryAttArchive;
   1.490 +			}
   1.491 +		else if (attrName == KEntryAttXIPStr)
   1.492 +			{
   1.493 +			attr = KEntryAttXIP;
   1.494 +			}
   1.495 +		else
   1.496 +			{
   1.497 +			errHappened = ETrue;
   1.498 +			}
   1.499 +			
   1.500 +		if ( errHappened )
   1.501 +			{
   1.502 +			ERR_PRINTF2( _L( "Unknown attribute name parameter: %S" ), &attrName );
   1.503 +			SetBlockResult( EFail );
   1.504 +			}
   1.505 +		else
   1.506 +			{
   1.507 +			TPtrC attrStateString;
   1.508 +			GET_MANDATORY_STRING_PARAMETER( KParamState, aSection, attrStateString );
   1.509 +			INFO_PRINTF3( _L( "SetAttribute(%S, %S)" ),  &attrName, &attrStateString);
   1.510 +			
   1.511 +			if ( attrState ) // set attribute
   1.512 +				{
   1.513 +				iEntry->iAtt = iEntry->iAtt | attr;
   1.514 +				}
   1.515 +			else // reset attribute
   1.516 +				{
   1.517 +				iEntry->iAtt = iEntry->iAtt ^ ( iEntry->iAtt & attr );
   1.518 +				}
   1.519 +			}
   1.520 +		}
   1.521 +	}
   1.522 +
   1.523 +
   1.524 +TBool CT_EntryData::CompareBool( TBool aResult, TBool aExpected )
   1.525 +/** compare 2 TBool values, which can be !=0 and !=1 - some TEntry functions return 2, 3 etc */
   1.526 +	{
   1.527 +	return ( ( aResult > 0 ) == ( aExpected > 0 ) );
   1.528 +	}
   1.529 +