1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TestStepMidiClntAllocFailOpen.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,773 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// This file contains an example Test step implementation
1.18 +// This demonstrates the various functions provided
1.19 +// by the CTestStep base class which are available within
1.20 +// a test step
1.21 +//
1.22 +//
1.23 +
1.24 +// EPOC includes
1.25 +#include <e32base.h>
1.26 +#include <e32test.h>
1.27 +#include <e32keys.h>
1.28 +#include <c32comm.h>
1.29 +#include <f32file.h>
1.30 +#include <etel.h>
1.31 +#include <etelmm.h>
1.32 +#include <testframework.h>
1.33 +
1.34 +// Test system includes
1.35 +#include <testframework.h>
1.36 +
1.37 +#include "TSU_MMFMIDICLNT.h"
1.38 +#include "TS_MMFMIDICLNTsuite.h"
1.39 +
1.40 +#include "TestStepMidiClntAllocFailOpen.h"
1.41 +
1.42 +// --------------------------------------------
1.43 +
1.44 +/**
1.45 + *
1.46 + * Static constructor for CTestStepMidiClntAllocFailOpenFile.
1.47 + *
1.48 + *
1.49 + * @return "CTestStepMidiClntAllocFailOpenFile*"
1.50 + * The constructed CTestStepMidiClntAllocFailOpenFile
1.51 + *
1.52 + * @xxxx
1.53 + *
1.54 + */
1.55 +CTestStepMidiClntAllocFailOpenFile* CTestStepMidiClntAllocFailOpenFile::NewL(const TDesC& aTestName)
1.56 + {
1.57 + CTestStepMidiClntAllocFailOpenFile* self = new(ELeave) CTestStepMidiClntAllocFailOpenFile(aTestName);
1.58 + return self;
1.59 + }
1.60 +
1.61 +/**
1.62 + *
1.63 + * Test step constructor.
1.64 + * Each test step initialises its own name.
1.65 + *
1.66 + * @xxxx
1.67 + *
1.68 + */
1.69 +CTestStepMidiClntAllocFailOpenFile::CTestStepMidiClntAllocFailOpenFile(const TDesC& aTestName)
1.70 + {
1.71 + // store the name of this test case
1.72 + // this is the name that is used by the script file
1.73 + iTestStepName = aTestName;
1.74 + }
1.75 +
1.76 +/**
1.77 + *
1.78 + * Test step destructor.
1.79 + *
1.80 + * @xxxx
1.81 + *
1.82 + */
1.83 +CTestStepMidiClntAllocFailOpenFile::~CTestStepMidiClntAllocFailOpenFile()
1.84 + {
1.85 + }
1.86 +
1.87 +
1.88 +/**
1.89 + *
1.90 + * Test step Preamble.
1.91 + *
1.92 + * @xxxx
1.93 + *
1.94 + */
1.95 +TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepPreambleL(void)
1.96 + {
1.97 + enum TVerdict verdict;
1.98 + // This installs the scheduler
1.99 + verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
1.100 +
1.101 + //[ Printing to the console and log file ]
1.102 + INFO_PRINTF1(iTestStepName);
1.103 + INFO_PRINTF1(_L("This is a memory allocation failure test of CTestStepMidiClntAllocFailOpenFile"));
1.104 +
1.105 + if(!GetStringFromConfig(_L("SectionOne"), _L("filename"), iFileName))
1.106 + {
1.107 + verdict = EInconclusive;
1.108 + }
1.109 +
1.110 + //[ Create the MidiClientUtility ]
1.111 + if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
1.112 + {
1.113 + verdict = EInconclusive;
1.114 + }
1.115 +
1.116 + //[ Connect to File System using RFs ]
1.117 + User::LeaveIfError(iFs.Connect());
1.118 + User::LeaveIfError(iFs.ShareProtected());
1.119 +
1.120 + //[ Open the file using RFile ]
1.121 + INFO_PRINTF2(_L("Opening the file : %S"), &iFileName);
1.122 +
1.123 + TInt theRes = iFile.Open(iFs, iFileName, EFileRead);
1.124 + if (theRes != KErrNone)
1.125 + {
1.126 + INFO_PRINTF2(_L("Errors in Opening the file : %S"), &iFileName);
1.127 + User::Leave(theRes);
1.128 + }
1.129 +
1.130 + return verdict;
1.131 + }
1.132 +
1.133 +/**
1.134 + *
1.135 + * Test step Postamble.
1.136 + *
1.137 + * @xxxx
1.138 + *
1.139 + */
1.140 +TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepPostambleL(void)
1.141 + {
1.142 + //[ Create the MidiClientUtility ]
1.143 + delete iMidiClnt;
1.144 + iMidiClnt = NULL;
1.145 + //[ Close Files ]
1.146 + iFile.Close();
1.147 + iFs.Close();
1.148 + //[ Destroy the scheduler ]
1.149 + return CTestMmfMidiClntStep::DoTestStepPostambleL();
1.150 + }
1.151 +
1.152 +void CTestStepMidiClntAllocFailOpenFile::OpenFileAndStartSchedulerL()
1.153 + {
1.154 + iMidiClnt->OpenFile(iFileName);
1.155 + CActiveScheduler::Start();
1.156 + }
1.157 +
1.158 +void CTestStepMidiClntAllocFailOpenFile::OpenFileByHandleAndStartSchedulerL()
1.159 + {
1.160 + iMidiClnt->OpenFile(iFile);
1.161 + CActiveScheduler::Start();
1.162 + }
1.163 +
1.164 +
1.165 +/**
1.166 + *
1.167 + * Do the test step.
1.168 + * Each test step must supply an implementation for DoTestStepL.
1.169 + *
1.170 + * @return "TVerdict"
1.171 + * The result of the test step
1.172 + *
1.173 + * @xxxx
1.174 + *
1.175 + */
1.176 +TVerdict CTestStepMidiClntAllocFailOpenFile::DoTestStepL()
1.177 + {
1.178 + //[ Initialise Class Variables ]
1.179 + iTestStepResult = EPass;
1.180 +
1.181 + //[ Declare Local Variables ]
1.182 + TInt err = KErrNone;
1.183 + TInt failCount = 1;
1.184 + TBool completed = EFalse;
1.185 + TBool badResult = EFalse;
1.186 + TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
1.187 + TBool useFileHandle = EFalse;
1.188 +
1.189 + if(iTestStepName.Compare(_L("MM-MMF-MIDICLNT-U-1003")) == 0)
1.190 + {
1.191 + useFileHandle = ETrue;
1.192 + }
1.193 +
1.194 +
1.195 + //[ Start of main ALLOC test loop ]
1.196 + for(;;)
1.197 + {
1.198 + __UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
1.199 + __MM_HEAP_MARK;
1.200 +
1.201 + if(!useFileHandle)
1.202 + {
1.203 + TRAP( err, OpenFileAndStartSchedulerL() );
1.204 + }
1.205 + else
1.206 + {
1.207 + TRAP( err, OpenFileByHandleAndStartSchedulerL() );
1.208 + }
1.209 +
1.210 + completed = EFalse;
1.211 + if ((err == KErrNone) && (iError == KErrNone))
1.212 + {
1.213 + TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
1.214 + if (testAlloc==NULL)
1.215 + {
1.216 + reachedEnd = ETrue;
1.217 + failCount--; // -= 1;
1.218 + }
1.219 + else
1.220 + {
1.221 + User::Free(testAlloc);
1.222 + }
1.223 +
1.224 + // see if valid result and break if wrong - might be premature result
1.225 + if (iMidiClnt == NULL || iError != KErrNone )
1.226 + {
1.227 + badResult = ETrue;
1.228 + }
1.229 +
1.230 + if(iMidiClnt)
1.231 + {
1.232 + iMidiClnt->Close();
1.233 + }
1.234 +
1.235 + completed = reachedEnd || badResult;
1.236 + }
1.237 + else
1.238 + {
1.239 +
1.240 + if (((err != KErrNone) && (err != KErrNoMemory)) ||
1.241 + ((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
1.242 + {
1.243 + completed = ETrue;
1.244 + }
1.245 + }
1.246 +
1.247 + __MM_HEAP_MARKEND;
1.248 + __UHEAP_SETFAIL(RHeap::ENone ,0);
1.249 +
1.250 + if (completed)
1.251 + {
1.252 + break; // exit loop
1.253 + }
1.254 + failCount++;
1.255 + }
1.256 +
1.257 + failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
1.258 +
1.259 + if (err != KErrNone || badResult)
1.260 + {
1.261 + if (badResult)
1.262 + {
1.263 + INFO_PRINTF2(_L("Bad result with %d memory allocations tested"), failCount);
1.264 + }
1.265 + else
1.266 + {
1.267 + INFO_PRINTF3(_L("Error(%d) with %d memory allocations tested"), err, failCount);
1.268 + }
1.269 + iTestStepResult = EFail;
1.270 + }
1.271 + else
1.272 + {
1.273 + INFO_PRINTF2(_L("Completed OK with %d memory allocations tested"), failCount);
1.274 + iTestStepResult = EPass;
1.275 + }
1.276 +
1.277 +
1.278 + INFO_PRINTF1(_L("finished with this test step"));
1.279 + return iTestStepResult;
1.280 + }
1.281 +
1.282 +// from MMidiClientUtilityObserver
1.283 +void CTestStepMidiClntAllocFailOpenFile::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
1.284 + {
1.285 + iError = aError;
1.286 + CActiveScheduler::Stop();
1.287 + }
1.288 +
1.289 +void CTestStepMidiClntAllocFailOpenFile::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
1.290 + {
1.291 + }
1.292 +void CTestStepMidiClntAllocFailOpenFile::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
1.293 + {
1.294 + }
1.295 +void CTestStepMidiClntAllocFailOpenFile::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
1.296 + {
1.297 + }
1.298 +void CTestStepMidiClntAllocFailOpenFile::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
1.299 + {
1.300 + }
1.301 +void CTestStepMidiClntAllocFailOpenFile::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
1.302 + {
1.303 + }
1.304 +void CTestStepMidiClntAllocFailOpenFile::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
1.305 + {
1.306 + }
1.307 +void CTestStepMidiClntAllocFailOpenFile::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
1.308 + {
1.309 + }
1.310 +void CTestStepMidiClntAllocFailOpenFile::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
1.311 + {
1.312 + }
1.313 +
1.314 +
1.315 +// --------------------------------------------
1.316 +
1.317 +/**
1.318 + *
1.319 + * Static constructor for CTestStepMidiClntAllocFailOpenDes.
1.320 + *
1.321 + *
1.322 + * @return "CTestStepMidiClntAllocFailOpenDes*"
1.323 + * The constructed CTestStepMidiClntAllocFailOpenDes
1.324 + *
1.325 + * @xxxx
1.326 + *
1.327 + */
1.328 +CTestStepMidiClntAllocFailOpenDes* CTestStepMidiClntAllocFailOpenDes::NewL()
1.329 + {
1.330 + CTestStepMidiClntAllocFailOpenDes* self = new(ELeave) CTestStepMidiClntAllocFailOpenDes;
1.331 + return self;
1.332 + }
1.333 +
1.334 +/**
1.335 + *
1.336 + * Test step constructor.
1.337 + * Each test step initialises its own name.
1.338 + *
1.339 + * @xxxx
1.340 + *
1.341 + */
1.342 +CTestStepMidiClntAllocFailOpenDes::CTestStepMidiClntAllocFailOpenDes()
1.343 + {
1.344 + // store the name of this test case
1.345 + // this is the name that is used by the script file
1.346 + iTestStepName = _L("MM-MMF-MIDICLNT-U-0201-CP");
1.347 + }
1.348 +
1.349 +/**
1.350 + *
1.351 + * Test step destructor.
1.352 + *
1.353 + * @xxxx
1.354 + *
1.355 + */
1.356 +CTestStepMidiClntAllocFailOpenDes::~CTestStepMidiClntAllocFailOpenDes()
1.357 + {
1.358 + }
1.359 +
1.360 +
1.361 +/**
1.362 + *
1.363 + * Test step Preamble.
1.364 + *
1.365 + * @xxxx
1.366 + *
1.367 + */
1.368 +TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepPreambleL(void)
1.369 + {
1.370 + enum TVerdict verdict;
1.371 + //this installs the scheduler
1.372 + verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
1.373 +
1.374 + // Printing to the console and log file
1.375 + INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0201-CP"));
1.376 + INFO_PRINTF1(_L("this is a memory allocation failure test of CTestStepMidiClntAllocFailOpenDes"));
1.377 +
1.378 + if(!GetStringFromConfig(_L("SectionOne"), _L("filename"), iFilename))
1.379 + return EInconclusive;
1.380 +
1.381 + RFs fs;
1.382 + RFile file;
1.383 + TInt size = 0;
1.384 +
1.385 + // connect to file system and open file
1.386 + User::LeaveIfError(fs.Connect());
1.387 + User::LeaveIfError(file.Open(fs,iFilename,EFileRead));
1.388 + CleanupClosePushL(file);
1.389 +
1.390 + // Set HBuf size
1.391 + User::LeaveIfError(file.Size(size));
1.392 + INFO_PRINTF2(_L("size of file = %d\n"),size);
1.393 +
1.394 + iAudio = HBufC8::NewMaxL(size);
1.395 +
1.396 + // read data into Hbuf
1.397 + TPtr8 bufferDes(iAudio->Des());
1.398 + User::LeaveIfError(file.Read(bufferDes));
1.399 +
1.400 + CleanupStack::PopAndDestroy(); //file
1.401 +
1.402 + // create the Midi utility
1.403 + if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
1.404 + return EInconclusive;
1.405 +
1.406 + return verdict;
1.407 + }
1.408 +
1.409 +/**
1.410 + *
1.411 + * Test step Postamble.
1.412 + *
1.413 + * @xxxx
1.414 + *
1.415 + */
1.416 +TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepPostambleL(void)
1.417 + {
1.418 + delete iMidiClnt;
1.419 + iMidiClnt = NULL;
1.420 + delete iAudio;
1.421 + iAudio = NULL;
1.422 + //[ Destroy the scheduler ]
1.423 + return CTestMmfMidiClntStep::DoTestStepPostambleL();
1.424 + }
1.425 +
1.426 +void CTestStepMidiClntAllocFailOpenDes::OpenDesAndStartSchedulerL()
1.427 + {
1.428 + iMidiClnt->OpenDes(iAudio->Des());
1.429 + CActiveScheduler::Start();
1.430 + }
1.431 +
1.432 +/**
1.433 + *
1.434 + * Do the test step.
1.435 + * Each test step must supply an implementation for DoTestStepL.
1.436 + *
1.437 + * @return "TVerdict"
1.438 + * The result of the test step
1.439 + *
1.440 + * @xxxx
1.441 + *
1.442 + */
1.443 +TVerdict CTestStepMidiClntAllocFailOpenDes::DoTestStepL()
1.444 + {
1.445 + iTestStepResult = EPass;
1.446 + TInt err = KErrNone;
1.447 +
1.448 + TInt failCount = 1;
1.449 + TBool completed = EFalse;
1.450 + TBool badResult = EFalse;
1.451 + TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
1.452 + for(;;)
1.453 + {
1.454 + __UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
1.455 + __MM_HEAP_MARK;
1.456 +
1.457 + TRAP( err, OpenDesAndStartSchedulerL() );
1.458 +
1.459 + completed = EFalse;
1.460 + if ((err == KErrNone) && (iError == KErrNone))
1.461 + {
1.462 + TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
1.463 + if (testAlloc==NULL)
1.464 + {
1.465 + reachedEnd = ETrue;
1.466 + failCount--; // -= 1;
1.467 + }
1.468 + else
1.469 + User::Free(testAlloc);
1.470 +
1.471 +
1.472 + // see if valid result and break if wrong - might be premature result
1.473 + if (iMidiClnt == NULL ||
1.474 + iError != KErrNone )
1.475 + badResult = ETrue;
1.476 +
1.477 + if(iMidiClnt)
1.478 + iMidiClnt->Close();
1.479 +
1.480 + completed = reachedEnd || badResult;
1.481 + }
1.482 + else if (((err != KErrNone) && (err != KErrNoMemory)) ||
1.483 + ((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
1.484 + completed = ETrue;
1.485 +
1.486 + __MM_HEAP_MARKEND;
1.487 + __UHEAP_SETFAIL(RHeap::ENone ,0);
1.488 +
1.489 + if (completed)
1.490 + break; // exit loop
1.491 +
1.492 + failCount++;
1.493 + }
1.494 +
1.495 + delete iMidiClnt;
1.496 + iMidiClnt = NULL;
1.497 +
1.498 + //failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
1.499 +
1.500 + if (err != KErrNone || badResult)
1.501 + {
1.502 + if (badResult)
1.503 + INFO_PRINTF2(_L(" Bad result with %d memory allocations tested"), failCount);
1.504 + else
1.505 + INFO_PRINTF3(_L(" Error(%d) with %d memory allocations tested"), err, failCount);
1.506 + iTestStepResult = EFail;
1.507 + }
1.508 + else
1.509 + {
1.510 + INFO_PRINTF2(_L(" Completed OK with %d memory allocations tested"), failCount);
1.511 + iTestStepResult = EPass;
1.512 + }
1.513 +
1.514 + INFO_PRINTF1(_L("finished with this test step"));
1.515 + // test steps return a result
1.516 + return iTestStepResult;
1.517 + }
1.518 +
1.519 + // from MMidiClientUtilityObserver
1.520 +void CTestStepMidiClntAllocFailOpenDes::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
1.521 + {
1.522 + iError = aError;
1.523 + CActiveScheduler::Stop();
1.524 + }
1.525 +
1.526 +void CTestStepMidiClntAllocFailOpenDes::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
1.527 + {
1.528 + }
1.529 +void CTestStepMidiClntAllocFailOpenDes::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
1.530 + {
1.531 + }
1.532 +void CTestStepMidiClntAllocFailOpenDes::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
1.533 + {
1.534 + }
1.535 +void CTestStepMidiClntAllocFailOpenDes::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
1.536 + {
1.537 + }
1.538 +void CTestStepMidiClntAllocFailOpenDes::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
1.539 + {
1.540 + }
1.541 +void CTestStepMidiClntAllocFailOpenDes::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
1.542 + {
1.543 + }
1.544 +void CTestStepMidiClntAllocFailOpenDes::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
1.545 + {
1.546 + }
1.547 +void CTestStepMidiClntAllocFailOpenDes::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
1.548 + {
1.549 + }
1.550 +
1.551 +
1.552 +// --------------------------------------------
1.553 +
1.554 +/**
1.555 + *
1.556 + * Static constructor for CTestStepMidiClntAllocFailOpenUrl.
1.557 + *
1.558 + *
1.559 + * @return "CTestStepMidiClntAllocFailOpenUrl*"
1.560 + * The constructed CTestStepMidiClntAllocFailOpenUrl
1.561 + *
1.562 + * @xxxx
1.563 + *
1.564 + */
1.565 +CTestStepMidiClntAllocFailOpenUrl* CTestStepMidiClntAllocFailOpenUrl::NewL()
1.566 + {
1.567 + CTestStepMidiClntAllocFailOpenUrl* self = new(ELeave) CTestStepMidiClntAllocFailOpenUrl;
1.568 + return self;
1.569 + }
1.570 +
1.571 +/**
1.572 + *
1.573 + * Test step constructor.
1.574 + * Each test step initialises its own name.
1.575 + *
1.576 + * @xxxx
1.577 + *
1.578 + */
1.579 +CTestStepMidiClntAllocFailOpenUrl::CTestStepMidiClntAllocFailOpenUrl()
1.580 + {
1.581 + // store the name of this test case
1.582 + // this is the name that is used by the script file
1.583 + iTestStepName = _L("MM-MMF-MIDICLNT-U-0202-CP");
1.584 + }
1.585 +
1.586 +/**
1.587 + *
1.588 + * Test step destructor.
1.589 + *
1.590 + * @xxxx
1.591 + *
1.592 + */
1.593 +CTestStepMidiClntAllocFailOpenUrl::~CTestStepMidiClntAllocFailOpenUrl()
1.594 + {
1.595 + }
1.596 +
1.597 +
1.598 +/**
1.599 + *
1.600 + * Test step Preamble.
1.601 + *
1.602 + * @xxxx
1.603 + *
1.604 + */
1.605 +TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepPreambleL(void)
1.606 + {
1.607 + enum TVerdict verdict;
1.608 + // this installs the scheduler
1.609 + verdict = CTestMmfMidiClntStep::DoTestStepPreambleL();
1.610 +
1.611 + // Printing to the console and log file
1.612 + INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0202-CP"));
1.613 + INFO_PRINTF1(_L("this is a memory allocation failure test of CTestStepMidiClntAllocFailOpenUrl"));
1.614 +
1.615 + if(!GetStringFromConfig(iSectName,iKeyName,iUrlname))
1.616 + return EInconclusive;
1.617 +
1.618 + /*
1.619 + if(!GetStringFromConfig(_L("SectionOne"), _L("AudioPlayFName7"), iFileName) ||
1.620 + !GetStringFromConfig(_L("SectionOne"), _L("AudioFNameToConvert"), iFileName2))
1.621 + {
1.622 + //INFO_PRINTF2(_L("file name %s not found..."), fileptr);
1.623 + return EInconclusive;
1.624 + }
1.625 + */
1.626 +
1.627 + // create the Midi utility
1.628 + if ( (iMidiClnt = CMidiClientUtility::NewL(*this)) == NULL )
1.629 + verdict = EInconclusive;
1.630 +
1.631 + return verdict;
1.632 +
1.633 + }
1.634 +
1.635 +/**
1.636 + *
1.637 + * Test step Postamble.
1.638 + *
1.639 + * @xxxx
1.640 + *
1.641 + */
1.642 +TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepPostambleL(void)
1.643 + {
1.644 + delete iMidiClnt;
1.645 + iMidiClnt = NULL;
1.646 + //[ Destroy the scheduler ]
1.647 + return CTestMmfMidiClntStep::DoTestStepPostambleL();
1.648 + }
1.649 +
1.650 +void CTestStepMidiClntAllocFailOpenUrl::OpenUrlAndStartSchedulerL()
1.651 + {
1.652 + iMidiClnt->OpenUrl(iUrlname);
1.653 + CActiveScheduler::Start();
1.654 + }
1.655 +
1.656 +/**
1.657 + *
1.658 + * Do the test step.
1.659 + * Each test step must supply an implementation for DoTestStepL.
1.660 + *
1.661 + * @return "TVerdict"
1.662 + * The result of the test step
1.663 + *
1.664 + * @xxxx
1.665 + *
1.666 + */
1.667 +TVerdict CTestStepMidiClntAllocFailOpenUrl::DoTestStepL()
1.668 + {
1.669 + iTestStepResult = EPass;
1.670 + TInt err = KErrNone;
1.671 +
1.672 + TInt failCount = 1;
1.673 + TBool completed = EFalse;
1.674 + TBool badResult = EFalse;
1.675 + TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
1.676 + for(;;)
1.677 + {
1.678 + __UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
1.679 + __MM_HEAP_MARK;
1.680 +
1.681 + TRAP( err, OpenUrlAndStartSchedulerL() );
1.682 +
1.683 + completed = EFalse;
1.684 + if ((err == KErrNone) && (iError == KErrNone))
1.685 + {
1.686 + TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
1.687 + if (testAlloc==NULL)
1.688 + {
1.689 + reachedEnd = ETrue;
1.690 + failCount--; // -= 1;
1.691 + }
1.692 + else
1.693 + User::Free(testAlloc);
1.694 +
1.695 +
1.696 + // see if valid result and break if wrong - might be premature result
1.697 + if (iMidiClnt == NULL ||
1.698 + iError != KErrNone )
1.699 + badResult = ETrue;
1.700 +
1.701 + if(iMidiClnt)
1.702 + iMidiClnt->Close();
1.703 +
1.704 + completed = reachedEnd || badResult;
1.705 + }
1.706 + else if (((err != KErrNone) && (err != KErrNoMemory)) ||
1.707 + ((iError != KErrNone) && (iError != KErrNoMemory))) // bad error code
1.708 + completed = ETrue;
1.709 +
1.710 + __MM_HEAP_MARKEND;
1.711 + __UHEAP_SETFAIL(RHeap::ENone ,0);
1.712 +
1.713 + if (completed)
1.714 + break; // exit loop
1.715 +
1.716 + failCount++;
1.717 + }
1.718 +
1.719 + delete iMidiClnt;
1.720 + iMidiClnt = NULL;
1.721 +
1.722 + //failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
1.723 +
1.724 + if (err != KErrNone || badResult)
1.725 + {
1.726 + if (badResult)
1.727 + INFO_PRINTF2(_L(" Bad result with %d memory allocations tested"), failCount);
1.728 + else
1.729 + INFO_PRINTF3(_L(" Error(%d) with %d memory allocations tested"), err, failCount);
1.730 + iTestStepResult = EFail;
1.731 + }
1.732 + else
1.733 + {
1.734 + INFO_PRINTF2(_L(" Completed OK with %d memory allocations tested"), failCount);
1.735 + iTestStepResult = EPass;
1.736 + }
1.737 +
1.738 + INFO_PRINTF1(_L("finished with this test step"));
1.739 + // test steps return a result
1.740 + return iTestStepResult;
1.741 + }
1.742 +
1.743 + // from MMidiClientUtilityObserver
1.744 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
1.745 + {
1.746 + iError = aError;
1.747 + CActiveScheduler::Stop();
1.748 + }
1.749 +
1.750 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
1.751 + {
1.752 + }
1.753 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
1.754 + {
1.755 + }
1.756 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
1.757 + {
1.758 + }
1.759 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
1.760 + {
1.761 + }
1.762 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
1.763 + {
1.764 + }
1.765 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
1.766 + {
1.767 + }
1.768 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
1.769 + {
1.770 + }
1.771 +void CTestStepMidiClntAllocFailOpenUrl::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
1.772 + {
1.773 + }
1.774 +
1.775 +
1.776 +