1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_RawDiskData.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,490 @@
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 +
1.26 +This contains CT_RawDiskData
1.27 +*/
1.28 +
1.29 +// User includes
1.30 +#include "T_RawDiskData.h"
1.31 +
1.32 +/*@{*/
1.33 +/// Parameters
1.34 +_LIT(KDrive, "drive");
1.35 +_LIT(KObjectName, "object_name");
1.36 +_LIT(KData, "data");
1.37 +_LIT(KPosition, "position");
1.38 +
1.39 +///Commands
1.40 +_LIT(KCmdOpen, "Open");
1.41 +_LIT(KCmdClose, "Close");
1.42 +_LIT(KCmdNew, "new" );
1.43 +_LIT(KCmdDestructor, "~" );
1.44 +_LIT(KCmdRead, "Read");
1.45 +_LIT(KCmdWrite, "Write");
1.46 +
1.47 +_LIT(KDriveA, "EDriveA");
1.48 +_LIT(KDriveB, "EDriveB");
1.49 +_LIT(KDriveC, "EDriveC");
1.50 +_LIT(KDriveD, "EDriveD");
1.51 +_LIT(KDriveE, "EDriveE");
1.52 +_LIT(KDriveF, "EDriveF");
1.53 +_LIT(KDriveG, "EDriveG");
1.54 +_LIT(KDriveH, "EDriveH");
1.55 +_LIT(KDriveI, "EDriveI");
1.56 +_LIT(KDriveJ, "EDriveJ");
1.57 +_LIT(KDriveK, "EDriveK");
1.58 +_LIT(KDriveL, "EDriveL");
1.59 +_LIT(KDriveM, "EDriveM");
1.60 +_LIT(KDriveN, "EDriveN");
1.61 +_LIT(KDriveO, "EDriveO");
1.62 +_LIT(KDriveP, "EDriveP");
1.63 +_LIT(KDriveQ, "EDriveQ");
1.64 +_LIT(KDriveR, "EDriveR");
1.65 +_LIT(KDriveS, "EDriveS");
1.66 +_LIT(KDriveT, "EDriveT");
1.67 +_LIT(KDriveU, "EDriveU");
1.68 +_LIT(KDriveV, "EDriveV");
1.69 +_LIT(KDriveW, "EDriveW");
1.70 +_LIT(KDriveX, "EDriveX");
1.71 +_LIT(KDriveY, "EDriveY");
1.72 +_LIT(KDriveZ, "EDriveZ");
1.73 +/*@}*/
1.74 +
1.75 +CT_RawDiskData* CT_RawDiskData::NewL()
1.76 +/**
1.77 +* Two phase constructor
1.78 +*/
1.79 + {
1.80 + CT_RawDiskData* ret = new (ELeave) CT_RawDiskData();
1.81 + CleanupStack::PushL(ret);
1.82 + ret->ConstructL();
1.83 + CleanupStack::Pop(ret);
1.84 + return ret;
1.85 + }
1.86 +
1.87 +CT_RawDiskData::CT_RawDiskData()
1.88 +: iRawDisk(NULL)
1.89 +/**
1.90 +* Protected constructor. First phase construction
1.91 +*/
1.92 + {
1.93 + }
1.94 +
1.95 +void CT_RawDiskData::ConstructL()
1.96 +/**
1.97 +* Protected constructor. Second phase construction
1.98 +*/
1.99 + {
1.100 + }
1.101 +
1.102 +CT_RawDiskData::~CT_RawDiskData()
1.103 +/**
1.104 +* Destructor.
1.105 +*/
1.106 + {
1.107 + DoCleanup();
1.108 + }
1.109 +
1.110 +void CT_RawDiskData::DoCleanup()
1.111 +/**
1.112 +* Contains cleanup implementation
1.113 +*/
1.114 + {
1.115 + //Deleting RRawDisk.
1.116 + if (iRawDisk)
1.117 + {
1.118 + DoCmdClose();
1.119 + INFO_PRINTF1(_L("Deleting current RRawDisk"));
1.120 + delete iRawDisk;
1.121 + iRawDisk = NULL;
1.122 + }
1.123 + }
1.124 +
1.125 +TAny* CT_RawDiskData::GetObject()
1.126 +/**
1.127 +* Return a pointer to the object that the data wraps
1.128 +*
1.129 +* @return pointer to the object that the data wraps
1.130 +*/
1.131 + {
1.132 + return iRawDisk;
1.133 + }
1.134 +
1.135 +TBool CT_RawDiskData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
1.136 +/**
1.137 + * Process a command read from the ini file
1.138 + *
1.139 + * @param aCommand requiring command to be processed
1.140 + * @param aSection the section in the ini file requiring the command to be processed
1.141 + * @param aAsyncErrorIndex the index of asynchronous command error code belongs to.
1.142 + *
1.143 + * @leave system wide error
1.144 + *
1.145 + * @return ETrue if the command is processed
1.146 + */
1.147 + {
1.148 + TBool retVal = ETrue;
1.149 +
1.150 + if (aCommand == KCmdNew)
1.151 + {
1.152 + DoCmdNewL();
1.153 + }
1.154 + else if (aCommand == KCmdDestructor)
1.155 + {
1.156 + DoCmdDestructor();
1.157 + }
1.158 + else if (aCommand == KCmdOpen)
1.159 + {
1.160 + DoCmdOpen(aSection);
1.161 + }
1.162 + else if (aCommand == KCmdClose)
1.163 + {
1.164 + DoCmdClose();
1.165 + }
1.166 + else if (aCommand == KCmdRead)
1.167 + {
1.168 + DoCmdReadL(aSection);
1.169 + }
1.170 + else if (aCommand == KCmdWrite)
1.171 + {
1.172 + DoCmdWriteL(aSection);
1.173 + }
1.174 + else
1.175 + {
1.176 + retVal = EFalse;
1.177 + }
1.178 + return retVal;
1.179 + }
1.180 +
1.181 +
1.182 +void CT_RawDiskData::DoCmdNewL()
1.183 +/** Creates new RRawDisk class instance */
1.184 + {
1.185 + //Deletes previous RRawDisk class instance if it was already created.
1.186 + DoCleanup();
1.187 +
1.188 + INFO_PRINTF1(_L("Create new RRawDisk class instance"));
1.189 +
1.190 + // do create
1.191 + TRAPD(err, iRawDisk = new (ELeave) RRawDisk());
1.192 + if (err != KErrNone)
1.193 + {
1.194 + ERR_PRINTF2(_L("new error %d"), err);
1.195 + SetError(err);
1.196 + }
1.197 + else
1.198 + {
1.199 + INFO_PRINTF1(_L("Create new RRawDisk class instance completed successfully!"));
1.200 + }
1.201 + }
1.202 +
1.203 +
1.204 +void CT_RawDiskData::DoCmdDestructor()
1.205 +/** Destroy RRawDisk the object */
1.206 + {
1.207 + DoCleanup();
1.208 + }
1.209 +
1.210 +
1.211 +void CT_RawDiskData::DoCmdOpen(const TDesC& aSection)
1.212 +/** RRawDisk::Open */
1.213 + {
1.214 + INFO_PRINTF1(_L("Opening a direct access channel to the disk!"));
1.215 +
1.216 + RFs* rfsObject = NULL;
1.217 + TPtrC rfsObjectName;
1.218 + if (GET_MANDATORY_STRING_PARAMETER(KObjectName, aSection, rfsObjectName))
1.219 + {
1.220 + TRAPD(err, rfsObject = (RFs*)GetDataObjectL(rfsObjectName));
1.221 +
1.222 + if (err == KErrNone)
1.223 + {
1.224 + // get drive number from parameters
1.225 + TDriveNumber driveNumber = EDriveA;
1.226 + if (!GetDriveNumber(aSection, KDrive(), driveNumber))
1.227 + {
1.228 + ERR_PRINTF2(_L("No %S"), &KDrive());
1.229 + SetBlockResult(EFail);
1.230 + }
1.231 + else
1.232 + {
1.233 + TInt err = KErrNone;
1.234 + err = iRawDisk->Open(*rfsObject, driveNumber);
1.235 +
1.236 + if (err != KErrNone)
1.237 + {
1.238 + ERR_PRINTF2(_L("Opening iRawDisk failed with error : %d"), err);
1.239 + SetError( err );
1.240 + }
1.241 + else
1.242 + {
1.243 + INFO_PRINTF1(_L("Opening iRawDisk completed successfully!"));
1.244 + }
1.245 + }
1.246 + }
1.247 + else
1.248 + {
1.249 + ERR_PRINTF1(_L("Error with fileserver"));
1.250 + SetBlockResult(EFail);
1.251 + }
1.252 + }
1.253 + }
1.254 +
1.255 +
1.256 +void CT_RawDiskData::DoCmdClose()
1.257 +/** RRawDisk::Close */
1.258 + {
1.259 + INFO_PRINTF1(_L("Closing current RRawDisk"));
1.260 + iRawDisk->Close();
1.261 + }
1.262 +
1.263 +
1.264 +void CT_RawDiskData::DoCmdReadL( const TDesC& aSection )
1.265 + {
1.266 + INFO_PRINTF1(_L("Reading directly from disc!"));
1.267 + TInt err = KErrNone;
1.268 +
1.269 + TPtrC expectedData;
1.270 + if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, expectedData))
1.271 + {
1.272 + HBufC* expectedResultBuf = HBufC::NewL(expectedData.Length());
1.273 +
1.274 + TPtr expectedResult = expectedResultBuf->Des();
1.275 + expectedResult.Copy(expectedData);
1.276 +
1.277 + INFO_PRINTF2(_L("Expecting data: %S"), &expectedResult);
1.278 +
1.279 + HBufC8* readBuf = HBufC8::NewL( expectedData.Length());
1.280 + TPtr8 readBufPtr = readBuf->Des();
1.281 +
1.282 + TInt64 pos = 0;
1.283 + GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos);
1.284 +
1.285 + err = iRawDisk->Read(pos, readBufPtr);
1.286 +
1.287 + if(err == KErrNone)
1.288 + {
1.289 + HBufC* readResultBuf = HBufC::NewL(readBufPtr.Length());
1.290 +
1.291 + TPtr readResult = readResultBuf->Des();
1.292 + readResult.Copy(readBufPtr);
1.293 +
1.294 + INFO_PRINTF2(_L("Reading data: %S"), &readResult);
1.295 +
1.296 + if (readResult != expectedResult)
1.297 + {
1.298 + ERR_PRINTF3(_L("Read data does not match expected data! Read: %S expected: %S"), &readResult, &expectedResult);
1.299 + SetBlockResult( EFail );
1.300 + }
1.301 + else
1.302 + {
1.303 + INFO_PRINTF1(_L("Reading data directly from disc was successful!"));
1.304 + }
1.305 + delete readResultBuf;
1.306 + readResultBuf = NULL;
1.307 + }
1.308 + else
1.309 + {
1.310 + ERR_PRINTF2(_L("Reading data directly from disc failed with error %d"), err);
1.311 + SetError(err);
1.312 + }
1.313 + delete expectedResultBuf;
1.314 + expectedResultBuf = NULL;
1.315 + delete readBuf;
1.316 + readBuf = NULL;
1.317 + }
1.318 + else
1.319 + {
1.320 + ERR_PRINTF2(_L("No %S"), &KData());
1.321 + SetBlockResult(EFail);
1.322 + }
1.323 + }
1.324 +
1.325 +
1.326 +void CT_RawDiskData::DoCmdWriteL( const TDesC& aSection )
1.327 + {
1.328 + INFO_PRINTF1(_L("Writing directly to disc!"));
1.329 +
1.330 + TPtrC writeData;
1.331 + if(GET_MANDATORY_STRING_PARAMETER(KData(), aSection, writeData))
1.332 + {
1.333 +
1.334 + INFO_PRINTF2(_L("Writing following data: %S"), &writeData);
1.335 +
1.336 + HBufC8* writeBuf = NULL;
1.337 + TRAPD (err, writeBuf = HBufC8::NewL( writeData.Length() ));
1.338 + if (err == KErrNone)
1.339 + {
1.340 + TPtr8 writeBufPtr = writeBuf->Des();
1.341 + writeBufPtr.Copy(writeData);
1.342 +
1.343 + TInt64 pos = 0;
1.344 + GET_OPTIONAL_INT64_PARAMETER(KPosition(), aSection, pos);
1.345 +
1.346 + err = iRawDisk->Write(pos, writeBufPtr);
1.347 +
1.348 + if(err == KErrNone)
1.349 + {
1.350 + INFO_PRINTF1(_L("Writing data directly to disc was successful!"));
1.351 + }
1.352 + else
1.353 + {
1.354 + ERR_PRINTF2(_L("Writing data directly to disc failed with error %d"), err);
1.355 + SetError(err);
1.356 + }
1.357 + delete writeBuf;
1.358 + writeBuf = NULL;
1.359 + }
1.360 + }
1.361 + else
1.362 + {
1.363 + ERR_PRINTF2(_L("No %S"), &KData());
1.364 + SetBlockResult(EFail);
1.365 + }
1.366 + }
1.367 +
1.368 +
1.369 +TBool CT_RawDiskData::GetDriveNumber(const TDesC& aSection, const TDesC& aParameterName, TDriveNumber& aDriveNumber)
1.370 +/** Reads drive number from INI-file */
1.371 + {
1.372 + // Read drive number from INI file
1.373 + TPtrC driveNumberStr;
1.374 + TBool ret = GET_OPTIONAL_STRING_PARAMETER(aParameterName, aSection, driveNumberStr);
1.375 + if (ret)
1.376 + {
1.377 + if (driveNumberStr == KDriveA)
1.378 + {
1.379 + aDriveNumber = EDriveA;
1.380 + }
1.381 + else if (driveNumberStr == KDriveB)
1.382 + {
1.383 + aDriveNumber = EDriveB;
1.384 + }
1.385 + else if (driveNumberStr == KDriveC)
1.386 + {
1.387 + aDriveNumber = EDriveC;
1.388 + }
1.389 + else if (driveNumberStr == KDriveD)
1.390 + {
1.391 + aDriveNumber = EDriveD;
1.392 + }
1.393 + else if (driveNumberStr == KDriveE)
1.394 + {
1.395 + aDriveNumber = EDriveE;
1.396 + }
1.397 + else if (driveNumberStr == KDriveF)
1.398 + {
1.399 + aDriveNumber = EDriveF;
1.400 + }
1.401 + else if (driveNumberStr == KDriveG)
1.402 + {
1.403 + aDriveNumber = EDriveG;
1.404 + }
1.405 + else if (driveNumberStr == KDriveH)
1.406 + {
1.407 + aDriveNumber = EDriveH;
1.408 + }
1.409 + else if (driveNumberStr == KDriveI)
1.410 + {
1.411 + aDriveNumber = EDriveI;
1.412 + }
1.413 + else if (driveNumberStr == KDriveJ)
1.414 + {
1.415 + aDriveNumber = EDriveJ;
1.416 + }
1.417 + else if (driveNumberStr == KDriveK)
1.418 + {
1.419 + aDriveNumber = EDriveK;
1.420 + }
1.421 + else if (driveNumberStr == KDriveL)
1.422 + {
1.423 + aDriveNumber = EDriveL;
1.424 + }
1.425 + else if (driveNumberStr == KDriveM)
1.426 + {
1.427 + aDriveNumber = EDriveM;
1.428 + }
1.429 + else if (driveNumberStr == KDriveN)
1.430 + {
1.431 + aDriveNumber = EDriveN;
1.432 + }
1.433 + else if (driveNumberStr == KDriveO)
1.434 + {
1.435 + aDriveNumber = EDriveO;
1.436 + }
1.437 + else if (driveNumberStr == KDriveP)
1.438 + {
1.439 + aDriveNumber = EDriveP;
1.440 + }
1.441 + else if (driveNumberStr == KDriveQ)
1.442 + {
1.443 + aDriveNumber = EDriveQ;
1.444 + }
1.445 + else if (driveNumberStr == KDriveR)
1.446 + {
1.447 + aDriveNumber = EDriveR;
1.448 + }
1.449 + else if (driveNumberStr == KDriveS)
1.450 + {
1.451 + aDriveNumber = EDriveS;
1.452 + }
1.453 + else if (driveNumberStr == KDriveT)
1.454 + {
1.455 + aDriveNumber = EDriveT;
1.456 + }
1.457 + else if (driveNumberStr == KDriveU)
1.458 + {
1.459 + aDriveNumber = EDriveU;
1.460 + }
1.461 + else if (driveNumberStr == KDriveV)
1.462 + {
1.463 + aDriveNumber = EDriveV;
1.464 + }
1.465 + else if (driveNumberStr == KDriveW)
1.466 + {
1.467 + aDriveNumber = EDriveW;
1.468 + }
1.469 + else if (driveNumberStr == KDriveX)
1.470 + {
1.471 + aDriveNumber = EDriveX;
1.472 + }
1.473 + else if (driveNumberStr == KDriveY)
1.474 + {
1.475 + aDriveNumber = EDriveY;
1.476 + }
1.477 + else if (driveNumberStr == KDriveZ)
1.478 + {
1.479 + aDriveNumber = EDriveZ;
1.480 + }
1.481 + else
1.482 + {
1.483 + TInt driveNumber = 0;
1.484 + ret = GET_OPTIONAL_INT_PARAMETER(aParameterName, aSection, driveNumber);
1.485 + if (ret)
1.486 + {
1.487 + aDriveNumber = (TDriveNumber) driveNumber ;
1.488 + }
1.489 + }
1.490 + }
1.491 +
1.492 + return ret;
1.493 + }