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