baseapitest/basesvs/performance/f32/t_perf/src/SeekFileStep.cpp
changeset 0 a41df078684a
child 15 4122176ea935
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 the License "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 #include "SeekFileStep.h"
       
    19 
       
    20 /*@{*/
       
    21 // Literals Used
       
    22 _LIT(KT_SeekMode,						"seekMode");
       
    23 _LIT(KT_SeekStart,						"ESeekStart");
       
    24 _LIT(KT_SeekCurrent,					"ESeekCurrent");
       
    25 _LIT(KT_SeekEnd,						"ESeekEnd ");
       
    26 /*@}*/
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 // Function : CT_SeekFileStep
       
    32 // Description :CT_SeekFileStep class constructor
       
    33 CT_SeekFileStep ::CT_SeekFileStep ()
       
    34 :	CT_F32BaseStep(ETrue)
       
    35 ,	iSeekMode(ESeekStart)//default
       
    36 	{
       
    37 	SetTestStepName(KT_SeekFileStep);
       
    38 	}
       
    39 
       
    40 
       
    41 
       
    42 
       
    43 // Function : ~CT_SeekFileStep
       
    44 // Description :CT_SeekFileStep class destructor
       
    45 CT_SeekFileStep ::~CT_SeekFileStep ()
       
    46 	{
       
    47 	}
       
    48 
       
    49 
       
    50 // Function : doTestStepPreambleL()
       
    51 // Description :
       
    52 // @return :TVerdict EPass/EFail
       
    53 TVerdict CT_SeekFileStep ::doTestStepPreambleL()
       
    54 	{
       
    55 	//call base class doTestStepPreambleL
       
    56 	TVerdict 	result=CT_F32BaseStep::doTestStepPreambleL();
       
    57 
       
    58 	TPtrC 	seekmode;
       
    59 	if (!GetStringFromConfig(ConfigSection(),KT_SeekMode,seekmode))
       
    60 		{
       
    61 		SetSeekMode(seekmode);	//set data:seekmode
       
    62 		WARN_PRINTF1( _L("Corrupt seekmode will revert to default:ESeekStart"));
       
    63 		}	
       
    64 	return result;
       
    65 	}
       
    66 
       
    67 
       
    68 
       
    69 // Function : SetSeekMode
       
    70 // Description :
       
    71 //@param :TDesC& aSeekmode
       
    72 void CT_SeekFileStep::SetSeekMode(TDesC& aSeekmode)
       
    73 	{
       
    74 	if (aSeekmode==KT_SeekStart)
       
    75 		{
       
    76 		iSeekMode=ESeekStart;
       
    77 		}
       
    78 	else if (aSeekmode==KT_SeekCurrent)
       
    79 		{
       
    80 		iSeekMode=ESeekCurrent;
       
    81 		}
       
    82 	else if (aSeekmode==KT_SeekEnd)
       
    83 		{
       
    84 		iSeekMode=ESeekCurrent;
       
    85 		}
       
    86 	else
       
    87 		{
       
    88 		iSeekMode=ESeekStart;//default
       
    89 		}
       
    90 	}
       
    91 
       
    92 
       
    93 // Function : ThreadFunc
       
    94 // Description :Thread call back that seeks positions in files
       
    95 // @return :TInt
       
    96 TInt CT_SeekFileStep::ThreadFuncL(RFs& /*aSession*/)
       
    97 	{
       
    98  	RFile	file;	//	File that all operations are acted upon
       
    99  	//set up
       
   100 	TInt	result=KErrNone;
       
   101 	HBufC8*	data=HBufC8::NewLC(iBlockSize);
       
   102   	TPtr8	buf(data->Des());
       
   103   	buf.SetLength(iBlockSize);
       
   104 
       
   105   	TInt 	i=0;
       
   106 	TInt 	pos=0;
       
   107 	TInt 	sizebuf=iFileSize-iBlockSize;
       
   108 	TTime 	startTime;
       
   109 	TTime 	endTime;	//End timer
       
   110 	startTime.UniversalTime();		// Start timer
       
   111 	for(i=0; (i<iFuncCalls) && (result==KErrNone);i++)
       
   112 		{
       
   113 		pos=i%2?sizebuf-i/2:i/2;
       
   114 		file=iFileArray[i%iNumOfFiles];
       
   115 		result=(file.Seek(iSeekMode,pos));
       
   116 		}
       
   117 	endTime.UniversalTime();
       
   118 
       
   119 	//calculate extra time taken for pos calc (file offset calc)
       
   120 	TInt	calls=i;
       
   121 	TInt	res=KErrNone;
       
   122 	TTime 	startPos;	// Start pos timer
       
   123 	TTime 	endPos;	//End Pos timer
       
   124 	startPos.UniversalTime();
       
   125 	for(TInt j=0; (j<calls) && (res==KErrNone); j++)
       
   126 		{
       
   127 		pos=j%2?sizebuf-j/2:j/2;
       
   128 		file=iFileArray[j%iNumOfFiles];
       
   129 		}
       
   130 	endPos.UniversalTime();
       
   131 	endTime=endTime-(endPos.MicroSecondsFrom(startPos));
       
   132 	iTotalTime=endTime.MicroSecondsFrom(startTime);	//Store time-taken
       
   133 
       
   134 	CleanupStack::PopAndDestroy(1, data);// data
       
   135 	return result;
       
   136  	}