os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_SignConversionCodecs.cpp
Update contrib.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // TSU_MMF_CodecTests.cpp
24 // Test system includes
25 #include "TSU_MMF_DeviceSuite.h"
26 #include "TSU_MMF_SignConversionCodecs.h"
29 #include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
30 #include "MmfPcm16toAlawhwDevice.h"
31 #include "MmfALawToPcm16HwDevice.h"
32 #include "mmfpcm16toMulawhwdevice.h"
33 #include "MmfMuLawToPcm16hwDevice.h"
34 #include "mmfpcmS8ToPcmS16HwDevice.h"
35 #include "mmfpcmS16PcmS8HwDevice.h"
36 #include "mmfpcm16topcmU16BEHwDevice.h"
37 #include "mmfpcm16SwapEndianhwdevice.h"
38 #include "mmfpcm16ToImaAdpcm.h"
39 #include "MmfImaAdpcmtopcm16hwdevice.h"
40 #include "MMFpcm16ToPcm16HwDevice.h"
41 #include "MMFpcm16ToPcmU8HwDevice.h"
42 #include "MMFpcmU8ToPcm16HwDevice.h"
43 #include "mmfpcmS16PcmS8HwDevice.h"
46 //[ Codec Unit tests structure
47 // The unit tests shall use text files
48 // for small portions of test data
49 // which should be stored are stored in a simple format
50 // containing the relevant parameters for the test
52 class TSignConversionTestParams
55 const TText* iTestName; // name of the test
58 // constant table of parameters for tests
59 const TSignConversionTestParams KSignConversionParameters[] =
61 {_S("MM-MMF-SWCODECDEVICES-U-0017-HP")},
62 {_S("MM-MMF-SWCODECDEVICES-U-0018-HP")},
63 {_S("MM-MMF-SWCODECDEVICES-U-0019-HP")},
64 {_S("MM-MMF-SWCODECDEVICES-U-0020-HP")},
65 {_S("MM-MMF-SWCODECDEVICES-U-0021-HP")}
70 * PrintComparisonDataL
71 * @param aCodedData the coded data buffer
72 * @param aRefCodedData the reference coded data buffer
75 void CMMFDataGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
77 //[precondition reference coded data is equal in size or longer than coded data ]
78 if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
80 //[coded data is longer than reference data]
81 // RDebug::Print(_L("Coded Data is longer than refernce data")); Commented under DEF105143
82 User::Leave( KErrCorrupt );
85 TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
86 TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
87 TInt length = aCodedData.Data().Length();
88 //[ now print the results for comparison ]
89 for( TInt i = 0; i < length; i++ )
91 RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (*ptr1-*ptr2), *ptr1++, *ptr2++ );
98 * @param aData src data buffer
99 * @param aValue resultant value
100 * @param aBigEndian whether the value is in BigEndian format
101 * @precondition aData is not null and has length >= 2
104 void CMMFDataGenerator::AssembleValue( TUint8* aData, TInt16& aValue, TBool aBigEndian )
106 __ASSERT_DEBUG( aData, Panic(EBadArgument));
109 aValue = static_cast<TInt16>( aData[1] &KAndMask8bit );
110 aValue |= static_cast<TInt16>((aData[0] << 8 ));
114 aValue = static_cast<TInt16>( aData[0] &KAndMask8bit);
115 aValue |= static_cast<TInt16>((aData[1] << 8 ));
122 * @param aData src data buffer
123 * @param aValue resultant value
124 * @param aBigEndian whether the value is in BigEndian format
125 * @precondition aData is not null and has length >= 2
128 void CMMFDataGenerator::AssembleValue( TUint8* aData, TUint16& aValue, TBool aBigEndian )
130 __ASSERT_DEBUG( aData, Panic(EBadArgument));
133 aValue = aData[1] ; //[ big endian format]
134 aValue |= (aData[0] << 8 );
139 aValue |= (aData[1] << 8 );
144 * CMMFPcmU16toPcmU16BGenerator
147 CMMFPcmU16toPcmU16BGenerator::CMMFPcmU16toPcmU16BGenerator()
153 * ~CMMFPcmU16toPcmU16BGenerator
156 CMMFPcmU16toPcmU16BGenerator::~CMMFPcmU16toPcmU16BGenerator()
162 * GenerateSourceDataL
165 void CMMFPcmU16toPcmU16BGenerator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
167 const TUint16 KScale2 = 32000;
169 //[ create a buffer large enough to fill with the data ]
170 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
172 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
174 //[ lets fill it with a 400hz signal at approx -3db ]
176 TUint16 srcValue = 0;
180 TInt noSamples = aSize/sizeof(TInt16);
181 for(TInt i=0; i< noSamples; i++)
183 //[ assign data and place in buffer]
184 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
185 // better reproduction through gsm codec
186 User::LeaveIfError(Math::Sin(val,theta));
187 srcValue = static_cast<TUint16>( (KScale2 * val ) + KScale2+0.5);
188 *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
189 *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
192 aBuffer->Data().SetLength(aSize);
197 * GenerateComparisonDataL
200 void CMMFPcmU16toPcmU16BGenerator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
202 const TUint16 KScale2 = 32000;
204 //[ create a buffer large eneough to fill with the data ]
205 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
207 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
209 //[ lets fill it with a 400hz signal at approx -3db ]
211 TUint16 srcValue = 0;
215 TInt noSamples = aSize/sizeof(TInt16);
216 for(TInt i=0; i< noSamples; i++)
218 //[ assign data and place in buffer]
219 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
220 // better reproduction through gsm codec
221 User::LeaveIfError(Math::Sin(val,theta));
222 srcValue = static_cast<TUint16>( (KScale2 * val)+KScale2 +0.5);
223 //[endian swap here ]
224 *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
225 *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
228 aBuffer->Data().SetLength(aSize);
233 * PrintComparisonDataL
234 * Prints out coded results for comparison with the
235 * Reference values and is used when the results differ
238 void CMMFPcmU16toPcmU16BGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
240 //[precondition reference coded data is equal in size or longer than coded data ]
241 if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
243 //[coded data is longer than reference data]
244 // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
245 User::Leave( KErrCorrupt );
248 //[ now print the results for comparison ]
249 TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
250 TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
251 TInt length = aCodedData.Data().Length();
252 length /= 2; // [for 16bit words length is half]
253 //[ assert invariant length is even ]
254 __ASSERT_DEBUG( (length % 2 == 0 ), Panic(EBadInvariant));
256 TUint16 codedValue = 0;
257 TUint16 refCodedValue = 0;
258 //[ now print the results for comparison ]
259 for( TInt i = 0; i < length; i++ )
261 //[ assemble 16bit values from buffer values ]
262 AssembleValue( ptr1, codedValue, ETrue );
263 AssembleValue( ptr2, refCodedValue, ETrue );
264 RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue );
265 if( i % 100 == 0 ) //deal with debug printf deficiencies
276 * CMMFPcmU16BtoPcmU16Generator
279 CMMFPcmU16BtoPcmU16Generator::CMMFPcmU16BtoPcmU16Generator()
285 * ~CMMFPcmU16BtoPcmU16Generator
288 CMMFPcmU16BtoPcmU16Generator::~CMMFPcmU16BtoPcmU16Generator()
294 * GenerateSourceDataL
297 void CMMFPcmU16BtoPcmU16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
299 const TUint8 KScale2 = 127;
301 //[ create a buffer large eneough to fill with the data ]
302 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
304 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
306 //[ lets fill it with a 400hz signal at approx -3db ]
312 TInt noSamples = aSize/sizeof(TInt16);
313 for(TInt i=0; i< noSamples; i++)
315 //[ assign data and place in buffer]
316 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
317 // better reproduction through gsm codec
318 User::LeaveIfError(Math::Sin(val,theta));
319 srcValue = static_cast<TUint8>( (KScale2 * val) );
320 //[endian swap here ]
321 *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
322 *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
325 aBuffer->Data().SetLength(aSize);
330 * GenerateComparisonDataL
333 void CMMFPcmU16BtoPcmU16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
335 const TUint8 KScale2 = 127;
337 //[ create a buffer large eneough to fill with the data ]
338 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
340 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
342 //[ lets fill it with a 400hz signal at approx -3db ]
344 TUint16 srcValue = 0;
347 TInt noSamples = aSize/sizeof(TInt16);
348 for(TInt i=0; i< noSamples; i++)
350 //[ assign data and place in buffer]
351 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
352 // better reproduction through gsm codec
353 User::LeaveIfError(Math::Sin(val,theta));
354 srcValue = static_cast<TUint16>( KScale2 * val );
355 *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
356 *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
359 aBuffer->Data().SetLength(aSize);
364 * PrintComparisonDataL
365 * Prints out coded results for comparison with the
366 * Reference values and is used when the results differ
369 void CMMFPcmU16BtoPcmU16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
371 //[precondition reference coded data is equal in size or longer than coded data ]
372 if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
374 //[coded data is longer than reference data]
375 // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
376 User::Leave( KErrCorrupt );
379 //[ now print the results for comparison ]
380 TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
381 TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
382 TInt length = aCodedData.Data().Length();
383 length /= 2; //[ for 16bit words ]
384 TUint16 codedValue = 0;
385 TUint16 refCodedValue = 0;
386 //[ now print the results for comparison ]
387 for( TInt i = 0; i < length; i++ )
389 // assemble 16bit values
390 AssembleValue( ptr1, codedValue, EFalse);
391 AssembleValue( ptr2, refCodedValue, EFalse );
392 RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue );
393 if( i % 100 == 0 ) //deal with debug printf deficiencies
404 * CMMFPcm8ToPcm16Generator
407 CMMFPcm8ToPcm16Generator::CMMFPcm8ToPcm16Generator()
413 * CMMFPcm8ToPcm16Generator
416 CMMFPcm8ToPcm16Generator::~CMMFPcm8ToPcm16Generator()
422 * GenerateSourceDataL
425 void CMMFPcm8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
427 const TInt8 KScale2 = 127;
429 //[ create a buffer large eneough to fill with the data ]
430 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
432 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
434 //[ lets fill it with a 400hz signal at approx -3db ]
439 TInt noSamples = aSize/sizeof(TInt8);
440 for(TInt i=0; i< noSamples; i++)
442 //[ assign data and place in buffer]
443 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
444 // better reproduction through gsm codec
445 User::LeaveIfError(Math::Sin(val,theta));
446 srcValue = static_cast<TInt8>( (KScale2 * val) );
450 aBuffer->Data().SetLength(aSize);
455 * GenerateSourceDataL
458 void CMMFPcm8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
460 const TInt8 KScale2 = 127;
462 //[ create a buffer large eneough to fill with the data ]
463 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
465 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
467 //[ lets fill it with a 400hz signal at approx -3db ]
472 TInt noSamples = aSize/sizeof(TInt16);
473 for(TInt i=0; i< noSamples; i++)
475 //[ assign data and place in buffer]
476 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
477 // better reproduction through gsm codec
478 User::LeaveIfError(Math::Sin(val,theta));
479 TInt8 temp = static_cast<TInt8>((KScale2 * val));
480 srcValue = static_cast<TInt16>( temp << 8);
481 *pDst++ = static_cast<TInt8>( srcValue&KAndMask8bit);
482 *pDst++ = static_cast<TInt8>((srcValue>>8)&KAndMask8bit);
485 aBuffer->Data().SetLength(aSize);
490 * PrintComparisonDataL
491 * Prints out coded results for comparison with the
492 * Reference values and is used when the results differ
495 void CMMFPcm8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
497 //[precondition reference coded data is equal in size or longer than coded data ]
498 if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
500 //[coded data is longer than reference data]
501 // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
502 User::Leave( KErrCorrupt );
505 //[ now print the results for comparison ]
506 TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
507 TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
508 TInt length = aCodedData.Data().Length();
509 length /= 2; //[ for 16bit words ]
510 TInt16 codedValue = 0;
511 TInt16 refCodedValue = 0;
512 //[ now print the results for comparison ]
513 for( TInt i = 0; i < length; i++ )
515 // assemble 16bit values
516 AssembleValue( ptr1, codedValue, EFalse );
517 AssembleValue( ptr2, refCodedValue, EFalse );
518 RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (refCodedValue-codedValue), codedValue, refCodedValue );
519 if( i % 100 == 0 ) //deal with debug printf deficiencies
530 * CMMFPcmU8ToPcm16Generator
533 CMMFPcmU8ToPcm16Generator::CMMFPcmU8ToPcm16Generator()
539 * ~CMMFPcmU8ToPcm16Generator
542 CMMFPcmU8ToPcm16Generator::~CMMFPcmU8ToPcm16Generator()
548 * GenerateSourceDataL
550 * @param aSize in bytes
553 void CMMFPcmU8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
555 const TUint8 KScale2 = 127;
557 //[ create a buffer large eneough to fill with the data ]
558 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
560 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
562 //[ lets fill it with a 400hz signal at approx -3db ]
567 TInt noSamples = aSize/sizeof(TUint8);
568 for(TInt i=0; i< noSamples; i++)
570 //[ assign data and place in buffer]
571 theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or
572 // better reproduction through gsm codec
573 User::LeaveIfError(Math::Sin(val,theta));
575 srcValue = static_cast<TUint8>((KScale2 * val+KScale2+0.5));
577 //RDebug::Print( _L("U8 = %u"), srcValue ); Statement commented under DEf105143
580 aBuffer->Data().SetLength(aSize);
585 * GenerateComparisonDataL
590 void CMMFPcmU8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
592 const TInt8 KScale2 = 127;
594 //[ create a buffer large eneough to fill with the data ]
595 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
597 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
599 //[ lets fill it with a 400hz signal at approx -3db ]
601 // RDebug::Print( _L("Generation"));Commented under DEF105143
606 TInt length = aSize/sizeof(TInt16);
607 for(TInt i=0; i< length; i++)
609 //[ assign data and place in buffer]
610 theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or
611 // better reproduction through gsm codec
612 User::LeaveIfError(Math::Sin(val,theta));
613 theValue = static_cast<TUint8>(KScale2 *val + KScale2 + 0.5);
614 //[ apply the same transformation as the codec ]
615 rrr = static_cast<TUint8>( theValue^KMaskSign8bit );
616 //RDebug::Print( _L("U8 = %u"), theValue ); Statement commented under DEf105143
621 aBuffer->Data().SetLength(aSize);
626 * PrintComparisonDataL
627 * Prints out coded results for comparison with the
628 * Reference values and is used when the results differ
631 void CMMFPcmU8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
633 //[precondition reference coded data is equal in size or longer than coded data ]
634 if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
636 //[coded data is longer than reference data]
637 // RDebug::Print( _L("Coded Data is longer than reference data"));Commented under DEF105143
638 User::Leave( KErrCorrupt );
641 //[ now print the results for comparison ]
642 TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
643 TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
644 TInt length = aCodedData.Data().Length();
645 length /= 2; //[ for 16bit words ]
646 TInt16 codedValue = 0;
647 TInt16 refCodedValue = 0;
648 //[ now print the results for comparison ]
649 for( TInt i = 0; i < length; i++ )
651 // assemble 16bit values
652 AssembleValue( ptr1, codedValue, EFalse );
653 AssembleValue( ptr2, refCodedValue, EFalse );
654 RDebug::Print( _L("delta %d c %d, rf %d"), (refCodedValue-codedValue), codedValue, refCodedValue );
655 if( i % 100 == 0 ) //deal with debug printf deficiencies
667 * CMMFPcm16ToPcmU8Generator
670 CMMFPcm16ToPcmU8Generator::CMMFPcm16ToPcmU8Generator()
677 * CMMFPcm16ToPcmU8Generator
680 CMMFPcm16ToPcmU8Generator::~CMMFPcm16ToPcmU8Generator()
687 * GenerateSourceDataL
689 * @param aSize in bytes
690 * This function generates a 400hz sine wav
691 * under the assumption the sampling frequency is 8khz
694 void CMMFPcm16ToPcmU8Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
696 const TInt KScale = 320;
698 //[ create a buffer large eneough to fill with the data ]
699 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
701 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
703 //[ lets fill it with a 400hz signal at approx -3db ]
708 TInt noSamples = aSize/sizeof(TInt16);
709 for(TInt i=0; i< noSamples; i++)
711 //[ assign data and place in buffer]
712 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
713 // better reproduction through gsm codec
714 User::LeaveIfError(Math::Sin(val,theta));
715 srcValue = static_cast<TInt16>( KScale * val );
716 *pDst++ = static_cast<TUint8>( srcValue & KAndMask8bit);
717 *pDst++ = static_cast<TUint8>((srcValue >> 8) & KAndMask8bit );
720 aBuffer->Data().SetLength(aSize);
725 * GenerateComparisonDataL
727 * @param aSize in bytes
728 * This function generates a 400hz sine wav
729 * under the assumption the sampling frequency is 8khz
731 //[ use partial sopecialization to provide copncrete implmentation]
732 void CMMFPcm16ToPcmU8Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
734 const TInt KScale2 = 320; //low value chosen to emphasize the distortion of this codec!
736 //[ create a buffer large eneough to fill with the data ]
737 aBuffer = CMMFDescriptorBuffer::NewL(aSize);
739 TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
741 //[ lets fill it with a 400hz signal at approx -3db ]
746 TInt noSamples = aSize/sizeof(TUint8);
747 for(TInt i=0; i< noSamples; i++)
749 //[ assign data and place in buffer]
750 theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
751 // better reproduction through gsm codec
752 User::LeaveIfError(Math::Sin(val,theta));
753 srcValue = static_cast<TInt16>( KScale2 * val );
754 *pDst++ = static_cast<TUint8>( (srcValue >> 8) - KMaskSign8bit);
757 aBuffer->Data().SetLength(aSize);
762 * PrintComparisonDataL
763 * Prints out coded results for comparison with the
764 * Reference values and is used when the results differ
767 void CMMFPcm16ToPcmU8Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
769 //[precondition reference coded data is equal in size or longer than coded data ]
770 if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
772 //[coded data is longer than reference data]
773 // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
774 User::Leave( KErrCorrupt );
777 //[ now print the results for comparison ]
778 TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
779 TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
780 TInt length = aCodedData.Data().Length();
781 //[ now print the results for comparison ]
782 for( TInt i = 0; i < length; i++ )
784 RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (*ptr1-*ptr2), *ptr1, *ptr2 );
785 if( i % 100 == 0 ) //deal with debug printf deficiencies
797 * @param aData1 first data buffer for comparison
798 * @param aData2 second data buffer for comparison
799 * result TBool data is the same
800 * @precondition aData1 has the same amount of data as aData2
803 template <class T, class Generator, TInt index>
804 TBool CTestStepSignConversionTest<T, Generator, index>::CompareData( CMMFDataBuffer* aData1, CMMFDataBuffer* aData2)
806 TBool result = ETrue;
808 //[ precondition aData1 != NULL ]
811 User::Leave( KErrArgument );
814 //[ precondition aData2 != NULL ]
817 User::Leave( KErrArgument );
820 //[precondition aData1 length == aData2 length ]
821 if( aData1->Data().Length() != aData2->Data().Length() )
823 User::Leave( KErrArgument );
826 //[Now Compare the data]
827 TUint8* ptr1 = CONST_CAST(TUint8*, aData1->Data().Ptr());
828 TUint8* ptr2 = CONST_CAST(TUint8*, aData2->Data().Ptr());
829 TInt dataLength = aData2->Data().Length();
830 if( Mem::Compare( ptr1, dataLength, ptr2, dataLength )!=0)
836 INFO_PRINTF1(_L("------------------------------"));
837 for( TInt i = 0; i < dataLength/2; i++ )
839 s1 = static_cast<TInt16>( p1[0] &KAndMask8bit);
840 s1 |= static_cast<TInt16>((p1[1] << 8 ));
841 s2 = static_cast<TInt16>( p2[0] &KAndMask8bit);
842 s2 |= static_cast<TInt16>((p2[1] << 8 ));
843 INFO_PRINTF3(_L("%d %d"), s1, s2);
847 INFO_PRINTF1(_L("------------------------------"));
848 // RDebug::Print( _L("Comparison has failed")); Commented under DEF105143
849 iGenerator->PrintComparisonDataL( *aData1, *aData2 );
861 template <class T, class Generator, TInt index>
862 TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepL()
865 TVerdict result = EPass;
867 //[pre condition iSourceData ]
870 INFO_PRINTF1(_L("Source Data Failure"));
871 User::Leave( KErrCorrupt);
873 //[precondition iCodedData ]
876 INFO_PRINTF1(_L("Coded Data Failure"));
877 User::Leave( KErrCorrupt);
879 //[precondition iRefData ]
882 INFO_PRINTF1(_L("RefCodedData Argument Failure"));
883 User::Leave( KErrCorrupt);
886 //[ lets code the data and compare it to the reference data ]
887 iCodecUnderTest->ProcessL(*iSourceData, *iCodedData);
888 if(!CompareData(iCodedData, iRefCodedData))
890 INFO_PRINTF1(_L("Coded Results do not match reference coded results"));
901 * DoTestStepPostambleL
905 template <class T, class Generator, TInt index>
906 TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepPostambleL()
908 TVerdict result = EPass;
909 //[delete the buffers & Codec]
910 delete iCodecUnderTest;
914 delete iRefCodedData;
920 * DoTestStepPreambleL
924 template <class T, class Generator, TInt index>
925 TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepPreambleL()
927 TVerdict result = EPass;
929 iCodecUnderTest = new(ELeave) T; // a cmmfcodec ;
930 iGenerator = new(ELeave) Generator; // src generator
932 //[ensure the number of samples is >= srcbuffers]
933 const TInt KNumBuffers = 2;
934 const TInt dataSrcSize = KNumBuffers * iCodecUnderTest->SourceBufferSize();
936 //[generate src data]
937 iGenerator->GenerateSourceDataL( iSourceData, dataSrcSize);
939 const TInt dataSinkSize = KNumBuffers * iCodecUnderTest->SinkBufferSize();
941 //[generate comparison data]
942 iGenerator->GenerateComparisonDataL( iRefCodedData, dataSinkSize);
944 //[reserve space for coded data ]
945 iCodedData = CMMFDescriptorBuffer::NewL(dataSinkSize);
952 * CTestStepCodecUnitTest
955 template <class T, class Generator, TInt index>
956 CTestStepSignConversionTest<T, Generator, index>::CTestStepSignConversionTest()
958 // store the name of this test case
959 // this is the name that is used by the script file
960 iTestStepName = (&KSignConversionParameters[index])->iTestName;
965 * CTestStepCodecUnitTest
968 template <class T, class Generator, TInt index>
969 CTestStepSignConversionTest<T, Generator, index>::~CTestStepSignConversionTest()
975 * This is used for template instantiation.
979 template class CTestStepSignConversionTest<CMMFPcm16ToPcmU8Codec,CMMFPcm16ToPcmU8Generator,0>;
980 template class CTestStepSignConversionTest<CMMFPcm8ToPcm16Codec,CMMFPcm8ToPcm16Generator,1>;
981 template class CTestStepSignConversionTest<CMMFPcm16SwapEndianCodec,CMMFPcmU16toPcmU16BGenerator,2>;
982 template class CTestStepSignConversionTest<CMMFPcm16SwapEndianCodec,CMMFPcmU16BtoPcmU16Generator,3>;
983 template class CTestStepSignConversionTest<CMMFPcmU8ToPcm16Codec,CMMFPcmU8ToPcm16Generator,4>;