os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_DriveUnitData.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_DriveUnitData
    24 */
    25 
    26 //	User includes
    27 #include "T_DriveUnitData.h"
    28 
    29 /*@{*/
    30 ///	Parameters
    31 _LIT(KDriveNameType,					"driveNameType");
    32 _LIT(KDriveName,						"driveName");
    33 _LIT(KDriveExpValue,                    "driveExpValue");
    34 _LIT(KDriveNameExpValue,				"driveNameExpValue");
    35 
    36 ///	Commands
    37 _LIT(KCmdNew,							"new");
    38 _LIT(KCmdDestructor,					"~");
    39 _LIT(KCmdAssign,                        "=");
    40 _LIT(KCmdConvertToInt,                  "convertToInt");
    41 _LIT(KCmdName,					        "name");
    42 /*@}*/
    43 
    44 CT_DriveUnitData* CT_DriveUnitData::NewL()
    45 /**
    46 * Two phase constructor
    47 */
    48 	{
    49 	CT_DriveUnitData* ret = new (ELeave) CT_DriveUnitData();
    50 	CleanupStack::PushL(ret);
    51 	ret->ConstructL();
    52 	CleanupStack::Pop(ret);
    53 	return ret;
    54 	}
    55 
    56 CT_DriveUnitData::CT_DriveUnitData()
    57 :	iDriveUnit(NULL)
    58 /**
    59 * Protected constructor. First phase construction
    60 */
    61 	{
    62 	}
    63 
    64 void CT_DriveUnitData::ConstructL()
    65 /**
    66 * Protected constructor. Second phase construction
    67 */	
    68 	{
    69 	}
    70 
    71 CT_DriveUnitData::~CT_DriveUnitData()
    72 /**
    73 * Destructor.
    74 */
    75 	{
    76 	DoCleanup();
    77 	}
    78 
    79 void CT_DriveUnitData::DoCleanup()
    80 /**
    81 * Contains cleanup implementation
    82 */
    83 	{
    84 	if (iDriveUnit)
    85 		{
    86 		INFO_PRINTF1(_L("Deleting current TDriveUnit"));
    87 		delete iDriveUnit;
    88 		iDriveUnit = NULL;
    89 		}
    90 	}
    91 
    92 TAny* CT_DriveUnitData::GetObject()
    93 /**
    94 * Return a pointer to the object that the data wraps
    95 *
    96 * @return pointer to the object that the data wraps
    97 */
    98 	{
    99 	return iDriveUnit;
   100 	}
   101 
   102 TBool CT_DriveUnitData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   103 /**
   104  * Process a command read from the ini file
   105  *
   106  * @param	aCommand requiring command to be processed
   107  * @param	aSection the section in the ini file requiring the command to be processed
   108  * @param	aAsyncErrorIndex the index of asynchronous command error code belongs to.
   109  *
   110  * @leave	system wide error
   111  *
   112  * @return	ETrue if the command is processed
   113  */
   114 	{
   115 	TBool retVal = ETrue;
   116 
   117 	if (aCommand == KCmdNew)
   118 		{
   119 		DoCmdNewL(aSection);
   120 		}
   121 	else if (aCommand == KCmdDestructor)
   122 		{
   123 		DoCmdDestructor();
   124 		}
   125 	else if (aCommand == KCmdAssign)
   126 	    {
   127 	    DoCmdAssign(aSection);
   128 	    }
   129 	else if (aCommand == KCmdConvertToInt)
   130 	    {
   131 	    DoCmdConvertToInt(aSection);
   132 	    }
   133 	else if (aCommand == KCmdName)
   134 	    {
   135 	    DoCmdName(aSection);
   136 	    }
   137 	else
   138 		{
   139 		retVal = EFalse;
   140 		}
   141 	return retVal;
   142 	}
   143 
   144 void CT_DriveUnitData::DoCmdNewL(const TDesC& aSection)
   145 /** Creates new TDriveUnit class instance */
   146 	{
   147 	//Deletes previous TDriveUnit class instance if it was already created.
   148 	DoCleanup();
   149 
   150 	INFO_PRINTF1(_L("Create new TDriveUnit class instance"));
   151     
   152 	TPtrC driveNameType;
   153 	if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
   154 	    {
   155 
   156 	    if (driveNameType == _L("number"))
   157 	        {
   158 	       	TInt driveNumber;
   159         	if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
   160 	            {
   161             	// do create
   162             	TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveNumber));
   163             	
   164             	if (err != KErrNone)
   165         			{
   166         			ERR_PRINTF2(_L("Error creating TDriveUnit(driveNumber): %d"), err);
   167         			SetError( err );
   168         			}
   169 	            }
   170 	        }
   171         else if (driveNameType == _L("letter"))
   172             {
   173             TPtrC driveLetter;
   174             if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
   175                 {
   176                	// do create
   177             	TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit(driveLetter));
   178                 
   179                 if (err != KErrNone)
   180         			{
   181         			ERR_PRINTF2(_L("Error creating TDriveUnit(driveLetter): %d"), err);
   182         			SetError( err );
   183         			}
   184                 }
   185             }
   186         else
   187             {
   188             TRAPD(err, iDriveUnit = new (ELeave) TDriveUnit());
   189 
   190         	if (err != KErrNone)
   191         		{
   192         		ERR_PRINTF2(_L("Error creating TDriveUnit(): %d"), err);
   193         		SetError( err );
   194         		}
   195             }
   196         }
   197 	}
   198 
   199 void CT_DriveUnitData::DoCmdAssign(const TDesC& aSection)
   200 /** Assigns the drive number or letter to the drive unit */
   201     {
   202 	TPtrC driveNameType;
   203 	if (GET_MANDATORY_STRING_PARAMETER(KDriveNameType(), aSection, driveNameType))
   204 	    {
   205 	    if (driveNameType == _L("number"))
   206 	        {
   207             TInt driveNumber;
   208         	if (GET_MANDATORY_INT_PARAMETER(KDriveName(), aSection, driveNumber))
   209         	    {
   210         	    INFO_PRINTF1(_L("Assign a new drive number to the drive unit"));
   211         	    *iDriveUnit = iDriveUnit->operator=(driveNumber);
   212         	    
   213         	    }
   214 	        }
   215 	    else if (driveNameType == _L("letter"))
   216 	        {
   217             TPtrC driveLetter;
   218             if (GET_MANDATORY_STRING_PARAMETER(KDriveName(), aSection, driveLetter))
   219                 {
   220                 INFO_PRINTF1(_L("Assign a new drive letter to the drive unit"));
   221                 *iDriveUnit = iDriveUnit->operator=(driveLetter);
   222                 }
   223 	        }
   224         else
   225             {
   226             ERR_PRINTF1(_L("Drive name type is not specified!"));
   227             SetBlockResult(EFail);
   228             }
   229 	    }
   230     }
   231 
   232 void CT_DriveUnitData::DoCmdConvertToInt(const TDesC& aSection)
   233 /** Converts the drive unit to integer */
   234     {
   235     INFO_PRINTF1(_L("Convert the drive unit to an integer value"));
   236 
   237     TInt intValue = iDriveUnit->operator TInt();
   238     INFO_PRINTF2(_L("Drive unit integer value is %d"), intValue);
   239 
   240     TInt driveExpValue;
   241 	if (GET_OPTIONAL_INT_PARAMETER(KDriveExpValue(), aSection, driveExpValue))
   242 	    {	    
   243         if ( driveExpValue != intValue )
   244             {
   245             ERR_PRINTF3(_L("Drive expected integer value does not match! Expected value: %d, actual value: %d"), driveExpValue, intValue);
   246             SetBlockResult(EFail);
   247             }
   248 	    else
   249 	    	{
   250 	    	INFO_PRINTF1(_L("Drive expected integer value matches the actual value!"));
   251 	    	}
   252 	    }    
   253     }
   254 
   255 void CT_DriveUnitData::DoCmdName(const TDesC& aSection)
   256 /** Get the drive unit name as text */
   257     {
   258     INFO_PRINTF1(_L("Get the drive unit name as text with a colon in the end using Name()"));
   259 
   260     TDriveName driveName = iDriveUnit->Name();
   261 
   262     INFO_PRINTF2(_L("Drive name: %S"), &driveName);
   263     
   264     TPtrC driveNameExpValue;
   265     if (GET_OPTIONAL_STRING_PARAMETER(KDriveNameExpValue(), aSection, driveNameExpValue))
   266 	    {	    
   267         if ( driveNameExpValue != driveName )
   268             {
   269             ERR_PRINTF3(_L("Drive expected name value does not match! Expected value: %S, actual value: %S"), &driveNameExpValue, &driveName);
   270             SetBlockResult(EFail);
   271             }
   272 	    else
   273 	    	{
   274 	    	INFO_PRINTF1(_L("Drive expected name value matches the actual value!"));
   275 	    	}
   276 	    } 
   277     }
   278 
   279 void CT_DriveUnitData::DoCmdDestructor()
   280 /** Destroy TDriveUnit the object */
   281 	{
   282 	DoCleanup();
   283 	}