os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_Oom.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_Oom.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,290 @@
     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 +#include <mmf/common/mmfpaniccodes.h>
    1.22 +
    1.23 +// Test system includes
    1.24 +#include "TSU_MMF_DeviceSuite.h"
    1.25 +#include "TSU_MMF_Oom.h"
    1.26 +
    1.27 +//[ actual codec includes ]
    1.28 +#include "MmfPcm16toAlawhwDevice.h"
    1.29 +#include "MmfALawToPcm16HwDevice.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 TOomTestParams
    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 TOomTestParams KOomParameters[] =
    1.59 +	{	
    1.60 +		{_S("MM-MMF-SWCODECDEVICES-U-0041-HP")},
    1.61 +		{_S("MM-MMF-SWCODECDEVICES-U-0042-HP")},
    1.62 +		{_S("MM-MMF-SWCODECDEVICES-U-0043-HP")},
    1.63 +		{_S("MM-MMF-SWCODECDEVICES-U-0044-HP")},
    1.64 +		{_S("MM-MMF-SWCODECDEVICES-U-0045-HP")},
    1.65 +		{_S("MM-MMF-SWCODECDEVICES-U-0046-HP")},
    1.66 +		{_S("MM-MMF-SWCODECDEVICES-U-0047-HP")},
    1.67 +		{_S("MM-MMF-SWCODECDEVICES-U-0048-HP")},
    1.68 +		{_S("MM-MMF-SWCODECDEVICES-U-0049-HP")},
    1.69 +		{_S("MM-MMF-SWCODECDEVICES-U-0050-HP")},
    1.70 +		{_S("MM-MMF-SWCODECDEVICES-U-0051-HP")},
    1.71 +		{_S("MM-MMF-SWCODECDEVICES-U-0052-HP")},
    1.72 +		{_S("MM-MMF-SWCODECDEVICES-U-0053-HP")},
    1.73 +		{_S("MM-MMF-SWCODECDEVICES-U-0054-HP")},
    1.74 +		{_S("MM-MMF-SWCODECDEVICES-U-0055-HP")},
    1.75 +		{_S("MM-MMF-SWCODECDEVICES-U-0056-HP")}
    1.76 +	};
    1.77 +
    1.78 +/**
    1.79 +*
    1.80 +* CTestStepOomTest
    1.81 +*
    1.82 +*/
    1.83 +template <class Codec>
    1.84 +CTestStepOomTest<Codec>::CTestStepOomTest( 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 +//	__ASSERT_DEBUG( (aTestIndex >= 0) && ( aTestIndex < sizeof(KOomParameters)/sizeof(TOomTestParams)),Panic(EBadInvariant));
    1.89 +	__ASSERT_DEBUG( ( aTestIndex < sizeof(KOomParameters)/sizeof(TOomTestParams)),Panic(EBadInvariant));	// EABI warning removal
    1.90 +	iTestStepName = (&KOomParameters[aTestIndex])->iTestName;
    1.91 +	}
    1.92 +
    1.93 +/**
    1.94 +*
    1.95 +* ~CTestStepOomTest
    1.96 +*
    1.97 +*/
    1.98 +template <class Codec>
    1.99 +CTestStepOomTest<Codec>::~CTestStepOomTest()
   1.100 +	{
   1.101 +	}
   1.102 +
   1.103 +/**
   1.104 +*
   1.105 +* DoTestStepL
   1.106 +*
   1.107 +**/
   1.108 +template <class Codec>
   1.109 +TVerdict CTestStepOomTest<Codec>::DoTestStepL()
   1.110 +	{
   1.111 +	TVerdict result = EPass;
   1.112 +
   1.113 +	TBool testOK = ETrue;
   1.114 +	TUint failCount = 1;
   1.115 +	TBool testComplete = EFalse;
   1.116 +
   1.117 +	while (!testComplete)
   1.118 +		{
   1.119 +		__UHEAP_FAILNEXT(failCount);
   1.120 +		__MM_HEAP_MARK;
   1.121 +		TRAPD(err, Oom());
   1.122 +		switch (err)
   1.123 +			{
   1.124 +			case KErrNoMemory :
   1.125 +				break;
   1.126 +			case KErrNone :
   1.127 +				{
   1.128 +				//attempt to allocate another cell. If this fails, we have tested all 
   1.129 +				//of the memory allocs carried out by ProcessL.
   1.130 +				TAny *testAlloc = User::Alloc(1);
   1.131 +				if (testAlloc==NULL)
   1.132 +					{
   1.133 +					testComplete = ETrue;
   1.134 +					failCount --;
   1.135 +					}
   1.136 +				else
   1.137 +					User::Free(testAlloc);
   1.138 +				break;
   1.139 +				}
   1.140 +			default:
   1.141 +				{
   1.142 +				testOK = EFalse;
   1.143 +				testComplete = ETrue;
   1.144 +				break;
   1.145 +				}
   1.146 +			}
   1.147 +		
   1.148 +		__MM_HEAP_MARKEND;
   1.149 +		__UHEAP_RESET;
   1.150 +		failCount++;
   1.151 +		}
   1.152 +
   1.153 +	if(!testOK)
   1.154 +		{
   1.155 +		result = EFail;
   1.156 +		}
   1.157 +
   1.158 +	return result;
   1.159 +	}
   1.160 +
   1.161 +/**
   1.162 +*
   1.163 +* Oom performs the oom test on the codec in question
   1.164 +* @param srcBuffer
   1.165 +* @param dstBuffer 
   1.166 +* @return TInt error status
   1.167 +*
   1.168 +**/
   1.169 +template <class Codec>
   1.170 +TInt CTestStepOomTest<Codec>::Oom()
   1.171 +	{
   1.172 +	//instantiate codec via a factory function which allows 
   1.173 +	//two phase construction if needed as in the case of gsm610
   1.174 +	// by derivation.
   1.175 +	Codec* theCodec = GetCodecL(); 
   1.176 +	CleanupStack::PushL(theCodec);
   1.177 +	
   1.178 +	//create buffers
   1.179 +	TInt srcBufferSize  = theCodec->SourceBufferSize();
   1.180 +	TInt sinkBufferSize = theCodec->SinkBufferSize();
   1.181 +	CMMFDataBuffer *srcBuffer = CMMFDataBuffer::NewL(srcBufferSize);
   1.182 +	srcBuffer->Data().SetLength( srcBufferSize);
   1.183 +	CleanupStack::PushL(srcBuffer);
   1.184 +	CMMFDataBuffer *dstBuffer = CMMFDataBuffer::NewL(sinkBufferSize);
   1.185 +	dstBuffer->Data().SetLength( sinkBufferSize );
   1.186 +	CleanupStack::PushL(dstBuffer);
   1.187 +    
   1.188 +	//[perform the coding operation]
   1.189 +	theCodec->ProcessL(*srcBuffer, *dstBuffer);
   1.190 +
   1.191 +	CleanupStack::PopAndDestroy(3,theCodec); //theCodec,dstBuffer, srcBuffer
   1.192 +	return KErrNone;
   1.193 +	}
   1.194 +
   1.195 +/**
   1.196 +*
   1.197 +* GetCodec()
   1.198 +* @return fully contrsucted codec pointer
   1.199 +* note the client of this function is responsible for deallocation
   1.200 +*
   1.201 +**/
   1.202 +template <class Codec>
   1.203 +Codec* CTestStepOomTest<Codec>::GetCodecL()
   1.204 +	{
   1.205 +	return new(ELeave) Codec();
   1.206 +	}
   1.207 +
   1.208 +
   1.209 +/**
   1.210 +*
   1.211 +* DoTestStepPreambleL
   1.212 +*
   1.213 +**/
   1.214 +template <class Codec>
   1.215 +TVerdict CTestStepOomTest<Codec>::DoTestStepPreambleL(void)
   1.216 +	{
   1.217 +	return EPass;
   1.218 +	}
   1.219 +
   1.220 +/**
   1.221 +*
   1.222 +* DoTestStepPostambleL
   1.223 +*
   1.224 +*/
   1.225 +template <class Codec>
   1.226 +TVerdict CTestStepOomTest<Codec>::DoTestStepPostambleL(void)
   1.227 +	{
   1.228 +	return EPass;
   1.229 +	}
   1.230 +
   1.231 +/**
   1.232 +*
   1.233 +* GetCodecL()
   1.234 +* @return CMMFGsm610ToPcm16Codec*
   1.235 +*
   1.236 +**/
   1.237 +CMMFGsm610ToPcm16Codec* CTestStepGsm610ToPcm16OomTest::GetCodecL()
   1.238 +		{
   1.239 +		CMMFGsm610ToPcm16Codec* theCodec = new (ELeave) CMMFGsm610ToPcm16Codec;
   1.240 +		CleanupStack::PushL(theCodec);
   1.241 +		theCodec->ConstructL();
   1.242 +		CleanupStack::Pop(1); // theCodec
   1.243 +		return theCodec;
   1.244 +		}
   1.245 +/**
   1.246 +*
   1.247 +* GetCodecL
   1.248 +* @return CMMFGsm610ToPcm16Codec*
   1.249 +*
   1.250 +**/
   1.251 +CMMFGsm610ToPcm16Codec* CTestStepPcm16ToGsm610OomTest::GetCodecL()
   1.252 +	{
   1.253 +	CMMFGsm610ToPcm16Codec* theCodec = new (ELeave) CMMFGsm610ToPcm16Codec();
   1.254 +	CleanupStack::PushL(theCodec);
   1.255 +	theCodec->ConstructL();
   1.256 +	CleanupStack::Pop(1); // theCodec
   1.257 +	return theCodec;	
   1.258 +	}
   1.259 + 
   1.260 +/**
   1.261 +*
   1.262 +* This is used for template instantiation.
   1.263 +*
   1.264 +* Normally templated classes are defined in header files..
   1.265 +* Here we use them in *.cpp which requires an explicit instantiation.
   1.266 +* We know that any other reference to CTestStepOomTest<class> within
   1.267 +* this dll will instantiate the template and we do not want the compiler
   1.268 +* to remind us about that.
   1.269 +*
   1.270 +**/
   1.271 +
   1.272 +#ifdef __VC32__
   1.273 +#pragma warning( disable : 4660 )	
   1.274 +#endif
   1.275 +
   1.276 +template class CTestStepOomTest<CMMFPcm16ToALawCodec>;
   1.277 +template class CTestStepOomTest<CMMFAlawToPcm16Codec>;
   1.278 +template class CTestStepOomTest<CMMFGsm610ToPcm16Codec>;
   1.279 +template class CTestStepOomTest<CMMFImaAdpcmToPcm16Codec>;
   1.280 +template class CTestStepOomTest<CMMFMulawToPcm16Codec>;
   1.281 +template class CTestStepOomTest<CMMFPcm16SwapEndianCodec>;
   1.282 +template class CTestStepOomTest<CMMFPcm16ToImaAdpcmCodec>;
   1.283 +template class CTestStepOomTest<CMMFPcm16ToMuLawCodec>;
   1.284 +template class CTestStepOomTest<CMMFPcm16ToPcmU16BECodec>;
   1.285 +template class CTestStepOomTest<CMMFPcm16ToPcmU8Codec>;
   1.286 +template class CTestStepOomTest<CMMFPcmS16ToPcmS8Codec>;
   1.287 +template class CTestStepOomTest<CMMFPcm16ToPcmU16CodecCodec>;
   1.288 +template class CTestStepOomTest<CMMFPcm8ToPcm16Codec>;
   1.289 +template class CTestStepOomTest<CMMFPcmU16BeToPcmS16Codec>;
   1.290 +
   1.291 +#ifdef __VC32__
   1.292 +#pragma warning( default : 4660 )
   1.293 +#endif