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