0
|
1 |
// Copyright (c) 2002-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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
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
|
|
17 |
// a test step
|
|
18 |
//
|
|
19 |
//
|
|
20 |
|
|
21 |
// EPOC includes
|
|
22 |
#include <e32base.h>
|
|
23 |
#include <e32test.h>
|
|
24 |
#include <e32keys.h>
|
|
25 |
#include <c32comm.h>
|
|
26 |
#include <f32file.h>
|
|
27 |
#include <etel.h>
|
|
28 |
#include <etelmm.h>
|
|
29 |
#include <testframework.h>
|
|
30 |
|
|
31 |
#include <mdaaudiosampleplayer.h>
|
|
32 |
//#include <MdaAudioSampleEditor.h>
|
|
33 |
//#include <MdaAudioTonePlayer.h>
|
|
34 |
|
|
35 |
// Test system includes
|
|
36 |
#include <testframework.h>
|
|
37 |
|
|
38 |
// Specific includes for this test suite
|
|
39 |
#include "TestStepUnitMMFAudClient.h"
|
|
40 |
#include "TestSuiteUnitMMFAudClient.h"
|
|
41 |
|
|
42 |
// Specific includes for these test steps
|
|
43 |
#include "TestStepPlayerAllocFailNew.h"
|
|
44 |
|
|
45 |
#include "mmfclientaudioplayer.h"
|
|
46 |
|
|
47 |
// --------------------------------------------
|
|
48 |
|
|
49 |
/**
|
|
50 |
*
|
|
51 |
* Static constructor for CTestStepPlayerAllocFailNewFilePlayer.
|
|
52 |
*
|
|
53 |
*
|
|
54 |
* @return "CTestStepPlayerAllocFailNewFilePlayer*"
|
|
55 |
* The constructed CTestStepPlayerAllocFailNewFilePlayer
|
|
56 |
*
|
|
57 |
* @xxxx
|
|
58 |
*
|
|
59 |
*/
|
|
60 |
CTestStepPlayerAllocFailNewFilePlayer* CTestStepPlayerAllocFailNewFilePlayer::NewL()
|
|
61 |
{
|
|
62 |
CTestStepPlayerAllocFailNewFilePlayer* self = new(ELeave) CTestStepPlayerAllocFailNewFilePlayer;
|
|
63 |
return self;
|
|
64 |
}
|
|
65 |
|
|
66 |
/**
|
|
67 |
*
|
|
68 |
* Test step constructor.
|
|
69 |
* Each test step initialises its own name.
|
|
70 |
*
|
|
71 |
* @xxxx
|
|
72 |
*
|
|
73 |
*/
|
|
74 |
CTestStepPlayerAllocFailNewFilePlayer::CTestStepPlayerAllocFailNewFilePlayer()
|
|
75 |
{
|
|
76 |
// store the name of this test case
|
|
77 |
// this is the name that is used by the script file
|
|
78 |
iTestStepName = _L("MM-MMF-ACLNT-U-0101-CP");
|
|
79 |
}
|
|
80 |
|
|
81 |
/**
|
|
82 |
*
|
|
83 |
* Test step destructor.
|
|
84 |
*
|
|
85 |
* @xxxx
|
|
86 |
*
|
|
87 |
*/
|
|
88 |
CTestStepPlayerAllocFailNewFilePlayer::~CTestStepPlayerAllocFailNewFilePlayer()
|
|
89 |
{
|
|
90 |
}
|
|
91 |
/**
|
|
92 |
* Implementation of the MMdaAudioPlayerCallback interface functions
|
|
93 |
**/
|
|
94 |
void CTestStepPlayerAllocFailNewFilePlayer::MapcInitComplete(TInt aError,
|
|
95 |
const TTimeIntervalMicroSeconds &/*aDuration*/)
|
|
96 |
{
|
|
97 |
iError = aError;
|
|
98 |
|
|
99 |
// INFO_PRINTF2(_L("callback error: %d"), aError);
|
|
100 |
CActiveScheduler::Stop();
|
|
101 |
}
|
|
102 |
|
|
103 |
void CTestStepPlayerAllocFailNewFilePlayer::MapcPlayComplete(TInt aError)
|
|
104 |
{
|
|
105 |
iError = aError;
|
|
106 |
CActiveScheduler::Stop();
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
*
|
|
111 |
* Test step Preamble.
|
|
112 |
*
|
|
113 |
* @xxxx
|
|
114 |
*
|
|
115 |
*/
|
|
116 |
enum TVerdict CTestStepPlayerAllocFailNewFilePlayer::DoTestStepPreambleL(void)
|
|
117 |
{
|
|
118 |
enum TVerdict verdict;
|
|
119 |
// this installs the scheduler
|
|
120 |
verdict = CTestStepUnitMMFAudClient::DoTestStepPreambleL();
|
|
121 |
|
|
122 |
// Printing to the console and log file
|
|
123 |
INFO_PRINTF1(_L("MM-MMF-ACLNT-U-0101-CP"));
|
|
124 |
INFO_PRINTF1(_L("this is an Alloc failure test of the CMMFMdaAudioPlayerUtility::NewFilelayerL() "));
|
|
125 |
|
|
126 |
iError = KErrNone; //KErrTimedOut;
|
|
127 |
|
|
128 |
if(!GetStringFromConfig(_L("SectionOne"), _L("AudioPlayFName1"), iFileName))
|
|
129 |
{
|
|
130 |
//INFO_PRINTF2(_L("file name %s not found..."), fileptr);
|
|
131 |
return EInconclusive;
|
|
132 |
}
|
|
133 |
|
|
134 |
return verdict;
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
*
|
|
139 |
* Test step Postamble.
|
|
140 |
*
|
|
141 |
* @xxxx
|
|
142 |
*
|
|
143 |
*/
|
|
144 |
enum TVerdict CTestStepPlayerAllocFailNewFilePlayer::DoTestStepPostambleL(void)
|
|
145 |
{
|
|
146 |
delete iPlayer;
|
|
147 |
iPlayer = NULL;
|
|
148 |
//[ Destroy the scheduler ]
|
|
149 |
return CTestStepUnitMMFAudClient::DoTestStepPostambleL();
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
*
|
|
154 |
* The commands to be included in the TRAP command
|
|
155 |
*
|
|
156 |
* @xxxx
|
|
157 |
*
|
|
158 |
*/
|
|
159 |
void CTestStepPlayerAllocFailNewFilePlayer::StartNewFilePlayerSchedulerL()
|
|
160 |
{
|
|
161 |
TRAPD(err, iPlayer = CMMFMdaAudioPlayerUtility::NewFilePlayerL(iFileName, *this) );
|
|
162 |
// examining value
|
|
163 |
if (err != KErrNone)
|
|
164 |
User::Leave(err); // or User::LeaveIfError....
|
|
165 |
CActiveScheduler::Start();
|
|
166 |
}
|
|
167 |
|
|
168 |
/**
|
|
169 |
*
|
|
170 |
* Do the test step.
|
|
171 |
* Each test step must supply an implementation for DoTestStepL.
|
|
172 |
*
|
|
173 |
* @return "TVerdict"
|
|
174 |
* The result of the test step
|
|
175 |
*
|
|
176 |
* @xxxx
|
|
177 |
*
|
|
178 |
*/
|
|
179 |
TVerdict CTestStepPlayerAllocFailNewFilePlayer::DoTestStepL()
|
|
180 |
{
|
|
181 |
iTestStepResult = EPass;
|
|
182 |
TInt err = KErrNone;
|
|
183 |
|
|
184 |
TInt failCount = 1;
|
|
185 |
TBool completed = EFalse;
|
|
186 |
TBool badResult = EFalse;
|
|
187 |
TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
|
|
188 |
for(;;)
|
|
189 |
{
|
|
190 |
iError = KErrNone;
|
|
191 |
__UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
|
|
192 |
__MM_HEAP_MARK;
|
|
193 |
|
|
194 |
TRAP( err, StartNewFilePlayerSchedulerL() );
|
|
195 |
|
|
196 |
completed = EFalse;
|
|
197 |
if (err == KErrNone && iError == KErrNone)
|
|
198 |
{
|
|
199 |
TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
|
|
200 |
if (testAlloc==NULL)
|
|
201 |
{
|
|
202 |
reachedEnd = ETrue;
|
|
203 |
failCount--; // -= 1;
|
|
204 |
}
|
|
205 |
else
|
|
206 |
User::Free(testAlloc);
|
|
207 |
// see if valid result and break if wrong - might be premature result
|
|
208 |
TInt err1 = KErrNone;
|
|
209 |
TInt err2 = KErrNone;
|
|
210 |
TInt state = 0;
|
|
211 |
TMMFMessageDestination* srcHandle = NULL;
|
|
212 |
err1 = GetAudPlayerState(iPlayer, state);
|
|
213 |
err2 = GetAudPlayerSourceHandle(iPlayer, srcHandle);
|
|
214 |
if ( err1 != KErrNone ||
|
|
215 |
err2 != KErrNone ||
|
|
216 |
&srcHandle == NULL ||
|
|
217 |
state != CMMFMdaAudioPlayerUtility::EStopped ||
|
|
218 |
iPlayer->Duration() == TTimeIntervalMicroSeconds(0) || // we know the duration of the file is more than 0
|
|
219 |
iError != KErrNone)
|
|
220 |
badResult = ETrue;
|
|
221 |
if (iPlayer != NULL)
|
|
222 |
{
|
|
223 |
delete iPlayer;
|
|
224 |
iPlayer = NULL;
|
|
225 |
}
|
|
226 |
completed = reachedEnd || badResult;
|
|
227 |
}
|
|
228 |
else if ((err && err != KErrNoMemory) || (err == KErrNone && iError != KErrNoMemory)) // bad error code
|
|
229 |
completed = ETrue;
|
|
230 |
|
|
231 |
if (iError != KErrNone)
|
|
232 |
{
|
|
233 |
// Error from a callback - free iPlayer for next time round the loop
|
|
234 |
delete iPlayer;
|
|
235 |
iPlayer = NULL;
|
|
236 |
}
|
|
237 |
|
|
238 |
__MM_HEAP_MARKEND;
|
|
239 |
__UHEAP_SETFAIL(RHeap::ENone ,0);
|
|
240 |
|
|
241 |
if (completed)
|
|
242 |
break; // exit loop
|
|
243 |
|
|
244 |
failCount++;
|
|
245 |
}
|
|
246 |
|
|
247 |
//failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
|
|
248 |
|
|
249 |
if (err != KErrNone || badResult)
|
|
250 |
{
|
|
251 |
if (badResult)
|
|
252 |
INFO_PRINTF2(_L(" Bad result with %d memory allocations tested"), failCount);
|
|
253 |
else
|
|
254 |
INFO_PRINTF3(_L(" Error(%d) with %d memory allocations tested"), err, failCount);
|
|
255 |
iTestStepResult = EFail;
|
|
256 |
}
|
|
257 |
else
|
|
258 |
{
|
|
259 |
INFO_PRINTF2(_L(" Completed OK with %d memory allocations tested"), failCount);
|
|
260 |
iTestStepResult = EPass;
|
|
261 |
}
|
|
262 |
INFO_PRINTF1(_L("finished with this test step"));
|
|
263 |
// test steps return a result
|
|
264 |
return iTestStepResult;
|
|
265 |
}
|
|
266 |
|