os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DirData.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 /**
    20 @test
    21 @internalComponent
    22 v
    23 This contains CT_DirData
    24 */
    25 
    26 //	User includes
    27 #include "T_DirData.h"
    28 #include "T_SfSrvServer.h"
    29 
    30 /*@{*/
    31 ///	Parameters
    32 _LIT(KArrayElementNumber,						"element_number");
    33 _LIT(KExpected,									"expected");
    34 _LIT(KSortkey,									"sortkey");
    35 _LIT(KNumSortkey,								"numsortkey");
    36 _LIT(KEntryObject,								"entryObject");
    37 
    38 ///Commands
    39 _LIT(KCmdCount,									"Count");
    40 _LIT(KCmdOperatorBrackets,						"[]");
    41 _LIT(KCmdSort,									"Sort");
    42 _LIT(KCmdDestructor,							"~");
    43 
    44 
    45 //Sort keys
    46 _LIT(KESortNone,								"ESortNone");
    47 _LIT(KESortByName,								"ESortByName");
    48 _LIT(KESortByExt,								"ESortByExt");
    49 _LIT(KESortBySize,								"ESortBySize");
    50 _LIT(KESortByDate,								"ESortByDate");
    51 _LIT(KESortByUid,								"ESortByUid");
    52 _LIT(KEDirsAnyOrder,							"EDirsAnyOrder");
    53 _LIT(KEDirsFirst,								"EDirsFirst");
    54 _LIT(KEDirsLast,								"EDirsLast");
    55 _LIT(KEAscending,								"EAscending");
    56 _LIT(KEDescending,								"EDescending");
    57 _LIT(KEDirDescending,							"EDirDescending");
    58 
    59 
    60 CT_DirData* CT_DirData::NewL()
    61 /**
    62 * Two phase constructor
    63 */
    64 	{
    65 	CT_DirData* ret = new (ELeave) CT_DirData();
    66 	CleanupStack::PushL(ret);
    67 	ret->ConstructL();
    68 	CleanupStack::Pop(ret);
    69 	return ret;
    70 	}
    71 
    72 
    73 CT_DirData::CT_DirData()
    74 :	iDir(NULL)
    75 /**
    76 * Protected constructor. First phase construction
    77 */
    78 	{
    79 	}
    80 
    81 
    82 void CT_DirData::ConstructL()
    83 /**
    84 * Protected constructor. Second phase construction
    85 */
    86 	{
    87 	}
    88 
    89 
    90 CT_DirData::~CT_DirData()
    91 /**
    92 * Destructor.
    93 */
    94 	{
    95 	DoCleanup();
    96 	}
    97 
    98 
    99 TAny* CT_DirData::GetObject()
   100 	{
   101 	return iDir;
   102 	}
   103 	
   104 	
   105 void CT_DirData::SetObjectL(TAny* aAny)
   106 	{
   107 	DoCleanup();
   108 	iDir = static_cast<CDir*> (aAny);
   109 	}
   110 
   111 
   112 void CT_DirData::DisownObjectL()
   113 	{
   114 	iDir = NULL;
   115 	}
   116 	
   117 	
   118 inline TCleanupOperation CT_DirData::CleanupOperation()
   119 	{
   120 	return CleanupOperation;
   121 	}
   122 
   123 
   124 void CT_DirData::CleanupOperation(TAny* aAny)
   125 	{
   126 	CDir* dir=static_cast<CDir*>(aAny);
   127 	delete dir;
   128 	}
   129 
   130 
   131 TBool CT_DirData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   132 /**
   133 * Process a command read from the ini file
   134 *
   135 * @param aCommand	the command to process
   136 * @param aSection	the entry in the ini file requiring the command to be processed
   137 *
   138 * @return ETrue if the command is processed
   139 */
   140 	{
   141 	TBool retVal = ETrue;
   142 
   143 	if (aCommand == KCmdCount)
   144 		{
   145 		DoCmdCount(aSection);
   146 		}
   147 	else if (aCommand == KCmdOperatorBrackets)
   148 		{
   149 		DoCmdOperatorBracketsL(aSection);
   150 		}
   151 	else if (aCommand == KCmdSort)
   152 		{
   153 		DoCmdSort(aSection);
   154 		}
   155 	else if (aCommand == KCmdDestructor)
   156 		{
   157 		DoCleanup();
   158 		}
   159 	else
   160 		{
   161 		retVal = EFalse;
   162 		}
   163 	return retVal;
   164 	}
   165 
   166 
   167 void CT_DirData::DoCleanup()
   168 	{
   169 	INFO_PRINTF1(_L("Doing cleanup"));
   170 	if (iDir)
   171 		{
   172 		delete iDir;
   173 		iDir = NULL;
   174 		}
   175 	}
   176 	
   177 void CT_DirData::DoCmdCount(const TDesC& aSection)
   178 	{
   179 	INFO_PRINTF1(_L("Counts directory entries!"));
   180 	
   181 	TInt	expected;
   182 	if (GET_MANDATORY_INT_PARAMETER(KExpected, aSection, expected))
   183 		{
   184 		TInt count = iDir->Count();
   185 		if (count != expected)
   186 			{
   187 			ERR_PRINTF3(_L("Result didn't match with expected result! COUNT: %d, expected: %d"), count, expected);
   188 			SetBlockResult(EFail);
   189 			}
   190 		else
   191 			{
   192 			INFO_PRINTF2(_L("Result matched with expected result (%d)!"), count);
   193 			}
   194 		}
   195 	}
   196 	
   197 	
   198 void CT_DirData::DoCmdOperatorBracketsL(const TDesC& aSection)
   199 	{
   200 	INFO_PRINTF1(_L("Getting element and compare it with expected!"));
   201 	
   202 	TInt	elementNumber;
   203 		
   204 	if (GET_MANDATORY_INT_PARAMETER(KArrayElementNumber, aSection, elementNumber))
   205 		{
   206         INFO_PRINTF2( _L( "Get element[%d]" ), elementNumber);
   207 		TEntry* entryObject = new(ELeave) TEntry();
   208 		CleanupStack::PushL(entryObject);
   209 		
   210 		*entryObject = iDir->operator[](elementNumber);
   211 
   212 	    if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *entryObject))
   213    		    {
   214    		    SetBlockResult(EFail);
   215    		    }
   216     		    
   217 		TPtrC	entryObjectName;
   218 		if (GET_OPTIONAL_STRING_PARAMETER(KEntryObject, aSection, entryObjectName))
   219 			{
   220 			CT_EntryData* entryWrapperObject = static_cast<CT_EntryData*>(GetDataWrapperL(entryObjectName));
   221 		    if(entryWrapperObject)
   222 				{
   223 				entryWrapperObject->SetObjectL(entryObject);
   224 				entryObject = NULL;
   225 				}
   226 			else
   227 				{
   228 				SetBlockResult(EFail);
   229 				}
   230 			}
   231 			
   232 		CleanupStack::Pop();
   233 		delete entryObject;
   234 		entryObject = NULL;
   235 		}
   236 	}	
   237    	
   238 void CT_DirData::DoCmdSort(const TDesC& aSection)
   239 	{
   240 	INFO_PRINTF1(_L("Sorting directory entries!"));
   241 	
   242 	TPtrC	sortKey;
   243 		
   244 	if (GET_OPTIONAL_STRING_PARAMETER(KSortkey, aSection, sortKey))
   245 		{	
   246 		TUint fixedKey = 0;
   247 		
   248 		if ( !ConvertSortKeys(sortKey, fixedKey) )
   249 			{
   250 			ERR_PRINTF2(_L("Given sortkey (%S) is invalid"), &sortKey);
   251 			SetBlockResult(EFail);
   252 			}
   253 					
   254 		TInt err = iDir->Sort(fixedKey);
   255 		
   256 		if (err != KErrNone)
   257 			{
   258 			ERR_PRINTF2(_L("Directory entries have not been sorted! Error code = %d"), err);
   259 			SetError(err);
   260 			}
   261 		else
   262 			{
   263 			INFO_PRINTF1(_L("Directory entries have been sorted!"));
   264 			}
   265 		}
   266 	else
   267 		{
   268 		TInt	numSortKey;
   269 		if (GET_MANDATORY_INT_PARAMETER(KNumSortkey, aSection, numSortKey))
   270 			{
   271 			TInt err = iDir->Sort(numSortKey);
   272 			
   273 			if (err != KErrNone)
   274 				{
   275 				ERR_PRINTF2(_L("Directory entries has not been sorted! Error code = %d"), err);
   276 				SetError(err);
   277 				}
   278 			else
   279 				{
   280 				INFO_PRINTF1(_L("Directory entries has been sorted!"));
   281 				}
   282 			}
   283 		}
   284 	INFO_PRINTF1(_L("Results after sorting!"));
   285 	for (TInt i = 0; i < iDir->Count(); i++)
   286 	    {
   287 		INFO_PRINTF3(_L("%d) %S"), i+1, &(*iDir)[i].iName);
   288 		}
   289 	}
   290 	
   291 TBool CT_DirData::ConvertSortKeys(TDesC &aConstantName, TUint& aSortKey)
   292 	{
   293 	
   294 	TBool ret = ETrue;
   295 	
   296 	if (aConstantName == KESortByName)
   297 		{
   298 		aSortKey = ESortByName;
   299 		}
   300 	else if (aConstantName == KESortByExt)
   301 		{
   302 		aSortKey = ESortByExt;
   303 		}
   304 	else if (aConstantName == KESortBySize)
   305 		{
   306 		aSortKey = ESortBySize;
   307 		}
   308 	else if (aConstantName == KESortByDate)
   309 		{
   310 		aSortKey = ESortByDate;
   311 		}
   312 	else if (aConstantName == KESortByUid)
   313 		{
   314 		aSortKey = ESortByUid;
   315 		}
   316 	else if (aConstantName == KEDirsAnyOrder)
   317 		{
   318 		aSortKey = EDirsAnyOrder;
   319 		}
   320 	else if (aConstantName == KEDirsFirst)
   321 		{
   322 		aSortKey = EDirsFirst;
   323 		}
   324 	else if (aConstantName == KEDirsLast)
   325 		{
   326 		aSortKey = EDirsLast;
   327 		}
   328 	else if (aConstantName == KEAscending)
   329 		{
   330 		aSortKey = EAscending;
   331 		}
   332 	else if (aConstantName == KEDescending)
   333 		{
   334 		aSortKey = EDescending;
   335 		}
   336 	else if (aConstantName == KEDirDescending)
   337 		{
   338 		aSortKey = EDirDescending;
   339 		}
   340 	else if (aConstantName == KESortNone)
   341 		{
   342 		aSortKey = ESortNone;
   343 		}
   344 	else
   345 		{
   346 		TInt	location = aConstantName.Match(_L("*|*"));
   347 		if( location != KErrNotFound )
   348 			{
   349 			//Converting Left part of the data
   350 			TPtrC	tempStr = aConstantName.Left(location);
   351 			ret = ConvertSortKeys(tempStr, aSortKey);
   352 
   353 			//Converting right data can be with another "|"
   354 			tempStr.Set(aConstantName.Mid(location + 1));
   355 
   356 			TUint	tmp;
   357 			if ( ConvertSortKeys(tempStr, tmp) )
   358 				{
   359 				aSortKey |= tmp;
   360 				}
   361 			else
   362 				{
   363 				ret = EFalse;
   364 				}
   365 			}
   366 		}
   367 
   368 	return ret;
   369 	}