First public contribution.
1 // Copyright (c) 2004-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 // This file contains an example Test step implementation
15 // This demonstrates the various functions provided
16 // by the CTestStep base class which are available within
29 #include <testframework.h>
31 // Test system includes
32 #include <testframework.h>
34 #include "TSU_MMFMIDICLNT.h"
35 #include "TS_MMFMIDICLNTsuite.h"
37 #include "TestStepMidiClntAllocFailOpen.h"
39 // --------------------------------------------
43 * Static constructor for CTestStepMidiClntAllocFailOpenFile.
46 * @return "CTestStepMidiClntAllocFailOpenFile*"
47 * The constructed CTestStepMidiClntAllocFailOpenFile
52 CTestStepMidiClntAllocFailOpenFile* CTestStepMidiClntAllocFailOpenFile::NewL(const TDesC& aTestName)
54 CTestStepMidiClntAllocFailOpenFile* self = new(ELeave) CTestStepMidiClntAllocFailOpenFile(aTestName);
60 * Test step constructor.
61 * Each test step initialises its own name.
66 CTestStepMidiClntAllocFailOpenFile::CTestStepMidiClntAllocFailOpenFile(const TDesC& aTestName)
68 // store the name of this test case
69 // this is the name that is used by the script file
70 iTestStepName = aTestName;
75 * Test step destructor.
80 CTestStepMidiClntAllocFailOpenFile::~CTestStepMidiClntAllocFailOpenFile()
92 TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepPreambleL(void)
94 enum TVerdict verdict;
95 // This installs the scheduler
96 verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
98 //[ Printing to the console and log file ]
99 INFO_PRINTF1(iTestStepName);
100 INFO_PRINTF1(_L("This is a memory allocation failure test of CTestStepMidiClntAllocFailOpenFile"));
102 if(!GetStringFromConfig(_L("SectionOne"), _L("filename"), iFileName))
104 verdict = EInconclusive;
107 //[ Create the MidiClientUtility ]
108 if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
110 verdict = EInconclusive;
113 //[ Connect to File System using RFs ]
114 User::LeaveIfError(iFs.Connect());
115 User::LeaveIfError(iFs.ShareProtected());
117 //[ Open the file using RFile ]
118 INFO_PRINTF2(_L("Opening the file : %S"), &iFileName);
120 TInt theRes = iFile.Open(iFs, iFileName, EFileRead);
121 if (theRes != KErrNone)
123 INFO_PRINTF2(_L("Errors in Opening the file : %S"), &iFileName);
132 * Test step Postamble.
137 TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepPostambleL(void)
139 //[ Create the MidiClientUtility ]
145 //[ Destroy the scheduler ]
146 return CTestMmfMidiClntStep::DoTestStepPostambleL();
149 void CTestStepMidiClntAllocFailOpenFile::OpenFileAndStartSchedulerL()
151 iMidiClnt->OpenFile(iFileName);
152 CActiveScheduler::Start();
155 void CTestStepMidiClntAllocFailOpenFile::OpenFileByHandleAndStartSchedulerL()
157 iMidiClnt->OpenFile(iFile);
158 CActiveScheduler::Start();
165 * Each test step must supply an implementation for DoTestStepL.
168 * The result of the test step
173 TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepL()
175 //[ Initialise Class Variables ]
176 iTestStepResult = EPass;
178 //[ Declare Local Variables ]
181 TBool completed = EFalse;
182 TBool badResult = EFalse;
183 TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
184 TBool useFileHandle = EFalse;
186 if(iTestStepName.Compare(_L("MM-MMF-MIDICLNT-U-1003")) == 0)
188 useFileHandle = ETrue;
192 //[ Start of main ALLOC test loop ]
195 __UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
200 TRAP( err, OpenFileAndStartSchedulerL() );
204 TRAP( err, OpenFileByHandleAndStartSchedulerL() );
208 if ((err == KErrNone) && (iError == KErrNone))
210 TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
214 failCount--; // -= 1;
218 User::Free(testAlloc);
221 // see if valid result and break if wrong - might be premature result
222 if (iMidiClnt == NULL || iError != KErrNone )
232 completed = reachedEnd || badResult;
237 if (((err != KErrNone) && (err != KErrNoMemory)) ||
238 ((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
245 __UHEAP_SETFAIL(RHeap::ENone ,0);
254 failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
256 if (err != KErrNone || badResult)
260 INFO_PRINTF2(_L("Bad result with %d memory allocations tested"), failCount);
264 INFO_PRINTF3(_L("Error(%d) with %d memory allocations tested"), err, failCount);
266 iTestStepResult = EFail;
270 INFO_PRINTF2(_L("Completed OK with %d memory allocations tested"), failCount);
271 iTestStepResult = EPass;
275 INFO_PRINTF1(_L("finished with this test step"));
276 return iTestStepResult;
279 // from MMidiClientUtilityObserver
280 void CTestStepMidiClntAllocFailOpenFile::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
283 CActiveScheduler::Stop();
286 void CTestStepMidiClntAllocFailOpenFile::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
289 void CTestStepMidiClntAllocFailOpenFile::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
292 void CTestStepMidiClntAllocFailOpenFile::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
295 void CTestStepMidiClntAllocFailOpenFile::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
298 void CTestStepMidiClntAllocFailOpenFile::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
301 void CTestStepMidiClntAllocFailOpenFile::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
304 void CTestStepMidiClntAllocFailOpenFile::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
307 void CTestStepMidiClntAllocFailOpenFile::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
312 // --------------------------------------------
316 * Static constructor for CTestStepMidiClntAllocFailOpenDes.
319 * @return "CTestStepMidiClntAllocFailOpenDes*"
320 * The constructed CTestStepMidiClntAllocFailOpenDes
325 CTestStepMidiClntAllocFailOpenDes* CTestStepMidiClntAllocFailOpenDes::NewL()
327 CTestStepMidiClntAllocFailOpenDes* self = new(ELeave) CTestStepMidiClntAllocFailOpenDes;
333 * Test step constructor.
334 * Each test step initialises its own name.
339 CTestStepMidiClntAllocFailOpenDes::CTestStepMidiClntAllocFailOpenDes()
341 // store the name of this test case
342 // this is the name that is used by the script file
343 iTestStepName = _L("MM-MMF-MIDICLNT-U-0201-CP");
348 * Test step destructor.
353 CTestStepMidiClntAllocFailOpenDes::~CTestStepMidiClntAllocFailOpenDes()
360 * Test step Preamble.
365 TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepPreambleL(void)
367 enum TVerdict verdict;
368 //this installs the scheduler
369 verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
371 // Printing to the console and log file
372 INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0201-CP"));
373 INFO_PRINTF1(_L("this is a memory allocation failure test of CTestStepMidiClntAllocFailOpenDes"));
375 if(!GetStringFromConfig(_L("SectionOne"), _L("filename"), iFilename))
376 return EInconclusive;
382 // connect to file system and open file
383 User::LeaveIfError(fs.Connect());
384 User::LeaveIfError(file.Open(fs,iFilename,EFileRead));
385 CleanupClosePushL(file);
388 User::LeaveIfError(file.Size(size));
389 INFO_PRINTF2(_L("size of file = %d\n"),size);
391 iAudio = HBufC8::NewMaxL(size);
393 // read data into Hbuf
394 TPtr8 bufferDes(iAudio->Des());
395 User::LeaveIfError(file.Read(bufferDes));
397 CleanupStack::PopAndDestroy(); //file
399 // create the Midi utility
400 if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
401 return EInconclusive;
408 * Test step Postamble.
413 TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepPostambleL(void)
419 //[ Destroy the scheduler ]
420 return CTestMmfMidiClntStep::DoTestStepPostambleL();
423 void CTestStepMidiClntAllocFailOpenDes::OpenDesAndStartSchedulerL()
425 iMidiClnt->OpenDes(iAudio->Des());
426 CActiveScheduler::Start();
432 * Each test step must supply an implementation for DoTestStepL.
435 * The result of the test step
440 TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepL()
442 iTestStepResult = EPass;
446 TBool completed = EFalse;
447 TBool badResult = EFalse;
448 TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
451 __UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
454 TRAP( err, OpenDesAndStartSchedulerL() );
457 if ((err == KErrNone) && (iError == KErrNone))
459 TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
463 failCount--; // -= 1;
466 User::Free(testAlloc);
469 // see if valid result and break if wrong - might be premature result
470 if (iMidiClnt == NULL ||
477 completed = reachedEnd || badResult;
479 else if (((err != KErrNone) && (err != KErrNoMemory)) ||
480 ((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
484 __UHEAP_SETFAIL(RHeap::ENone ,0);
495 //failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
497 if (err != KErrNone || badResult)
500 INFO_PRINTF2(_L(" Bad result with %d memory allocations tested"), failCount);
502 INFO_PRINTF3(_L(" Error(%d) with %d memory allocations tested"), err, failCount);
503 iTestStepResult = EFail;
507 INFO_PRINTF2(_L(" Completed OK with %d memory allocations tested"), failCount);
508 iTestStepResult = EPass;
511 INFO_PRINTF1(_L("finished with this test step"));
512 // test steps return a result
513 return iTestStepResult;
516 // from MMidiClientUtilityObserver
517 void CTestStepMidiClntAllocFailOpenDes::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
520 CActiveScheduler::Stop();
523 void CTestStepMidiClntAllocFailOpenDes::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
526 void CTestStepMidiClntAllocFailOpenDes::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
529 void CTestStepMidiClntAllocFailOpenDes::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
532 void CTestStepMidiClntAllocFailOpenDes::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
535 void CTestStepMidiClntAllocFailOpenDes::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
538 void CTestStepMidiClntAllocFailOpenDes::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
541 void CTestStepMidiClntAllocFailOpenDes::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
544 void CTestStepMidiClntAllocFailOpenDes::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
549 // --------------------------------------------
553 * Static constructor for CTestStepMidiClntAllocFailOpenUrl.
556 * @return "CTestStepMidiClntAllocFailOpenUrl*"
557 * The constructed CTestStepMidiClntAllocFailOpenUrl
562 CTestStepMidiClntAllocFailOpenUrl* CTestStepMidiClntAllocFailOpenUrl::NewL()
564 CTestStepMidiClntAllocFailOpenUrl* self = new(ELeave) CTestStepMidiClntAllocFailOpenUrl;
570 * Test step constructor.
571 * Each test step initialises its own name.
576 CTestStepMidiClntAllocFailOpenUrl::CTestStepMidiClntAllocFailOpenUrl()
578 // store the name of this test case
579 // this is the name that is used by the script file
580 iTestStepName = _L("MM-MMF-MIDICLNT-U-0202-CP");
585 * Test step destructor.
590 CTestStepMidiClntAllocFailOpenUrl::~CTestStepMidiClntAllocFailOpenUrl()
597 * Test step Preamble.
602 TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepPreambleL(void)
604 enum TVerdict verdict;
605 // this installs the scheduler
606 verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
608 // Printing to the console and log file
609 INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0202-CP"));
610 INFO_PRINTF1(_L("this is a memory allocation failure test of CTestStepMidiClntAllocFailOpenUrl"));
612 if(!GetStringFromConfig(iSectName,iKeyName,iUrlname))
613 return EInconclusive;
616 if(!GetStringFromConfig(_L("SectionOne"), _L("AudioPlayFName7"), iFileName) ||
617 !GetStringFromConfig(_L("SectionOne"), _L("AudioFNameToConvert"), iFileName2))
619 //INFO_PRINTF2(_L("file name %s not found..."), fileptr);
620 return EInconclusive;
624 // create the Midi utility
625 if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
626 verdict = EInconclusive;
634 * Test step Postamble.
639 TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepPostambleL(void)
643 //[ Destroy the scheduler ]
644 return CTestMmfMidiClntStep::DoTestStepPostambleL();
647 void CTestStepMidiClntAllocFailOpenUrl::OpenUrlAndStartSchedulerL()
649 iMidiClnt->OpenUrl(iUrlname);
650 CActiveScheduler::Start();
656 * Each test step must supply an implementation for DoTestStepL.
659 * The result of the test step
664 TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepL()
666 iTestStepResult = EPass;
670 TBool completed = EFalse;
671 TBool badResult = EFalse;
672 TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
675 __UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
678 TRAP( err, OpenUrlAndStartSchedulerL() );
681 if ((err == KErrNone) && (iError == KErrNone))
683 TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
687 failCount--; // -= 1;
690 User::Free(testAlloc);
693 // see if valid result and break if wrong - might be premature result
694 if (iMidiClnt == NULL ||
701 completed = reachedEnd || badResult;
703 else if (((err != KErrNone) && (err != KErrNoMemory)) ||
704 ((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
708 __UHEAP_SETFAIL(RHeap::ENone ,0);
719 //failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
721 if (err != KErrNone || badResult)
724 INFO_PRINTF2(_L(" Bad result with %d memory allocations tested"), failCount);
726 INFO_PRINTF3(_L(" Error(%d) with %d memory allocations tested"), err, failCount);
727 iTestStepResult = EFail;
731 INFO_PRINTF2(_L(" Completed OK with %d memory allocations tested"), failCount);
732 iTestStepResult = EPass;
735 INFO_PRINTF1(_L("finished with this test step"));
736 // test steps return a result
737 return iTestStepResult;
740 // from MMidiClientUtilityObserver
741 void CTestStepMidiClntAllocFailOpenUrl::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
744 CActiveScheduler::Stop();
747 void CTestStepMidiClntAllocFailOpenUrl::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
750 void CTestStepMidiClntAllocFailOpenUrl::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
753 void CTestStepMidiClntAllocFailOpenUrl::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
756 void CTestStepMidiClntAllocFailOpenUrl::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
759 void CTestStepMidiClntAllocFailOpenUrl::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
762 void CTestStepMidiClntAllocFailOpenUrl::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
765 void CTestStepMidiClntAllocFailOpenUrl::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
768 void CTestStepMidiClntAllocFailOpenUrl::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)