devsound/devsoundrefplugin/tsrc/SwCodecDevices/TSU_MMF_Loop.cpp
changeset 0 79dd3e2336a0
equal deleted inserted replaced
-1:000000000000 0:79dd3e2336a0
       
     1 // Copyright (c) 2003-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 // EPOC includes
       
    17 #include <e32base.h>
       
    18 
       
    19 // Test system includes
       
    20 #include "TSU_MMF_DeviceSuite.h"
       
    21 #include "TSU_MMF_Loop.h"
       
    22 
       
    23 //[ actual codec includes ]
       
    24 #include "MmfPcm16toAlawhwDevice.h"
       
    25 #include "MmfALawToPcm16HwDevice.h"
       
    26 #include "GSM610.H"
       
    27 #include "MmfImaAdpcmtopcm16hwdevice.h"
       
    28 #include "MmfMuLawToPcm16hwDevice.h"
       
    29 #include "mmfpcm16SwapEndianhwdevice.h"
       
    30 #include "mmfpcm16ToImaAdpcm.h"
       
    31 #include "mmfpcm16toMulawhwdevice.h"
       
    32 #include "mmfpcm16topcmU16BEHwDevice.h"
       
    33 #include "MMFpcm16ToPcmU8HwDevice.h"
       
    34 #include "MMFpcm16ToPcmU8HwDevice.h"
       
    35 #include "mmfpcmS16PcmS8HwDevice.h"
       
    36 #include "mmfpcmS16topcmU16Codec.h"
       
    37 #include "mmfpcmS8ToPcmS16HwDevice.h"
       
    38 #include "mmfpcmU16BeToPcmS16HwDevice.h"
       
    39 #include "mmfpcmU16TopcmS16HwDevice.h"
       
    40 #include "MMFpcmU8ToPcm16HwDevice.h"
       
    41 
       
    42 //[ Codec Unit tests  structure 
       
    43 // The unit tests shall use text files
       
    44 // for small portions of test data 
       
    45 // which should be stored are stored in a simple format
       
    46 // containing the relevant parameters for the test
       
    47 //]
       
    48 class TLoopTestParams
       
    49 	{	
       
    50 public:
       
    51 	const TText* iTestName;       // name of the test
       
    52 	};
       
    53 
       
    54 // constant table of parameters for tests
       
    55 const TLoopTestParams KLoopParameters[] =
       
    56 	{	
       
    57 		{_S("MM-MMF-SWCODECDEVICES-U-0061-HP")},
       
    58 		{_S("MM-MMF-SWCODECDEVICES-U-0062-HP")},
       
    59 		{_S("MM-MMF-SWCODECDEVICES-U-0063-HP")},
       
    60 		{_S("MM-MMF-SWCODECDEVICES-U-0064-HP")},
       
    61 		{_S("MM-MMF-SWCODECDEVICES-U-0065-HP")},
       
    62 		{_S("MM-MMF-SWCODECDEVICES-U-0066-HP")},
       
    63 		{_S("MM-MMF-SWCODECDEVICES-U-0067-HP")},
       
    64 		{_S("MM-MMF-SWCODECDEVICES-U-0068-HP")},
       
    65 		{_S("MM-MMF-SWCODECDEVICES-U-0069-HP")},
       
    66 		{_S("MM-MMF-SWCODECDEVICES-U-0070-HP")},
       
    67 		{_S("MM-MMF-SWCODECDEVICES-U-0071-HP")},
       
    68 		{_S("MM-MMF-SWCODECDEVICES-U-0072-HP")},
       
    69 		{_S("MM-MMF-SWCODECDEVICES-U-0073-HP")},
       
    70 		{_S("MM-MMF-SWCODECDEVICES-U-0074-HP")},
       
    71 		{_S("MM-MMF-SWCODECDEVICES-U-0075-HP")},
       
    72 		{_S("MM-MMF-SWCODECDEVICES-U-0076-HP")}
       
    73 	};
       
    74 
       
    75 /**
       
    76 *
       
    77 * CTestStepLoopTest
       
    78 *
       
    79 */
       
    80 template <class Codec>
       
    81 CTestStepLoopTest<Codec>::CTestStepLoopTest( TUint aTestIndex )
       
    82 	{
       
    83 	// store the name of this test case
       
    84 	// this is the name that is used by the script file
       
    85 	iTestStepName = (&KLoopParameters[aTestIndex])->iTestName;
       
    86 	}
       
    87 
       
    88 /**
       
    89 *
       
    90 * ~CTestStepLoopTest
       
    91 *
       
    92 */
       
    93 template <class Codec>
       
    94 CTestStepLoopTest<Codec>::~CTestStepLoopTest()
       
    95 	{
       
    96 	}
       
    97 
       
    98 /**
       
    99 *
       
   100 * DoTestStepL
       
   101 * This method tests codec src & destination buffer size violations
       
   102 * and position violations.
       
   103 *
       
   104 **/
       
   105 template <class Codec>
       
   106 TVerdict CTestStepLoopTest<Codec>::DoTestStepL()
       
   107 	{
       
   108 	__MM_HEAP_MARK;	
       
   109 	TVerdict result = EPass;
       
   110 
       
   111 	//[ Buffer size violation on the src ]
       
   112 	const TInt KSrcDataBufferSize  = iCodecUnderTest->SourceBufferSize();
       
   113 	const TInt KSinkDataBufferSize = iCodecUnderTest->SinkBufferSize();
       
   114 
       
   115 	//[ create the data buffers and do not worry about filling them since
       
   116 	// this is simply a precondition test ]
       
   117 	TInt srcDataBufferSize  = KSrcDataBufferSize*2;
       
   118 	TInt sinkDataBufferSize = KSinkDataBufferSize;
       
   119 	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize ) == KErrNone )
       
   120 		{
       
   121         //[ info print here ]
       
   122 		INFO_PRINTF1(_L("Src Data Buffer precondition violation"));
       
   123 		result = EFail;
       
   124 		}
       
   125 
       
   126 	//[ Buffer size violation on the Destination ]
       
   127 	srcDataBufferSize  = KSrcDataBufferSize;
       
   128 	sinkDataBufferSize = KSinkDataBufferSize/4;
       
   129 	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize ) == KErrNone )
       
   130 		{
       
   131        	INFO_PRINTF1(_L("Sink Data Buffer precondition violation"));
       
   132 		result = EFail;
       
   133 		}
       
   134 
       
   135 	//[ Position violation on the src ]
       
   136 	srcDataBufferSize  = KSrcDataBufferSize;
       
   137 	sinkDataBufferSize = KSinkDataBufferSize;
       
   138 	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize, srcDataBufferSize/2, 0 ) == KErrNone )
       
   139 		{
       
   140         INFO_PRINTF1(_L("Src Data Buffer position precondition violation"));
       
   141 		result = EFail;
       
   142 		}
       
   143 
       
   144 	//[ Position violation on the Destination ]
       
   145 	srcDataBufferSize  = KSrcDataBufferSize;
       
   146 	sinkDataBufferSize = KSinkDataBufferSize;
       
   147 	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize,0, sinkDataBufferSize/2 ) == KErrNone )
       
   148 		{
       
   149         INFO_PRINTF1(_L("Sink Data Buffer position precondition violation"));
       
   150 		result = EFail;
       
   151 		}
       
   152 
       
   153 	delete iSourceData;
       
   154 	delete iCodedData ;
       
   155 	iSourceData = NULL;
       
   156 	iCodedData   = NULL;
       
   157 
       
   158 	__MM_HEAP_MARKEND;
       
   159 	return result;
       
   160 	}
       
   161 
       
   162 /**
       
   163 *
       
   164 * CodecPreconditionTest
       
   165 * @precondition 0<= aSrcPosition  < aSrcDataBufferSize
       
   166 * @precondition 0<= aSinkPosition < aSinkDataBufferSize
       
   167 * @return TInt error code 
       
   168 **/
       
   169 template <class Codec>
       
   170 TInt CTestStepLoopTest<Codec>::CodecPreconditionTestL( TInt aSrcDataBufferSize, TInt aSinkDataBufferSize, TInt aSrcPosition, TInt aSinkPosition )
       
   171 	{
       
   172 	TInt result = KErrNone;
       
   173 	//[ assert preconditions ]
       
   174 	ASSERT( (0 <= aSrcPosition ) && ( aSrcPosition < aSrcDataBufferSize ));
       
   175 	ASSERT( (0 <= aSinkPosition ) && ( aSinkPosition < aSinkDataBufferSize ));
       
   176 
       
   177 	delete iSourceData;
       
   178 	delete iCodedData ;
       
   179 	iSourceData = NULL;
       
   180 	iCodedData   = NULL;
       
   181 	iSourceData = CMMFDescriptorBuffer::NewL(aSrcDataBufferSize * sizeof(TUint8));
       
   182 	iCodedData   = CMMFDescriptorBuffer::NewL(aSinkDataBufferSize * sizeof(TUint8));
       
   183     //set the lengths of the buffers
       
   184 	iSourceData->Data().SetLength(aSrcDataBufferSize);
       
   185 	iCodedData->Data().SetLength(aSinkDataBufferSize);
       
   186 	
       
   187 	//set the positions on the buffers	
       
   188 	iSourceData->SetPosition(aSrcPosition);
       
   189 	iCodedData->SetPosition(aSinkPosition);
       
   190 
       
   191 	TRAP(result,iCodecUnderTest->ProcessL(*iSourceData, *iCodedData));
       
   192 
       
   193 	return result;
       
   194 	}
       
   195 
       
   196 /**
       
   197 *
       
   198 * DoTestStepPreambleL
       
   199 *
       
   200 **/
       
   201 template <class Codec>
       
   202 TVerdict CTestStepLoopTest<Codec>::DoTestStepPreambleL(void)
       
   203 	{
       
   204 	iCodecUnderTest = new (ELeave) Codec;
       
   205 	return EPass;
       
   206 	}
       
   207 
       
   208 /**
       
   209 *
       
   210 * DoTestStepPostambleL
       
   211 *
       
   212 */
       
   213 template <class Codec>
       
   214 TVerdict CTestStepLoopTest<Codec>::DoTestStepPostambleL(void)
       
   215 	{
       
   216 	delete iCodecUnderTest;
       
   217 	iCodecUnderTest = NULL;
       
   218 	delete 	iSourceData;
       
   219 	iSourceData = NULL;
       
   220 	delete  iCodedData;
       
   221 	iCodedData = NULL;
       
   222 	return EPass;
       
   223 	}
       
   224 
       
   225 /**
       
   226 *
       
   227 * This is used for template instantiation.
       
   228 *
       
   229 **/
       
   230 
       
   231 template class CTestStepLoopTest<CMMFPcm16ToALawCodec>;
       
   232 template class CTestStepLoopTest<CMMFAlawToPcm16Codec>;
       
   233 template class CTestStepLoopTest<CMMFGsm610ToPcm16Codec>;
       
   234 template class CTestStepLoopTest<CMMFImaAdpcmToPcm16Codec>;
       
   235 template class CTestStepLoopTest<CMMFMulawToPcm16Codec>;
       
   236 template class CTestStepLoopTest<CMMFPcm16SwapEndianCodec>;
       
   237 template class CTestStepLoopTest<CMMFPcm16ToImaAdpcmCodec>;
       
   238 template class CTestStepLoopTest<CMMFPcm16ToMuLawCodec>;
       
   239 template class CTestStepLoopTest<CMMFPcm16ToPcmU16BECodec>;
       
   240 template class CTestStepLoopTest<CMMFPcm16ToPcmU8Codec>;
       
   241 template class CTestStepLoopTest<CMMFPcmS16ToPcmS8Codec>;
       
   242 template class CTestStepLoopTest<CMMFPcm16ToPcmU16CodecCodec>;
       
   243 template class CTestStepLoopTest<CMMFPcm8ToPcm16Codec>;
       
   244 template class CTestStepLoopTest<CMMFPcmU16BeToPcmS16Codec>;
       
   245 template class CTestStepLoopTest<CMMFPcm16ToGsm610Codec>;
       
   246