os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_Loop.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_Loop.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,246 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +// EPOC includes
    1.20 +#include <e32base.h>
    1.21 +
    1.22 +// Test system includes
    1.23 +#include "TSU_MMF_DeviceSuite.h"
    1.24 +#include "TSU_MMF_Loop.h"
    1.25 +
    1.26 +//[ actual codec includes ]
    1.27 +#include "MmfPcm16toAlawhwDevice.h"
    1.28 +#include "MmfALawToPcm16HwDevice.h"
    1.29 +#include "GSM610.H"
    1.30 +#include "MmfImaAdpcmtopcm16hwdevice.h"
    1.31 +#include "MmfMuLawToPcm16hwDevice.h"
    1.32 +#include "mmfpcm16SwapEndianhwdevice.h"
    1.33 +#include "mmfpcm16ToImaAdpcm.h"
    1.34 +#include "mmfpcm16toMulawhwdevice.h"
    1.35 +#include "mmfpcm16topcmU16BEHwDevice.h"
    1.36 +#include "MMFpcm16ToPcmU8HwDevice.h"
    1.37 +#include "MMFpcm16ToPcmU8HwDevice.h"
    1.38 +#include "mmfpcmS16PcmS8HwDevice.h"
    1.39 +#include "mmfpcmS16topcmU16Codec.h"
    1.40 +#include "mmfpcmS8ToPcmS16HwDevice.h"
    1.41 +#include "mmfpcmU16BeToPcmS16HwDevice.h"
    1.42 +#include "mmfpcmU16TopcmS16HwDevice.h"
    1.43 +#include "MMFpcmU8ToPcm16HwDevice.h"
    1.44 +
    1.45 +//[ Codec Unit tests  structure 
    1.46 +// The unit tests shall use text files
    1.47 +// for small portions of test data 
    1.48 +// which should be stored are stored in a simple format
    1.49 +// containing the relevant parameters for the test
    1.50 +//]
    1.51 +class TLoopTestParams
    1.52 +	{	
    1.53 +public:
    1.54 +	const TText* iTestName;       // name of the test
    1.55 +	};
    1.56 +
    1.57 +// constant table of parameters for tests
    1.58 +const TLoopTestParams KLoopParameters[] =
    1.59 +	{	
    1.60 +		{_S("MM-MMF-SWCODECDEVICES-U-0061-HP")},
    1.61 +		{_S("MM-MMF-SWCODECDEVICES-U-0062-HP")},
    1.62 +		{_S("MM-MMF-SWCODECDEVICES-U-0063-HP")},
    1.63 +		{_S("MM-MMF-SWCODECDEVICES-U-0064-HP")},
    1.64 +		{_S("MM-MMF-SWCODECDEVICES-U-0065-HP")},
    1.65 +		{_S("MM-MMF-SWCODECDEVICES-U-0066-HP")},
    1.66 +		{_S("MM-MMF-SWCODECDEVICES-U-0067-HP")},
    1.67 +		{_S("MM-MMF-SWCODECDEVICES-U-0068-HP")},
    1.68 +		{_S("MM-MMF-SWCODECDEVICES-U-0069-HP")},
    1.69 +		{_S("MM-MMF-SWCODECDEVICES-U-0070-HP")},
    1.70 +		{_S("MM-MMF-SWCODECDEVICES-U-0071-HP")},
    1.71 +		{_S("MM-MMF-SWCODECDEVICES-U-0072-HP")},
    1.72 +		{_S("MM-MMF-SWCODECDEVICES-U-0073-HP")},
    1.73 +		{_S("MM-MMF-SWCODECDEVICES-U-0074-HP")},
    1.74 +		{_S("MM-MMF-SWCODECDEVICES-U-0075-HP")},
    1.75 +		{_S("MM-MMF-SWCODECDEVICES-U-0076-HP")}
    1.76 +	};
    1.77 +
    1.78 +/**
    1.79 +*
    1.80 +* CTestStepLoopTest
    1.81 +*
    1.82 +*/
    1.83 +template <class Codec>
    1.84 +CTestStepLoopTest<Codec>::CTestStepLoopTest( TUint aTestIndex )
    1.85 +	{
    1.86 +	// store the name of this test case
    1.87 +	// this is the name that is used by the script file
    1.88 +	iTestStepName = (&KLoopParameters[aTestIndex])->iTestName;
    1.89 +	}
    1.90 +
    1.91 +/**
    1.92 +*
    1.93 +* ~CTestStepLoopTest
    1.94 +*
    1.95 +*/
    1.96 +template <class Codec>
    1.97 +CTestStepLoopTest<Codec>::~CTestStepLoopTest()
    1.98 +	{
    1.99 +	}
   1.100 +
   1.101 +/**
   1.102 +*
   1.103 +* DoTestStepL
   1.104 +* This method tests codec src & destination buffer size violations
   1.105 +* and position violations.
   1.106 +*
   1.107 +**/
   1.108 +template <class Codec>
   1.109 +TVerdict CTestStepLoopTest<Codec>::DoTestStepL()
   1.110 +	{
   1.111 +	__MM_HEAP_MARK;	
   1.112 +	TVerdict result = EPass;
   1.113 +
   1.114 +	//[ Buffer size violation on the src ]
   1.115 +	const TInt KSrcDataBufferSize  = iCodecUnderTest->SourceBufferSize();
   1.116 +	const TInt KSinkDataBufferSize = iCodecUnderTest->SinkBufferSize();
   1.117 +
   1.118 +	//[ create the data buffers and do not worry about filling them since
   1.119 +	// this is simply a precondition test ]
   1.120 +	TInt srcDataBufferSize  = KSrcDataBufferSize*2;
   1.121 +	TInt sinkDataBufferSize = KSinkDataBufferSize;
   1.122 +	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize ) == KErrNone )
   1.123 +		{
   1.124 +        //[ info print here ]
   1.125 +		INFO_PRINTF1(_L("Src Data Buffer precondition violation"));
   1.126 +		result = EFail;
   1.127 +		}
   1.128 +
   1.129 +	//[ Buffer size violation on the Destination ]
   1.130 +	srcDataBufferSize  = KSrcDataBufferSize;
   1.131 +	sinkDataBufferSize = KSinkDataBufferSize/4;
   1.132 +	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize ) == KErrNone )
   1.133 +		{
   1.134 +       	INFO_PRINTF1(_L("Sink Data Buffer precondition violation"));
   1.135 +		result = EFail;
   1.136 +		}
   1.137 +
   1.138 +	//[ Position violation on the src ]
   1.139 +	srcDataBufferSize  = KSrcDataBufferSize;
   1.140 +	sinkDataBufferSize = KSinkDataBufferSize;
   1.141 +	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize, srcDataBufferSize/2, 0 ) == KErrNone )
   1.142 +		{
   1.143 +        INFO_PRINTF1(_L("Src Data Buffer position precondition violation"));
   1.144 +		result = EFail;
   1.145 +		}
   1.146 +
   1.147 +	//[ Position violation on the Destination ]
   1.148 +	srcDataBufferSize  = KSrcDataBufferSize;
   1.149 +	sinkDataBufferSize = KSinkDataBufferSize;
   1.150 +	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize,0, sinkDataBufferSize/2 ) == KErrNone )
   1.151 +		{
   1.152 +        INFO_PRINTF1(_L("Sink Data Buffer position precondition violation"));
   1.153 +		result = EFail;
   1.154 +		}
   1.155 +
   1.156 +	delete iSourceData;
   1.157 +	delete iCodedData ;
   1.158 +	iSourceData = NULL;
   1.159 +	iCodedData   = NULL;
   1.160 +
   1.161 +	__MM_HEAP_MARKEND;
   1.162 +	return result;
   1.163 +	}
   1.164 +
   1.165 +/**
   1.166 +*
   1.167 +* CodecPreconditionTest
   1.168 +* @precondition 0<= aSrcPosition  < aSrcDataBufferSize
   1.169 +* @precondition 0<= aSinkPosition < aSinkDataBufferSize
   1.170 +* @return TInt error code 
   1.171 +**/
   1.172 +template <class Codec>
   1.173 +TInt CTestStepLoopTest<Codec>::CodecPreconditionTestL( TInt aSrcDataBufferSize, TInt aSinkDataBufferSize, TInt aSrcPosition, TInt aSinkPosition )
   1.174 +	{
   1.175 +	TInt result = KErrNone;
   1.176 +	//[ assert preconditions ]
   1.177 +	ASSERT( (0 <= aSrcPosition ) && ( aSrcPosition < aSrcDataBufferSize ));
   1.178 +	ASSERT( (0 <= aSinkPosition ) && ( aSinkPosition < aSinkDataBufferSize ));
   1.179 +
   1.180 +	delete iSourceData;
   1.181 +	delete iCodedData ;
   1.182 +	iSourceData = NULL;
   1.183 +	iCodedData   = NULL;
   1.184 +	iSourceData = CMMFDescriptorBuffer::NewL(aSrcDataBufferSize * sizeof(TUint8));
   1.185 +	iCodedData   = CMMFDescriptorBuffer::NewL(aSinkDataBufferSize * sizeof(TUint8));
   1.186 +    //set the lengths of the buffers
   1.187 +	iSourceData->Data().SetLength(aSrcDataBufferSize);
   1.188 +	iCodedData->Data().SetLength(aSinkDataBufferSize);
   1.189 +	
   1.190 +	//set the positions on the buffers	
   1.191 +	iSourceData->SetPosition(aSrcPosition);
   1.192 +	iCodedData->SetPosition(aSinkPosition);
   1.193 +
   1.194 +	TRAP(result,iCodecUnderTest->ProcessL(*iSourceData, *iCodedData));
   1.195 +
   1.196 +	return result;
   1.197 +	}
   1.198 +
   1.199 +/**
   1.200 +*
   1.201 +* DoTestStepPreambleL
   1.202 +*
   1.203 +**/
   1.204 +template <class Codec>
   1.205 +TVerdict CTestStepLoopTest<Codec>::DoTestStepPreambleL(void)
   1.206 +	{
   1.207 +	iCodecUnderTest = new (ELeave) Codec;
   1.208 +	return EPass;
   1.209 +	}
   1.210 +
   1.211 +/**
   1.212 +*
   1.213 +* DoTestStepPostambleL
   1.214 +*
   1.215 +*/
   1.216 +template <class Codec>
   1.217 +TVerdict CTestStepLoopTest<Codec>::DoTestStepPostambleL(void)
   1.218 +	{
   1.219 +	delete iCodecUnderTest;
   1.220 +	iCodecUnderTest = NULL;
   1.221 +	delete 	iSourceData;
   1.222 +	iSourceData = NULL;
   1.223 +	delete  iCodedData;
   1.224 +	iCodedData = NULL;
   1.225 +	return EPass;
   1.226 +	}
   1.227 +
   1.228 +/**
   1.229 +*
   1.230 +* This is used for template instantiation.
   1.231 +*
   1.232 +**/
   1.233 +
   1.234 +template class CTestStepLoopTest<CMMFPcm16ToALawCodec>;
   1.235 +template class CTestStepLoopTest<CMMFAlawToPcm16Codec>;
   1.236 +template class CTestStepLoopTest<CMMFGsm610ToPcm16Codec>;
   1.237 +template class CTestStepLoopTest<CMMFImaAdpcmToPcm16Codec>;
   1.238 +template class CTestStepLoopTest<CMMFMulawToPcm16Codec>;
   1.239 +template class CTestStepLoopTest<CMMFPcm16SwapEndianCodec>;
   1.240 +template class CTestStepLoopTest<CMMFPcm16ToImaAdpcmCodec>;
   1.241 +template class CTestStepLoopTest<CMMFPcm16ToMuLawCodec>;
   1.242 +template class CTestStepLoopTest<CMMFPcm16ToPcmU16BECodec>;
   1.243 +template class CTestStepLoopTest<CMMFPcm16ToPcmU8Codec>;
   1.244 +template class CTestStepLoopTest<CMMFPcmS16ToPcmS8Codec>;
   1.245 +template class CTestStepLoopTest<CMMFPcm16ToPcmU16CodecCodec>;
   1.246 +template class CTestStepLoopTest<CMMFPcm8ToPcm16Codec>;
   1.247 +template class CTestStepLoopTest<CMMFPcmU16BeToPcmS16Codec>;
   1.248 +template class CTestStepLoopTest<CMMFPcm16ToGsm610Codec>;
   1.249 +