baseintegtests/baseintegrationtest/testsuites/fat32/src/basetestfat32writeraw.cpp
branchanywhere
changeset 20 d63d727ee0a6
parent 19 f6d3d9676ee4
parent 16 6d8ad5bee44b
child 21 af091391d962
equal deleted inserted replaced
19:f6d3d9676ee4 20:d63d727ee0a6
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Performs various operations to write to the raw disk.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "basetestfat32writeraw.h"
       
    19 
       
    20 static RRawDisk TheDisk;
       
    21 
       
    22 /**
       
    23 Class Constructor
       
    24 */		    
       
    25 CBaseTestFat32WriteRaw::CBaseTestFat32WriteRaw() 
       
    26 	{
       
    27 	SetTestStepName(KTestStepWriteRaw);
       
    28 	}
       
    29 	
       
    30 /**
       
    31 Class Destructor
       
    32 */
       
    33 CBaseTestFat32WriteRaw::~CBaseTestFat32WriteRaw() 
       
    34 	{
       
    35 	}
       
    36 
       
    37 /** 
       
    38 This function performs the following actions:
       
    39 1. Get the position at which to write on the raw disk from the ini file
       
    40 	-> if a cluster is specified, get the position from the GetCluster function 
       
    41 2. Get the number of bytes to write from the ini file 
       
    42 3. Obtain the values to be written to the disk from the ini file. 
       
    43 4. Write the values to the disk byte by byte.
       
    44 
       
    45 @return EPass if test passes and EFail if test fails
       
    46 */ 
       
    47 TVerdict CBaseTestFat32WriteRaw::doTestStepL()
       
    48 	{
       
    49 	SetTestStepResult(EFail);
       
    50 	_LIT(KPosition,"WritePosition");
       
    51 	_LIT(KNumOfBytes,"NumberOfBytes");
       
    52 	_LIT(KCluster,"ClusterNumber");
       
    53 	TInt writevalues[12];
       
    54 	TInt position; 
       
    55 	TInt64 clusterPosition;
       
    56 	TInt cluster; 
       
    57 	TInt numbyte;
       
    58 	TInt r;
       
    59 	TBool alright = GetHexFromConfig(ConfigSection(), KPosition, position);
       
    60 	if(alright)
       
    61 		{
       
    62 		if (iMedia == 1 && position >= 16384)
       
    63 			{
       
    64 			INFO_PRINTF2(_L("Position = %d"), position);
       
    65 			INFO_PRINTF2(_L("iBPB_ResvdSecCnt = %d"), iBPB_ResvdSecCnt);
       
    66 			position = (iBPB_ResvdSecCnt * 512) + (position - 0x4000);
       
    67 			INFO_PRINTF2(_L("New Position = %d"), position);
       
    68 			}
       
    69 		TBool alright2 = GetHexFromConfig(ConfigSection(), KNumOfBytes, numbyte);
       
    70 		if (alright2)
       
    71 			{
       
    72 			TBool alright2 = GetIntFromConfig(ConfigSection(), KCluster, cluster);
       
    73 			if (alright2)
       
    74 				{
       
    75 				r = GetCluster(cluster, clusterPosition);
       
    76 				position = clusterPosition;
       
    77 				}
       
    78 			else
       
    79 				{
       
    80 				position = position;
       
    81 				}
       
    82 			_LIT(KWritePosition, "The position on the disk being written to is %d");
       
    83 			INFO_PRINTF2(KWritePosition,position);
       
    84 			r = GetWriteValue(numbyte,writevalues);
       
    85 			TInt i;
       
    86 			r = TheDisk.Open(iTheFs, CurrentDrive());
       
    87 			if (r!=KErrNone)
       
    88 				{
       
    89 				_LIT(KErrorOpen, "Cannot open the raw disk - r=%d");
       
    90 				INFO_PRINTF2(KErrorOpen, r);
       
    91 				}
       
    92 			for (i=0;i<numbyte;i++)
       
    93 				{
       
    94 				r = WriteRaw(position+i, writevalues[i]);
       
    95 				if(r != KErrNone)
       
    96 					{
       
    97 					_LIT(KErrorRead, "Cannot write to the raw disk at position %d with value %d");
       
    98 					INFO_PRINTF3(KErrorRead,position, writevalues[i]);
       
    99 					SetTestStepResult(EFail);
       
   100 					return TestStepResult();
       
   101 					}
       
   102 				}
       
   103 			TheDisk.Close();
       
   104 			}
       
   105 		else
       
   106 			{
       
   107 			_LIT(KNoIniNumByte, "Cannot read the number of bytes from the ini file");
       
   108 			INFO_PRINTF1(KNoIniNumByte);
       
   109 			SetTestStepResult(EFail);
       
   110 			return TestStepResult();		
       
   111 			}
       
   112 		}
       
   113 	else
       
   114 		{
       
   115 		_LIT(KNoIniPos, "Cannot read the position from the ini file");
       
   116 		INFO_PRINTF1(KNoIniPos);
       
   117 		SetTestStepResult(EFail);
       
   118 		return TestStepResult();	
       
   119 		}
       
   120 
       
   121 	
       
   122 	SetTestStepResult(EPass);
       
   123 	_LIT(KWritePass, "Write Passed");
       
   124 	INFO_PRINTF1(KWritePass);
       
   125 	return TestStepResult();
       
   126 	}
       
   127 
       
   128 /** 
       
   129 Writing a value to the raw disk
       
   130 
       
   131 @param aPos The position from which to start writing to the raw disk
       
   132 @param aValue The value to write to the raw disk
       
   133 
       
   134 @return KErrNone if successfull
       
   135 */
       
   136 TInt CBaseTestFat32WriteRaw::WriteRaw(TInt64 aPos,TInt aValue)
       
   137 	{
       
   138 //	int val = 0;
       
   139 	TInt r;
       
   140 	TUint8 data[1];
       
   141 	TPtr8 buffer((TUint8*)&data[0],1);
       
   142 	r = TheDisk.Read(aPos,buffer);
       
   143 	data[0] = aValue;
       
   144 	r = TheDisk.Write(aPos,buffer);
       
   145 	if (r != KErrNone)
       
   146 		{
       
   147 		_LIT(KErrorWrite, "Cannot write to the raw disk - r=%d");
       
   148 		INFO_PRINTF2(KErrorWrite,r);
       
   149 		}		
       
   150 	return r; 
       
   151 	}
       
   152 	
       
   153 /** 
       
   154 Get the values that are to be written to the disk byte by byte 
       
   155 and place into an array
       
   156 
       
   157 @param aNumberOfBytes the nummber of bytes to write to the raw disk
       
   158 @param aValueArray Array containing the values to write to the raw disk
       
   159 
       
   160 @return KErrNone if successfull
       
   161 */
       
   162 TInt CBaseTestFat32WriteRaw::GetWriteValue(TInt aNumOfBytes,TInt* aValueArray)
       
   163 	{
       
   164 	TInt value;
       
   165 	TInt i;
       
   166 	_LIT(KWriteValues,"WriteValue%d");
       
   167 	for (i = 1; i < aNumOfBytes + 1; i++)
       
   168 		{
       
   169 		TBuf<20> writeValue;
       
   170 		writeValue.Format(KWriteValues, i);
       
   171 		TBool alright3 = GetHexFromConfig(ConfigSection(), writeValue, value);
       
   172 		if (alright3)
       
   173 			{
       
   174 			aValueArray[i-1] = value;
       
   175 			}
       
   176 		else
       
   177 			{
       
   178 			INFO_PRINTF1(_L("Cannot read WriteValue from ini file"));
       
   179 			return KErrGeneral;
       
   180 			}
       
   181 		}
       
   182 	return KErrNone;
       
   183 	}
       
   184 
       
   185 /** 
       
   186 Get the position by calulating from the entry and position in the entry 
       
   187 specified in the ini file
       
   188 
       
   189 @param aClusterNumber The cluster on the disk to write to
       
   190 @param aPosition the position within an entry
       
   191 
       
   192 @return KErrNone if successfull
       
   193 */
       
   194 TInt CBaseTestFat32WriteRaw::GetCluster(TInt aClusterNumber,TInt64 &aPosition)
       
   195 	{
       
   196 	TInt entry;
       
   197 	_LIT(KEntry,"Entry");
       
   198 	TInt entryposition;
       
   199 	_LIT(KPositionInEntry,"PositionInEntry");
       
   200 	TBool alright = GetIntFromConfig(ConfigSection(), KEntry, entry);
       
   201 		if (alright)
       
   202 			{
       
   203 			TBool alright2 = GetIntFromConfig(ConfigSection(), KPositionInEntry, entryposition);
       
   204 			if (alright2)
       
   205 				{
       
   206 				aPosition = (iBPB_ResvdSecCnt + (iBPB_FATSz32*2) + (iBPB_SecPerClus * (aClusterNumber - 2))) * 512;
       
   207 				aPosition = aPosition + ((entry - 1)*96)+ entryposition;//(32 * (entry - 1));
       
   208 				}
       
   209 			}
       
   210 	return KErrNone;
       
   211 	}
       
   212