sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: // EPOC includes sl@0: #include sl@0: #include sl@0: sl@0: // Test system includes sl@0: #include "TSU_MMF_DeviceSuite.h" sl@0: #include "TSU_MMF_Oom.h" sl@0: sl@0: //[ actual codec includes ] sl@0: #include "MmfPcm16toAlawhwDevice.h" sl@0: #include "MmfALawToPcm16HwDevice.h" sl@0: #include "MmfImaAdpcmtopcm16hwdevice.h" sl@0: #include "MmfMuLawToPcm16hwDevice.h" sl@0: #include "mmfpcm16SwapEndianhwdevice.h" sl@0: #include "mmfpcm16ToImaAdpcm.h" sl@0: #include "mmfpcm16toMulawhwdevice.h" sl@0: #include "mmfpcm16topcmU16BEHwDevice.h" sl@0: #include "MMFpcm16ToPcmU8HwDevice.h" sl@0: #include "MMFpcm16ToPcmU8HwDevice.h" sl@0: #include "mmfpcmS16PcmS8HwDevice.h" sl@0: #include "mmfpcmS16topcmU16Codec.h" sl@0: #include "mmfpcmS8ToPcmS16HwDevice.h" sl@0: #include "mmfpcmU16BeToPcmS16HwDevice.h" sl@0: #include "mmfpcmU16TopcmS16HwDevice.h" sl@0: #include "MMFpcmU8ToPcm16HwDevice.h" sl@0: sl@0: //[ Codec Unit tests structure sl@0: // The unit tests shall use text files sl@0: // for small portions of test data sl@0: // which should be stored are stored in a simple format sl@0: // containing the relevant parameters for the test sl@0: //] sl@0: class TOomTestParams sl@0: { sl@0: public: sl@0: const TText* iTestName; // name of the test sl@0: }; sl@0: sl@0: // constant table of parameters for tests sl@0: const TOomTestParams KOomParameters[] = sl@0: { sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0041-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0042-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0043-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0044-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0045-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0046-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0047-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0048-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0049-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0050-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0051-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0052-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0053-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0054-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0055-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0056-HP")} sl@0: }; sl@0: sl@0: /** sl@0: * sl@0: * CTestStepOomTest sl@0: * sl@0: */ sl@0: template sl@0: CTestStepOomTest::CTestStepOomTest( TUint aTestIndex ) sl@0: { sl@0: // store the name of this test case sl@0: // this is the name that is used by the script file sl@0: // __ASSERT_DEBUG( (aTestIndex >= 0) && ( aTestIndex < sizeof(KOomParameters)/sizeof(TOomTestParams)),Panic(EBadInvariant)); sl@0: __ASSERT_DEBUG( ( aTestIndex < sizeof(KOomParameters)/sizeof(TOomTestParams)),Panic(EBadInvariant)); // EABI warning removal sl@0: iTestStepName = (&KOomParameters[aTestIndex])->iTestName; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * ~CTestStepOomTest sl@0: * sl@0: */ sl@0: template sl@0: CTestStepOomTest::~CTestStepOomTest() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoTestStepL sl@0: * sl@0: **/ sl@0: template sl@0: TVerdict CTestStepOomTest::DoTestStepL() sl@0: { sl@0: TVerdict result = EPass; sl@0: sl@0: TBool testOK = ETrue; sl@0: TUint failCount = 1; sl@0: TBool testComplete = EFalse; sl@0: sl@0: while (!testComplete) sl@0: { sl@0: __UHEAP_FAILNEXT(failCount); sl@0: __MM_HEAP_MARK; sl@0: TRAPD(err, Oom()); sl@0: switch (err) sl@0: { sl@0: case KErrNoMemory : sl@0: break; sl@0: case KErrNone : sl@0: { sl@0: //attempt to allocate another cell. If this fails, we have tested all sl@0: //of the memory allocs carried out by ProcessL. sl@0: TAny *testAlloc = User::Alloc(1); sl@0: if (testAlloc==NULL) sl@0: { sl@0: testComplete = ETrue; sl@0: failCount --; sl@0: } sl@0: else sl@0: User::Free(testAlloc); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: testOK = EFalse; sl@0: testComplete = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: __MM_HEAP_MARKEND; sl@0: __UHEAP_RESET; sl@0: failCount++; sl@0: } sl@0: sl@0: if(!testOK) sl@0: { sl@0: result = EFail; sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * Oom performs the oom test on the codec in question sl@0: * @param srcBuffer sl@0: * @param dstBuffer sl@0: * @return TInt error status sl@0: * sl@0: **/ sl@0: template sl@0: TInt CTestStepOomTest::Oom() sl@0: { sl@0: //instantiate codec via a factory function which allows sl@0: //two phase construction if needed as in the case of gsm610 sl@0: // by derivation. sl@0: Codec* theCodec = GetCodecL(); sl@0: CleanupStack::PushL(theCodec); sl@0: sl@0: //create buffers sl@0: TInt srcBufferSize = theCodec->SourceBufferSize(); sl@0: TInt sinkBufferSize = theCodec->SinkBufferSize(); sl@0: CMMFDataBuffer *srcBuffer = CMMFDataBuffer::NewL(srcBufferSize); sl@0: srcBuffer->Data().SetLength( srcBufferSize); sl@0: CleanupStack::PushL(srcBuffer); sl@0: CMMFDataBuffer *dstBuffer = CMMFDataBuffer::NewL(sinkBufferSize); sl@0: dstBuffer->Data().SetLength( sinkBufferSize ); sl@0: CleanupStack::PushL(dstBuffer); sl@0: sl@0: //[perform the coding operation] sl@0: theCodec->ProcessL(*srcBuffer, *dstBuffer); sl@0: sl@0: CleanupStack::PopAndDestroy(3,theCodec); //theCodec,dstBuffer, srcBuffer sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GetCodec() sl@0: * @return fully contrsucted codec pointer sl@0: * note the client of this function is responsible for deallocation sl@0: * sl@0: **/ sl@0: template sl@0: Codec* CTestStepOomTest::GetCodecL() sl@0: { sl@0: return new(ELeave) Codec(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * sl@0: * DoTestStepPreambleL sl@0: * sl@0: **/ sl@0: template sl@0: TVerdict CTestStepOomTest::DoTestStepPreambleL(void) sl@0: { sl@0: return EPass; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoTestStepPostambleL sl@0: * sl@0: */ sl@0: template sl@0: TVerdict CTestStepOomTest::DoTestStepPostambleL(void) sl@0: { sl@0: return EPass; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GetCodecL() sl@0: * @return CMMFGsm610ToPcm16Codec* sl@0: * sl@0: **/ sl@0: CMMFGsm610ToPcm16Codec* CTestStepGsm610ToPcm16OomTest::GetCodecL() sl@0: { sl@0: CMMFGsm610ToPcm16Codec* theCodec = new (ELeave) CMMFGsm610ToPcm16Codec; sl@0: CleanupStack::PushL(theCodec); sl@0: theCodec->ConstructL(); sl@0: CleanupStack::Pop(1); // theCodec sl@0: return theCodec; sl@0: } sl@0: /** sl@0: * sl@0: * GetCodecL sl@0: * @return CMMFGsm610ToPcm16Codec* sl@0: * sl@0: **/ sl@0: CMMFGsm610ToPcm16Codec* CTestStepPcm16ToGsm610OomTest::GetCodecL() sl@0: { sl@0: CMMFGsm610ToPcm16Codec* theCodec = new (ELeave) CMMFGsm610ToPcm16Codec(); sl@0: CleanupStack::PushL(theCodec); sl@0: theCodec->ConstructL(); sl@0: CleanupStack::Pop(1); // theCodec sl@0: return theCodec; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * This is used for template instantiation. sl@0: * sl@0: * Normally templated classes are defined in header files.. sl@0: * Here we use them in *.cpp which requires an explicit instantiation. sl@0: * We know that any other reference to CTestStepOomTest within sl@0: * this dll will instantiate the template and we do not want the compiler sl@0: * to remind us about that. sl@0: * sl@0: **/ sl@0: sl@0: #ifdef __VC32__ sl@0: #pragma warning( disable : 4660 ) sl@0: #endif sl@0: sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: template class CTestStepOomTest; sl@0: sl@0: #ifdef __VC32__ sl@0: #pragma warning( default : 4660 ) sl@0: #endif