os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_Oom.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
// EPOC includes
sl@0
    17
#include <e32base.h>
sl@0
    18
#include <mmf/common/mmfpaniccodes.h>
sl@0
    19
sl@0
    20
// Test system includes
sl@0
    21
#include "TSU_MMF_DeviceSuite.h"
sl@0
    22
#include "TSU_MMF_Oom.h"
sl@0
    23
sl@0
    24
//[ actual codec includes ]
sl@0
    25
#include "MmfPcm16toAlawhwDevice.h"
sl@0
    26
#include "MmfALawToPcm16HwDevice.h"
sl@0
    27
#include "MmfImaAdpcmtopcm16hwdevice.h"
sl@0
    28
#include "MmfMuLawToPcm16hwDevice.h"
sl@0
    29
#include "mmfpcm16SwapEndianhwdevice.h"
sl@0
    30
#include "mmfpcm16ToImaAdpcm.h"
sl@0
    31
#include "mmfpcm16toMulawhwdevice.h"
sl@0
    32
#include "mmfpcm16topcmU16BEHwDevice.h"
sl@0
    33
#include "MMFpcm16ToPcmU8HwDevice.h"
sl@0
    34
#include "MMFpcm16ToPcmU8HwDevice.h"
sl@0
    35
#include "mmfpcmS16PcmS8HwDevice.h"
sl@0
    36
#include "mmfpcmS16topcmU16Codec.h"
sl@0
    37
#include "mmfpcmS8ToPcmS16HwDevice.h"
sl@0
    38
#include "mmfpcmU16BeToPcmS16HwDevice.h"
sl@0
    39
#include "mmfpcmU16TopcmS16HwDevice.h"
sl@0
    40
#include "MMFpcmU8ToPcm16HwDevice.h"
sl@0
    41
sl@0
    42
//[ Codec Unit tests  structure 
sl@0
    43
// The unit tests shall use text files
sl@0
    44
// for small portions of test data 
sl@0
    45
// which should be stored are stored in a simple format
sl@0
    46
// containing the relevant parameters for the test
sl@0
    47
//]
sl@0
    48
class TOomTestParams
sl@0
    49
	{	
sl@0
    50
public:
sl@0
    51
	const TText* iTestName;       // name of the test
sl@0
    52
	};
sl@0
    53
sl@0
    54
// constant table of parameters for tests
sl@0
    55
const TOomTestParams KOomParameters[] =
sl@0
    56
	{	
sl@0
    57
		{_S("MM-MMF-SWCODECDEVICES-U-0041-HP")},
sl@0
    58
		{_S("MM-MMF-SWCODECDEVICES-U-0042-HP")},
sl@0
    59
		{_S("MM-MMF-SWCODECDEVICES-U-0043-HP")},
sl@0
    60
		{_S("MM-MMF-SWCODECDEVICES-U-0044-HP")},
sl@0
    61
		{_S("MM-MMF-SWCODECDEVICES-U-0045-HP")},
sl@0
    62
		{_S("MM-MMF-SWCODECDEVICES-U-0046-HP")},
sl@0
    63
		{_S("MM-MMF-SWCODECDEVICES-U-0047-HP")},
sl@0
    64
		{_S("MM-MMF-SWCODECDEVICES-U-0048-HP")},
sl@0
    65
		{_S("MM-MMF-SWCODECDEVICES-U-0049-HP")},
sl@0
    66
		{_S("MM-MMF-SWCODECDEVICES-U-0050-HP")},
sl@0
    67
		{_S("MM-MMF-SWCODECDEVICES-U-0051-HP")},
sl@0
    68
		{_S("MM-MMF-SWCODECDEVICES-U-0052-HP")},
sl@0
    69
		{_S("MM-MMF-SWCODECDEVICES-U-0053-HP")},
sl@0
    70
		{_S("MM-MMF-SWCODECDEVICES-U-0054-HP")},
sl@0
    71
		{_S("MM-MMF-SWCODECDEVICES-U-0055-HP")},
sl@0
    72
		{_S("MM-MMF-SWCODECDEVICES-U-0056-HP")}
sl@0
    73
	};
sl@0
    74
sl@0
    75
/**
sl@0
    76
*
sl@0
    77
* CTestStepOomTest
sl@0
    78
*
sl@0
    79
*/
sl@0
    80
template <class Codec>
sl@0
    81
CTestStepOomTest<Codec>::CTestStepOomTest( TUint aTestIndex )
sl@0
    82
	{
sl@0
    83
	// store the name of this test case
sl@0
    84
	// this is the name that is used by the script file
sl@0
    85
//	__ASSERT_DEBUG( (aTestIndex >= 0) && ( aTestIndex < sizeof(KOomParameters)/sizeof(TOomTestParams)),Panic(EBadInvariant));
sl@0
    86
	__ASSERT_DEBUG( ( aTestIndex < sizeof(KOomParameters)/sizeof(TOomTestParams)),Panic(EBadInvariant));	// EABI warning removal
sl@0
    87
	iTestStepName = (&KOomParameters[aTestIndex])->iTestName;
sl@0
    88
	}
sl@0
    89
sl@0
    90
/**
sl@0
    91
*
sl@0
    92
* ~CTestStepOomTest
sl@0
    93
*
sl@0
    94
*/
sl@0
    95
template <class Codec>
sl@0
    96
CTestStepOomTest<Codec>::~CTestStepOomTest()
sl@0
    97
	{
sl@0
    98
	}
sl@0
    99
sl@0
   100
/**
sl@0
   101
*
sl@0
   102
* DoTestStepL
sl@0
   103
*
sl@0
   104
**/
sl@0
   105
template <class Codec>
sl@0
   106
TVerdict CTestStepOomTest<Codec>::DoTestStepL()
sl@0
   107
	{
sl@0
   108
	TVerdict result = EPass;
sl@0
   109
sl@0
   110
	TBool testOK = ETrue;
sl@0
   111
	TUint failCount = 1;
sl@0
   112
	TBool testComplete = EFalse;
sl@0
   113
sl@0
   114
	while (!testComplete)
sl@0
   115
		{
sl@0
   116
		__UHEAP_FAILNEXT(failCount);
sl@0
   117
		__MM_HEAP_MARK;
sl@0
   118
		TRAPD(err, Oom());
sl@0
   119
		switch (err)
sl@0
   120
			{
sl@0
   121
			case KErrNoMemory :
sl@0
   122
				break;
sl@0
   123
			case KErrNone :
sl@0
   124
				{
sl@0
   125
				//attempt to allocate another cell. If this fails, we have tested all 
sl@0
   126
				//of the memory allocs carried out by ProcessL.
sl@0
   127
				TAny *testAlloc = User::Alloc(1);
sl@0
   128
				if (testAlloc==NULL)
sl@0
   129
					{
sl@0
   130
					testComplete = ETrue;
sl@0
   131
					failCount --;
sl@0
   132
					}
sl@0
   133
				else
sl@0
   134
					User::Free(testAlloc);
sl@0
   135
				break;
sl@0
   136
				}
sl@0
   137
			default:
sl@0
   138
				{
sl@0
   139
				testOK = EFalse;
sl@0
   140
				testComplete = ETrue;
sl@0
   141
				break;
sl@0
   142
				}
sl@0
   143
			}
sl@0
   144
		
sl@0
   145
		__MM_HEAP_MARKEND;
sl@0
   146
		__UHEAP_RESET;
sl@0
   147
		failCount++;
sl@0
   148
		}
sl@0
   149
sl@0
   150
	if(!testOK)
sl@0
   151
		{
sl@0
   152
		result = EFail;
sl@0
   153
		}
sl@0
   154
sl@0
   155
	return result;
sl@0
   156
	}
sl@0
   157
sl@0
   158
/**
sl@0
   159
*
sl@0
   160
* Oom performs the oom test on the codec in question
sl@0
   161
* @param srcBuffer
sl@0
   162
* @param dstBuffer 
sl@0
   163
* @return TInt error status
sl@0
   164
*
sl@0
   165
**/
sl@0
   166
template <class Codec>
sl@0
   167
TInt CTestStepOomTest<Codec>::Oom()
sl@0
   168
	{
sl@0
   169
	//instantiate codec via a factory function which allows 
sl@0
   170
	//two phase construction if needed as in the case of gsm610
sl@0
   171
	// by derivation.
sl@0
   172
	Codec* theCodec = GetCodecL(); 
sl@0
   173
	CleanupStack::PushL(theCodec);
sl@0
   174
	
sl@0
   175
	//create buffers
sl@0
   176
	TInt srcBufferSize  = theCodec->SourceBufferSize();
sl@0
   177
	TInt sinkBufferSize = theCodec->SinkBufferSize();
sl@0
   178
	CMMFDataBuffer *srcBuffer = CMMFDataBuffer::NewL(srcBufferSize);
sl@0
   179
	srcBuffer->Data().SetLength( srcBufferSize);
sl@0
   180
	CleanupStack::PushL(srcBuffer);
sl@0
   181
	CMMFDataBuffer *dstBuffer = CMMFDataBuffer::NewL(sinkBufferSize);
sl@0
   182
	dstBuffer->Data().SetLength( sinkBufferSize );
sl@0
   183
	CleanupStack::PushL(dstBuffer);
sl@0
   184
    
sl@0
   185
	//[perform the coding operation]
sl@0
   186
	theCodec->ProcessL(*srcBuffer, *dstBuffer);
sl@0
   187
sl@0
   188
	CleanupStack::PopAndDestroy(3,theCodec); //theCodec,dstBuffer, srcBuffer
sl@0
   189
	return KErrNone;
sl@0
   190
	}
sl@0
   191
sl@0
   192
/**
sl@0
   193
*
sl@0
   194
* GetCodec()
sl@0
   195
* @return fully contrsucted codec pointer
sl@0
   196
* note the client of this function is responsible for deallocation
sl@0
   197
*
sl@0
   198
**/
sl@0
   199
template <class Codec>
sl@0
   200
Codec* CTestStepOomTest<Codec>::GetCodecL()
sl@0
   201
	{
sl@0
   202
	return new(ELeave) Codec();
sl@0
   203
	}
sl@0
   204
sl@0
   205
sl@0
   206
/**
sl@0
   207
*
sl@0
   208
* DoTestStepPreambleL
sl@0
   209
*
sl@0
   210
**/
sl@0
   211
template <class Codec>
sl@0
   212
TVerdict CTestStepOomTest<Codec>::DoTestStepPreambleL(void)
sl@0
   213
	{
sl@0
   214
	return EPass;
sl@0
   215
	}
sl@0
   216
sl@0
   217
/**
sl@0
   218
*
sl@0
   219
* DoTestStepPostambleL
sl@0
   220
*
sl@0
   221
*/
sl@0
   222
template <class Codec>
sl@0
   223
TVerdict CTestStepOomTest<Codec>::DoTestStepPostambleL(void)
sl@0
   224
	{
sl@0
   225
	return EPass;
sl@0
   226
	}
sl@0
   227
sl@0
   228
/**
sl@0
   229
*
sl@0
   230
* GetCodecL()
sl@0
   231
* @return CMMFGsm610ToPcm16Codec*
sl@0
   232
*
sl@0
   233
**/
sl@0
   234
CMMFGsm610ToPcm16Codec* CTestStepGsm610ToPcm16OomTest::GetCodecL()
sl@0
   235
		{
sl@0
   236
		CMMFGsm610ToPcm16Codec* theCodec = new (ELeave) CMMFGsm610ToPcm16Codec;
sl@0
   237
		CleanupStack::PushL(theCodec);
sl@0
   238
		theCodec->ConstructL();
sl@0
   239
		CleanupStack::Pop(1); // theCodec
sl@0
   240
		return theCodec;
sl@0
   241
		}
sl@0
   242
/**
sl@0
   243
*
sl@0
   244
* GetCodecL
sl@0
   245
* @return CMMFGsm610ToPcm16Codec*
sl@0
   246
*
sl@0
   247
**/
sl@0
   248
CMMFGsm610ToPcm16Codec* CTestStepPcm16ToGsm610OomTest::GetCodecL()
sl@0
   249
	{
sl@0
   250
	CMMFGsm610ToPcm16Codec* theCodec = new (ELeave) CMMFGsm610ToPcm16Codec();
sl@0
   251
	CleanupStack::PushL(theCodec);
sl@0
   252
	theCodec->ConstructL();
sl@0
   253
	CleanupStack::Pop(1); // theCodec
sl@0
   254
	return theCodec;	
sl@0
   255
	}
sl@0
   256
 
sl@0
   257
/**
sl@0
   258
*
sl@0
   259
* This is used for template instantiation.
sl@0
   260
*
sl@0
   261
* Normally templated classes are defined in header files..
sl@0
   262
* Here we use them in *.cpp which requires an explicit instantiation.
sl@0
   263
* We know that any other reference to CTestStepOomTest<class> within
sl@0
   264
* this dll will instantiate the template and we do not want the compiler
sl@0
   265
* to remind us about that.
sl@0
   266
*
sl@0
   267
**/
sl@0
   268
sl@0
   269
#ifdef __VC32__
sl@0
   270
#pragma warning( disable : 4660 )	
sl@0
   271
#endif
sl@0
   272
sl@0
   273
template class CTestStepOomTest<CMMFPcm16ToALawCodec>;
sl@0
   274
template class CTestStepOomTest<CMMFAlawToPcm16Codec>;
sl@0
   275
template class CTestStepOomTest<CMMFGsm610ToPcm16Codec>;
sl@0
   276
template class CTestStepOomTest<CMMFImaAdpcmToPcm16Codec>;
sl@0
   277
template class CTestStepOomTest<CMMFMulawToPcm16Codec>;
sl@0
   278
template class CTestStepOomTest<CMMFPcm16SwapEndianCodec>;
sl@0
   279
template class CTestStepOomTest<CMMFPcm16ToImaAdpcmCodec>;
sl@0
   280
template class CTestStepOomTest<CMMFPcm16ToMuLawCodec>;
sl@0
   281
template class CTestStepOomTest<CMMFPcm16ToPcmU16BECodec>;
sl@0
   282
template class CTestStepOomTest<CMMFPcm16ToPcmU8Codec>;
sl@0
   283
template class CTestStepOomTest<CMMFPcmS16ToPcmS8Codec>;
sl@0
   284
template class CTestStepOomTest<CMMFPcm16ToPcmU16CodecCodec>;
sl@0
   285
template class CTestStepOomTest<CMMFPcm8ToPcm16Codec>;
sl@0
   286
template class CTestStepOomTest<CMMFPcmU16BeToPcmS16Codec>;
sl@0
   287
sl@0
   288
#ifdef __VC32__
sl@0
   289
#pragma warning( default : 4660 )
sl@0
   290
#endif