0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <e32base.h>
|
|
17 |
#include <f32file.h>
|
|
18 |
#include <testframework.h>
|
|
19 |
|
|
20 |
#include "TestStepUnitMMFAudClient.h"
|
|
21 |
#include "TestSuiteUnitMMFAudClient.h"
|
|
22 |
#include "TestStepPlayerAllocFailOpen.h"
|
|
23 |
// --------------------------------------------
|
|
24 |
|
|
25 |
|
|
26 |
/*
|
|
27 |
*
|
|
28 |
* Static constructor for CTestStepPlayerAllocFailOpenFile.
|
|
29 |
*
|
|
30 |
*
|
|
31 |
* @return "CTestStepPlayerAllocFailOpenFile*"
|
|
32 |
* The constructed CTestStepPlayerAllocFailOpenFile
|
|
33 |
*
|
|
34 |
* @xxxx
|
|
35 |
*
|
|
36 |
*/
|
|
37 |
CTestStepPlayerAllocFailOpenFile* CTestStepPlayerAllocFailOpenFile::NewL(TBool aUseFileHandle)
|
|
38 |
{
|
|
39 |
CTestStepPlayerAllocFailOpenFile* self = new(ELeave) CTestStepPlayerAllocFailOpenFile;
|
|
40 |
if (aUseFileHandle)
|
|
41 |
{
|
|
42 |
self->iTestStepName = _L("MM-MMF-ACLNT-U-0110-CP");
|
|
43 |
}
|
|
44 |
else
|
|
45 |
{
|
|
46 |
self->iTestStepName = _L("MM-MMF-ACLNT-U-0104-CP");
|
|
47 |
}
|
|
48 |
self->iHeapSize = 100000;
|
|
49 |
self->iUseFileHandle = aUseFileHandle;
|
|
50 |
return self;
|
|
51 |
}
|
|
52 |
|
|
53 |
/**
|
|
54 |
*
|
|
55 |
* Test step Preamble.
|
|
56 |
*
|
|
57 |
* @xxxx
|
|
58 |
*
|
|
59 |
*/
|
|
60 |
enum TVerdict CTestStepPlayerAllocFailOpenFile::DoTestStepPreambleL(void)
|
|
61 |
{
|
|
62 |
// Printing to the console and log file
|
|
63 |
INFO_PRINTF1(iTestStepName);
|
|
64 |
INFO_PRINTF1(_L("This is Alloc failure test of CMMFMdaAudioPlayerUtility::OpenDesL"));
|
|
65 |
|
|
66 |
if(!GetStringFromConfig(_L("SectionOne"), _L("AudioPlayFName7"), iFileName))
|
|
67 |
{
|
|
68 |
INFO_PRINTF1(_L("file not found: "));
|
|
69 |
INFO_PRINTF1(iFileName);
|
|
70 |
return EInconclusive;
|
|
71 |
}
|
|
72 |
|
|
73 |
// this installs the scheduler
|
|
74 |
return CTestStepUnitMMFAudClient::DoTestStepPreambleL();
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
*
|
|
79 |
* Test step Postamble.
|
|
80 |
*
|
|
81 |
* @xxxx
|
|
82 |
*
|
|
83 |
*/
|
|
84 |
enum TVerdict CTestStepPlayerAllocFailOpenFile::DoTestStepPostambleL(void)
|
|
85 |
{
|
|
86 |
delete iPlayer; iPlayer = NULL;
|
|
87 |
|
|
88 |
iFile.Close();
|
|
89 |
iFs.Close();
|
|
90 |
|
|
91 |
//[ Destroy the scheduler ]
|
|
92 |
return CTestStepUnitMMFAudClient::DoTestStepPostambleL();
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Implementation of the MMdaAudioPlayerCallback interface functions
|
|
97 |
**/
|
|
98 |
void CTestStepPlayerAllocFailOpenFile::MapcInitComplete(TInt aErrorcCode,
|
|
99 |
const TTimeIntervalMicroSeconds &/*aDuration*/)
|
|
100 |
{
|
|
101 |
#ifdef __WINS__
|
|
102 |
iKErrGeneralIgnored = EFalse;
|
|
103 |
if ( aErrorcCode == KErrGeneral )
|
|
104 |
iKErrGeneralIgnored = ETrue; //Ignore KErrGeneral on EMULATOR
|
|
105 |
#endif
|
|
106 |
|
|
107 |
if ( aErrorcCode == KErrNone || aErrorcCode == KErrNoMemory )
|
|
108 |
{
|
|
109 |
iAllocOK = ETrue;
|
|
110 |
|
|
111 |
if ( aErrorcCode == KErrNone
|
|
112 |
&& iPlayer->Duration() > TTimeIntervalMicroSeconds(0) )
|
|
113 |
{
|
|
114 |
iResultOK = ETrue;
|
|
115 |
}
|
|
116 |
}
|
|
117 |
else
|
|
118 |
{
|
|
119 |
INFO_PRINTF2(_L("Unexpected error %d seen"), aErrorcCode);
|
|
120 |
iAllocOK = EFalse;
|
|
121 |
}
|
|
122 |
|
|
123 |
CActiveScheduler::Stop();
|
|
124 |
}
|
|
125 |
|
|
126 |
void CTestStepPlayerAllocFailOpenFile::MapcPlayComplete(TInt /*aErrorcCode*/)
|
|
127 |
{
|
|
128 |
ASSERT(0);
|
|
129 |
}
|
|
130 |
|
|
131 |
/**
|
|
132 |
*
|
|
133 |
* Do the test step.
|
|
134 |
* Each test step must supply an implementation for DoTestStepL.
|
|
135 |
*
|
|
136 |
* @return "TVerdict"
|
|
137 |
* The result of the test step
|
|
138 |
*
|
|
139 |
* @xxxx
|
|
140 |
*
|
|
141 |
*/
|
|
142 |
TVerdict CTestStepPlayerAllocFailOpenFile::DoTestStepL()
|
|
143 |
{
|
|
144 |
iAllocOK = ETrue;
|
|
145 |
iResultOK = EFalse;
|
|
146 |
TInt count;
|
|
147 |
|
|
148 |
INFO_PRINTF1(_L("Testing CMdaAudioPlayerUtility::OpenFileL()"));
|
|
149 |
|
|
150 |
__MM_HEAP_MARK;
|
|
151 |
|
|
152 |
//create the player, leave if unsuccessful
|
|
153 |
iPlayer = CMdaAudioPlayerUtility::NewL(*this);
|
|
154 |
|
|
155 |
if (iUseFileHandle)
|
|
156 |
{
|
|
157 |
User::LeaveIfError(iFs.Connect());
|
|
158 |
User::LeaveIfError(iFs.ShareProtected());
|
|
159 |
User::LeaveIfError(iFile.Open(iFs,iFileName, EFileRead));
|
|
160 |
}
|
|
161 |
|
|
162 |
TInt error = KErrNone;
|
|
163 |
|
|
164 |
for( count = 0; iAllocOK; count++ )
|
|
165 |
{
|
|
166 |
User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext,count);
|
|
167 |
if (iUseFileHandle)
|
|
168 |
{
|
|
169 |
TRAP( error, iPlayer->OpenFileL( iFile ) );
|
|
170 |
}
|
|
171 |
else
|
|
172 |
{
|
|
173 |
TRAP( error, iPlayer->OpenFileL( iFileName ) );
|
|
174 |
}
|
|
175 |
|
|
176 |
if ( error != KErrNone && error != KErrNoMemory )
|
|
177 |
{
|
|
178 |
INFO_PRINTF3(_L("Unexpected error %d seen on interaction %d"), error, count);
|
|
179 |
iAllocOK = EFalse;
|
|
180 |
}
|
|
181 |
|
|
182 |
if ( error == KErrNone )
|
|
183 |
CActiveScheduler::Start();
|
|
184 |
|
|
185 |
iPlayer->Close();
|
|
186 |
TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
|
|
187 |
if ( testAlloc == NULL )
|
|
188 |
break;
|
|
189 |
User::Free(testAlloc);
|
|
190 |
}
|
|
191 |
User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext,NULL);
|
|
192 |
|
|
193 |
delete iPlayer; iPlayer = NULL;
|
|
194 |
__MM_HEAP_MARKEND;
|
|
195 |
|
|
196 |
//determine result and print info
|
|
197 |
iTestStepResult = EFail;
|
|
198 |
if (iAllocOK)
|
|
199 |
{
|
|
200 |
if (iResultOK)
|
|
201 |
{
|
|
202 |
INFO_PRINTF2(_L("Completed OK with %d memory allocations tested"),count);
|
|
203 |
iTestStepResult = EPass;
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
INFO_PRINTF2(_L("Bad result with %d memory allocations tested"),count);
|
|
208 |
}
|
|
209 |
}
|
|
210 |
else
|
|
211 |
{
|
|
212 |
INFO_PRINTF2(_L("Error occured with %d memory allocations tested"),count);
|
|
213 |
|
|
214 |
#ifdef __WINS__
|
|
215 |
//Ignore KErrGeneral on EMULATOR
|
|
216 |
if ( iKErrGeneralIgnored )
|
|
217 |
{
|
|
218 |
INFO_PRINTF1(_L("KErrGeneral has been ignored on EMULATOR"));
|
|
219 |
INFO_PRINTF1(_L("Subsequent steps may fail with KErrGeneral"));
|
|
220 |
iTestStepResult = EPass;
|
|
221 |
}
|
|
222 |
#endif
|
|
223 |
}
|
|
224 |
|
|
225 |
INFO_PRINTF1(_L("Finished with this test step"));
|
|
226 |
return iTestStepResult;
|
|
227 |
}
|
|
228 |
|