devsound/devsoundrefplugin/tsrc/SbcCodec/TSU_MMF_SbcCodec.cpp
changeset 0 79dd3e2336a0
equal deleted inserted replaced
-1:000000000000 0:79dd3e2336a0
       
     1 // Copyright (c) 2004-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 "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 //
       
    15 
       
    16 #include <e32base.h>
       
    17 #include <f32file.h>
       
    18 #include <s32file.h>
       
    19 #include <mmf/plugin/mmfsbccodecimplementationuids.hrh>
       
    20 
       
    21 #include "TSU_MMF_SbcCodec.h"
       
    22 #include "TSU_MMF_SbcCodecSuite.h"
       
    23 
       
    24 /**
       
    25  * Size of PCM16 wave file header is 44
       
    26  */
       
    27 const TInt  KWavFileHeaderSize = 44;
       
    28 /**
       
    29  * The default buffer size
       
    30  */
       
    31 const TUint KDefaultBufferSize = 4096;
       
    32 
       
    33 /**
       
    34  * UID of sbc encoder ECom plugin
       
    35  */
       
    36 const TUid  KSbcCodecPluginUid = { KMmfUidCodecPCM16ToSBC };
       
    37 /**
       
    38  * UID of sbc encoder configuration
       
    39  */
       
    40 const TUid	KSbcCodecConfigUid = { KMmfUidSBCConfigure };
       
    41 
       
    42 #ifdef __WINS__
       
    43 
       
    44 _LIT(KSourceFileDir, "c:\\mm\\mmf\\testfiles\\sbc\\");
       
    45 _LIT(KOutputFileDir, "c:\\mm\\mmf\\testfiles\\sbc\\");
       
    46 _LIT(KReferenceFileDir, "c:\\mm\\mmf\\ref\\sbc\\");
       
    47 
       
    48 #else
       
    49 
       
    50 /**
       
    51  * armv5 directories
       
    52  * All source and comparison files need to be copied manually onto the flash card.
       
    53  * This code assumes the flash card is represented by drive E: on the target board.
       
    54  */
       
    55 
       
    56 /**
       
    57  * we don't copy all the wave files onto C: as they are too big, leave them on E:
       
    58  */
       
    59 _LIT(KSourceFileDir, "e:\\");
       
    60 /**
       
    61  * This folder keeps all the output files
       
    62  */
       
    63 _LIT(KOutputFileDir, "c:\\sbc\\");
       
    64 /**
       
    65  * This folder keeps all the reference files for comparison
       
    66  */
       
    67 _LIT(KReferenceFileDir, "c:\\sbc\\ref\\");
       
    68 
       
    69 #endif
       
    70 
       
    71 // Test source files names
       
    72 _LIT(KTestWavFile01, "sbc_test_01.wav");
       
    73 _LIT(KTestWavFile02, "sbc_test_02.wav");
       
    74 _LIT(KTestWavFile03, "sbc_test_03.wav"); 
       
    75 _LIT(KTestWavFile04, "sbc_test_04.wav");
       
    76 _LIT(KTestWavFile05, "sbc_test_05.wav"); 
       
    77 _LIT(KTestWavFile06, "sbc_test_06.wav");
       
    78 _LIT(KTestWavFile07, "sbc_test_07.wav"); 
       
    79 _LIT(KTestWavFile08, "sbc_test_08.wav");
       
    80 _LIT(KTestWavFile09, "sbc_test_09.wav"); 
       
    81 _LIT(KTestWavFile10, "sbc_test_10.wav");
       
    82 
       
    83 _LIT(KTestWavFile11, "sbc_test_11.wav"); 
       
    84 _LIT(KTestWavFile12, "sbc_test_12.wav");
       
    85 _LIT(KTestWavFile13, "sbc_test_13.wav"); 
       
    86 _LIT(KTestWavFile14, "sbc_test_14.wav");
       
    87 _LIT(KTestWavFile15, "sbc_test_15.wav"); 
       
    88 _LIT(KTestWavFile16, "sbc_test_16.wav");
       
    89 _LIT(KTestWavFile17, "sbc_test_17.wav"); 
       
    90 _LIT(KTestWavFile18, "sbc_test_18.wav");
       
    91 _LIT(KTestWavFile19, "sbc_test_19.wav"); 
       
    92 _LIT(KTestWavFile20, "sbc_test_20.wav");
       
    93 
       
    94 _LIT(KTestWavFile21, "sbc_test_21.wav"); 
       
    95 _LIT(KTestWavFile22, "sbc_test_22.wav");
       
    96 _LIT(KTestWavFile23, "sbc_test_23.wav"); 
       
    97 _LIT(KTestWavFile24, "sbc_test_24.wav");
       
    98 _LIT(KTestWavFile25, "sbc_test_25.wav"); 
       
    99 _LIT(KTestWavFile26, "sbc_test_26.wav");
       
   100 _LIT(KTestWavFile27, "sbc_test_27.wav"); 
       
   101 _LIT(KTestWavFile28, "sbc_test_28.wav");
       
   102 
       
   103 // Test reference file name
       
   104 _LIT(KRefSbcFile01, "sbc_test_01.sbc"); 
       
   105 _LIT(KRefSbcFile02, "sbc_test_02.sbc");
       
   106 _LIT(KRefSbcFile03, "sbc_test_03.sbc"); 
       
   107 _LIT(KRefSbcFile04, "sbc_test_04.sbc");
       
   108 _LIT(KRefSbcFile05, "sbc_test_05.sbc"); 
       
   109 _LIT(KRefSbcFile06, "sbc_test_06.sbc");
       
   110 _LIT(KRefSbcFile07, "sbc_test_07.sbc"); 
       
   111 _LIT(KRefSbcFile08, "sbc_test_08.sbc");
       
   112 _LIT(KRefSbcFile09, "sbc_test_09.sbc"); 
       
   113 _LIT(KRefSbcFile10, "sbc_test_10.sbc");
       
   114 
       
   115 _LIT(KRefSbcFile11, "sbc_test_11.sbc"); 
       
   116 _LIT(KRefSbcFile12, "sbc_test_12.sbc");
       
   117 _LIT(KRefSbcFile13, "sbc_test_13.sbc"); 
       
   118 _LIT(KRefSbcFile14, "sbc_test_14.sbc");
       
   119 _LIT(KRefSbcFile15, "sbc_test_15.sbc"); 
       
   120 _LIT(KRefSbcFile16, "sbc_test_16.sbc");
       
   121 _LIT(KRefSbcFile17, "sbc_test_17.sbc"); 
       
   122 _LIT(KRefSbcFile18, "sbc_test_18.sbc");
       
   123 _LIT(KRefSbcFile19, "sbc_test_19.sbc"); 
       
   124 _LIT(KRefSbcFile20, "sbc_test_20.sbc");
       
   125 
       
   126 _LIT(KRefSbcFile21, "sbc_test_21.sbc"); 
       
   127 _LIT(KRefSbcFile22, "sbc_test_22.sbc");
       
   128 _LIT(KRefSbcFile23, "sbc_test_23.sbc"); 
       
   129 _LIT(KRefSbcFile24, "sbc_test_24.sbc");
       
   130 _LIT(KRefSbcFile25, "sbc_test_25.sbc"); 
       
   131 _LIT(KRefSbcFile26, "sbc_test_26.sbc");
       
   132 _LIT(KRefSbcFile27, "sbc_test_27.sbc"); 
       
   133 _LIT(KRefSbcFile28, "sbc_test_28.sbc");
       
   134 
       
   135 /**
       
   136  * List of channel mode settings
       
   137  */
       
   138 enum TChannelMode
       
   139 	{
       
   140 	/**
       
   141 	channel mode is Mono
       
   142 	*/
       
   143 	EMono,
       
   144 	/**
       
   145 	channel mode is Dual Channel
       
   146 	*/
       
   147 	EDual,
       
   148 	/**
       
   149 	channel mode is Stereo
       
   150 	*/
       
   151 	EStereo,
       
   152 	/**
       
   153 	channel mode is Joint Stereo
       
   154 	*/
       
   155 	EJoint
       
   156 	};
       
   157 
       
   158 /**
       
   159  * List of allocation method settings
       
   160  */
       
   161 enum TAllocMethod
       
   162 	{
       
   163 	/**
       
   164 	allocation method is SNR
       
   165 	*/
       
   166 	ESNR,
       
   167 	/**
       
   168 	allocation method is Loudness
       
   169 	*/
       
   170 	ELoud
       
   171 	};
       
   172 	
       
   173 /**
       
   174  * Table of all 28 tests configurations, each row contains the following fields in order
       
   175  * subbands, block length, sampling frequency, channel mode, allocation method, bitpool
       
   176  */
       
   177 const TInt gSbcConfig[28][6] = 
       
   178 	{
       
   179 		// configuration tests (8)
       
   180 		{ 4, 16, 48000, EMono,   ESNR,   18 },
       
   181 		{ 4, 16, 48000, EDual,   ESNR,   16 },
       
   182 		{ 8,  8, 44100, EMono,   ELoud,  32 },
       
   183 		{ 8,  8, 44100, EJoint,  ELoud,  56 },
       
   184 		{ 8,  4, 32000, EMono,   ESNR,   24 },
       
   185 		{ 8,  4, 32000, EStereo, ESNR,   48 },
       
   186 		{ 4, 12, 16000, EMono,   ELoud,  20 },
       
   187 		{ 4, 12, 16000, EJoint,  ELoud,  42 },
       
   188 		
       
   189 		// vbr tests (2)
       
   190 		{ 4, 16, 44100, EMono,   ELoud,  15 },
       
   191 		{ 8, 12, 48000, EJoint,  ELoud,  51 },
       
   192 		
       
   193 		// maximum bit rate tests (8)
       
   194 		{ 8, 16, 16000, EMono,   ELoud, 128 },
       
   195 		{ 8, 16, 16000, EJoint,  ESNR,  249 },
       
   196 		{ 8, 16, 32000, EMono,   ELoud,  76 },
       
   197 		{ 8, 16, 32000, EJoint,  ESNR,  121 },
       
   198 		{ 8, 16, 44100, EMono,   ELoud,  54 },
       
   199 		{ 8, 16, 44100, EJoint,  ESNR,   86 },
       
   200 		{ 8, 16, 48000, EMono,   ELoud,  49 },
       
   201 		{ 8, 16, 48000, EJoint,  ESNR,   78 },
       
   202 
       
   203 		// special tests (2)
       
   204 		{ 8, 16, 48000, EMono,   ESNR,   29 },
       
   205 		{ 8, 16, 44100, EJoint,  ESNR,   53 },
       
   206 
       
   207 		// typical tests (8)
       
   208 		{ 8, 16, 44100, EMono,   ELoud,  19 },
       
   209 		{ 8, 16, 48000, EMono,   ELoud,  18 },
       
   210 		{ 8, 16, 44100, EJoint,  ELoud,  35 },
       
   211 		{ 8, 16, 48000, EJoint,  ELoud,  33 },
       
   212 		{ 8, 16, 44100, EMono,   ELoud,  31 },
       
   213 		{ 8, 16, 48000, EMono,   ELoud,  29 },
       
   214 		{ 8, 16, 44100, EJoint,  ELoud,  53 },
       
   215 		{ 8, 16, 48000, EJoint,  ELoud,  51 }
       
   216 	};
       
   217 
       
   218 /**
       
   219  * This function converts number of subbands into TSBCFrameParameters::TSubbands value
       
   220  * @param 	"TInt aSubbands"
       
   221  *		  	number of subbands
       
   222  * @return	"TSBCFrameParameters::TSubbands"
       
   223  *			TSBCFrameParameters::TSubbands value
       
   224  */
       
   225 static inline TSBCFrameParameters::TSubbands GetSubbandsL(TInt aSubbands)
       
   226 	{
       
   227 	switch (aSubbands)
       
   228 		{
       
   229 		case 4: return TSBCFrameParameters::E4Subbands;
       
   230 		case 8: return TSBCFrameParameters::E8Subbands;
       
   231 		}
       
   232 	User::Leave(KErrArgument);
       
   233 	return TSBCFrameParameters::E4Subbands; // just make the compiler happy
       
   234 	}
       
   235 	
       
   236 /**
       
   237  * This function converts number of blocks into TSBCFrameParameters::TBlockLength value
       
   238  * @param 	"TInt aBlocks"
       
   239  *		  	number of blocks
       
   240  * @return	"TSBCFrameParameters::TBlockLength"
       
   241  *			TSBCFrameParameters::TBlockLength value
       
   242  */
       
   243 static inline TSBCFrameParameters::TBlockLength GetBlockLengthL(TInt aBlocks)
       
   244 	{
       
   245 	switch (aBlocks)
       
   246 		{
       
   247 		case 4: return TSBCFrameParameters::E4Blocks;
       
   248 		case 8: return TSBCFrameParameters::E8Blocks;
       
   249 		case 12: return TSBCFrameParameters::E12Blocks;
       
   250 		case 16: return TSBCFrameParameters::E16Blocks;
       
   251 		}
       
   252 	User::Leave(KErrArgument);
       
   253 	return TSBCFrameParameters::E4Blocks; //just make the compiler happy
       
   254 	}
       
   255 
       
   256 /**
       
   257  * This function converts sampling frequency value into TSBCFrameParameters::TSamplingFrequency value
       
   258  * @param 	"TInt aSampFreq"
       
   259  *		  	real sampling frequency value
       
   260  * @return	"TSBCFrameParameters::TSamplingFrequency"
       
   261  *			TSBCFrameParameters::TSamplingFrequency value
       
   262  */
       
   263 static inline TSBCFrameParameters::TSamplingFrequency GetSampFreqL(TInt aSampFreq)
       
   264 	{
       
   265 	switch (aSampFreq)
       
   266 		{
       
   267 		case 16000: return TSBCFrameParameters::E16000Hz;
       
   268 		case 32000: return TSBCFrameParameters::E32000Hz;
       
   269 		case 44100: return TSBCFrameParameters::E44100Hz;
       
   270 		case 48000: return TSBCFrameParameters::E48000Hz;
       
   271 		}
       
   272 	User::Leave(KErrArgument);
       
   273 	return TSBCFrameParameters::E16000Hz; // just make the compiler happy
       
   274 	}
       
   275 
       
   276 /**
       
   277  * This function converts ChannelMode enum value into TSBCFrameParameters::TChannelMode value
       
   278  * @param 	"TInt aChnlMode"
       
   279  *		  	ChannelMode enum value
       
   280  * @return	"TSBCFrameParameters::TChannelMode"
       
   281  *			TSBCFrameParameters::TChannelMode value
       
   282  */
       
   283 static inline TSBCFrameParameters::TChannelMode GetChannelModeL(TInt aChnlMode)
       
   284 	{
       
   285 	switch (aChnlMode)
       
   286 		{
       
   287 		case EMono: return TSBCFrameParameters::EMono;
       
   288 		case EDual: return TSBCFrameParameters::EDualChannel;
       
   289 		case EStereo: return TSBCFrameParameters::EStereo;
       
   290 		case EJoint: return TSBCFrameParameters::EJointStereo;
       
   291 		}
       
   292 	User::Leave(KErrArgument);
       
   293 	return TSBCFrameParameters::EMono; // just make the compiler happy
       
   294 	}
       
   295 	
       
   296 /**
       
   297  * This function converts AllocMethod enum value into TSBCFrameParameters::TAllocationMethod value
       
   298  * @param 	"TInt aAllocMthd"
       
   299  *		  	AllocMethod enum value
       
   300  * @return	"TSBCFrameParameters::TAllocationMethod"
       
   301  *			TSBCFrameParameters::TAllocationMethod value
       
   302  */
       
   303 static inline TSBCFrameParameters::TAllocationMethod GetAllocMethodL(TInt aAllocMthd)
       
   304 	{
       
   305 	switch (aAllocMthd)
       
   306 		{
       
   307 		case ESNR: return TSBCFrameParameters::ESNR;
       
   308 		case ELoud: return TSBCFrameParameters::ELoudness;
       
   309 		}
       
   310 	User::Leave(KErrArgument);
       
   311 	return TSBCFrameParameters::ESNR;
       
   312 	}
       
   313 	
       
   314 /**
       
   315  * This function gets the configuration for one test from SbcConfig[28]
       
   316  * @param 	"TInt aTestNumber"
       
   317  *		  	test number
       
   318  * @return	"TSBCFrameParameters"
       
   319  *			the sbc frame parameters used to configure sbc codec
       
   320  */
       
   321 static TSBCFrameParameters SbcParametersL(TInt aTestNumber)
       
   322 	{
       
   323 	if (aTestNumber < 0 || aTestNumber > 28)
       
   324 		{
       
   325 		User::Leave(KErrArgument);
       
   326 		}
       
   327 		
       
   328 	TSBCFrameParameters param;
       
   329 	param.SetSubbands(GetSubbandsL(gSbcConfig[aTestNumber - 1][0]) );
       
   330 	param.SetBlockLength(GetBlockLengthL(gSbcConfig[aTestNumber - 1][1]) );
       
   331 	param.SetSamplingFrequency(GetSampFreqL(gSbcConfig[aTestNumber - 1][2]) );
       
   332 	param.SetChannelMode(GetChannelModeL(gSbcConfig[aTestNumber - 1][3]) );
       
   333 	param.SetAllocationMethod(GetAllocMethodL(gSbcConfig[aTestNumber - 1][4]) );
       
   334 	param.SetBitpool(static_cast<TUint8>(gSbcConfig[aTestNumber - 1][5]) );
       
   335 	return param;
       
   336 	}
       
   337 	
       
   338 /**
       
   339  * Constructor
       
   340  */
       
   341 CTestStep_MMF_SbcCodec::CTestStep_MMF_SbcCodec()
       
   342 	{
       
   343 	}
       
   344 
       
   345 /**
       
   346  * Destructor
       
   347  */
       
   348 CTestStep_MMF_SbcCodec::~CTestStep_MMF_SbcCodec()
       
   349 	{
       
   350 	}
       
   351 
       
   352 /**
       
   353  * This function gets test source file name for one test
       
   354  * @param 	"TInt aTestNumber"
       
   355  *		  	test number
       
   356  * @return 	"const TDesC&"
       
   357  * 			test file name
       
   358  */
       
   359 const TDesC& CTestStep_MMF_SbcCodec::GetTestFileName(TInt aTestNumber)
       
   360 	{
       
   361 	switch (aTestNumber)
       
   362 		{
       
   363 		case 1 : return KTestWavFile01;
       
   364 		case 2 : return KTestWavFile02;
       
   365 		case 3 : return KTestWavFile03;
       
   366 		case 4 : return KTestWavFile04;
       
   367 		case 5 : return KTestWavFile05;
       
   368 		case 6 : return KTestWavFile06;
       
   369 		case 7 : return KTestWavFile07;
       
   370 		case 8 : return KTestWavFile08;
       
   371 		case 9 : return KTestWavFile09;
       
   372 		case 10: return KTestWavFile10;
       
   373 
       
   374 		case 11: return KTestWavFile11;
       
   375 		case 12: return KTestWavFile12;
       
   376 		case 13: return KTestWavFile13;
       
   377 		case 14: return KTestWavFile14;
       
   378 		case 15: return KTestWavFile15;
       
   379 		case 16: return KTestWavFile16;
       
   380 		case 17: return KTestWavFile17;
       
   381 		case 18: return KTestWavFile18;
       
   382 		case 19: return KTestWavFile19;
       
   383 		case 20: return KTestWavFile20;
       
   384 
       
   385 		case 21: return KTestWavFile21;
       
   386 		case 22: return KTestWavFile22;
       
   387 		case 23: return KTestWavFile23;
       
   388 		case 24: return KTestWavFile24;
       
   389 		case 25: return KTestWavFile25;
       
   390 		case 26: return KTestWavFile26;
       
   391 		case 27: return KTestWavFile27;
       
   392 		case 28: return KTestWavFile28;
       
   393 		}
       
   394 	User::Panic(_L("Invalid test number"), KErrArgument);
       
   395 	return KTestWavFile01;
       
   396 	}
       
   397 	
       
   398 /**
       
   399  * This function gets test reference file name for one test
       
   400  * @param 	"TInt aTestNumber"
       
   401  *		  	test number
       
   402  * @return 	"const TDesC&"
       
   403  * 			reference file name
       
   404  */
       
   405 const TDesC& CTestStep_MMF_SbcCodec::GetRefFileName(TInt aTestNumber)
       
   406 	{
       
   407 	switch (aTestNumber)
       
   408 		{
       
   409 		case 1 : return KRefSbcFile01;
       
   410 		case 2 : return KRefSbcFile02;
       
   411 		case 3 : return KRefSbcFile03;
       
   412 		case 4 : return KRefSbcFile04;
       
   413 		case 5 : return KRefSbcFile05;
       
   414 		case 6 : return KRefSbcFile06;
       
   415 		case 7 : return KRefSbcFile07;
       
   416 		case 8 : return KRefSbcFile08;
       
   417 		case 9 : return KRefSbcFile09;
       
   418 		case 10: return KRefSbcFile10;
       
   419 
       
   420 		case 11: return KRefSbcFile11;
       
   421 		case 12: return KRefSbcFile12;
       
   422 		case 13: return KRefSbcFile13;
       
   423 		case 14: return KRefSbcFile14;
       
   424 		case 15: return KRefSbcFile15;
       
   425 		case 16: return KRefSbcFile16;
       
   426 		case 17: return KRefSbcFile17;
       
   427 		case 18: return KRefSbcFile18;
       
   428 		case 19: return KRefSbcFile19;
       
   429 		case 20: return KRefSbcFile20;
       
   430 
       
   431 		case 21: return KRefSbcFile21;
       
   432 		case 22: return KRefSbcFile22;
       
   433 		case 23: return KRefSbcFile23;
       
   434 		case 24: return KRefSbcFile24;
       
   435 		case 25: return KRefSbcFile25;
       
   436 		case 26: return KRefSbcFile26;
       
   437 		case 27: return KRefSbcFile27;
       
   438 		case 28: return KRefSbcFile28;
       
   439 		}
       
   440 	User::Panic(_L("Invalid test number"), KErrArgument);
       
   441 	return KRefSbcFile01;
       
   442 	}
       
   443 	
       
   444 /**
       
   445  * This function reads source out from source file from a specific position 
       
   446  and fill the srouce into the source buffer.
       
   447  * @param 	"const TDesC& aFileName"
       
   448  *		  	the source file name
       
   449  * @param 	"TDes8& aSrcBuffer"
       
   450  *		  	the source buffer
       
   451  * @param 	"TInt aFilePos"
       
   452  *		  	the file position
       
   453  * @leave if reading file failed
       
   454  */
       
   455 void CTestStep_MMF_SbcCodec::ReadSourceL(const TDesC& aFileName, TDes8& aSrcBuffer, TInt aFilePos)
       
   456 	{
       
   457 	TFileName srcFileName(KSourceFileDir);
       
   458 	srcFileName.Append(aFileName);
       
   459 	
       
   460 	// connect to file service
       
   461 	RFs fs;
       
   462 	User::LeaveIfError(fs.Connect());
       
   463 	CleanupClosePushL(fs);
       
   464 
       
   465 	RFile srcFile;
       
   466 	User::LeaveIfError(srcFile.Open(fs, srcFileName, EFileRead | EFileShareAny) );
       
   467 	CleanupClosePushL(srcFile);
       
   468 	
       
   469 	aFilePos += KWavFileHeaderSize; // skip wave file header
       
   470 	User::LeaveIfError(srcFile.Seek(ESeekStart, aFilePos) );
       
   471 	User::LeaveIfError(srcFile.Read(aSrcBuffer) );
       
   472 	
       
   473 	CleanupStack::PopAndDestroy(2);
       
   474 	}
       
   475 	
       
   476 /**
       
   477  * This function writes destination into destination file from a specific position.
       
   478  * @param 	"const TDesC& aFileName"
       
   479  *		  	the destination file name
       
   480  * @param 	"TDes8& aDstBuffer"
       
   481  *		  	the destination buffer
       
   482  * @param 	"TInt aFilePos"
       
   483  *		  	the file position
       
   484  * @leave if writing file failed
       
   485  */
       
   486 void CTestStep_MMF_SbcCodec::WriteDstToFileL(const TDesC& aFileName, const TDes8& aDstBuffer, TInt aFilePos)
       
   487 	{
       
   488 	TFileName dstFileName(KOutputFileDir);
       
   489 	dstFileName.Append(aFileName);
       
   490 	
       
   491 	// connect to file service
       
   492 	RFs fs;
       
   493 	User::LeaveIfError(fs.Connect());
       
   494 	CleanupClosePushL(fs);
       
   495 
       
   496 	RFile dstFile;
       
   497 	TInt err = dstFile.Open(fs, dstFileName, EFileWrite);
       
   498 	if (err == KErrNotFound) // file does not exist - create it
       
   499 		{
       
   500 		err = dstFile.Create(fs, dstFileName, EFileWrite);
       
   501 		}
       
   502 	if (err != KErrNone)
       
   503 		{
       
   504 		User::Leave(err);
       
   505 		}
       
   506     CleanupClosePushL(dstFile);
       
   507 	
       
   508 	User::LeaveIfError(dstFile.Seek(ESeekStart, aFilePos) );
       
   509 	User::LeaveIfError(dstFile.Write(aDstBuffer) );
       
   510 		
       
   511 	CleanupStack::PopAndDestroy(2);
       
   512 	}
       
   513 
       
   514 /**
       
   515  * This function compares two files to check if they are the same.
       
   516  * @param 	"const TDesC& aFileName"
       
   517  *		  	the compare and reference files name
       
   518  * @return	"TInt"
       
   519  * 			0: two files are the same
       
   520  *			-1: two files are NOT the same
       
   521  * @leave if reading tow files failed
       
   522  */
       
   523 TInt CTestStep_MMF_SbcCodec::CompareFileL(const TDesC& aFileName)
       
   524 	{
       
   525 	TFileName cmpFileName(KOutputFileDir);
       
   526 	cmpFileName.Append(aFileName);
       
   527 	
       
   528 	TFileName refFileName(KReferenceFileDir);
       
   529 	refFileName.Append(aFileName);
       
   530 	
       
   531 	// connect to file service
       
   532 	RFs fs;
       
   533 	User::LeaveIfError(fs.Connect());
       
   534 	CleanupClosePushL(fs);
       
   535 
       
   536 	RFile cmpFile;
       
   537 	User::LeaveIfError(cmpFile.Open(fs, cmpFileName, EFileRead) );
       
   538     CleanupClosePushL(cmpFile);
       
   539     
       
   540 	RFile refFile;
       
   541 	User::LeaveIfError(refFile.Open(fs, refFileName, EFileRead) );
       
   542     CleanupClosePushL(refFile);
       
   543     
       
   544     TInt cmpFileSize = 0;
       
   545     TInt refFileSize = 0;
       
   546     
       
   547     cmpFile.Size(cmpFileSize);
       
   548     refFile.Size(refFileSize);
       
   549     
       
   550     if (cmpFileSize != refFileSize)
       
   551     	{
       
   552 		CleanupStack::PopAndDestroy(3); // refFile, cmpFile, fs
       
   553     	return -1;
       
   554     	}
       
   555     	
       
   556 	CMMFDataBuffer* cmpFileBuf = CMMFDataBuffer::NewL(KDefaultBufferSize);
       
   557 	CleanupStack::PushL(cmpFileBuf);
       
   558 	CMMFDataBuffer* refFileBuf = CMMFDataBuffer::NewL(KDefaultBufferSize);
       
   559 	CleanupStack::PushL(refFileBuf);
       
   560     
       
   561     TInt result = 0;
       
   562     for (;;)
       
   563     	{
       
   564     	User::LeaveIfError(cmpFile.Read(cmpFileBuf->Data() ) );
       
   565     	if (cmpFileBuf->Data().Length() == 0) // end of file
       
   566     		{
       
   567     		break;
       
   568     		}
       
   569     	
       
   570     	User::LeaveIfError(refFile.Read(refFileBuf->Data() ) );
       
   571     	if (cmpFileBuf->Data() != refFileBuf->Data() )
       
   572     		{
       
   573     		result = -1;
       
   574     		break;
       
   575     		}
       
   576     		
       
   577     	cmpFileBuf->Data().Zero();
       
   578     	refFileBuf->Data().Zero();
       
   579     	}
       
   580     	
       
   581 	CleanupStack::PopAndDestroy(5); // refFileBuff, cmpFileBuff, refFile, cmpFile, fs
       
   582 	return result;
       
   583 	}
       
   584 	
       
   585 /**
       
   586  * This function is called by two TestNewL() tests, it calls ProcessL() once 
       
   587  * and checks the result.
       
   588  * @param 	"CMMFCodec* aCodec"
       
   589  * 			the codec for test
       
   590  * @return	"TVerdict"
       
   591  *			EPass: at least one byte src processed and one byte of dst generated and no error 
       
   592  *			EFail: other wise.
       
   593  * @leave if out of memory or ProcessL() leaves
       
   594  */
       
   595 TVerdict CTestStep_MMF_SbcCodec::ProcessOnceForNewL(CMMFCodec* aCodec)
       
   596 	{
       
   597 	TVerdict testResult = EFail;
       
   598 	
       
   599 	// create buffers
       
   600 	CMMFDataBuffer* srcBuffer = CMMFDataBuffer::NewL(KDefaultBufferSize);
       
   601 	CleanupStack::PushL(srcBuffer);
       
   602 	CMMFDataBuffer* dstBuffer = CMMFDataBuffer::NewL(KDefaultBufferSize);
       
   603 	CleanupStack::PushL(dstBuffer);
       
   604 	
       
   605 	TInt testNumber = 28;
       
   606 	TPckgBuf<TSBCFrameParameters> config(SbcParametersL(testNumber) );
       
   607 	aCodec->ConfigureL(KSbcCodecConfigUid, config);
       
   608 	
       
   609 	ReadSourceL(GetTestFileName(testNumber), srcBuffer->Data(), 0);
       
   610 		
       
   611 	if (srcBuffer->Data().Length() > 0) // end of file
       
   612 		{
       
   613 		TCodecProcessResult result = aCodec->ProcessL(*srcBuffer, *dstBuffer);
       
   614 		
       
   615 		if (result.iDstBytesAdded > 0 && result.iSrcBytesProcessed > 0)
       
   616 			{
       
   617 			testResult = EPass;
       
   618 			}
       
   619 		}
       
   620 	else
       
   621 		{
       
   622 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::ProcessOnceForNewL no source read") );
       
   623 		}
       
   624 
       
   625 	CleanupStack::PopAndDestroy(2); // dstBuffer, srcBuffer
       
   626 
       
   627 	return testResult;
       
   628 }
       
   629 
       
   630 /**
       
   631  * This function tests codec instantiation by ECom plugin UID.
       
   632  * @param 	"TUid aCodecUID"
       
   633  * 			the codec ECom UID
       
   634  * @return	"TVerdict"
       
   635  *			EPass: ProcessOnceForNewL() passes 
       
   636  *			EFail: ProcessOnceForNewL() fails
       
   637  * @leave if CMMFCodec::NewL() leaves
       
   638  */
       
   639 TVerdict CTestStep_MMF_SbcCodec::TestNewL(TUid aCodecUID)
       
   640 	{
       
   641 	//create codec from uid
       
   642 	CMMFCodec* codec = NULL;
       
   643 	TRAPD(err, codec = CMMFCodec::NewL(aCodecUID) );
       
   644 	
       
   645 	if (err != KErrNone)
       
   646 		{
       
   647 		ERR_PRINTF2(_L(">> CTestStep_MMF_SbcCodec::TestNewL Leave occurred in NewL, error code %d"), err);
       
   648 		return EFail;
       
   649 		}
       
   650 	if (!codec)
       
   651 		{
       
   652 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestNewL NewL returned NULL") );
       
   653 		return EFail;
       
   654 		}
       
   655 
       
   656 	CleanupStack::PushL(codec);
       
   657 	TVerdict result = ProcessOnceForNewL(codec);
       
   658 	CleanupStack::PopAndDestroy(); //codec
       
   659 	return result;
       
   660 	}
       
   661 
       
   662 /**
       
   663  * This function tests codec instantiation by two FourCC codes.
       
   664  * @param 	"const TFourCC& aSrcFourCC"
       
   665  * 			the FourCC code of source media type
       
   666  * @param 	"const TFourCC& aDstFourCC"
       
   667  * 			the FourCC code of destination media type
       
   668  * @return	"TVerdict"
       
   669  *			EPass: ProcessOnceForNewL() passes
       
   670  *			EFail: ProcessOnceForNewL() fails
       
   671  * @leave if CMMFCodec::NewL() or ProcessOnceForNewL() leaves
       
   672  */
       
   673 TVerdict CTestStep_MMF_SbcCodec::TestNewL(const TFourCC& aSrcFourCC, const TFourCC& aDstFourCC)
       
   674 	{
       
   675 	//create codec from uid
       
   676 	CMMFCodec* codec = NULL;
       
   677 	TRAPD(err, codec = CMMFCodec::NewL(aSrcFourCC, aDstFourCC) );
       
   678 	
       
   679 	if (err != KErrNone)
       
   680 		{
       
   681 		ERR_PRINTF2(_L(">> CTestStep_MMF_SbcCodec::TestNewL Leave occurred in NewL, error code %d"), err);
       
   682 		return EFail;
       
   683 		}
       
   684 	if (!codec)
       
   685 		{
       
   686 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestNewL NewL returned NULL") );
       
   687 		return EFail;
       
   688 		}
       
   689 
       
   690 	CleanupStack::PushL(codec);
       
   691 	TVerdict result = ProcessOnceForNewL(codec);
       
   692 	CleanupStack::PopAndDestroy(); //codec
       
   693 	return result;
       
   694 	}
       
   695 	
       
   696 /**
       
   697  * Performance test
       
   698  * This function tests ProcessL() function, it checks if ProcessL() returns the 
       
   699  * correct result with different buffer size settings
       
   700  * @return	"TVerdict"
       
   701  * 			EPass: the results are expected ones. 
       
   702  * 			EFail: otherwise. 
       
   703  * @leave if out of memory or ProcessL(), ReadSourceL() leaves
       
   704  */
       
   705 TVerdict CTestStep_MMF_SbcCodec::TestProcessL()
       
   706 	{
       
   707 	//create codec from uid
       
   708 	CMMFCodec* codec = NULL;
       
   709 	TRAPD(err, codec = CMMFCodec::NewL(KSbcCodecPluginUid) );
       
   710 	
       
   711 	if (err != KErrNone)
       
   712 		{
       
   713 		ERR_PRINTF2(_L(">> CTestStep_MMF_SbcCodec::TestProcessL Leave occurred in NewL, error code %d"), err);
       
   714 		return EFail;
       
   715 		}
       
   716 	if (!codec)
       
   717 		{
       
   718 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessL NewL returned NULL") );
       
   719 		return EFail;
       
   720 		}
       
   721 
       
   722 	CleanupStack::PushL(codec);
       
   723 
       
   724 	const TInt testNumber = 28;
       
   725 	
       
   726 	TSBCFrameParameters param = SbcParametersL(testNumber);
       
   727 	
       
   728 	const TUint sbcFrameLength = param.CalcFrameLength();
       
   729 	const TUint pcmFrameSize = sizeof(TInt16) * param.BlockLength() * param.Channels() * param.Subbands();
       
   730 	
       
   731 	// create src buffer
       
   732 	CMMFDataBuffer* srcBuffer = CMMFDataBuffer::NewL(pcmFrameSize);
       
   733 	CleanupStack::PushL(srcBuffer);
       
   734 	
       
   735 	// dummy buffer, smaller than one frame length
       
   736 	CMMFDataBuffer* dummyBuffer = CMMFDataBuffer::NewL(sbcFrameLength - 1);
       
   737 	CleanupStack::PushL(dummyBuffer);
       
   738 	
       
   739 	// create dst buffer
       
   740 	CMMFDataBuffer* dstBuffer = CMMFDataBuffer::NewL(sbcFrameLength); 
       
   741 	CleanupStack::PushL(dstBuffer);
       
   742 	
       
   743 	ReadSourceL(GetTestFileName(testNumber), srcBuffer->Data(), 0);
       
   744 	
       
   745 	if (static_cast<TUint>(srcBuffer->Data().Length() ) != pcmFrameSize)
       
   746 		{
       
   747 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessL read source failed") );
       
   748 		CleanupStack::PopAndDestroy(3); // dstBuffer, srcBuffer, codec
       
   749 		return EFail;
       
   750 		}
       
   751 
       
   752 	TVerdict testResult = EPass;
       
   753 	TCodecProcessResult procResult;
       
   754 	
       
   755 	/** test ProcessL() without ConfigureL() called, should leave with KErrAbort */
       
   756 	
       
   757 	TRAP(err, procResult = codec->ProcessL(*srcBuffer, *dstBuffer) );
       
   758 	
       
   759 	if (err != KErrAbort || 
       
   760 		procResult.iSrcBytesProcessed != 0 || 
       
   761 		procResult.iDstBytesAdded != 0 || 
       
   762 		procResult.iStatus != TCodecProcessResult::EProcessError)
       
   763 		{
       
   764 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessL failed, ProcessL didn't leave with KErrAbort when ConfigureL() is not called") );
       
   765 		testResult = EFail;
       
   766 		}
       
   767 	
       
   768 	/** test ProcessL() with small dst buffer size, should leave with KErrArgument */
       
   769 	
       
   770 	TPckgBuf<TSBCFrameParameters> config(param);
       
   771 	codec->ConfigureL(KSbcCodecConfigUid, config);
       
   772 	
       
   773 	codec->ResetL();
       
   774 	TRAP(err, procResult = codec->ProcessL(*srcBuffer, *dummyBuffer) );
       
   775 	
       
   776 	if (err != KErrArgument || 
       
   777 		procResult.iSrcBytesProcessed != 0 || 
       
   778 		procResult.iDstBytesAdded != 0 || 
       
   779 		procResult.iStatus != TCodecProcessResult::EProcessError)
       
   780 		{
       
   781 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessL failed in ProcessL") );
       
   782 		testResult = EFail;
       
   783 		}
       
   784 		
       
   785 	/** test ProcessL() with correct settings, should return EProcessComplete */
       
   786 	
       
   787 	codec->ResetL();
       
   788 	TRAP(err, procResult = codec->ProcessL(*srcBuffer, *dstBuffer) );
       
   789 	
       
   790 	if (err != KErrNone || 
       
   791 		procResult.iSrcBytesProcessed != pcmFrameSize || 
       
   792 		procResult.iDstBytesAdded != sbcFrameLength || 
       
   793 		procResult.iStatus != TCodecProcessResult::EProcessComplete)
       
   794 		{
       
   795 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessL failed, ProcessL didn't work propertly with correct settings") );
       
   796 		testResult = EFail;
       
   797 		}
       
   798 	
       
   799 	/** test ProcessL() with not enough dst buffer remained, should return EProcessIncomplete */
       
   800 
       
   801 	// now the remaining dst buffer size is one byte less than one frame length
       
   802 	dstBuffer->SetPosition(1); 
       
   803 	
       
   804 	codec->ResetL();
       
   805 	TRAP(err, procResult = codec->ProcessL(*srcBuffer, *dstBuffer) );
       
   806 	
       
   807 	if (err != KErrNone || 
       
   808 		procResult.iSrcBytesProcessed != 0 || 
       
   809 		procResult.iDstBytesAdded != 0 || 
       
   810 		procResult.iStatus != TCodecProcessResult::EProcessIncomplete)
       
   811 		{
       
   812 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessL failed, ProcessL didn't return EProcessIncomplete when there is not enough dst buffer") );
       
   813 		testResult = EFail;
       
   814 		}
       
   815 	
       
   816 	/** test ProcessL() with not enough src buffer remained, should return EDstNotFilled */
       
   817 
       
   818 	// set this position to an even value as only even number of samples will be cached
       
   819 	const TInt srcPos = 2;
       
   820 	// the remaining src buffer size is less than one frame, it should be cached, 
       
   821 	// and return EProcessDstNotFilled 
       
   822 	srcBuffer->SetPosition(srcPos); 
       
   823 	// now the remaining dst buffer size is one frame length
       
   824 	dstBuffer->SetPosition(0);
       
   825 	
       
   826 	codec->ResetL();
       
   827 	TRAP(err, procResult = codec->ProcessL(*srcBuffer, *dstBuffer) );
       
   828 	
       
   829 	if (err != KErrNone || 
       
   830 		procResult.iSrcBytesProcessed != pcmFrameSize - srcPos || 
       
   831 		procResult.iDstBytesAdded != 0 || 
       
   832 		procResult.iStatus != TCodecProcessResult::EDstNotFilled)
       
   833 		{
       
   834 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessL failed, ProcessL didn't return EDstNotFilled when there is not enough src buffer") );
       
   835 		testResult = EFail;
       
   836 		}
       
   837 		
       
   838 	CleanupStack::PopAndDestroy(4); // dstBuffer, dummyBuffer, srcBuffer, codec
       
   839 	return testResult;
       
   840 	}
       
   841 
       
   842 /**
       
   843  * This function tests the whole encoding routine with a specific settings (e.g. 
       
   844  * sbc frameparameters, src buffer size, dst buffer size) and compares the result 
       
   845  * file with reference file.
       
   846  * @param	"TInt aTestNumber"
       
   847  * 			the test number.
       
   848  * @param	"TInt aSrcBufSize"
       
   849  * 			the source buffer size.
       
   850  * @param	"TInt aDstBufSize"
       
   851  * 			the destination buffer size.
       
   852  * @return	"TVerdict"
       
   853  * 			EPass: encoded file is the same as the reference file. 
       
   854  * 			EFail: encoded file is NOT the same as the reference file. 
       
   855  * @leave if out of memory or ProcessL(), ReadSourceL(), WriteDstToFileL() leaves
       
   856  */
       
   857 TVerdict CTestStep_MMF_SbcCodec::TestEncodeL(TInt aTestNumber, TInt aSrcBufSize, TInt aDstBufSize)
       
   858 	{
       
   859 	//create codec from uid
       
   860 	CMMFCodec* codec = NULL;
       
   861 	TRAPD(err, codec = CMMFCodec::NewL(KSbcCodecPluginUid) );
       
   862 	
       
   863 	if (err != KErrNone)
       
   864 		{
       
   865 		ERR_PRINTF2(_L(">> CTestStep_MMF_SbcCodec::TestEncodeL Leave occurred in NewL, error code %d"), err);
       
   866 		return EFail;
       
   867 		}
       
   868 	if (!codec)
       
   869 		{
       
   870 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestEncodeL NewL returned NULL") );
       
   871 		return EFail;
       
   872 		}
       
   873 
       
   874 	CleanupStack::PushL(codec);
       
   875 
       
   876 	// create buffers
       
   877 	CMMFDataBuffer* srcBuffer = CMMFDataBuffer::NewL(aSrcBufSize);
       
   878 	CleanupStack::PushL(srcBuffer);
       
   879 	CMMFDataBuffer* dstBuffer = CMMFDataBuffer::NewL(aDstBufSize);
       
   880 	CleanupStack::PushL(dstBuffer);
       
   881 	
       
   882 	TPckgBuf<TSBCFrameParameters> config(SbcParametersL(aTestNumber) );
       
   883 	codec->ConfigureL(KSbcCodecConfigUid, config);
       
   884 	
       
   885 	TInt srcFilePos = 0;
       
   886 	TInt dstFilePos = 0;
       
   887 	
       
   888 	for (;;)
       
   889 		{
       
   890 		ReadSourceL(GetTestFileName(aTestNumber), srcBuffer->Data(), srcFilePos);
       
   891 		
       
   892 		if (srcBuffer->Data().Length() == 0) // end of file
       
   893 			{
       
   894 			break;
       
   895 			}
       
   896 		
       
   897 		TCodecProcessResult result = codec->ProcessL(*srcBuffer, *dstBuffer);
       
   898 
       
   899 		WriteDstToFileL(GetRefFileName(aTestNumber), dstBuffer->Data(), dstFilePos);
       
   900 		
       
   901 		srcBuffer->Data().Zero();
       
   902 		dstBuffer->Data().Zero();
       
   903 		
       
   904 		srcFilePos += result.iSrcBytesProcessed;
       
   905 		dstFilePos += result.iDstBytesAdded;
       
   906 		}
       
   907 	
       
   908 	TVerdict result = EPass;
       
   909 	if (CompareFileL(GetRefFileName(aTestNumber) ) != 0)
       
   910 		{
       
   911 		result = EFail;
       
   912 		}
       
   913 		
       
   914 	CleanupStack::PopAndDestroy(3); // dstBuffer, srcBuffer, codec
       
   915 	return result;
       
   916 	}
       
   917 
       
   918 /**
       
   919  * This function tests codec ResetL() function make sure the cach buffer 
       
   920  * gets cleared when it gets called. It compares the encoded file with the reference file
       
   921  * @return	"TVerdict"
       
   922  * 			EPass: encoded file is the same as the reference file. 
       
   923  * 			EFail: encoded file is NOT the same as the reference file. 
       
   924  * @leave if out of memory or ProcessL(), ReadSourceL(), WriteDstToFileL() leaves
       
   925  */
       
   926 TVerdict CTestStep_MMF_SbcCodec::TestRepositionL()
       
   927 	{
       
   928 	//create codec from uid
       
   929 	CMMFCodec* codec = NULL;
       
   930 	TRAPD(err, codec = CMMFCodec::NewL(KSbcCodecPluginUid) );
       
   931 	
       
   932 	if (err != KErrNone)
       
   933 		{
       
   934 		ERR_PRINTF2(_L(">> CTestStep_MMF_SbcCodec::TestRepositionL Leave occurred in NewL, error code %d"), err);
       
   935 		return EFail;
       
   936 		}
       
   937 	if (!codec)
       
   938 		{
       
   939 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestRepositionL NewL returned NULL") );
       
   940 		return EFail;
       
   941 		}
       
   942 
       
   943 	CleanupStack::PushL(codec);
       
   944 
       
   945 	const TInt testNumber = 28;
       
   946 	// this size will make sure some samples will be cached, 
       
   947 	// also make sure it is an EVEN number
       
   948 	const TInt srcBufSize = 4094; 
       
   949 	const TInt dstBufSize = 2048;
       
   950 	
       
   951 	// create buffers
       
   952 	CMMFDataBuffer* srcBuffer = CMMFDataBuffer::NewL(srcBufSize);
       
   953 	CleanupStack::PushL(srcBuffer);
       
   954 	CMMFDataBuffer* dstBuffer = CMMFDataBuffer::NewL(dstBufSize);
       
   955 	CleanupStack::PushL(dstBuffer);
       
   956 	
       
   957 	TSBCFrameParameters param = SbcParametersL(testNumber);
       
   958 	
       
   959 	TPckgBuf<TSBCFrameParameters> config(param);
       
   960 	codec->ConfigureL(KSbcCodecConfigUid, config);
       
   961 	
       
   962 	const TUint pcmFrameSize = sizeof(TInt16) * param.BlockLength() * param.Channels() * param.Subbands();
       
   963 	
       
   964 	TInt srcFilePos = 0;
       
   965 	TInt dstFilePos = 0;
       
   966 	
       
   967 	for (;;)
       
   968 		{
       
   969 		ReadSourceL(GetTestFileName(testNumber), srcBuffer->Data(), srcFilePos);
       
   970 		
       
   971 		if (srcBuffer->Data().Length() == 0) // end of file
       
   972 			{
       
   973 			break;
       
   974 			}
       
   975 			
       
   976 		TCodecProcessResult result = codec->ProcessL(*srcBuffer, *dstBuffer);
       
   977 		
       
   978 		WriteDstToFileL(GetRefFileName(testNumber), dstBuffer->Data(), dstFilePos);
       
   979 		
       
   980 		// clear up any cached samples
       
   981 		codec->ResetL();
       
   982 		// the iSrcBytesProcessed includes the encoded src size plus the cached src size, 
       
   983 		// here set the iSrcBytesProcessed to the encoded src size only as we cleared up 
       
   984 		// the cached samples
       
   985 		result.iSrcBytesProcessed -= srcBuffer->Data().Length() % pcmFrameSize;
       
   986 		
       
   987 		srcBuffer->Data().Zero();
       
   988 		dstBuffer->Data().Zero();
       
   989 		
       
   990 		// set new src file position, which is the end of encoded src (no cached src)
       
   991 		srcFilePos += result.iSrcBytesProcessed;
       
   992 		// set new dst file position
       
   993 		dstFilePos += result.iDstBytesAdded;
       
   994 		}
       
   995 
       
   996 	TVerdict result = EPass;
       
   997 	if (CompareFileL(GetRefFileName(testNumber) ) != 0)
       
   998 		{
       
   999 		result = EFail;
       
  1000 		}
       
  1001 		
       
  1002 	CleanupStack::PopAndDestroy(3); // dstBuffer, srcBuffer, codec
       
  1003 	return result;
       
  1004 	}
       
  1005 
       
  1006 /**
       
  1007  * This test tests changing configuration for the codec. It calls ConfigureL() once to 
       
  1008  * encode one sbc bitstream, then changes a different configuration by calling ConfigureL() 
       
  1009  * and encode another sbc bitstream.
       
  1010  * @return	"TVerdict"
       
  1011  *			EPass: if encoded sbc files are the same as the reference files.
       
  1012  *			EFail: if not.
       
  1013  * @leave if ReadSourceL(), ProcessL() leaves
       
  1014  */
       
  1015 TVerdict CTestStep_MMF_SbcCodec::TestChangeConfigL()
       
  1016 	{
       
  1017 	//create codec from uid
       
  1018 	CMMFCodec* codec = NULL;
       
  1019 	TRAPD(err, codec = CMMFCodec::NewL(KSbcCodecPluginUid) );
       
  1020 	
       
  1021 	if (err != KErrNone)
       
  1022 		{
       
  1023 		ERR_PRINTF2(_L(">> CTestStep_MMF_SbcCodec::TestChangeConfigL Leave occurred in NewL, error code %d"), err);
       
  1024 		return EFail;
       
  1025 		}
       
  1026 	if (!codec)
       
  1027 		{
       
  1028 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestChangeConfigL NewL returned NULL") );
       
  1029 		return EFail;
       
  1030 		}
       
  1031 
       
  1032 	CleanupStack::PushL(codec);
       
  1033 
       
  1034 	const TInt testNumber[2] = {1, 28};
       
  1035 	// this size will make sure some samples will be cached, 
       
  1036 	// also make sure it is an EVEN number
       
  1037 	const TInt srcBufSize = 4094; 
       
  1038 	const TInt dstBufSize = 2048;
       
  1039 	
       
  1040 	// create buffers
       
  1041 	CMMFDataBuffer* srcBuffer = CMMFDataBuffer::NewL(srcBufSize);
       
  1042 	CleanupStack::PushL(srcBuffer);
       
  1043 	CMMFDataBuffer* dstBuffer = CMMFDataBuffer::NewL(dstBufSize);
       
  1044 	CleanupStack::PushL(dstBuffer);
       
  1045 	
       
  1046 	TVerdict result = EPass;
       
  1047 	for (TInt test = 0; test < 2; test++)
       
  1048 		{
       
  1049 		TSBCFrameParameters param = SbcParametersL(testNumber[test]);
       
  1050 		
       
  1051 		TPckgBuf<TSBCFrameParameters> config(param);
       
  1052 		codec->ConfigureL(KSbcCodecConfigUid, config);
       
  1053 		codec->ResetL();
       
  1054 		
       
  1055 		TInt srcFilePos = 0;
       
  1056 		TInt dstFilePos = 0;
       
  1057 		
       
  1058 		for (;;)
       
  1059 			{
       
  1060 			ReadSourceL(GetTestFileName(testNumber[test]), srcBuffer->Data(), srcFilePos);
       
  1061 			
       
  1062 			if (srcBuffer->Data().Length() == 0) // end of file
       
  1063 				{
       
  1064 				break;
       
  1065 				}
       
  1066 				
       
  1067 			TCodecProcessResult result = codec->ProcessL(*srcBuffer, *dstBuffer);
       
  1068 			
       
  1069 			WriteDstToFileL(GetRefFileName(testNumber[test]), dstBuffer->Data(), dstFilePos);
       
  1070 			
       
  1071 			srcBuffer->Data().Zero();
       
  1072 			dstBuffer->Data().Zero();
       
  1073 			
       
  1074 			srcFilePos += result.iSrcBytesProcessed;
       
  1075 			dstFilePos += result.iDstBytesAdded;
       
  1076 			}
       
  1077 
       
  1078 		if (CompareFileL(GetRefFileName(testNumber[test]) ) != 0)
       
  1079 			{
       
  1080 			result = EFail;
       
  1081 			}
       
  1082 		}
       
  1083 		
       
  1084 	CleanupStack::PopAndDestroy(3); // dstBuffer, srcBuffer, codec
       
  1085 	return result;
       
  1086 	}
       
  1087 	
       
  1088 /**
       
  1089  * This tests memory scribble for ProcessL(). It creates a buffer size of frame_length + 2, 
       
  1090  * the first byte and last byte are used to detect memory scribble,
       
  1091  * the middle frame_length bytes are used for destination buffer. It calls ProcessL() once.
       
  1092  * and checks if the first or last byte value changed to check memory scribble.
       
  1093  * @return	"TVerdict"
       
  1094  *			EPass: if there is no momery scribble.
       
  1095  *			EFail: if there is momery scribble.
       
  1096  * @leave if ReadSourceL(), ProcessL() leaves
       
  1097  */
       
  1098 TVerdict CTestStep_MMF_SbcCodec::TestMemoryScribbleL()
       
  1099 	{
       
  1100 	//create codec from uid
       
  1101 	CMMFCodec* codec = NULL;
       
  1102 	TRAPD(err, codec = CMMFCodec::NewL(KSbcCodecPluginUid) );
       
  1103 	
       
  1104 	if (err != KErrNone)
       
  1105 		{
       
  1106 		ERR_PRINTF2(_L(">> CTestStep_MMF_SbcCodec::TestMemoryScribbleL Leave occurred in NewL, error code %d"), err);
       
  1107 		return EFail;
       
  1108 		}
       
  1109 	if (!codec)
       
  1110 		{
       
  1111 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestMemoryScribbleL NewL returned NULL") );
       
  1112 		return EFail;
       
  1113 		}
       
  1114 
       
  1115 	CleanupStack::PushL(codec);
       
  1116 
       
  1117 	const TInt testNumber = 28;
       
  1118 	
       
  1119 	TSBCFrameParameters param = SbcParametersL(testNumber);
       
  1120 	
       
  1121 	TPckgBuf<TSBCFrameParameters> config(param);
       
  1122 	codec->ConfigureL(KSbcCodecConfigUid, config);
       
  1123 	
       
  1124 	const TUint sbcFrameLength = param.CalcFrameLength();
       
  1125 	const TUint pcmFrameSize = sizeof(TInt16) * param.BlockLength() * param.Channels() * param.Subbands();
       
  1126 	
       
  1127 	// create buffers
       
  1128 	CMMFDataBuffer* srcBuffer = CMMFDataBuffer::NewL(pcmFrameSize);
       
  1129 	CleanupStack::PushL(srcBuffer);
       
  1130 	
       
  1131 	// front and end bytes are used to detect memory scribble
       
  1132 	CMMFDataBuffer* buffer = CMMFDataBuffer::NewL(sbcFrameLength + 2); 
       
  1133 	CleanupStack::PushL(buffer);
       
  1134 	
       
  1135 	TUint8* firstByte = const_cast<TUint8*>(buffer->Data().Ptr() );
       
  1136 	TUint8* lastByte = firstByte + sbcFrameLength + 1;
       
  1137 	
       
  1138 	const TUint8 initValue = 0xaa; // 10101010
       
  1139 	
       
  1140 	*firstByte = initValue;
       
  1141 	*lastByte = initValue;
       
  1142 	
       
  1143 	CMMFPtrBuffer* dstBuffer = CMMFPtrBuffer::NewL(TPtr8(firstByte + 1, sbcFrameLength) );
       
  1144 	CleanupStack::PushL(dstBuffer);
       
  1145 	
       
  1146 	ReadSourceL(GetTestFileName(testNumber), srcBuffer->Data(), 0);
       
  1147 	
       
  1148 	TVerdict testResult = EPass;
       
  1149 	if (static_cast<TUint>(srcBuffer->Data().Length() ) == pcmFrameSize)
       
  1150 		{
       
  1151 		TCodecProcessResult result = codec->ProcessL(*srcBuffer, *dstBuffer);
       
  1152 		
       
  1153 		if (result.iSrcBytesProcessed != pcmFrameSize ||
       
  1154 			result.iDstBytesAdded != sbcFrameLength ||
       
  1155 			result.iStatus != TCodecProcessResult::EProcessComplete)
       
  1156 			{
       
  1157 			ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestMemoryScribbleL failed in ProcessL") );
       
  1158 			testResult = EFail;
       
  1159 			}
       
  1160 			
       
  1161 		if (*firstByte != initValue || *lastByte != initValue ) // memory been scribbled
       
  1162 			{
       
  1163 			ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestMemoryScribbleL memory scribble occured") );
       
  1164 			testResult = EFail;
       
  1165 			}
       
  1166 		}
       
  1167 	else
       
  1168 		{
       
  1169 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestMemoryScribbleL read source failed") );
       
  1170 		testResult = EFail;
       
  1171 		}
       
  1172 		
       
  1173 	CleanupStack::PopAndDestroy(4); // dstBuffer, buffer, srcBuffer, codec
       
  1174 	return testResult;
       
  1175 	}
       
  1176 
       
  1177 /**
       
  1178  * This tests all the codec APIs (here we are using TestRepositionL() test as it 
       
  1179  * uses all the APIs) and checks if there is any memory leak, it panics if so.
       
  1180  * @return	"TVerdict"
       
  1181  *			EPass: if there is no momery leak.
       
  1182  *			EFail: if there is momery leak.
       
  1183  * @leave if TestRepositionL() leaves
       
  1184  */
       
  1185 TVerdict CTestStep_MMF_SbcCodec::TestMemoryLeakL()
       
  1186 	{
       
  1187 	__MM_HEAP_MARK;
       
  1188 	
       
  1189 	TestRepositionL();
       
  1190 	
       
  1191 	__MM_HEAP_MARKEND;
       
  1192 	
       
  1193 	return EPass;
       
  1194 	}
       
  1195 
       
  1196 /**
       
  1197  * This function tests how NewL deals with a memory allocation failure. This test 
       
  1198  * will pass if NewL leaves with the correct error code on every memory allocation.
       
  1199  *
       
  1200  * @return	"TVerdict"
       
  1201  *			EPass: if the test passes.
       
  1202  *			EFail: if the test fails.
       
  1203  */
       
  1204 TVerdict CTestStep_MMF_SbcCodec::TestNewLOutOfMemoryL()
       
  1205 	{
       
  1206 	TVerdict testResult = EPass;
       
  1207 	TInt failCount = 1;
       
  1208 	
       
  1209 	for (;;)
       
  1210 		{
       
  1211 		__MM_HEAP_MARK;
       
  1212 		__UHEAP_FAILNEXT(failCount);
       
  1213 
       
  1214 		CMMFCodec* codec = NULL;
       
  1215 		TRAPD(err, codec = CMMFCodec::NewL(KSbcCodecPluginUid) );
       
  1216 		
       
  1217 		// it should return either KErrNone or KErrNoMemory, 
       
  1218 		// ideally should only return KErrNone when codec is created.
       
  1219 		if (err == KErrNone)
       
  1220 			{
       
  1221 			TAny *testAlloc = User::Alloc(1);
       
  1222 			
       
  1223 			delete codec;
       
  1224 			if (testAlloc == NULL)
       
  1225 				{
       
  1226 				break;
       
  1227 				}
       
  1228 			User::Free(testAlloc);
       
  1229 			}
       
  1230 		else if (err != KErrNoMemory)
       
  1231 			{
       
  1232 			delete codec;
       
  1233 			testResult = EFail;
       
  1234 			break;
       
  1235 			}
       
  1236 			
       
  1237 		failCount++;
       
  1238 		
       
  1239 		__UHEAP_RESET;
       
  1240 		__MM_HEAP_MARKEND;
       
  1241 		} // while(1)
       
  1242 	
       
  1243 	INFO_PRINTF2(_L("NewL out of memory test finished at round %d"), failCount);
       
  1244 
       
  1245 	return testResult;
       
  1246 	}
       
  1247 
       
  1248 /**
       
  1249  * This function tests how the ProcessL() would deal with a memory allocation failure.
       
  1250  * @return	"TVerdict"
       
  1251  *			EPass: if the test passes.
       
  1252  *			EFail: if the test fails.
       
  1253  * @leave if out of memory or ConfigureL(), ReadSourceL leaves
       
  1254  */
       
  1255 TVerdict CTestStep_MMF_SbcCodec::TestProcessLOutOfMemoryL()
       
  1256 	{
       
  1257 	__MM_HEAP_MARK;
       
  1258 	
       
  1259 	CMMFCodec* codec = CMMFCodec::NewL(KSbcCodecPluginUid);
       
  1260 	if (!codec)
       
  1261 		{
       
  1262 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessLOutOfMemoryL returned NULL") );
       
  1263 		return EFail;
       
  1264 		}
       
  1265 
       
  1266 	CleanupStack::PushL(codec);
       
  1267 
       
  1268 	const TInt testNumber = 28;
       
  1269 	// this size will make sure some samples will be cached,
       
  1270 	// also make sure it is an EVEN number
       
  1271 	const TInt srcBufSize = 4094; 
       
  1272 	const TInt dstBufSize = 2048;
       
  1273 	
       
  1274 	TPckgBuf<TSBCFrameParameters> config(SbcParametersL(testNumber) );
       
  1275 	codec->ConfigureL(KSbcCodecConfigUid, config);
       
  1276 
       
  1277 	// create buffers
       
  1278 	CMMFDataBuffer* srcBuffer = CMMFDataBuffer::NewL(srcBufSize);
       
  1279 	CleanupStack::PushL(srcBuffer);
       
  1280 	CMMFDataBuffer* dstBuffer = CMMFDataBuffer::NewL(dstBufSize);
       
  1281 	CleanupStack::PushL(dstBuffer);
       
  1282 
       
  1283 	ReadSourceL(GetTestFileName(testNumber), srcBuffer->Data(), 0);
       
  1284 	if (srcBuffer->Data().Length() == 0) // end of file
       
  1285 		{
       
  1286 		ERR_PRINTF1(_L(">> CTestStep_MMF_SbcCodec::TestProcessLOutOfMemoryL no source read") );
       
  1287 		return EFail;
       
  1288 		}
       
  1289 		
       
  1290 	TVerdict testResult = EPass;
       
  1291 	TInt failCount = 1;
       
  1292 	
       
  1293 	for (;;)
       
  1294 		{
       
  1295 		__UHEAP_FAILNEXT(failCount);
       
  1296 
       
  1297 		TCodecProcessResult dummyResult; // don't care about this result
       
  1298 		TRAPD(err, dummyResult = codec->ProcessL(*srcBuffer, *dstBuffer) );
       
  1299 		
       
  1300 		// it should return either KErrNone or KErrNoMemory, 
       
  1301 		// ideally should only return KErrNone when codec is created.
       
  1302 		if (err == KErrNone)
       
  1303 			{
       
  1304 			// attempt to allocate another cell. If this fails, 
       
  1305 			// we have tested all of the memory allocs carried out by NewL.
       
  1306 			TAny *testAlloc = User::Alloc(1);
       
  1307 			
       
  1308 			if (testAlloc == NULL)
       
  1309 				{
       
  1310 				break;
       
  1311 				}
       
  1312 			User::Free(testAlloc);
       
  1313 			}
       
  1314 		else if (err != KErrNoMemory)
       
  1315 			{
       
  1316 			testResult = EFail;
       
  1317 			break;
       
  1318 			}
       
  1319 			
       
  1320 		failCount++;
       
  1321 		
       
  1322 		__UHEAP_RESET;
       
  1323 		} // while(1)
       
  1324 	
       
  1325 	INFO_PRINTF2(_L("ProcessL out of memory test finished at round %d"), failCount);
       
  1326 	
       
  1327 	CleanupStack::PopAndDestroy(3); // dstBuffer, srcBuffer, codec
       
  1328 
       
  1329 	__MM_HEAP_MARKEND;
       
  1330 		
       
  1331 	return testResult;
       
  1332 	}
       
  1333 
       
  1334 //------------------------------------------------------------------
       
  1335 //			** TEST MMF_SBCCODEC STEPS ***
       
  1336 //------------------------------------------------------------------
       
  1337 
       
  1338 /**
       
  1339  * Constructor
       
  1340  */
       
  1341 CTest_MMF_SbcCodec_U_001::CTest_MMF_SbcCodec_U_001()
       
  1342 	{
       
  1343 	iTestStepName = _L("MM-MMF-SbcCodec-U-001-HP");
       
  1344 	}
       
  1345 
       
  1346 /**
       
  1347  * Instantiate a codec with plugin UID
       
  1348  * @test Req. under test REQ2716
       
  1349  */
       
  1350 TVerdict CTest_MMF_SbcCodec_U_001::DoTestStepL()
       
  1351 	{
       
  1352 	TVerdict testResult = EFail;
       
  1353 	TRAPD(err, testResult = TestNewL(KSbcCodecPluginUid) );
       
  1354 
       
  1355 	if (err)
       
  1356 		{
       
  1357 		INFO_PRINTF2(_L("Test left with status %d"), err);
       
  1358 		}
       
  1359 	return testResult; 
       
  1360 	}
       
  1361 	
       
  1362 /**
       
  1363  * Constructor
       
  1364  */
       
  1365 CTest_MMF_SbcCodec_U_002::CTest_MMF_SbcCodec_U_002()
       
  1366 	{
       
  1367 	iTestStepName = _L("MM-MMF-SbcCodec-U-002-HP");
       
  1368 	}
       
  1369 
       
  1370 /**
       
  1371  * Instantiate a codec with FourCC Codes
       
  1372  * @test Req. under test REQ2716
       
  1373  */
       
  1374 TVerdict CTest_MMF_SbcCodec_U_002::DoTestStepL()
       
  1375 	{
       
  1376 	TVerdict testResult = EFail;
       
  1377 	TRAPD(err, testResult = TestNewL(KMMFFourCCCodePCM16, KMMFFourCCCodeSBC) );
       
  1378 
       
  1379 	if (err)
       
  1380 		{
       
  1381 		INFO_PRINTF2(_L("Test left with status %d"), err);
       
  1382 		}
       
  1383 	return testResult; 
       
  1384 	}
       
  1385 	
       
  1386 /**
       
  1387  * Constructor
       
  1388  */
       
  1389 CTest_MMF_SbcCodec_U_010::CTest_MMF_SbcCodec_U_010()
       
  1390 	{
       
  1391 	iTestStepName = _L("MM-MMF-SbcCodec-U-010-HP");
       
  1392 	}
       
  1393 
       
  1394 /**
       
  1395  * ProcessL() test
       
  1396  * This test tests the ProcessL() function with different buffer size settings, and
       
  1397  * check the returned results
       
  1398  * @test Req. under test REQ2716
       
  1399  */
       
  1400 TVerdict CTest_MMF_SbcCodec_U_010::DoTestStepL()
       
  1401 	{
       
  1402 	TVerdict testResult = EFail;
       
  1403 	TRAPD(err, testResult = TestProcessL() );
       
  1404 
       
  1405 	if (err)
       
  1406 		{
       
  1407 		INFO_PRINTF2(_L("Test left with status %d"), err);
       
  1408 		}
       
  1409 	return testResult; 
       
  1410 	}
       
  1411 	
       
  1412 /**
       
  1413  * Constructor
       
  1414  */
       
  1415 CTest_MMF_SbcCodec_U_011::CTest_MMF_SbcCodec_U_011()
       
  1416 	{
       
  1417 	iTestStepName = _L("MM-MMF-SbcCodec-U-011-HP");
       
  1418 	}
       
  1419 
       
  1420 /**
       
  1421  * Configuration tests
       
  1422  * This test tests if codec supports 8 different settings (see TSS & TP for A2DP spec)
       
  1423  * @test Req. under test REQ2716
       
  1424  */
       
  1425 TVerdict CTest_MMF_SbcCodec_U_011::DoTestStepL()
       
  1426 	{
       
  1427 	TVerdict testResult = EPass;
       
  1428 	TInt srcBufSize = KDefaultBufferSize; 
       
  1429 	TInt dstBufSize = KDefaultBufferSize >> 1;
       
  1430 
       
  1431 	for (TInt testNumber = 1; testNumber <= 8; testNumber++)
       
  1432 		{
       
  1433 		TVerdict result = EFail;
       
  1434 		
       
  1435 		TRAPD(err, result = TestEncodeL(testNumber, srcBufSize, dstBufSize) );
       
  1436 
       
  1437 		if (err)
       
  1438 			{
       
  1439 			INFO_PRINTF3(_L("Configuration test %d left with status %d"), testNumber, err);
       
  1440 			testResult = EFail;
       
  1441 			}
       
  1442 		if (result == EFail)
       
  1443 			{
       
  1444 			INFO_PRINTF2(_L("Configuration test %d failed"), testNumber);
       
  1445 			testResult = EFail;
       
  1446 			}
       
  1447 			
       
  1448 		// This is simulating different src buffer size by decreasing the 
       
  1449 		// src buffer size number each time, it covers sample caching and 
       
  1450 		// no caching various cases to make sure the codec can handle different
       
  1451 		// src buffer size correctly
       
  1452 		srcBufSize--;
       
  1453 		}
       
  1454 	return testResult; 
       
  1455 	}
       
  1456 	
       
  1457 /**
       
  1458  * Constructor
       
  1459  */
       
  1460 CTest_MMF_SbcCodec_U_012::CTest_MMF_SbcCodec_U_012()
       
  1461 	{
       
  1462 	iTestStepName = _L("MM-MMF-SbcCodec-U-012-HP");
       
  1463 	}
       
  1464 
       
  1465 /**
       
  1466  * Maximum Bit Rate tests
       
  1467  * This test tests sbc coded handles 8 different maximum bit rate settings (see TSS & TP for A2DP spec)
       
  1468  * @test Req. under test REQ2716
       
  1469  */
       
  1470 TVerdict CTest_MMF_SbcCodec_U_012::DoTestStepL()
       
  1471 	{
       
  1472 	TVerdict testResult = EPass;
       
  1473 	TInt srcBufSize = KDefaultBufferSize;
       
  1474 	TInt dstBufSize = KDefaultBufferSize >> 1;
       
  1475 	
       
  1476 	for (TInt testNumber = 11; testNumber <= 18; testNumber++)
       
  1477 		{
       
  1478 		TVerdict result = EFail;
       
  1479 		TRAPD(err, result = TestEncodeL(testNumber, srcBufSize, dstBufSize) );
       
  1480 
       
  1481 		if (err)
       
  1482 			{
       
  1483 			INFO_PRINTF3(_L("Max Bit Rate test %d left with status %d"), testNumber, err);
       
  1484 			testResult = EFail;
       
  1485 			}
       
  1486 		if (result == EFail)
       
  1487 			{
       
  1488 			INFO_PRINTF2(_L("Max Bit Rate test %d failed"), testNumber);
       
  1489 			testResult = EFail;
       
  1490 			}
       
  1491 
       
  1492 		// This is simulating different src buffer size by decreasing the 
       
  1493 		// src buffer size number each time, it covers sample caching and 
       
  1494 		// no caching various cases to make sure the codec can handle different
       
  1495 		// src buffer size correctly
       
  1496 		srcBufSize--;
       
  1497 		}
       
  1498 	return testResult; 
       
  1499 	}
       
  1500 	
       
  1501 /**
       
  1502  * Constructor
       
  1503  */
       
  1504 CTest_MMF_SbcCodec_U_013::CTest_MMF_SbcCodec_U_013()
       
  1505 	{
       
  1506 	iTestStepName = _L("MM-MMF-SbcCodec-U-013-HP");
       
  1507 	}
       
  1508 
       
  1509 /**
       
  1510  * Special tests
       
  1511  * This test tests sbc codec handles 2 special cases (see TSS & TP for A2DP spec)
       
  1512  * @test Req. under test REQ2716
       
  1513  */
       
  1514 TVerdict CTest_MMF_SbcCodec_U_013::DoTestStepL()
       
  1515 	{
       
  1516 	TVerdict testResult = EPass;
       
  1517 	TInt srcBufSize = KDefaultBufferSize;
       
  1518 	TInt dstBufSize = KDefaultBufferSize >> 1;
       
  1519 
       
  1520 	for (TInt testNumber = 19; testNumber <= 20; testNumber++)
       
  1521 		{
       
  1522 		TVerdict result = EFail;
       
  1523 		TRAPD(err, result = TestEncodeL(testNumber, srcBufSize, dstBufSize) );
       
  1524 
       
  1525 		if (err)
       
  1526 			{
       
  1527 			INFO_PRINTF3(_L("Special test %d left with status %d"), testNumber, err);
       
  1528 			testResult = EFail;
       
  1529 			}
       
  1530 		if (result == EFail)
       
  1531 			{
       
  1532 			INFO_PRINTF2(_L("Special test %d failed"), testNumber);
       
  1533 			testResult = EFail;
       
  1534 			}
       
  1535 
       
  1536 		// This is simulating different src buffer size by decreasing the 
       
  1537 		// src buffer size number each time, it covers sample caching and 
       
  1538 		// no caching various cases to make sure the codec can handle different
       
  1539 		// src buffer size correctly
       
  1540 		srcBufSize--;
       
  1541 		}
       
  1542 	return testResult; 
       
  1543 	}
       
  1544 	
       
  1545 /**
       
  1546  * Constructor
       
  1547  */
       
  1548 CTest_MMF_SbcCodec_U_014::CTest_MMF_SbcCodec_U_014()
       
  1549 	{
       
  1550 	iTestStepName = _L("MM-MMF-SbcCodec-U-014-HP");
       
  1551 	}
       
  1552 
       
  1553 /**
       
  1554  * Typical tests
       
  1555  * This test tests sbc codec handles 8 typical settings (see TSS & TP for A2DP spec) which 
       
  1556  * are required in REQ2716, our sbc encoder has to support these settings.
       
  1557  * @test Req. under test REQ2716
       
  1558  */
       
  1559 TVerdict CTest_MMF_SbcCodec_U_014::DoTestStepL()
       
  1560 	{
       
  1561 	TVerdict testResult = EPass;
       
  1562 	TInt srcBufSize = KDefaultBufferSize;
       
  1563 	TInt dstBufSize = KDefaultBufferSize >> 1;
       
  1564 
       
  1565 	for (TInt testNumber = 21; testNumber <= 28; testNumber++)
       
  1566 		{
       
  1567 		TVerdict result = EFail;
       
  1568 		TRAPD(err, result = TestEncodeL(testNumber, srcBufSize, dstBufSize) );
       
  1569 
       
  1570 		if (err)
       
  1571 			{
       
  1572 			INFO_PRINTF3(_L("Typical test %d left with status %d"), testNumber, err);
       
  1573 			testResult = EFail;
       
  1574 			}
       
  1575 		if (result == EFail)
       
  1576 			{
       
  1577 			INFO_PRINTF2(_L("Typical test %d failed"), testNumber);
       
  1578 			testResult = EFail;
       
  1579 			}
       
  1580 
       
  1581 		// This is simulating different src buffer size by decreasing the 
       
  1582 		// src buffer size number each time, it covers sample caching and 
       
  1583 		// no caching various cases to make sure the codec can handle different
       
  1584 		// src buffer size correctly
       
  1585 		srcBufSize--;
       
  1586 		}
       
  1587 	return testResult; 
       
  1588 	}
       
  1589 	
       
  1590 /**
       
  1591  * Constructor
       
  1592  */
       
  1593 CTest_MMF_SbcCodec_U_015::CTest_MMF_SbcCodec_U_015()
       
  1594 	{
       
  1595 	iTestStepName = _L("MM-MMF-SbcCodec-U-015-HP");
       
  1596 	}
       
  1597 
       
  1598 /**
       
  1599  * Reposition tests
       
  1600  * This test tests ResetL() function and audio sample cach issue
       
  1601  * @test Req. under test REQ2716
       
  1602  */
       
  1603 TVerdict CTest_MMF_SbcCodec_U_015::DoTestStepL()
       
  1604 	{
       
  1605 	TVerdict testResult = EFail;
       
  1606 	TRAPD(err, testResult = TestRepositionL() );
       
  1607 
       
  1608 	if (err)
       
  1609 		{
       
  1610 		INFO_PRINTF2(_L("Reposition test left with status %d"), err);
       
  1611 		testResult = EFail;
       
  1612 		}
       
  1613 	else
       
  1614 		{
       
  1615 		INFO_PRINTF1(_L("Reposition test passes") );
       
  1616 		}
       
  1617 
       
  1618 	return testResult; 
       
  1619 	}
       
  1620 	
       
  1621 /**
       
  1622  * Constructor
       
  1623  */
       
  1624 CTest_MMF_SbcCodec_U_016::CTest_MMF_SbcCodec_U_016()
       
  1625 	{
       
  1626 	iTestStepName = _L("MM-MMF-SbcCodec-U-016-HP");
       
  1627 	}
       
  1628 
       
  1629 /**
       
  1630  * Change configuration test
       
  1631  * This test tests reconfigure sbc codec by calling ConfigureL() function
       
  1632  * @test Req. under test REQ2716
       
  1633  */
       
  1634 TVerdict CTest_MMF_SbcCodec_U_016::DoTestStepL()
       
  1635 	{
       
  1636 	TVerdict testResult = EFail;
       
  1637 	TRAPD(err, testResult = TestChangeConfigL() );
       
  1638 
       
  1639 	if (err)
       
  1640 		{
       
  1641 		INFO_PRINTF2(_L("Change conguration test left with status %d"), err);
       
  1642 		testResult = EFail;
       
  1643 		}
       
  1644 	else
       
  1645 		{
       
  1646 		INFO_PRINTF1(_L("Change conguration test passes") );
       
  1647 		}
       
  1648 
       
  1649 	return testResult; 
       
  1650 	}
       
  1651 	
       
  1652 /**
       
  1653  * Constructor
       
  1654  */
       
  1655 CTest_MMF_SbcCodec_U_021::CTest_MMF_SbcCodec_U_021()
       
  1656 	{
       
  1657 	iTestStepName = _L("MM-MMF-SbcCodec-U-021-HP");
       
  1658 	}
       
  1659 
       
  1660 /**
       
  1661  * Memory Scribble test
       
  1662  * @test Req. under test REQ2716
       
  1663  */
       
  1664 TVerdict CTest_MMF_SbcCodec_U_021::DoTestStepL()
       
  1665 	{
       
  1666 	TVerdict testResult = EPass;
       
  1667 	
       
  1668 	TRAPD(err, testResult = TestMemoryScribbleL() );
       
  1669 
       
  1670 	if (err)
       
  1671 		{
       
  1672 		INFO_PRINTF2(_L("Memory scribble test left with status %d"), err);
       
  1673 		testResult = EFail;
       
  1674 		}
       
  1675 	else
       
  1676 		{
       
  1677 		INFO_PRINTF1(_L("Memory scribble test passes") );
       
  1678 		}
       
  1679 
       
  1680 	return testResult; 
       
  1681 	}
       
  1682 	
       
  1683 /**
       
  1684  * Constructor
       
  1685  */
       
  1686 CTest_MMF_SbcCodec_U_022::CTest_MMF_SbcCodec_U_022()
       
  1687 	{
       
  1688 	iTestStepName = _L("MM-MMF-SbcCodec-U-022-HP");
       
  1689 	}
       
  1690 
       
  1691 /**
       
  1692  * Memory Leak test
       
  1693  * @test Req. under test REQ2716
       
  1694  */
       
  1695 TVerdict CTest_MMF_SbcCodec_U_022::DoTestStepL()
       
  1696 	{
       
  1697 	TVerdict testResult = EPass;
       
  1698 
       
  1699 	TRAPD(err, testResult = TestMemoryLeakL() );
       
  1700 
       
  1701 	if (err)
       
  1702 		{
       
  1703 		INFO_PRINTF2(_L("Memory leak test left with status %d"), err);
       
  1704 		testResult = EFail;
       
  1705 		}
       
  1706 	else
       
  1707 		{
       
  1708 		INFO_PRINTF1(_L("Memory leak test passes") );
       
  1709 		}
       
  1710 	
       
  1711 	return testResult; 
       
  1712 	}
       
  1713 	
       
  1714 /**
       
  1715  * Constructor
       
  1716  */
       
  1717 CTest_MMF_SbcCodec_U_023::CTest_MMF_SbcCodec_U_023()
       
  1718 	{
       
  1719 	iTestStepName = _L("MM-MMF-SbcCodec-U-023-HP");
       
  1720 	}
       
  1721 
       
  1722 /**
       
  1723  * Out of Memory test for NewL()
       
  1724  * @test Req. under test REQ2716
       
  1725  */
       
  1726 TVerdict CTest_MMF_SbcCodec_U_023::DoTestStepL()
       
  1727 	{
       
  1728 	TVerdict testResult = EPass;
       
  1729 	
       
  1730 	TRAPD(err, testResult = TestNewLOutOfMemoryL() );
       
  1731 
       
  1732 	if (err)
       
  1733 		{
       
  1734 		INFO_PRINTF2(_L("NewL out of memory test left with status %d"), err);
       
  1735 		testResult = EFail;
       
  1736 		}
       
  1737 	else
       
  1738 		{
       
  1739 		INFO_PRINTF1(_L("NewL out of memory test passes") );
       
  1740 		}
       
  1741 	
       
  1742 	return testResult; 
       
  1743 	}
       
  1744 	
       
  1745 /**
       
  1746  * Constructor
       
  1747  */
       
  1748 CTest_MMF_SbcCodec_U_024::CTest_MMF_SbcCodec_U_024()
       
  1749 	{
       
  1750 	iTestStepName = _L("MM-MMF-SbcCodec-U-024-HP");
       
  1751 	}
       
  1752 
       
  1753 /**
       
  1754  * Out of Memory test for ProcessL()
       
  1755  * @test Req. under test REQ2716
       
  1756  */
       
  1757 TVerdict CTest_MMF_SbcCodec_U_024::DoTestStepL()
       
  1758 	{
       
  1759 	TVerdict testResult = EPass;
       
  1760 	
       
  1761 	TRAPD(err, testResult = TestProcessLOutOfMemoryL() );
       
  1762 
       
  1763 	if (err)
       
  1764 		{
       
  1765 		INFO_PRINTF2(_L("ProcessL out of memory test left with status %d"), err);
       
  1766 		testResult = EFail;
       
  1767 		}
       
  1768 	else
       
  1769 		{
       
  1770 		INFO_PRINTF1(_L("ProcessL out of memory test passes") );
       
  1771 		}
       
  1772 		
       
  1773 	return testResult; 
       
  1774 	}