os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_Loop.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
sl@0
    19
// Test system includes
sl@0
    20
#include "TSU_MMF_DeviceSuite.h"
sl@0
    21
#include "TSU_MMF_Loop.h"
sl@0
    22
sl@0
    23
//[ actual codec includes ]
sl@0
    24
#include "MmfPcm16toAlawhwDevice.h"
sl@0
    25
#include "MmfALawToPcm16HwDevice.h"
sl@0
    26
#include "GSM610.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 TLoopTestParams
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 TLoopTestParams KLoopParameters[] =
sl@0
    56
	{	
sl@0
    57
		{_S("MM-MMF-SWCODECDEVICES-U-0061-HP")},
sl@0
    58
		{_S("MM-MMF-SWCODECDEVICES-U-0062-HP")},
sl@0
    59
		{_S("MM-MMF-SWCODECDEVICES-U-0063-HP")},
sl@0
    60
		{_S("MM-MMF-SWCODECDEVICES-U-0064-HP")},
sl@0
    61
		{_S("MM-MMF-SWCODECDEVICES-U-0065-HP")},
sl@0
    62
		{_S("MM-MMF-SWCODECDEVICES-U-0066-HP")},
sl@0
    63
		{_S("MM-MMF-SWCODECDEVICES-U-0067-HP")},
sl@0
    64
		{_S("MM-MMF-SWCODECDEVICES-U-0068-HP")},
sl@0
    65
		{_S("MM-MMF-SWCODECDEVICES-U-0069-HP")},
sl@0
    66
		{_S("MM-MMF-SWCODECDEVICES-U-0070-HP")},
sl@0
    67
		{_S("MM-MMF-SWCODECDEVICES-U-0071-HP")},
sl@0
    68
		{_S("MM-MMF-SWCODECDEVICES-U-0072-HP")},
sl@0
    69
		{_S("MM-MMF-SWCODECDEVICES-U-0073-HP")},
sl@0
    70
		{_S("MM-MMF-SWCODECDEVICES-U-0074-HP")},
sl@0
    71
		{_S("MM-MMF-SWCODECDEVICES-U-0075-HP")},
sl@0
    72
		{_S("MM-MMF-SWCODECDEVICES-U-0076-HP")}
sl@0
    73
	};
sl@0
    74
sl@0
    75
/**
sl@0
    76
*
sl@0
    77
* CTestStepLoopTest
sl@0
    78
*
sl@0
    79
*/
sl@0
    80
template <class Codec>
sl@0
    81
CTestStepLoopTest<Codec>::CTestStepLoopTest( 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
	iTestStepName = (&KLoopParameters[aTestIndex])->iTestName;
sl@0
    86
	}
sl@0
    87
sl@0
    88
/**
sl@0
    89
*
sl@0
    90
* ~CTestStepLoopTest
sl@0
    91
*
sl@0
    92
*/
sl@0
    93
template <class Codec>
sl@0
    94
CTestStepLoopTest<Codec>::~CTestStepLoopTest()
sl@0
    95
	{
sl@0
    96
	}
sl@0
    97
sl@0
    98
/**
sl@0
    99
*
sl@0
   100
* DoTestStepL
sl@0
   101
* This method tests codec src & destination buffer size violations
sl@0
   102
* and position violations.
sl@0
   103
*
sl@0
   104
**/
sl@0
   105
template <class Codec>
sl@0
   106
TVerdict CTestStepLoopTest<Codec>::DoTestStepL()
sl@0
   107
	{
sl@0
   108
	__MM_HEAP_MARK;	
sl@0
   109
	TVerdict result = EPass;
sl@0
   110
sl@0
   111
	//[ Buffer size violation on the src ]
sl@0
   112
	const TInt KSrcDataBufferSize  = iCodecUnderTest->SourceBufferSize();
sl@0
   113
	const TInt KSinkDataBufferSize = iCodecUnderTest->SinkBufferSize();
sl@0
   114
sl@0
   115
	//[ create the data buffers and do not worry about filling them since
sl@0
   116
	// this is simply a precondition test ]
sl@0
   117
	TInt srcDataBufferSize  = KSrcDataBufferSize*2;
sl@0
   118
	TInt sinkDataBufferSize = KSinkDataBufferSize;
sl@0
   119
	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize ) == KErrNone )
sl@0
   120
		{
sl@0
   121
        //[ info print here ]
sl@0
   122
		INFO_PRINTF1(_L("Src Data Buffer precondition violation"));
sl@0
   123
		result = EFail;
sl@0
   124
		}
sl@0
   125
sl@0
   126
	//[ Buffer size violation on the Destination ]
sl@0
   127
	srcDataBufferSize  = KSrcDataBufferSize;
sl@0
   128
	sinkDataBufferSize = KSinkDataBufferSize/4;
sl@0
   129
	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize ) == KErrNone )
sl@0
   130
		{
sl@0
   131
       	INFO_PRINTF1(_L("Sink Data Buffer precondition violation"));
sl@0
   132
		result = EFail;
sl@0
   133
		}
sl@0
   134
sl@0
   135
	//[ Position violation on the src ]
sl@0
   136
	srcDataBufferSize  = KSrcDataBufferSize;
sl@0
   137
	sinkDataBufferSize = KSinkDataBufferSize;
sl@0
   138
	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize, srcDataBufferSize/2, 0 ) == KErrNone )
sl@0
   139
		{
sl@0
   140
        INFO_PRINTF1(_L("Src Data Buffer position precondition violation"));
sl@0
   141
		result = EFail;
sl@0
   142
		}
sl@0
   143
sl@0
   144
	//[ Position violation on the Destination ]
sl@0
   145
	srcDataBufferSize  = KSrcDataBufferSize;
sl@0
   146
	sinkDataBufferSize = KSinkDataBufferSize;
sl@0
   147
	if( CodecPreconditionTestL( srcDataBufferSize, sinkDataBufferSize,0, sinkDataBufferSize/2 ) == KErrNone )
sl@0
   148
		{
sl@0
   149
        INFO_PRINTF1(_L("Sink Data Buffer position precondition violation"));
sl@0
   150
		result = EFail;
sl@0
   151
		}
sl@0
   152
sl@0
   153
	delete iSourceData;
sl@0
   154
	delete iCodedData ;
sl@0
   155
	iSourceData = NULL;
sl@0
   156
	iCodedData   = NULL;
sl@0
   157
sl@0
   158
	__MM_HEAP_MARKEND;
sl@0
   159
	return result;
sl@0
   160
	}
sl@0
   161
sl@0
   162
/**
sl@0
   163
*
sl@0
   164
* CodecPreconditionTest
sl@0
   165
* @precondition 0<= aSrcPosition  < aSrcDataBufferSize
sl@0
   166
* @precondition 0<= aSinkPosition < aSinkDataBufferSize
sl@0
   167
* @return TInt error code 
sl@0
   168
**/
sl@0
   169
template <class Codec>
sl@0
   170
TInt CTestStepLoopTest<Codec>::CodecPreconditionTestL( TInt aSrcDataBufferSize, TInt aSinkDataBufferSize, TInt aSrcPosition, TInt aSinkPosition )
sl@0
   171
	{
sl@0
   172
	TInt result = KErrNone;
sl@0
   173
	//[ assert preconditions ]
sl@0
   174
	ASSERT( (0 <= aSrcPosition ) && ( aSrcPosition < aSrcDataBufferSize ));
sl@0
   175
	ASSERT( (0 <= aSinkPosition ) && ( aSinkPosition < aSinkDataBufferSize ));
sl@0
   176
sl@0
   177
	delete iSourceData;
sl@0
   178
	delete iCodedData ;
sl@0
   179
	iSourceData = NULL;
sl@0
   180
	iCodedData   = NULL;
sl@0
   181
	iSourceData = CMMFDescriptorBuffer::NewL(aSrcDataBufferSize * sizeof(TUint8));
sl@0
   182
	iCodedData   = CMMFDescriptorBuffer::NewL(aSinkDataBufferSize * sizeof(TUint8));
sl@0
   183
    //set the lengths of the buffers
sl@0
   184
	iSourceData->Data().SetLength(aSrcDataBufferSize);
sl@0
   185
	iCodedData->Data().SetLength(aSinkDataBufferSize);
sl@0
   186
	
sl@0
   187
	//set the positions on the buffers	
sl@0
   188
	iSourceData->SetPosition(aSrcPosition);
sl@0
   189
	iCodedData->SetPosition(aSinkPosition);
sl@0
   190
sl@0
   191
	TRAP(result,iCodecUnderTest->ProcessL(*iSourceData, *iCodedData));
sl@0
   192
sl@0
   193
	return result;
sl@0
   194
	}
sl@0
   195
sl@0
   196
/**
sl@0
   197
*
sl@0
   198
* DoTestStepPreambleL
sl@0
   199
*
sl@0
   200
**/
sl@0
   201
template <class Codec>
sl@0
   202
TVerdict CTestStepLoopTest<Codec>::DoTestStepPreambleL(void)
sl@0
   203
	{
sl@0
   204
	iCodecUnderTest = new (ELeave) Codec;
sl@0
   205
	return EPass;
sl@0
   206
	}
sl@0
   207
sl@0
   208
/**
sl@0
   209
*
sl@0
   210
* DoTestStepPostambleL
sl@0
   211
*
sl@0
   212
*/
sl@0
   213
template <class Codec>
sl@0
   214
TVerdict CTestStepLoopTest<Codec>::DoTestStepPostambleL(void)
sl@0
   215
	{
sl@0
   216
	delete iCodecUnderTest;
sl@0
   217
	iCodecUnderTest = NULL;
sl@0
   218
	delete 	iSourceData;
sl@0
   219
	iSourceData = NULL;
sl@0
   220
	delete  iCodedData;
sl@0
   221
	iCodedData = NULL;
sl@0
   222
	return EPass;
sl@0
   223
	}
sl@0
   224
sl@0
   225
/**
sl@0
   226
*
sl@0
   227
* This is used for template instantiation.
sl@0
   228
*
sl@0
   229
**/
sl@0
   230
sl@0
   231
template class CTestStepLoopTest<CMMFPcm16ToALawCodec>;
sl@0
   232
template class CTestStepLoopTest<CMMFAlawToPcm16Codec>;
sl@0
   233
template class CTestStepLoopTest<CMMFGsm610ToPcm16Codec>;
sl@0
   234
template class CTestStepLoopTest<CMMFImaAdpcmToPcm16Codec>;
sl@0
   235
template class CTestStepLoopTest<CMMFMulawToPcm16Codec>;
sl@0
   236
template class CTestStepLoopTest<CMMFPcm16SwapEndianCodec>;
sl@0
   237
template class CTestStepLoopTest<CMMFPcm16ToImaAdpcmCodec>;
sl@0
   238
template class CTestStepLoopTest<CMMFPcm16ToMuLawCodec>;
sl@0
   239
template class CTestStepLoopTest<CMMFPcm16ToPcmU16BECodec>;
sl@0
   240
template class CTestStepLoopTest<CMMFPcm16ToPcmU8Codec>;
sl@0
   241
template class CTestStepLoopTest<CMMFPcmS16ToPcmS8Codec>;
sl@0
   242
template class CTestStepLoopTest<CMMFPcm16ToPcmU16CodecCodec>;
sl@0
   243
template class CTestStepLoopTest<CMMFPcm8ToPcm16Codec>;
sl@0
   244
template class CTestStepLoopTest<CMMFPcmU16BeToPcmS16Codec>;
sl@0
   245
template class CTestStepLoopTest<CMMFPcm16ToGsm610Codec>;
sl@0
   246