1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DirData.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,369 @@
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_DirData
1.27 +*/
1.28 +
1.29 +// User includes
1.30 +#include "T_DirData.h"
1.31 +#include "T_SfSrvServer.h"
1.32 +
1.33 +/*@{*/
1.34 +/// Parameters
1.35 +_LIT(KArrayElementNumber, "element_number");
1.36 +_LIT(KExpected, "expected");
1.37 +_LIT(KSortkey, "sortkey");
1.38 +_LIT(KNumSortkey, "numsortkey");
1.39 +_LIT(KEntryObject, "entryObject");
1.40 +
1.41 +///Commands
1.42 +_LIT(KCmdCount, "Count");
1.43 +_LIT(KCmdOperatorBrackets, "[]");
1.44 +_LIT(KCmdSort, "Sort");
1.45 +_LIT(KCmdDestructor, "~");
1.46 +
1.47 +
1.48 +//Sort keys
1.49 +_LIT(KESortNone, "ESortNone");
1.50 +_LIT(KESortByName, "ESortByName");
1.51 +_LIT(KESortByExt, "ESortByExt");
1.52 +_LIT(KESortBySize, "ESortBySize");
1.53 +_LIT(KESortByDate, "ESortByDate");
1.54 +_LIT(KESortByUid, "ESortByUid");
1.55 +_LIT(KEDirsAnyOrder, "EDirsAnyOrder");
1.56 +_LIT(KEDirsFirst, "EDirsFirst");
1.57 +_LIT(KEDirsLast, "EDirsLast");
1.58 +_LIT(KEAscending, "EAscending");
1.59 +_LIT(KEDescending, "EDescending");
1.60 +_LIT(KEDirDescending, "EDirDescending");
1.61 +
1.62 +
1.63 +CT_DirData* CT_DirData::NewL()
1.64 +/**
1.65 +* Two phase constructor
1.66 +*/
1.67 + {
1.68 + CT_DirData* ret = new (ELeave) CT_DirData();
1.69 + CleanupStack::PushL(ret);
1.70 + ret->ConstructL();
1.71 + CleanupStack::Pop(ret);
1.72 + return ret;
1.73 + }
1.74 +
1.75 +
1.76 +CT_DirData::CT_DirData()
1.77 +: iDir(NULL)
1.78 +/**
1.79 +* Protected constructor. First phase construction
1.80 +*/
1.81 + {
1.82 + }
1.83 +
1.84 +
1.85 +void CT_DirData::ConstructL()
1.86 +/**
1.87 +* Protected constructor. Second phase construction
1.88 +*/
1.89 + {
1.90 + }
1.91 +
1.92 +
1.93 +CT_DirData::~CT_DirData()
1.94 +/**
1.95 +* Destructor.
1.96 +*/
1.97 + {
1.98 + DoCleanup();
1.99 + }
1.100 +
1.101 +
1.102 +TAny* CT_DirData::GetObject()
1.103 + {
1.104 + return iDir;
1.105 + }
1.106 +
1.107 +
1.108 +void CT_DirData::SetObjectL(TAny* aAny)
1.109 + {
1.110 + DoCleanup();
1.111 + iDir = static_cast<CDir*> (aAny);
1.112 + }
1.113 +
1.114 +
1.115 +void CT_DirData::DisownObjectL()
1.116 + {
1.117 + iDir = NULL;
1.118 + }
1.119 +
1.120 +
1.121 +inline TCleanupOperation CT_DirData::CleanupOperation()
1.122 + {
1.123 + return CleanupOperation;
1.124 + }
1.125 +
1.126 +
1.127 +void CT_DirData::CleanupOperation(TAny* aAny)
1.128 + {
1.129 + CDir* dir=static_cast<CDir*>(aAny);
1.130 + delete dir;
1.131 + }
1.132 +
1.133 +
1.134 +TBool CT_DirData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
1.135 +/**
1.136 +* Process a command read from the ini file
1.137 +*
1.138 +* @param aCommand the command to process
1.139 +* @param aSection the entry in the ini file requiring the command to be processed
1.140 +*
1.141 +* @return ETrue if the command is processed
1.142 +*/
1.143 + {
1.144 + TBool retVal = ETrue;
1.145 +
1.146 + if (aCommand == KCmdCount)
1.147 + {
1.148 + DoCmdCount(aSection);
1.149 + }
1.150 + else if (aCommand == KCmdOperatorBrackets)
1.151 + {
1.152 + DoCmdOperatorBracketsL(aSection);
1.153 + }
1.154 + else if (aCommand == KCmdSort)
1.155 + {
1.156 + DoCmdSort(aSection);
1.157 + }
1.158 + else if (aCommand == KCmdDestructor)
1.159 + {
1.160 + DoCleanup();
1.161 + }
1.162 + else
1.163 + {
1.164 + retVal = EFalse;
1.165 + }
1.166 + return retVal;
1.167 + }
1.168 +
1.169 +
1.170 +void CT_DirData::DoCleanup()
1.171 + {
1.172 + INFO_PRINTF1(_L("Doing cleanup"));
1.173 + if (iDir)
1.174 + {
1.175 + delete iDir;
1.176 + iDir = NULL;
1.177 + }
1.178 + }
1.179 +
1.180 +void CT_DirData::DoCmdCount(const TDesC& aSection)
1.181 + {
1.182 + INFO_PRINTF1(_L("Counts directory entries!"));
1.183 +
1.184 + TInt expected;
1.185 + if (GET_MANDATORY_INT_PARAMETER(KExpected, aSection, expected))
1.186 + {
1.187 + TInt count = iDir->Count();
1.188 + if (count != expected)
1.189 + {
1.190 + ERR_PRINTF3(_L("Result didn't match with expected result! COUNT: %d, expected: %d"), count, expected);
1.191 + SetBlockResult(EFail);
1.192 + }
1.193 + else
1.194 + {
1.195 + INFO_PRINTF2(_L("Result matched with expected result (%d)!"), count);
1.196 + }
1.197 + }
1.198 + }
1.199 +
1.200 +
1.201 +void CT_DirData::DoCmdOperatorBracketsL(const TDesC& aSection)
1.202 + {
1.203 + INFO_PRINTF1(_L("Getting element and compare it with expected!"));
1.204 +
1.205 + TInt elementNumber;
1.206 +
1.207 + if (GET_MANDATORY_INT_PARAMETER(KArrayElementNumber, aSection, elementNumber))
1.208 + {
1.209 + INFO_PRINTF2( _L( "Get element[%d]" ), elementNumber);
1.210 + TEntry* entryObject = new(ELeave) TEntry();
1.211 + CleanupStack::PushL(entryObject);
1.212 +
1.213 + *entryObject = iDir->operator[](elementNumber);
1.214 +
1.215 + if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *entryObject))
1.216 + {
1.217 + SetBlockResult(EFail);
1.218 + }
1.219 +
1.220 + TPtrC entryObjectName;
1.221 + if (GET_OPTIONAL_STRING_PARAMETER(KEntryObject, aSection, entryObjectName))
1.222 + {
1.223 + CT_EntryData* entryWrapperObject = static_cast<CT_EntryData*>(GetDataWrapperL(entryObjectName));
1.224 + if(entryWrapperObject)
1.225 + {
1.226 + entryWrapperObject->SetObjectL(entryObject);
1.227 + entryObject = NULL;
1.228 + }
1.229 + else
1.230 + {
1.231 + SetBlockResult(EFail);
1.232 + }
1.233 + }
1.234 +
1.235 + CleanupStack::Pop();
1.236 + delete entryObject;
1.237 + entryObject = NULL;
1.238 + }
1.239 + }
1.240 +
1.241 +void CT_DirData::DoCmdSort(const TDesC& aSection)
1.242 + {
1.243 + INFO_PRINTF1(_L("Sorting directory entries!"));
1.244 +
1.245 + TPtrC sortKey;
1.246 +
1.247 + if (GET_OPTIONAL_STRING_PARAMETER(KSortkey, aSection, sortKey))
1.248 + {
1.249 + TUint fixedKey = 0;
1.250 +
1.251 + if ( !ConvertSortKeys(sortKey, fixedKey) )
1.252 + {
1.253 + ERR_PRINTF2(_L("Given sortkey (%S) is invalid"), &sortKey);
1.254 + SetBlockResult(EFail);
1.255 + }
1.256 +
1.257 + TInt err = iDir->Sort(fixedKey);
1.258 +
1.259 + if (err != KErrNone)
1.260 + {
1.261 + ERR_PRINTF2(_L("Directory entries have not been sorted! Error code = %d"), err);
1.262 + SetError(err);
1.263 + }
1.264 + else
1.265 + {
1.266 + INFO_PRINTF1(_L("Directory entries have been sorted!"));
1.267 + }
1.268 + }
1.269 + else
1.270 + {
1.271 + TInt numSortKey;
1.272 + if (GET_MANDATORY_INT_PARAMETER(KNumSortkey, aSection, numSortKey))
1.273 + {
1.274 + TInt err = iDir->Sort(numSortKey);
1.275 +
1.276 + if (err != KErrNone)
1.277 + {
1.278 + ERR_PRINTF2(_L("Directory entries has not been sorted! Error code = %d"), err);
1.279 + SetError(err);
1.280 + }
1.281 + else
1.282 + {
1.283 + INFO_PRINTF1(_L("Directory entries has been sorted!"));
1.284 + }
1.285 + }
1.286 + }
1.287 + INFO_PRINTF1(_L("Results after sorting!"));
1.288 + for (TInt i = 0; i < iDir->Count(); i++)
1.289 + {
1.290 + INFO_PRINTF3(_L("%d) %S"), i+1, &(*iDir)[i].iName);
1.291 + }
1.292 + }
1.293 +
1.294 +TBool CT_DirData::ConvertSortKeys(TDesC &aConstantName, TUint& aSortKey)
1.295 + {
1.296 +
1.297 + TBool ret = ETrue;
1.298 +
1.299 + if (aConstantName == KESortByName)
1.300 + {
1.301 + aSortKey = ESortByName;
1.302 + }
1.303 + else if (aConstantName == KESortByExt)
1.304 + {
1.305 + aSortKey = ESortByExt;
1.306 + }
1.307 + else if (aConstantName == KESortBySize)
1.308 + {
1.309 + aSortKey = ESortBySize;
1.310 + }
1.311 + else if (aConstantName == KESortByDate)
1.312 + {
1.313 + aSortKey = ESortByDate;
1.314 + }
1.315 + else if (aConstantName == KESortByUid)
1.316 + {
1.317 + aSortKey = ESortByUid;
1.318 + }
1.319 + else if (aConstantName == KEDirsAnyOrder)
1.320 + {
1.321 + aSortKey = EDirsAnyOrder;
1.322 + }
1.323 + else if (aConstantName == KEDirsFirst)
1.324 + {
1.325 + aSortKey = EDirsFirst;
1.326 + }
1.327 + else if (aConstantName == KEDirsLast)
1.328 + {
1.329 + aSortKey = EDirsLast;
1.330 + }
1.331 + else if (aConstantName == KEAscending)
1.332 + {
1.333 + aSortKey = EAscending;
1.334 + }
1.335 + else if (aConstantName == KEDescending)
1.336 + {
1.337 + aSortKey = EDescending;
1.338 + }
1.339 + else if (aConstantName == KEDirDescending)
1.340 + {
1.341 + aSortKey = EDirDescending;
1.342 + }
1.343 + else if (aConstantName == KESortNone)
1.344 + {
1.345 + aSortKey = ESortNone;
1.346 + }
1.347 + else
1.348 + {
1.349 + TInt location = aConstantName.Match(_L("*|*"));
1.350 + if( location != KErrNotFound )
1.351 + {
1.352 + //Converting Left part of the data
1.353 + TPtrC tempStr = aConstantName.Left(location);
1.354 + ret = ConvertSortKeys(tempStr, aSortKey);
1.355 +
1.356 + //Converting right data can be with another "|"
1.357 + tempStr.Set(aConstantName.Mid(location + 1));
1.358 +
1.359 + TUint tmp;
1.360 + if ( ConvertSortKeys(tempStr, tmp) )
1.361 + {
1.362 + aSortKey |= tmp;
1.363 + }
1.364 + else
1.365 + {
1.366 + ret = EFalse;
1.367 + }
1.368 + }
1.369 + }
1.370 +
1.371 + return ret;
1.372 + }