os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_RawDiskData.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
sl@0
    23
This contains CT_RawDiskData
sl@0
    24
*/
sl@0
    25
sl@0
    26
//	User includes
sl@0
    27
#include "T_RawDiskData.h"
sl@0
    28
sl@0
    29
/*@{*/
sl@0
    30
///	Parameters
sl@0
    31
_LIT(KDrive,	        						"drive");
sl@0
    32
_LIT(KObjectName,                               "object_name");
sl@0
    33
_LIT(KData,										"data");
sl@0
    34
_LIT(KPosition,									"position");
sl@0
    35
sl@0
    36
///Commands
sl@0
    37
_LIT(KCmdOpen,                                  "Open");
sl@0
    38
_LIT(KCmdClose,                                 "Close");
sl@0
    39
_LIT(KCmdNew,                                   "new" );
sl@0
    40
_LIT(KCmdDestructor,                            "~" );
sl@0
    41
_LIT(KCmdRead,                                  "Read");
sl@0
    42
_LIT(KCmdWrite,                                 "Write");
sl@0
    43
sl@0
    44
_LIT(KDriveA,							        "EDriveA");
sl@0
    45
_LIT(KDriveB,				        			"EDriveB");
sl@0
    46
_LIT(KDriveC,	        						"EDriveC");
sl@0
    47
_LIT(KDriveD,						        	"EDriveD");
sl@0
    48
_LIT(KDriveE,		        					"EDriveE");
sl@0
    49
_LIT(KDriveF,		        					"EDriveF");
sl@0
    50
_LIT(KDriveG,				        			"EDriveG");
sl@0
    51
_LIT(KDriveH,		        					"EDriveH");
sl@0
    52
_LIT(KDriveI,		        					"EDriveI");
sl@0
    53
_LIT(KDriveJ,       							"EDriveJ");
sl@0
    54
_LIT(KDriveK,							        "EDriveK");
sl@0
    55
_LIT(KDriveL,					        		"EDriveL");
sl@0
    56
_LIT(KDriveM,				    	    		"EDriveM");
sl@0
    57
_LIT(KDriveN,		        					"EDriveN");
sl@0
    58
_LIT(KDriveO,       							"EDriveO");
sl@0
    59
_LIT(KDriveP,					    	    	"EDriveP");
sl@0
    60
_LIT(KDriveQ,					        		"EDriveQ");
sl@0
    61
_LIT(KDriveR,		        					"EDriveR");
sl@0
    62
_LIT(KDriveS,	    		    				"EDriveS");
sl@0
    63
_LIT(KDriveT,   				    			"EDriveT");
sl@0
    64
_LIT(KDriveU,							        "EDriveU");
sl@0
    65
_LIT(KDriveV,					        		"EDriveV");
sl@0
    66
_LIT(KDriveW,				        			"EDriveW");
sl@0
    67
_LIT(KDriveX,				           			"EDriveX");
sl@0
    68
_LIT(KDriveY,				    	    		"EDriveY");
sl@0
    69
_LIT(KDriveZ,			    	    			"EDriveZ");
sl@0
    70
/*@}*/
sl@0
    71
sl@0
    72
CT_RawDiskData* CT_RawDiskData::NewL()
sl@0
    73
/**
sl@0
    74
* Two phase constructor
sl@0
    75
*/
sl@0
    76
	{
sl@0
    77
	CT_RawDiskData* ret = new (ELeave) CT_RawDiskData();
sl@0
    78
	CleanupStack::PushL(ret);
sl@0
    79
	ret->ConstructL();
sl@0
    80
	CleanupStack::Pop(ret);
sl@0
    81
	return ret;
sl@0
    82
	}
sl@0
    83
sl@0
    84
CT_RawDiskData::CT_RawDiskData()
sl@0
    85
:	iRawDisk(NULL)
sl@0
    86
/**
sl@0
    87
* Protected constructor. First phase construction
sl@0
    88
*/
sl@0
    89
	{
sl@0
    90
	}
sl@0
    91
sl@0
    92
void CT_RawDiskData::ConstructL()
sl@0
    93
/**
sl@0
    94
* Protected constructor. Second phase construction
sl@0
    95
*/
sl@0
    96
	{
sl@0
    97
	}
sl@0
    98
	
sl@0
    99
CT_RawDiskData::~CT_RawDiskData()
sl@0
   100
/**
sl@0
   101
* Destructor.
sl@0
   102
*/
sl@0
   103
	{
sl@0
   104
	DoCleanup();
sl@0
   105
	}
sl@0
   106
sl@0
   107
void CT_RawDiskData::DoCleanup()
sl@0
   108
/**
sl@0
   109
* Contains cleanup implementation
sl@0
   110
*/
sl@0
   111
	{
sl@0
   112
	//Deleting RRawDisk.
sl@0
   113
	if (iRawDisk)
sl@0
   114
		{
sl@0
   115
		DoCmdClose();
sl@0
   116
		INFO_PRINTF1(_L("Deleting current RRawDisk"));
sl@0
   117
		delete iRawDisk;
sl@0
   118
		iRawDisk = NULL;
sl@0
   119
		}
sl@0
   120
	}
sl@0
   121
sl@0
   122
TAny* CT_RawDiskData::GetObject()
sl@0
   123
/**
sl@0
   124
* Return a pointer to the object that the data wraps
sl@0
   125
*
sl@0
   126
* @return pointer to the object that the data wraps
sl@0
   127
*/
sl@0
   128
	{
sl@0
   129
	return iRawDisk;
sl@0
   130
	}
sl@0
   131
sl@0
   132
TBool CT_RawDiskData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
sl@0
   133
/**
sl@0
   134
 * Process a command read from the ini file
sl@0
   135
 *
sl@0
   136
 * @param	aCommand requiring command to be processed
sl@0
   137
 * @param	aSection the section in the ini file requiring the command to be processed
sl@0
   138
 * @param	aAsyncErrorIndex the index of asynchronous command error code belongs to.
sl@0
   139
 *
sl@0
   140
 * @leave	system wide error
sl@0
   141
 *
sl@0
   142
 * @return	ETrue if the command is processed
sl@0
   143
 */
sl@0
   144
	{
sl@0
   145
	TBool retVal = ETrue;
sl@0
   146
	
sl@0
   147
	if (aCommand == KCmdNew)
sl@0
   148
		{
sl@0
   149
		DoCmdNewL();
sl@0
   150
		}
sl@0
   151
	else if (aCommand == KCmdDestructor)
sl@0
   152
		{
sl@0
   153
		DoCmdDestructor();
sl@0
   154
		}
sl@0
   155
    else if (aCommand == KCmdOpen)
sl@0
   156
	    {
sl@0
   157
	    DoCmdOpen(aSection);
sl@0
   158
	    }
sl@0
   159
	else if (aCommand == KCmdClose)
sl@0
   160
	    {
sl@0
   161
	    DoCmdClose();
sl@0
   162
	    }
sl@0
   163
    else if (aCommand == KCmdRead)
sl@0
   164
        {
sl@0
   165
        DoCmdReadL(aSection);
sl@0
   166
        }
sl@0
   167
    else if (aCommand == KCmdWrite)
sl@0
   168
        {
sl@0
   169
        DoCmdWriteL(aSection);
sl@0
   170
        }
sl@0
   171
	else
sl@0
   172
		{
sl@0
   173
		retVal = EFalse;
sl@0
   174
		}
sl@0
   175
	return retVal;
sl@0
   176
	}
sl@0
   177
sl@0
   178
sl@0
   179
void CT_RawDiskData::DoCmdNewL()
sl@0
   180
/** Creates new RRawDisk class instance */
sl@0
   181
	{
sl@0
   182
	//Deletes previous RRawDisk class instance if it was already created.
sl@0
   183
	DoCleanup();
sl@0
   184
sl@0
   185
	INFO_PRINTF1(_L("Create new RRawDisk class instance"));
sl@0
   186
sl@0
   187
	// do create
sl@0
   188
	TRAPD(err, iRawDisk = new (ELeave) RRawDisk());
sl@0
   189
	if (err != KErrNone)
sl@0
   190
		{
sl@0
   191
		ERR_PRINTF2(_L("new error %d"), err);
sl@0
   192
		SetError(err);
sl@0
   193
		}
sl@0
   194
	else
sl@0
   195
		{
sl@0
   196
		INFO_PRINTF1(_L("Create new RRawDisk class instance completed successfully!"));
sl@0
   197
		}
sl@0
   198
	}
sl@0
   199
	
sl@0
   200
	
sl@0
   201
void CT_RawDiskData::DoCmdDestructor()
sl@0
   202
/** Destroy RRawDisk the object */
sl@0
   203
	{
sl@0
   204
	DoCleanup();
sl@0
   205
	}
sl@0
   206
sl@0
   207
sl@0
   208
void CT_RawDiskData::DoCmdOpen(const TDesC& aSection)
sl@0
   209
/** RRawDisk::Open */
sl@0
   210
	{
sl@0
   211
	INFO_PRINTF1(_L("Opening a direct access channel to the disk!"));
sl@0
   212
sl@0
   213
	RFs* rfsObject = NULL;
sl@0
   214
	TPtrC rfsObjectName;
sl@0
   215
	if (GET_MANDATORY_STRING_PARAMETER(KObjectName, aSection, rfsObjectName))
sl@0
   216
		{
sl@0
   217
		TRAPD(err, rfsObject = (RFs*)GetDataObjectL(rfsObjectName));
sl@0
   218
		
sl@0
   219
		if (err == KErrNone)
sl@0
   220
			{
sl@0
   221
    		// get drive number from parameters
sl@0
   222
    		TDriveNumber driveNumber = EDriveA;
sl@0
   223
    		if (!GetDriveNumber(aSection, KDrive(), driveNumber))
sl@0
   224
    			{
sl@0
   225
    			ERR_PRINTF2(_L("No %S"), &KDrive());
sl@0
   226
    			SetBlockResult(EFail);
sl@0
   227
    			}
sl@0
   228
    		else
sl@0
   229
    		    {
sl@0
   230
		   		TInt err = KErrNone;
sl@0
   231
            	err = iRawDisk->Open(*rfsObject, driveNumber);
sl@0
   232
sl@0
   233
	    		if (err != KErrNone)
sl@0
   234
	    			{
sl@0
   235
	    			ERR_PRINTF2(_L("Opening iRawDisk failed with error : %d"), err);
sl@0
   236
	    			SetError( err );
sl@0
   237
	    			}
sl@0
   238
	    		else
sl@0
   239
					{
sl@0
   240
					INFO_PRINTF1(_L("Opening iRawDisk completed successfully!"));
sl@0
   241
					}
sl@0
   242
	    	    }
sl@0
   243
			}
sl@0
   244
		else
sl@0
   245
			{
sl@0
   246
			ERR_PRINTF1(_L("Error with fileserver"));
sl@0
   247
    		SetBlockResult(EFail);	
sl@0
   248
			}
sl@0
   249
		}
sl@0
   250
	}
sl@0
   251
sl@0
   252
sl@0
   253
void CT_RawDiskData::DoCmdClose()
sl@0
   254
/** RRawDisk::Close */
sl@0
   255
	{
sl@0
   256
	INFO_PRINTF1(_L("Closing current RRawDisk"));
sl@0
   257
	iRawDisk->Close();
sl@0
   258
	}
sl@0
   259
sl@0
   260
sl@0
   261
void CT_RawDiskData::DoCmdReadL( const TDesC& aSection )
sl@0
   262
    {
sl@0
   263
	INFO_PRINTF1(_L("Reading directly from disc!"));
sl@0
   264
    TInt err = KErrNone;
sl@0
   265
    
sl@0
   266
    TPtrC	expectedData;
sl@0
   267
	if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, expectedData))
sl@0
   268
		{		
sl@0
   269
		HBufC* expectedResultBuf = HBufC::NewL(expectedData.Length());
sl@0
   270
		
sl@0
   271
		TPtr expectedResult = expectedResultBuf->Des();
sl@0
   272
		expectedResult.Copy(expectedData);
sl@0
   273
		
sl@0
   274
		INFO_PRINTF2(_L("Expecting data: %S"), &expectedResult);
sl@0
   275
		
sl@0
   276
		HBufC8* readBuf = HBufC8::NewL( expectedData.Length());
sl@0
   277
		TPtr8 readBufPtr = readBuf->Des();
sl@0
   278
			
sl@0
   279
		TInt64 pos = 0;
sl@0
   280
		GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos);
sl@0
   281
			
sl@0
   282
		err = iRawDisk->Read(pos, readBufPtr);
sl@0
   283
sl@0
   284
		if(err == KErrNone)
sl@0
   285
			{
sl@0
   286
			HBufC* readResultBuf = HBufC::NewL(readBufPtr.Length());
sl@0
   287
			
sl@0
   288
			TPtr readResult = readResultBuf->Des();
sl@0
   289
			readResult.Copy(readBufPtr);
sl@0
   290
			
sl@0
   291
			INFO_PRINTF2(_L("Reading data: %S"), &readResult);
sl@0
   292
			
sl@0
   293
			if (readResult != expectedResult)
sl@0
   294
				{
sl@0
   295
				ERR_PRINTF3(_L("Read data does not match expected data! Read: %S expected: %S"), &readResult, &expectedResult);
sl@0
   296
				SetBlockResult( EFail );	
sl@0
   297
				}
sl@0
   298
			else
sl@0
   299
				{
sl@0
   300
				INFO_PRINTF1(_L("Reading data directly from disc was successful!"));	
sl@0
   301
				}
sl@0
   302
			delete readResultBuf;
sl@0
   303
			readResultBuf = NULL;
sl@0
   304
			}
sl@0
   305
		else
sl@0
   306
			{
sl@0
   307
			ERR_PRINTF2(_L("Reading data directly from disc failed with error %d"), err);
sl@0
   308
			SetError(err);
sl@0
   309
			}
sl@0
   310
		delete expectedResultBuf;
sl@0
   311
		expectedResultBuf = NULL;
sl@0
   312
		delete readBuf;
sl@0
   313
		readBuf = NULL;
sl@0
   314
		}
sl@0
   315
    else
sl@0
   316
    	{
sl@0
   317
    	ERR_PRINTF2(_L("No %S"), &KData());
sl@0
   318
    	SetBlockResult(EFail);
sl@0
   319
    	}
sl@0
   320
    }
sl@0
   321
sl@0
   322
sl@0
   323
void CT_RawDiskData::DoCmdWriteL( const TDesC& aSection )
sl@0
   324
    {
sl@0
   325
    INFO_PRINTF1(_L("Writing directly to disc!"));
sl@0
   326
    
sl@0
   327
    TPtrC	writeData;
sl@0
   328
	if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, writeData))
sl@0
   329
		{
sl@0
   330
		
sl@0
   331
		INFO_PRINTF2(_L("Writing following data: %S"), &writeData);
sl@0
   332
		
sl@0
   333
		HBufC8*	writeBuf = NULL;
sl@0
   334
		TRAPD (err, writeBuf = HBufC8::NewL( writeData.Length() ));
sl@0
   335
		if (err == KErrNone)
sl@0
   336
			{
sl@0
   337
			TPtr8 writeBufPtr = writeBuf->Des();
sl@0
   338
			writeBufPtr.Copy(writeData);
sl@0
   339
			
sl@0
   340
			TInt64 pos = 0;
sl@0
   341
			GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos);
sl@0
   342
			
sl@0
   343
			err = iRawDisk->Write(pos, writeBufPtr);
sl@0
   344
			
sl@0
   345
			if(err == KErrNone)
sl@0
   346
				{
sl@0
   347
				INFO_PRINTF1(_L("Writing data directly to disc was successful!"));
sl@0
   348
				}
sl@0
   349
			else
sl@0
   350
				{
sl@0
   351
				ERR_PRINTF2(_L("Writing data directly to disc failed with error %d"), err);
sl@0
   352
				SetError(err);
sl@0
   353
				}
sl@0
   354
			delete writeBuf;
sl@0
   355
			writeBuf = NULL;
sl@0
   356
			}
sl@0
   357
		}
sl@0
   358
    else
sl@0
   359
    	{
sl@0
   360
    	ERR_PRINTF2(_L("No %S"), &KData());
sl@0
   361
    	SetBlockResult(EFail);
sl@0
   362
    	}
sl@0
   363
    }
sl@0
   364
sl@0
   365
sl@0
   366
TBool CT_RawDiskData::GetDriveNumber(const TDesC& aSection, const TDesC& aParameterName, TDriveNumber& aDriveNumber)
sl@0
   367
/** Reads drive number from INI-file */
sl@0
   368
    {
sl@0
   369
	// Read drive number from INI file
sl@0
   370
	TPtrC driveNumberStr;
sl@0
   371
	TBool ret = GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, driveNumberStr);
sl@0
   372
	if (ret)
sl@0
   373
		{
sl@0
   374
		if (driveNumberStr == KDriveA)
sl@0
   375
			{
sl@0
   376
			aDriveNumber = EDriveA;
sl@0
   377
			}
sl@0
   378
		else if (driveNumberStr == KDriveB)
sl@0
   379
			{
sl@0
   380
			aDriveNumber = EDriveB;
sl@0
   381
			}
sl@0
   382
		else if (driveNumberStr == KDriveC)
sl@0
   383
			{
sl@0
   384
			aDriveNumber = EDriveC;
sl@0
   385
			}
sl@0
   386
		else if (driveNumberStr == KDriveD)
sl@0
   387
			{
sl@0
   388
			aDriveNumber = EDriveD;
sl@0
   389
			}
sl@0
   390
		else if (driveNumberStr == KDriveE)
sl@0
   391
			{
sl@0
   392
			aDriveNumber = EDriveE;
sl@0
   393
			}
sl@0
   394
		else if (driveNumberStr == KDriveF)
sl@0
   395
			{
sl@0
   396
			aDriveNumber = EDriveF;
sl@0
   397
			}
sl@0
   398
		else if (driveNumberStr == KDriveG)
sl@0
   399
			{
sl@0
   400
			aDriveNumber = EDriveG;
sl@0
   401
			}
sl@0
   402
		else if (driveNumberStr == KDriveH)
sl@0
   403
			{
sl@0
   404
			aDriveNumber = EDriveH;
sl@0
   405
			}
sl@0
   406
		else if (driveNumberStr == KDriveI)
sl@0
   407
			{
sl@0
   408
			aDriveNumber = EDriveI;
sl@0
   409
			}
sl@0
   410
		else if (driveNumberStr == KDriveJ)
sl@0
   411
			{
sl@0
   412
			aDriveNumber = EDriveJ;
sl@0
   413
			}
sl@0
   414
		else if (driveNumberStr == KDriveK)
sl@0
   415
			{
sl@0
   416
			aDriveNumber = EDriveK;
sl@0
   417
			}
sl@0
   418
		else if (driveNumberStr == KDriveL)
sl@0
   419
			{
sl@0
   420
			aDriveNumber = EDriveL;
sl@0
   421
			}
sl@0
   422
		else if (driveNumberStr == KDriveM)
sl@0
   423
			{
sl@0
   424
			aDriveNumber = EDriveM;
sl@0
   425
			}
sl@0
   426
		else if (driveNumberStr == KDriveN)
sl@0
   427
			{
sl@0
   428
			aDriveNumber = EDriveN;
sl@0
   429
			}
sl@0
   430
		else if (driveNumberStr == KDriveO)
sl@0
   431
			{
sl@0
   432
			aDriveNumber = EDriveO;
sl@0
   433
			}
sl@0
   434
		else if (driveNumberStr == KDriveP)
sl@0
   435
			{
sl@0
   436
			aDriveNumber = EDriveP;
sl@0
   437
			}
sl@0
   438
		else if (driveNumberStr == KDriveQ)
sl@0
   439
			{
sl@0
   440
			aDriveNumber = EDriveQ;
sl@0
   441
			}
sl@0
   442
		else if (driveNumberStr == KDriveR)
sl@0
   443
			{
sl@0
   444
			aDriveNumber = EDriveR;
sl@0
   445
			}
sl@0
   446
		else if (driveNumberStr == KDriveS)
sl@0
   447
			{
sl@0
   448
			aDriveNumber = EDriveS;
sl@0
   449
			}
sl@0
   450
		else if (driveNumberStr == KDriveT)
sl@0
   451
			{
sl@0
   452
			aDriveNumber = EDriveT;
sl@0
   453
			}
sl@0
   454
		else if (driveNumberStr == KDriveU)
sl@0
   455
			{
sl@0
   456
			aDriveNumber = EDriveU;
sl@0
   457
			}
sl@0
   458
		else if (driveNumberStr == KDriveV)
sl@0
   459
			{
sl@0
   460
			aDriveNumber = EDriveV;
sl@0
   461
			}
sl@0
   462
		else if (driveNumberStr == KDriveW)
sl@0
   463
			{
sl@0
   464
			aDriveNumber = EDriveW;
sl@0
   465
			}
sl@0
   466
		else if (driveNumberStr == KDriveX)
sl@0
   467
			{
sl@0
   468
			aDriveNumber = EDriveX;
sl@0
   469
			}
sl@0
   470
		else if (driveNumberStr == KDriveY)
sl@0
   471
			{
sl@0
   472
			aDriveNumber = EDriveY;
sl@0
   473
			}
sl@0
   474
		else if (driveNumberStr == KDriveZ)
sl@0
   475
			{
sl@0
   476
			aDriveNumber = EDriveZ;
sl@0
   477
			}
sl@0
   478
		else
sl@0
   479
			{
sl@0
   480
			TInt driveNumber = 0;
sl@0
   481
			ret = GET_OPTIONAL_INT_PARAMETER(aParameterName, aSection, driveNumber);
sl@0
   482
			if (ret)
sl@0
   483
				{
sl@0
   484
				aDriveNumber = (TDriveNumber) driveNumber ;
sl@0
   485
				}
sl@0
   486
			}
sl@0
   487
		}
sl@0
   488
sl@0
   489
	return ret;
sl@0
   490
	}