os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_EntryData.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "T_EntryData.h"
    20 #include "T_SfSrvServer.h"
    21 #include "FileserverUtil.h"
    22 
    23 // Commands
    24 _LIT( KCmdAssignmentOperator,	"=" );
    25 _LIT( KCmdIndexOperator,		"[]" );
    26 _LIT( KCmdDelete,				"~" );
    27 _LIT( KCmdIsArchive,			"IsArchive" );
    28 _LIT( KCmdIsDir,				"IsDir" );
    29 _LIT( KCmdIsHidden,				"IsHidden" );
    30 _LIT( KCmdIsReadOnly,			"IsReadOnly" );
    31 _LIT( KCmdIsSystem,				"IsSystem" );
    32 _LIT( KCmdIsTypeValid,			"IsTypeValid" );
    33 _LIT( KCmdIsUidPresent,			"IsUidPresent" );
    34 _LIT( KCmdMostDerivedUid,		"MostDerivedUid" );
    35 _LIT( KCmdNew,					"new" );
    36 _LIT( KCmdSetAttribute,			"SetAttribute" );
    37 
    38 // Parameters
    39 _LIT( KParamAttribute,			"attribute" );
    40 _LIT( KParamObject,				"object" );
    41 _LIT( KExpected,				"expected" );
    42 _LIT( KParamIndex,				"index" );
    43 _LIT( KParamState,				"state" );
    44 _LIT( KValue,					"value" );
    45 
    46 // Attributes
    47 _LIT(KEntryAttNormalStr, 		"KEntryAttNormal");
    48 _LIT(KEntryAttReadOnlyStr, 		"KEntryAttReadOnly");
    49 _LIT(KEntryAttHiddenStr, 		"KEntryAttHidden");
    50 _LIT(KEntryAttSystemStr, 		"KEntryAttSystem");
    51 _LIT(KEntryAttVolumeStr,		"KEntryAttVolume");
    52 _LIT(KEntryAttDirStr, 			"KEntryAttDir");
    53 _LIT(KEntryAttArchiveStr, 		"KEntryAttArchive");
    54 _LIT(KEntryAttXIPStr, 			"KEntryAttXIP");
    55 
    56 
    57 // other string values
    58 #define KTimeFormatSize 		30
    59 
    60 
    61 CT_EntryData* CT_EntryData::NewL( )
    62 /**
    63 * Two phase constructor
    64 */
    65 	{
    66 	CT_EntryData* ret = new (ELeave) CT_EntryData( );
    67 	CleanupStack::PushL( ret );
    68 	ret->ConstructL();
    69 	CleanupStack::Pop( ret );
    70 	return ret;
    71 	}
    72 
    73 CT_EntryData::CT_EntryData( )
    74 :	iEntry(NULL)
    75 ,	iFs(NULL)	
    76 
    77 /**
    78 * Protected constructor. First phase construction
    79 */
    80 	{
    81 	}
    82 	
    83 void CT_EntryData::ConstructL()
    84 /**
    85 * Protected constructor. Second phase construction
    86 */
    87 	{
    88 	}
    89 	
    90 CT_EntryData::~CT_EntryData()
    91 /**
    92 * Destructor.
    93 */
    94 	{
    95 	DoCleanup();
    96 	}
    97 	
    98 void CT_EntryData::DoCleanup()
    99 /** Deltes TEntry class instance */
   100     {
   101 	INFO_PRINTF1( _L( "Delete TEntry class instance" ) );
   102 	delete iEntry;
   103 	iEntry = NULL;
   104     }
   105     
   106 TAny* CT_EntryData::GetObject()
   107 /**
   108 * Return a pointer to the object that the data wraps
   109 *
   110 * @return pointer to the object that the data wraps
   111 */
   112 	{
   113 	return iEntry;
   114 	}
   115 
   116 void CT_EntryData::SetObjectL( TAny* aAny )
   117 /**
   118 * Set the wrapped data object with new value
   119 */
   120 	{
   121 	DoCleanup();
   122 	iEntry = static_cast<TEntry*> ( aAny );
   123 	}
   124 
   125 void CT_EntryData::DisownObjectL()
   126 /**
   127 * Clear the wrapped data object pointer w/o de-initialization
   128 */
   129 	{
   130 	iEntry = NULL;
   131 	}
   132 	
   133 inline TCleanupOperation CT_EntryData::CleanupOperation()
   134 /**
   135 * Return static cleanup function
   136 */
   137 	{
   138 	return CleanupOperation;
   139 	}
   140 
   141 void CT_EntryData::CleanupOperation( TAny* aAny )
   142 /**
   143 * Static cleanup function
   144 */
   145 	{
   146 	TEntry* entry = static_cast<TEntry*> ( aAny );
   147 	delete entry;
   148 	}
   149 
   150 TBool CT_EntryData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   151 /**
   152 * Process a command read from the ini file
   153 *
   154 * @param aCommand	the command to process
   155 * @param aSection		the entry in the ini file requiring the command to be processed
   156 *
   157 * @return ETrue if the command is processed
   158 */
   159 	{
   160 	TBool retVal = ETrue;
   161 	
   162 	if ( aCommand == KCmdAssignmentOperator )
   163 		{
   164 		DoCmdAssignmentOperatorL( aSection );
   165 		}
   166 	else if ( aCommand == KCmdIndexOperator )
   167 		{
   168 		DoCmdIndexOperator( aSection );
   169 		}
   170 	else if ( aCommand == KCmdDelete )
   171 		{
   172 		DoCleanup();
   173 		}
   174 	else if ( aCommand == KCmdIsArchive )
   175 		{
   176 		DoCmdIsArchive( aSection );
   177 		}
   178 	else if ( aCommand == KCmdIsDir )
   179 		{
   180 		DoCmdIsDir( aSection );
   181 		}
   182 	else if ( aCommand == KCmdIsHidden )
   183 		{
   184 		DoCmdIsHidden( aSection );
   185 		}
   186 	else if ( aCommand == KCmdIsReadOnly )
   187 		{
   188 		DoCmdIsReadOnly( aSection );
   189 		}
   190 	else if ( aCommand == KCmdIsSystem )
   191 		{
   192 		DoCmdIsSystem( aSection );
   193 		}
   194 	else if ( aCommand == KCmdIsTypeValid )
   195 		{
   196 		DoCmdIsTypeValid( aSection );
   197 		}
   198 	else if ( aCommand == KCmdIsUidPresent )
   199 		{
   200 		DoCmdIsUidPresent( aSection );
   201 		}
   202 	else if ( aCommand == KCmdMostDerivedUid )
   203 		{
   204 		DoCmdMostDerived( aSection );
   205 		}
   206 	else if ( aCommand == KCmdNew )
   207 		{
   208 		DoCmdNew( aSection );
   209 		}
   210 	else if ( aCommand == KCmdSetAttribute )
   211 		{
   212 		DoCmdSetAttribute( aSection );
   213 		}
   214 	else
   215 	    {
   216 	    retVal = EFalse;    
   217 	    }
   218 	
   219 	return retVal;
   220 	}
   221 
   222 void CT_EntryData::DoCmdNew( const TDesC& aSection )
   223 /** Creates new TEntry class instance */
   224 	{
   225 	DoCleanup();
   226 	
   227 	TPtrC entryObjectName;	
   228 	if( GET_OPTIONAL_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) )
   229 		{
   230 		INFO_PRINTF1( _L( "Create new TEntry(TEntry) class instance." ) );
   231 		
   232 		TEntry* entryObject = NULL;
   233 		TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName));
   234 		if ( err == KErrNone )
   235 			{
   236 			TRAPD( err, iEntry = new (ELeave) TEntry(*entryObject) );
   237 			if ( err != KErrNone )
   238 				{
   239 				ERR_PRINTF2( _L( "new TEntry(TEntry) error %d" ), err );
   240 				SetError( err );
   241 				}
   242 			}
   243 		else
   244 			{
   245 			ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &entryObjectName, err );
   246 			SetBlockResult( EFail );
   247 			}
   248 		}
   249 	else
   250 		{
   251 		INFO_PRINTF1( _L( "Create new TEntry() class instance." ) );
   252 		TRAPD( err, iEntry = new (ELeave) TEntry() );
   253 		if ( err!=KErrNone )
   254 			{
   255 			ERR_PRINTF2( _L( "new TEntry() error %d" ), err );
   256 			SetError( err );
   257 			}
   258 		}
   259 	}
   260 	
   261 void CT_EntryData::DoCmdIndexOperator( const TDesC& aSection )
   262 /** Checks if the given UID is the same as required */
   263 	{
   264 	TInt iniIndex;	
   265 	if ( GET_MANDATORY_INT_PARAMETER( KParamIndex, aSection, iniIndex ) )
   266 		{
   267 		TInt value = (*iEntry)[iniIndex].iUid;
   268 		INFO_PRINTF3( _L( "UID[%d] = %d" ), iniIndex, value );		
   269 		
   270 		TInt iniExpected;
   271 		if ( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, iniExpected ) )
   272 			{			
   273 			if ( value != iniExpected )
   274 				{
   275 				INFO_PRINTF3( _L( "values not the same %d != %d" ), value, iniExpected );
   276 				SetBlockResult( EFail );
   277 				}
   278 			}
   279 		}
   280 	}
   281 	
   282 void CT_EntryData::DoCmdAssignmentOperatorL( const TDesC& aSection )
   283 /** Assigns another TEntry to this TEntry using "=" operator */
   284 	{
   285 	TPtrC entryObjectName;
   286 	if( GET_MANDATORY_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) )
   287 		{
   288 		INFO_PRINTF2( _L( "Assign a %S to this TEntry" ), &entryObjectName );
   289 		
   290 		TEntry* entryObject = NULL;
   291 		TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName));
   292 		if ( err == KErrNone && entryObject)
   293 			{
   294 			*iEntry = iEntry->operator=(*entryObject);
   295 			}
   296 		else
   297 			{
   298 			ERR_PRINTF3( _L( "Object not found or not initialised: %S. Error %d"), &entryObjectName, err );
   299 			SetBlockResult( EFail );
   300 			}
   301 		}
   302 
   303 	if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *iEntry))
   304 		{
   305 		SetBlockResult(EFail);
   306 		}
   307 	}
   308 	
   309 void CT_EntryData::DoCmdIsArchive( const TDesC& aSection )
   310 /** Checks if TEntry has Archive attribute using IsArchive() function */
   311 	{
   312 	INFO_PRINTF1( _L( "IsArchive()" ) );
   313 	TBool result = iEntry->IsArchive();
   314 		
   315 	TBool expected;
   316 	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   317 		{
   318 		if ( !( CompareBool(result, expected) ) )
   319 			{
   320 			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   321 			SetBlockResult(EFail);
   322 			}
   323 		}
   324 	}
   325 	
   326 void CT_EntryData::DoCmdIsDir( const TDesC& aSection )
   327 /** Checks if TEntry has Dir attribute using IsDir() function */
   328 	{
   329 	INFO_PRINTF1( _L( "IsDir()" ) );
   330 	TBool result = iEntry->IsDir();
   331 						
   332 	TBool expected;
   333 	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   334 		{
   335 		if ( !( CompareBool(result, expected) ) )
   336 			{
   337 			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   338 			SetBlockResult(EFail);
   339 			}
   340 		}
   341 	}
   342 	
   343 void CT_EntryData::DoCmdIsHidden( const TDesC& aSection )
   344 /** Checks if TEntry has Hidden attribute using IsHidden() function */
   345 	{
   346 	INFO_PRINTF1( _L( "IsHidden()" ) );
   347 	TBool result = iEntry->IsHidden();
   348 		
   349 	TBool expected;
   350 	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   351 		{
   352 		if ( !( CompareBool(result, expected) ) )
   353 			{
   354 			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   355 			SetBlockResult(EFail);
   356 			}
   357 		}
   358 	}
   359 
   360 void CT_EntryData::DoCmdIsReadOnly( const TDesC& aSection )
   361 /** Checks if TEntry has ReadOnly attribute using IsReadOnly() function */
   362 	{
   363 	INFO_PRINTF1( _L( "IsReadOnly()" ) );
   364 	TBool result = iEntry->IsReadOnly();
   365 		
   366 	TBool expected;
   367 	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   368 		{
   369 		if ( !( CompareBool(result, expected) ) )
   370 			{
   371 			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   372 			SetBlockResult(EFail);
   373 			}
   374 		}
   375 	}
   376 
   377 void CT_EntryData::DoCmdIsSystem( const TDesC& aSection )
   378 /** Checks if TEntry has System attribute using IsSystem() function */
   379 	{
   380 	INFO_PRINTF1( _L( "IsSystem()" ) );
   381 	TBool result = iEntry->IsSystem();
   382 	
   383 	TBool expected;
   384 	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   385 		{
   386 		if ( !( CompareBool(result, expected) ) )
   387 			{
   388 			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   389 			SetBlockResult(EFail);
   390 			}
   391 		}
   392 	}
   393 
   394 void CT_EntryData::DoCmdIsTypeValid( const TDesC& aSection )
   395 /** Checks if TEntry has a valid UID using IsTypeValid() function */
   396 	{
   397 	INFO_PRINTF1( _L( "IsTypeValid()" ) );
   398 	TBool result = iEntry->IsTypeValid();
   399 		
   400 	TBool expected;
   401 	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) )
   402 		{
   403 		if ( !( CompareBool(result, expected) ) )
   404 			{
   405 			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   406 			SetBlockResult(EFail);
   407 			}
   408 		}
   409 	}
   410 	
   411 void CT_EntryData::DoCmdIsUidPresent( const TDesC& aSection )
   412 /** Checks if TEntry has a valid UID using IsTypeValid() function */
   413 	{
   414 	TInt theIntUid;
   415 	TBool expected;
   416 	if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) &&
   417 		GET_MANDATORY_INT_PARAMETER( KValue, aSection, theIntUid ) )
   418 		{
   419 		INFO_PRINTF2( _L( "IsUidPresent( Uid(%d) )" ), theIntUid );
   420 		TUid theUid;
   421 		theUid.iUid = theIntUid;
   422 		
   423 		TBool result = iEntry->IsUidPresent( theUid );
   424 		
   425 		if ( !( CompareBool(result, expected) ) )
   426 			{
   427 			ERR_PRINTF1( _L( "Error compare function result and expected value" ));
   428 			SetBlockResult(EFail);
   429 			}
   430 		}
   431 	}
   432 
   433 void CT_EntryData::DoCmdMostDerived( const TDesC& aSection )
   434 /** checks if UID with given index is the same as the most derived one by using MostDerived() function */
   435 	{
   436 	TInt id = iEntry->MostDerivedUid().iUid;		
   437 	INFO_PRINTF2( _L( "MostDerivedUid = %d" ), id);
   438 		
   439 	TInt expected;
   440 	if( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, expected ) )
   441 		{		
   442 		if ( expected  != id )
   443 			{
   444 			ERR_PRINTF3( _L( "Error compare UID %d != expected %d" ), id, expected );
   445 			SetBlockResult( EFail );
   446 			}
   447 		}
   448 	}
   449 	
   450 void CT_EntryData::DoCmdSetAttribute( const TDesC& aSection )
   451 /** Sets or resets attributes */
   452 	{
   453 	TPtrC attrName;
   454 	TBool attrState;	
   455 	if( GET_MANDATORY_BOOL_PARAMETER( KParamState, aSection, attrState ) &&
   456 		GET_MANDATORY_STRING_PARAMETER( KParamAttribute, aSection, attrName ) )
   457 		{
   458 		TBool errHappened = EFalse;
   459 		TUint attr;
   460 		if (attrName == KEntryAttNormalStr)
   461 			{
   462 			attr = KEntryAttNormal;
   463 			}
   464 		else if (attrName == KEntryAttReadOnlyStr)
   465 			{
   466 			attr = KEntryAttReadOnly;
   467 			}
   468 		else if (attrName == KEntryAttHiddenStr)
   469 			{
   470 			attr = KEntryAttHidden;
   471 			}
   472 		else if (attrName == KEntryAttSystemStr)
   473 			{
   474 			attr = KEntryAttSystem;
   475 			}
   476 		else if (attrName == KEntryAttVolumeStr)
   477 			{
   478 			attr = KEntryAttVolume;
   479 			}
   480 		else if (attrName == KEntryAttDirStr)
   481 			{
   482 			attr = KEntryAttDir;
   483 			}
   484 		else if (attrName == KEntryAttArchiveStr)
   485 			{
   486 			attr = KEntryAttArchive;
   487 			}
   488 		else if (attrName == KEntryAttXIPStr)
   489 			{
   490 			attr = KEntryAttXIP;
   491 			}
   492 		else
   493 			{
   494 			errHappened = ETrue;
   495 			}
   496 			
   497 		if ( errHappened )
   498 			{
   499 			ERR_PRINTF2( _L( "Unknown attribute name parameter: %S" ), &attrName );
   500 			SetBlockResult( EFail );
   501 			}
   502 		else
   503 			{
   504 			TPtrC attrStateString;
   505 			GET_MANDATORY_STRING_PARAMETER( KParamState, aSection, attrStateString );
   506 			INFO_PRINTF3( _L( "SetAttribute(%S, %S)" ),  &attrName, &attrStateString);
   507 			
   508 			if ( attrState ) // set attribute
   509 				{
   510 				iEntry->iAtt = iEntry->iAtt | attr;
   511 				}
   512 			else // reset attribute
   513 				{
   514 				iEntry->iAtt = iEntry->iAtt ^ ( iEntry->iAtt & attr );
   515 				}
   516 			}
   517 		}
   518 	}
   519 
   520 
   521 TBool CT_EntryData::CompareBool( TBool aResult, TBool aExpected )
   522 /** compare 2 TBool values, which can be !=0 and !=1 - some TEntry functions return 2, 3 etc */
   523 	{
   524 	return ( ( aResult > 0 ) == ( aExpected > 0 ) );
   525 	}
   526