os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DriveUnitData.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DriveUnitData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,283 @@
     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_DriveUnitData
    1.27 +*/
    1.28 +
    1.29 +//	User includes
    1.30 +#include "T_DriveUnitData.h"
    1.31 +
    1.32 +/*@{*/
    1.33 +///	Parameters
    1.34 +_LIT(KDriveNameType,					"driveNameType");
    1.35 +_LIT(KDriveName,						"driveName");
    1.36 +_LIT(KDriveExpValue,                    "driveExpValue");
    1.37 +_LIT(KDriveNameExpValue,				"driveNameExpValue");
    1.38 +
    1.39 +///	Commands
    1.40 +_LIT(KCmdNew,							"new");
    1.41 +_LIT(KCmdDestructor,					"~");
    1.42 +_LIT(KCmdAssign,                        "=");
    1.43 +_LIT(KCmdConvertToInt,                  "convertToInt");
    1.44 +_LIT(KCmdName,					        "name");
    1.45 +/*@}*/
    1.46 +
    1.47 +CT_DriveUnitData* CT_DriveUnitData::NewL()
    1.48 +/**
    1.49 +* Two phase constructor
    1.50 +*/
    1.51 +	{
    1.52 +	CT_DriveUnitData* ret = new (ELeave) CT_DriveUnitData();
    1.53 +	CleanupStack::PushL(ret);
    1.54 +	ret->ConstructL();
    1.55 +	CleanupStack::Pop(ret);
    1.56 +	return ret;
    1.57 +	}
    1.58 +
    1.59 +CT_DriveUnitData::CT_DriveUnitData()
    1.60 +:	iDriveUnit(NULL)
    1.61 +/**
    1.62 +* Protected constructor. First phase construction
    1.63 +*/
    1.64 +	{
    1.65 +	}
    1.66 +
    1.67 +void CT_DriveUnitData::ConstructL()
    1.68 +/**
    1.69 +* Protected constructor. Second phase construction
    1.70 +*/	
    1.71 +	{
    1.72 +	}
    1.73 +
    1.74 +CT_DriveUnitData::~CT_DriveUnitData()
    1.75 +/**
    1.76 +* Destructor.
    1.77 +*/
    1.78 +	{
    1.79 +	DoCleanup();
    1.80 +	}
    1.81 +
    1.82 +void CT_DriveUnitData::DoCleanup()
    1.83 +/**
    1.84 +* Contains cleanup implementation
    1.85 +*/
    1.86 +	{
    1.87 +	if (iDriveUnit)
    1.88 +		{
    1.89 +		INFO_PRINTF1(_L("Deleting current TDriveUnit"));
    1.90 +		delete iDriveUnit;
    1.91 +		iDriveUnit = NULL;
    1.92 +		}
    1.93 +	}
    1.94 +
    1.95 +TAny* CT_DriveUnitData::GetObject()
    1.96 +/**
    1.97 +* Return a pointer to the object that the data wraps
    1.98 +*
    1.99 +* @return pointer to the object that the data wraps
   1.100 +*/
   1.101 +	{
   1.102 +	return iDriveUnit;
   1.103 +	}
   1.104 +
   1.105 +TBool CT_DriveUnitData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   1.106 +/**
   1.107 + * Process a command read from the ini file
   1.108 + *
   1.109 + * @param	aCommand requiring command to be processed
   1.110 + * @param	aSection the section in the ini file requiring the command to be processed
   1.111 + * @param	aAsyncErrorIndex the index of asynchronous command error code belongs to.
   1.112 + *
   1.113 + * @leave	system wide error
   1.114 + *
   1.115 + * @return	ETrue if the command is processed
   1.116 + */
   1.117 +	{
   1.118 +	TBool retVal = ETrue;
   1.119 +
   1.120 +	if (aCommand == KCmdNew)
   1.121 +		{
   1.122 +		DoCmdNewL(aSection);
   1.123 +		}
   1.124 +	else if (aCommand == KCmdDestructor)
   1.125 +		{
   1.126 +		DoCmdDestructor();
   1.127 +		}
   1.128 +	else if (aCommand == KCmdAssign)
   1.129 +	    {
   1.130 +	    DoCmdAssign(aSection);
   1.131 +	    }
   1.132 +	else if (aCommand == KCmdConvertToInt)
   1.133 +	    {
   1.134 +	    DoCmdConvertToInt(aSection);
   1.135 +	    }
   1.136 +	else if (aCommand == KCmdName)
   1.137 +	    {
   1.138 +	    DoCmdName(aSection);
   1.139 +	    }
   1.140 +	else
   1.141 +		{
   1.142 +		retVal = EFalse;
   1.143 +		}
   1.144 +	return retVal;
   1.145 +	}
   1.146 +
   1.147 +void CT_DriveUnitData::DoCmdNewL(const TDesC& aSection)
   1.148 +/** Creates new TDriveUnit class instance */
   1.149 +	{
   1.150 +	//Deletes previous TDriveUnit class instance if it was already created.
   1.151 +	DoCleanup();
   1.152 +
   1.153 +	INFO_PRINTF1(_L("Create new TDriveUnit class instance"));
   1.154 +    
   1.155 +	TPtrC driveNameType;
   1.156 +	if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
   1.157 +	    {
   1.158 +
   1.159 +	    if (driveNameType == _L("number"))
   1.160 +	        {
   1.161 +	       	TInt driveNumber;
   1.162 +        	if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
   1.163 +	            {
   1.164 +            	// do create
   1.165 +            	TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveNumber));
   1.166 +            	
   1.167 +            	if (err != KErrNone)
   1.168 +        			{
   1.169 +        			ERR_PRINTF2(_L("Error creating TDriveUnit(driveNumber): %d"), err);
   1.170 +        			SetError( err );
   1.171 +        			}
   1.172 +	            }
   1.173 +	        }
   1.174 +        else if (driveNameType == _L("letter"))
   1.175 +            {
   1.176 +            TPtrC driveLetter;
   1.177 +            if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
   1.178 +                {
   1.179 +               	// do create
   1.180 +            	TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveLetter));
   1.181 +                
   1.182 +                if (err != KErrNone)
   1.183 +        			{
   1.184 +        			ERR_PRINTF2(_L("Error creating TDriveUnit(driveLetter): %d"), err);
   1.185 +        			SetError( err );
   1.186 +        			}
   1.187 +                }
   1.188 +            }
   1.189 +        else
   1.190 +            {
   1.191 +            TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit());
   1.192 +
   1.193 +        	if (err != KErrNone)
   1.194 +        		{
   1.195 +        		ERR_PRINTF2(_L("Error creating TDriveUnit(): %d"), err);
   1.196 +        		SetError( err );
   1.197 +        		}
   1.198 +            }
   1.199 +        }
   1.200 +	}
   1.201 +
   1.202 +void CT_DriveUnitData::DoCmdAssign(const TDesC& aSection)
   1.203 +/** Assigns the drive number or letter to the drive unit */
   1.204 +    {
   1.205 +	TPtrC driveNameType;
   1.206 +	if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
   1.207 +	    {
   1.208 +	    if (driveNameType == _L("number"))
   1.209 +	        {
   1.210 +            TInt driveNumber;
   1.211 +        	if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
   1.212 +        	    {
   1.213 +        	    INFO_PRINTF1(_L("Assign a new drive number to the drive unit"));
   1.214 +        	    *iDriveUnit = iDriveUnit->operator=(driveNumber);
   1.215 +        	    
   1.216 +        	    }
   1.217 +	        }
   1.218 +	    else if (driveNameType == _L("letter"))
   1.219 +	        {
   1.220 +            TPtrC driveLetter;
   1.221 +            if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
   1.222 +                {
   1.223 +                INFO_PRINTF1(_L("Assign a new drive letter to the drive unit"));
   1.224 +                *iDriveUnit = iDriveUnit->operator=(driveLetter);
   1.225 +                }
   1.226 +	        }
   1.227 +        else
   1.228 +            {
   1.229 +            ERR_PRINTF1(_L("Drive name type is not specified!"));
   1.230 +            SetBlockResult(EFail);
   1.231 +            }
   1.232 +	    }
   1.233 +    }
   1.234 +
   1.235 +void CT_DriveUnitData::DoCmdConvertToInt(const TDesC& aSection)
   1.236 +/** Converts the drive unit to integer */
   1.237 +    {
   1.238 +    INFO_PRINTF1(_L("Convert the drive unit to an integer value"));
   1.239 +
   1.240 +    TInt intValue = iDriveUnit->operator TInt();
   1.241 +    INFO_PRINTF2(_L("Drive unit integer value is %d"), intValue);
   1.242 +
   1.243 +    TInt driveExpValue;
   1.244 +	if (GET_OPTIONAL_INT_PARAMETER(KDriveExpValue(), aSection, driveExpValue))
   1.245 +	    {	    
   1.246 +        if ( driveExpValue != intValue )
   1.247 +            {
   1.248 +            ERR_PRINTF3(_L("Drive expected integer value does not match! Expected value: %d, actual value: %d"), driveExpValue, intValue);
   1.249 +            SetBlockResult(EFail);
   1.250 +            }
   1.251 +	    else
   1.252 +	    	{
   1.253 +	    	INFO_PRINTF1(_L("Drive expected integer value matches the actual value!"));
   1.254 +	    	}
   1.255 +	    }    
   1.256 +    }
   1.257 +
   1.258 +void CT_DriveUnitData::DoCmdName(const TDesC& aSection)
   1.259 +/** Get the drive unit name as text */
   1.260 +    {
   1.261 +    INFO_PRINTF1(_L("Get the drive unit name as text with a colon in the end using Name()"));
   1.262 +
   1.263 +    TDriveName driveName = iDriveUnit->Name();
   1.264 +
   1.265 +    INFO_PRINTF2(_L("Drive name: %S"), &driveName);
   1.266 +    
   1.267 +    TPtrC driveNameExpValue;
   1.268 +    if (GET_OPTIONAL_STRING_PARAMETER(KDriveNameExpValue(), aSection, driveNameExpValue))
   1.269 +	    {	    
   1.270 +        if ( driveNameExpValue != driveName )
   1.271 +            {
   1.272 +            ERR_PRINTF3(_L("Drive expected name value does not match! Expected value: %S, actual value: %S"), &driveNameExpValue, &driveName);
   1.273 +            SetBlockResult(EFail);
   1.274 +            }
   1.275 +	    else
   1.276 +	    	{
   1.277 +	    	INFO_PRINTF1(_L("Drive expected name value matches the actual value!"));
   1.278 +	    	}
   1.279 +	    } 
   1.280 +    }
   1.281 +
   1.282 +void CT_DriveUnitData::DoCmdDestructor()
   1.283 +/** Destroy TDriveUnit the object */
   1.284 +	{
   1.285 +	DoCleanup();
   1.286 +	}