os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DirScanData.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
@test
sl@0
    21
@internalComponent
sl@0
    22
v
sl@0
    23
This contains CT_DirScanData
sl@0
    24
*/
sl@0
    25
sl@0
    26
//	User includes
sl@0
    27
#include "T_DirScanData.h"
sl@0
    28
#include "T_SfSrvServer.h"
sl@0
    29
sl@0
    30
/*@{*/
sl@0
    31
///	Parameters
sl@0
    32
_LIT(KAttMask,							"attmask" );
sl@0
    33
_LIT(KRfsObject,						"rfsObject");
sl@0
    34
_LIT(KDirObject,						"dirObject");
sl@0
    35
_LIT(KExpected,							"expected");
sl@0
    36
_LIT(KPath,								"path");
sl@0
    37
_LIT(KEntrySortKey,						"sortkey");
sl@0
    38
_LIT(KScanDirection,					"scandirection");
sl@0
    39
sl@0
    40
///Commands
sl@0
    41
_LIT(KCmdNewL,							"NewL");
sl@0
    42
_LIT(KCmdNewLC,							"NewLC");
sl@0
    43
_LIT(KCmdSetScanDataL,					"SetScanDataL");
sl@0
    44
_LIT(KCmdFullPath,						"FullPath");
sl@0
    45
_LIT(KCmdAbbreviatedPath,				"AbbreviatedPath");
sl@0
    46
_LIT(KCmdNextL,							"NextL");
sl@0
    47
_LIT(KCmdDestructor,					"~");
sl@0
    48
sl@0
    49
//	Sort key
sl@0
    50
_LIT(KESortNone,						"ESortNone");
sl@0
    51
_LIT(KESortByName,						"ESortByName");
sl@0
    52
_LIT(KESortByExt,						"ESortByExt");
sl@0
    53
_LIT(KESortBySize,						"ESortBySize");
sl@0
    54
_LIT(KESortByDate,						"ESortByDate");
sl@0
    55
_LIT(KESortByUid,						"ESortByUid");
sl@0
    56
_LIT(KEDirsAnyOrder,					"EDirsAnyOrder");
sl@0
    57
_LIT(KEDirsFirst,						"EDirsFirst");
sl@0
    58
_LIT(KEDirsLast,						"EDirsLast");
sl@0
    59
_LIT(KEAscending,						"EAscending");
sl@0
    60
_LIT(KEDescending,						"EDescending");
sl@0
    61
_LIT(KEDirDescending,					"EDirDescending");
sl@0
    62
sl@0
    63
// Scan directions
sl@0
    64
_LIT(KEScanUpTree,	 					"EScanUpTree");
sl@0
    65
_LIT(KEScanDownTree,	 				"EScanDownTree");
sl@0
    66
sl@0
    67
sl@0
    68
CT_DirScanData* CT_DirScanData::NewL()
sl@0
    69
/**
sl@0
    70
* Two phase constructor
sl@0
    71
*/
sl@0
    72
	{
sl@0
    73
	CT_DirScanData* ret = new (ELeave) CT_DirScanData();
sl@0
    74
	CleanupStack::PushL(ret);
sl@0
    75
	ret->ConstructL();
sl@0
    76
	CleanupStack::Pop(ret);
sl@0
    77
	return ret;
sl@0
    78
	}
sl@0
    79
	
sl@0
    80
sl@0
    81
CT_DirScanData::CT_DirScanData()
sl@0
    82
:	iDirScan(NULL)
sl@0
    83
/**
sl@0
    84
* Protected constructor. First phase construction
sl@0
    85
*/
sl@0
    86
	{
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
void CT_DirScanData::ConstructL()
sl@0
    91
/**
sl@0
    92
* Protected constructor. Second phase construction
sl@0
    93
*/
sl@0
    94
	{
sl@0
    95
	}
sl@0
    96
sl@0
    97
sl@0
    98
CT_DirScanData::~CT_DirScanData()
sl@0
    99
/**
sl@0
   100
* Destructor.
sl@0
   101
*/
sl@0
   102
	{
sl@0
   103
	DoCleanup();
sl@0
   104
	}
sl@0
   105
sl@0
   106
sl@0
   107
TAny* CT_DirScanData::GetObject()
sl@0
   108
	{
sl@0
   109
	return iDirScan;
sl@0
   110
	}
sl@0
   111
sl@0
   112
sl@0
   113
TBool	CT_DirScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
sl@0
   114
/**
sl@0
   115
* Process a command read from the ini file
sl@0
   116
*
sl@0
   117
* @param aCommand	the command to process
sl@0
   118
* @param aSection	the section in the ini file requiring the command to be processed
sl@0
   119
*
sl@0
   120
* @return ETrue if the command is processed
sl@0
   121
*/
sl@0
   122
	{
sl@0
   123
	TBool	retVal = ETrue;
sl@0
   124
sl@0
   125
	if (aCommand == KCmdNewL)
sl@0
   126
		{
sl@0
   127
		DoCmdNewL(aSection);
sl@0
   128
		}
sl@0
   129
	else if (aCommand == KCmdDestructor)
sl@0
   130
		{
sl@0
   131
		DoCleanup();
sl@0
   132
		}
sl@0
   133
	else if (aCommand == KCmdNewLC)
sl@0
   134
		{
sl@0
   135
		DoCmdNewLC(aSection);
sl@0
   136
		}
sl@0
   137
	else if (aCommand == KCmdSetScanDataL)
sl@0
   138
		{
sl@0
   139
		DoCmdSetScanDataL(aSection);
sl@0
   140
		}
sl@0
   141
	else if (aCommand == KCmdNextL)
sl@0
   142
		{
sl@0
   143
		DoCmdNextL(aSection);
sl@0
   144
		}
sl@0
   145
	else if (aCommand == KCmdAbbreviatedPath)
sl@0
   146
		{
sl@0
   147
		DoCmdAbbreviatedPath(aSection);
sl@0
   148
		}
sl@0
   149
	else if (aCommand == KCmdFullPath)
sl@0
   150
		{
sl@0
   151
		DoCmdFullPath(aSection);
sl@0
   152
		}
sl@0
   153
	else
sl@0
   154
		{
sl@0
   155
		retVal = EFalse;
sl@0
   156
		}
sl@0
   157
	return retVal;
sl@0
   158
	}
sl@0
   159
sl@0
   160
void CT_DirScanData::DoCleanup()
sl@0
   161
	{
sl@0
   162
	INFO_PRINTF1(_L("Doing cleanup!"));
sl@0
   163
	
sl@0
   164
	if (iDirScan)
sl@0
   165
		{
sl@0
   166
		delete iDirScan;
sl@0
   167
		iDirScan = NULL;
sl@0
   168
		}
sl@0
   169
	}
sl@0
   170
		
sl@0
   171
void CT_DirScanData::DoCmdNewL(const TDesC& aSection)
sl@0
   172
	{
sl@0
   173
	INFO_PRINTF1(_L("Constructing CDirScan object!"));
sl@0
   174
	
sl@0
   175
	RFs*	rfsObject = NULL;
sl@0
   176
	TPtrC	rfsObjectName;
sl@0
   177
	if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
sl@0
   178
		{
sl@0
   179
		rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
sl@0
   180
		}
sl@0
   181
	
sl@0
   182
	DoCleanup();
sl@0
   183
	TRAPD (error, iDirScan = CDirScan::NewL(*rfsObject));
sl@0
   184
	if (error == KErrNone)
sl@0
   185
		{
sl@0
   186
		INFO_PRINTF1(_L("CDirScan object has been created with NewL constructor!"));			
sl@0
   187
		}
sl@0
   188
	else
sl@0
   189
		{
sl@0
   190
		ERR_PRINTF2(_L("CDirScan object is not created with NewL constructor! Error code: %d"), error);
sl@0
   191
		SetError(error);
sl@0
   192
		}
sl@0
   193
	}
sl@0
   194
	
sl@0
   195
void CT_DirScanData::DoCmdNewLC(const TDesC& aSection)
sl@0
   196
	{
sl@0
   197
	INFO_PRINTF1(_L("Constructing CDirScan object!"));
sl@0
   198
	
sl@0
   199
	RFs*	rfsObject = NULL;
sl@0
   200
	TPtrC	rfsObjectName;
sl@0
   201
	if (GET_MANDATORY_STRING_PARAMETER(KRfsObject, aSection, rfsObjectName))
sl@0
   202
		{
sl@0
   203
		rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
sl@0
   204
		}
sl@0
   205
	
sl@0
   206
	DoCleanup();
sl@0
   207
	TRAPD (error, iDirScan = CDirScan::NewLC(*rfsObject); CleanupStack::Pop(iDirScan) );
sl@0
   208
	if (error == KErrNone)
sl@0
   209
		{
sl@0
   210
		INFO_PRINTF1(_L("CDirScan object has been created with NewLC constructor!"));
sl@0
   211
		}
sl@0
   212
	else
sl@0
   213
		{
sl@0
   214
		ERR_PRINTF2(_L("CDirScan object is not created with NewLC constructor! Error code: %d"), error);
sl@0
   215
		SetError(error);
sl@0
   216
		}
sl@0
   217
	}
sl@0
   218
sl@0
   219
void CT_DirScanData::DoCmdSetScanDataL(const TDesC& aSection)
sl@0
   220
	{
sl@0
   221
	INFO_PRINTF1(_L("Setting data scanning!"));
sl@0
   222
	
sl@0
   223
	TBool	dataOk = ETrue;
sl@0
   224
	
sl@0
   225
	TPtrC	path;
sl@0
   226
	if (!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path))
sl@0
   227
		{
sl@0
   228
		dataOk = EFalse;
sl@0
   229
		}
sl@0
   230
sl@0
   231
	TUint	attMask = KEntryAttHidden;
sl@0
   232
	if ( !FileserverUtil::GetAttMask(*this, aSection, KAttMask(), attMask))
sl@0
   233
        {
sl@0
   234
       	dataOk = EFalse;
sl@0
   235
       	}
sl@0
   236
sl@0
   237
	TPtrC	entrySortKey;
sl@0
   238
	TUint	sortKey = ESortNone;
sl@0
   239
	
sl@0
   240
	if (GET_OPTIONAL_STRING_PARAMETER(KEntrySortKey(), aSection, entrySortKey))
sl@0
   241
		{
sl@0
   242
		if ( !ConvertToSortKey(entrySortKey, sortKey) )
sl@0
   243
			{
sl@0
   244
			TInt	intTemp;
sl@0
   245
			if ( GET_MANDATORY_INT_PARAMETER(KEntrySortKey(), aSection, intTemp) )
sl@0
   246
				{
sl@0
   247
				sortKey=intTemp;
sl@0
   248
				}
sl@0
   249
			else
sl@0
   250
				{
sl@0
   251
				dataOk = EFalse;
sl@0
   252
				}
sl@0
   253
			}
sl@0
   254
		}
sl@0
   255
		
sl@0
   256
	TPtrC						entryScanDirection;
sl@0
   257
	CDirScan::TScanDirection	scanDirection = CDirScan::EScanDownTree;
sl@0
   258
	
sl@0
   259
	if (GET_OPTIONAL_STRING_PARAMETER(KScanDirection(), aSection, entryScanDirection))
sl@0
   260
		{
sl@0
   261
		if ( !ConvertToScanDirection(entryScanDirection, scanDirection))
sl@0
   262
            {
sl@0
   263
           	dataOk = EFalse;
sl@0
   264
           	}
sl@0
   265
		}
sl@0
   266
		
sl@0
   267
	
sl@0
   268
	if (dataOk)
sl@0
   269
		{
sl@0
   270
		TRAPD (err, iDirScan->SetScanDataL(path, attMask, sortKey, scanDirection));
sl@0
   271
		if(err == KErrNone)
sl@0
   272
			{
sl@0
   273
			INFO_PRINTF1(_L("SetScanDataL complete!"));
sl@0
   274
			}
sl@0
   275
		else
sl@0
   276
			{
sl@0
   277
			ERR_PRINTF2(_L("SetScanDataL() Error: %d"), err);
sl@0
   278
			SetError(err);
sl@0
   279
			}
sl@0
   280
		}
sl@0
   281
	}	
sl@0
   282
sl@0
   283
void CT_DirScanData::DoCmdNextL(const TDesC& aSection)
sl@0
   284
	{
sl@0
   285
	INFO_PRINTF1(_L("Scanning next directory entries!"));
sl@0
   286
	
sl@0
   287
	CDir*		dirObject = NULL;
sl@0
   288
	CT_DirData* dirWrapperObject = NULL;
sl@0
   289
	TPtrC		dirObjectName;
sl@0
   290
	
sl@0
   291
	if (GET_MANDATORY_STRING_PARAMETER(KDirObject, aSection, dirObjectName))
sl@0
   292
		{
sl@0
   293
		dirWrapperObject = static_cast<CT_DirData*>(GetDataWrapperL(dirObjectName));
sl@0
   294
		}
sl@0
   295
	TRAPD (err, iDirScan->NextL(dirObject));
sl@0
   296
	if (err == KErrNone)
sl@0
   297
		{
sl@0
   298
		if (dirObject == NULL)
sl@0
   299
			{
sl@0
   300
			INFO_PRINTF1(_L("CDir instance is NULL, there is no directory left to go."));
sl@0
   301
			}
sl@0
   302
		else
sl@0
   303
			{
sl@0
   304
			INFO_PRINTF1(_L("Scanning the next directory entry completed successfully!"));
sl@0
   305
			}
sl@0
   306
		}
sl@0
   307
	else
sl@0
   308
		{
sl@0
   309
		ERR_PRINTF2(_L("Can't scan the next directory entry in the structure Error code: %d"), err);
sl@0
   310
		SetError(err);
sl@0
   311
		}
sl@0
   312
		
sl@0
   313
	if (dirObject)
sl@0
   314
		{
sl@0
   315
		if(dirWrapperObject)
sl@0
   316
			{
sl@0
   317
			dirWrapperObject->SetObjectL(dirObject);
sl@0
   318
			}
sl@0
   319
		else
sl@0
   320
		    {
sl@0
   321
		    delete dirObject;
sl@0
   322
		    dirObject = NULL;			        
sl@0
   323
		    }
sl@0
   324
		}	
sl@0
   325
	}
sl@0
   326
	
sl@0
   327
void CT_DirScanData::DoCmdAbbreviatedPath(const TDesC& aSection)
sl@0
   328
	{
sl@0
   329
	INFO_PRINTF1(_L("Getting directory abbreviated path!"));
sl@0
   330
	
sl@0
   331
	TPtrC	expected;
sl@0
   332
	if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
sl@0
   333
		{
sl@0
   334
		TPtrC	abbPath;
sl@0
   335
		abbPath.Set(iDirScan->AbbreviatedPath());
sl@0
   336
		
sl@0
   337
		if (abbPath != expected)
sl@0
   338
			{
sl@0
   339
			ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &abbPath, &expected);
sl@0
   340
			SetBlockResult(EFail);
sl@0
   341
			}
sl@0
   342
		else 
sl@0
   343
			{
sl@0
   344
			INFO_PRINTF2(_L("Result (%S) match with expected result!"), &abbPath);
sl@0
   345
			}
sl@0
   346
		}
sl@0
   347
	}
sl@0
   348
sl@0
   349
void CT_DirScanData::DoCmdFullPath(const TDesC& aSection)
sl@0
   350
	{
sl@0
   351
	INFO_PRINTF1(_L("Getting directory full path!"));
sl@0
   352
	
sl@0
   353
	TPtrC	expected;
sl@0
   354
	if (GET_MANDATORY_STRING_PARAMETER(KExpected(), aSection, expected))
sl@0
   355
		{
sl@0
   356
		TPtrC	fullPath;
sl@0
   357
		fullPath.Set(iDirScan->FullPath());
sl@0
   358
		
sl@0
   359
		if (fullPath != expected)
sl@0
   360
			{
sl@0
   361
			ERR_PRINTF3(_L("Result (%S) didn't match with expected result (%S)!"), &fullPath, &expected);
sl@0
   362
			SetBlockResult(EFail);
sl@0
   363
			}
sl@0
   364
		else 
sl@0
   365
			{
sl@0
   366
			INFO_PRINTF2(_L("Result (%S) match with expected result!"), &fullPath);
sl@0
   367
			}
sl@0
   368
		}
sl@0
   369
	}
sl@0
   370
	
sl@0
   371
	
sl@0
   372
TBool CT_DirScanData::ConvertToSortKey(const TDesC& aSortKeyStr, TUint& aSortKey)
sl@0
   373
	{
sl@0
   374
	TBool ret = ETrue;
sl@0
   375
sl@0
   376
	if (aSortKeyStr == KESortNone)
sl@0
   377
		{
sl@0
   378
		aSortKey = ESortNone;
sl@0
   379
		}
sl@0
   380
	else if (aSortKeyStr == KESortByName)
sl@0
   381
		{
sl@0
   382
		aSortKey = ESortByName;
sl@0
   383
		}
sl@0
   384
	else if (aSortKeyStr == KESortByExt)
sl@0
   385
		{
sl@0
   386
		aSortKey = ESortByExt;
sl@0
   387
		}
sl@0
   388
	else if (aSortKeyStr == KESortBySize)
sl@0
   389
		{
sl@0
   390
		aSortKey = ESortBySize;
sl@0
   391
		}
sl@0
   392
	else if (aSortKeyStr == KESortByDate)
sl@0
   393
		{
sl@0
   394
		aSortKey = ESortByDate;
sl@0
   395
		}
sl@0
   396
	else if (aSortKeyStr == KESortByUid)
sl@0
   397
		{
sl@0
   398
		aSortKey = ESortByUid;
sl@0
   399
		}
sl@0
   400
	else if (aSortKeyStr == KEDirsAnyOrder)
sl@0
   401
		{
sl@0
   402
		aSortKey = EDirsAnyOrder;
sl@0
   403
		}
sl@0
   404
	else if (aSortKeyStr == KEDirsFirst)
sl@0
   405
		{
sl@0
   406
		aSortKey = EDirsFirst;
sl@0
   407
		}
sl@0
   408
	else if (aSortKeyStr == KEDirsLast)
sl@0
   409
		{
sl@0
   410
		aSortKey = EDirsLast;
sl@0
   411
		}
sl@0
   412
	else if (aSortKeyStr == KEAscending)
sl@0
   413
		{
sl@0
   414
		aSortKey = EAscending;
sl@0
   415
		}
sl@0
   416
	else if (aSortKeyStr == KEDescending)
sl@0
   417
		{
sl@0
   418
		aSortKey = EDescending;
sl@0
   419
		}
sl@0
   420
	else if (aSortKeyStr == KEDirDescending)
sl@0
   421
		{
sl@0
   422
		aSortKey = EDirDescending;
sl@0
   423
		}
sl@0
   424
	else if (aSortKeyStr.Match((_L("*|*"))) != KErrNotFound)
sl@0
   425
		{
sl@0
   426
		TUint tmpSortKey;
sl@0
   427
sl@0
   428
		TInt location = aSortKeyStr.Match(_L("*|*"));
sl@0
   429
		//Converting Left part of the data
sl@0
   430
		TPtrC left = aSortKeyStr.Left(location);
sl@0
   431
		if (ConvertToSortKey(left, tmpSortKey))
sl@0
   432
			{
sl@0
   433
			aSortKey = tmpSortKey;
sl@0
   434
			}
sl@0
   435
		else
sl@0
   436
			{
sl@0
   437
			ret = EFalse;
sl@0
   438
			}
sl@0
   439
sl@0
   440
		//Converting right data can be with another "|"
sl@0
   441
		TPtrC right = aSortKeyStr.Mid(location + 1);
sl@0
   442
sl@0
   443
		if (ConvertToSortKey(right, tmpSortKey))
sl@0
   444
			{
sl@0
   445
			aSortKey = aSortKey | tmpSortKey;
sl@0
   446
			}
sl@0
   447
		else
sl@0
   448
			{
sl@0
   449
			ret = EFalse;
sl@0
   450
			}
sl@0
   451
		}
sl@0
   452
	else
sl@0
   453
		{
sl@0
   454
		ret = EFalse;
sl@0
   455
		}
sl@0
   456
sl@0
   457
	return ret;
sl@0
   458
	}
sl@0
   459
sl@0
   460
sl@0
   461
	
sl@0
   462
TBool CT_DirScanData::ConvertToScanDirection(const TDesC& aScanDirectionStr, CDirScan::TScanDirection& aScanDirection)
sl@0
   463
	{
sl@0
   464
	TBool ret = ETrue;
sl@0
   465
sl@0
   466
	if (aScanDirectionStr == KEScanUpTree)
sl@0
   467
		{
sl@0
   468
		aScanDirection = CDirScan::EScanUpTree;
sl@0
   469
		}
sl@0
   470
	else if (aScanDirectionStr == KEScanDownTree)
sl@0
   471
		{
sl@0
   472
		aScanDirection = CDirScan::EScanDownTree;
sl@0
   473
		}
sl@0
   474
	else
sl@0
   475
		{
sl@0
   476
		ret = EFalse;
sl@0
   477
		}
sl@0
   478
sl@0
   479
	return ret;
sl@0
   480
	}