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 <mdaaudiotoneplayer.h>
|
|
32 |
|
|
33 |
// Test system includes
|
|
34 |
#include <testframework.h>
|
|
35 |
|
|
36 |
// Specific includes for this test suite
|
|
37 |
#include "TestStepUnitMMFAudClient.h"
|
|
38 |
#include "TestSuiteUnitMMFAudClient.h"
|
|
39 |
|
|
40 |
// Specific includes for these test steps
|
|
41 |
#include "TestStepTone.h"
|
|
42 |
|
|
43 |
|
|
44 |
#include "mmfclienttoneplayer.h"
|
|
45 |
|
|
46 |
/**
|
|
47 |
*
|
|
48 |
* Static constructor for CTestStepTonePrepareToPlayDualTonePlay.
|
|
49 |
*
|
|
50 |
*
|
|
51 |
* @return "CTestStepTonePrepareToPlayDualTonePlay*"
|
|
52 |
* The constructed CTestStepTonePrepareToPlayDualTonePlay
|
|
53 |
*
|
|
54 |
*/
|
|
55 |
CTestStepTonePrepareToPlayDualTonePlay* CTestStepTonePrepareToPlayDualTonePlay::NewL()
|
|
56 |
{
|
|
57 |
CTestStepTonePrepareToPlayDualTonePlay* self = new(ELeave) CTestStepTonePrepareToPlayDualTonePlay;
|
|
58 |
return self;
|
|
59 |
}
|
|
60 |
|
|
61 |
/**
|
|
62 |
*
|
|
63 |
* Test step constructor.
|
|
64 |
* Each test step initialises its own name.
|
|
65 |
*
|
|
66 |
*/
|
|
67 |
CTestStepTonePrepareToPlayDualTonePlay::CTestStepTonePrepareToPlayDualTonePlay() : iError(KErrNone), iHasPlayed(EFalse)
|
|
68 |
{
|
|
69 |
// store the name of this test case
|
|
70 |
// this is the name that is used by the script file
|
|
71 |
iTestStepName = _L("MM-MMF-ACLNT-U-0467-CP");
|
|
72 |
// need a bigger heap size on EKA2 HW
|
|
73 |
#if !defined __WINS__
|
|
74 |
iHeapSize = KHeapSizeToneTestEKA2;
|
|
75 |
#endif // EKA2
|
|
76 |
}
|
|
77 |
|
|
78 |
/**
|
|
79 |
*
|
|
80 |
* Test step destructor.
|
|
81 |
*
|
|
82 |
*/
|
|
83 |
CTestStepTonePrepareToPlayDualTonePlay::~CTestStepTonePrepareToPlayDualTonePlay()
|
|
84 |
{
|
|
85 |
}
|
|
86 |
|
|
87 |
void CTestStepTonePrepareToPlayDualTonePlay::MatoPrepareComplete(TInt aError)
|
|
88 |
{
|
|
89 |
iError = aError;
|
|
90 |
CActiveScheduler::Stop();
|
|
91 |
}
|
|
92 |
|
|
93 |
void CTestStepTonePrepareToPlayDualTonePlay::MatoPlayComplete(TInt aError)
|
|
94 |
{
|
|
95 |
iError = aError;
|
|
96 |
CActiveScheduler::Stop();
|
|
97 |
}
|
|
98 |
|
|
99 |
/**
|
|
100 |
*
|
|
101 |
* Test step Preamble.
|
|
102 |
* Creates a tone utility
|
|
103 |
*
|
|
104 |
*/
|
|
105 |
enum TVerdict CTestStepTonePrepareToPlayDualTonePlay::DoTestStepPreambleL(void)
|
|
106 |
{
|
|
107 |
TInt err = KErrNone;
|
|
108 |
enum TVerdict verdict;
|
|
109 |
// this installs the scheduler
|
|
110 |
verdict = CTestStepUnitMMFAudClient::DoTestStepPreambleL();
|
|
111 |
|
|
112 |
// Printing to the console and log file
|
|
113 |
INFO_PRINTF1(_L("this is a test of CMdaAudioToneUtility::PrepareToPlayDualTone()"));
|
|
114 |
|
|
115 |
__MM_HEAP_MARK;
|
|
116 |
// create the Tone utility
|
|
117 |
TRAP( err, (iTone = CMMFMdaAudioToneUtility::NewL(*this)) );
|
|
118 |
if ( err != KErrNone ||
|
|
119 |
iTone->State() != EMdaAudioToneUtilityNotReady )
|
|
120 |
verdict = EInconclusive;
|
|
121 |
|
|
122 |
return verdict;
|
|
123 |
|
|
124 |
}
|
|
125 |
|
|
126 |
/**
|
|
127 |
*
|
|
128 |
* Test step Postamble.
|
|
129 |
* destroys the tone utility
|
|
130 |
*
|
|
131 |
*/
|
|
132 |
enum TVerdict CTestStepTonePrepareToPlayDualTonePlay::DoTestStepPostambleL(void)
|
|
133 |
{
|
|
134 |
delete iTone;
|
|
135 |
iTone = NULL;
|
|
136 |
|
|
137 |
__MM_HEAP_MARKEND;
|
|
138 |
|
|
139 |
//[ Destroy the scheduler ]
|
|
140 |
return CTestStepUnitMMFAudClient::DoTestStepPostambleL();
|
|
141 |
}
|
|
142 |
|
|
143 |
class TDualTone
|
|
144 |
{
|
|
145 |
public:
|
|
146 |
TInt iFreq1;
|
|
147 |
TInt iFreq2;
|
|
148 |
};
|
|
149 |
|
|
150 |
const TDualTone KDtmfToneTable[] =
|
|
151 |
{
|
|
152 |
{941, 1336},//0
|
|
153 |
{697, 1209},//1
|
|
154 |
{697, 1336},//2
|
|
155 |
{697, 1477},//3
|
|
156 |
{770, 1209},//4
|
|
157 |
{770, 1336},//5
|
|
158 |
{770, 1477},//6
|
|
159 |
{852, 1209},//7
|
|
160 |
{852, 1336},//8
|
|
161 |
{852, 1477},//9
|
|
162 |
|
|
163 |
{697, 1633},//A
|
|
164 |
{770, 1633},//B
|
|
165 |
{852, 1633},//C
|
|
166 |
{941, 1633},//D
|
|
167 |
{941, 1209},//E or *
|
|
168 |
{941, 1477},//F or #
|
|
169 |
{0, 0} // pause
|
|
170 |
};
|
|
171 |
|
|
172 |
|
|
173 |
_LIT(KTwinkleDTMFString,"1 1 9 9 # # 9-6 6 3 3 2 2 1-9 9 6 6 3 3 2-9 9 6 6 3 3 2-1 1 9 9 # # 9-6 6 3 3 2 2 1-");
|
|
174 |
|
|
175 |
const TInt KQuarterNote = 256000;
|
|
176 |
const TInt KHalfNote = 512000;
|
|
177 |
const TInt KEighthNote = 128000;
|
|
178 |
const TInt KSixteenthNote = 64000;
|
|
179 |
|
|
180 |
|
|
181 |
/**
|
|
182 |
* convert a DTMF string into an array of TToneInfo
|
|
183 |
*/
|
|
184 |
TInt CTestStepTonePrepareToPlayDualTonePlay::GetTune(const TDesC& aDtmfString, RArray<TToneInfo>& aTones)
|
|
185 |
{
|
|
186 |
TInt count = aDtmfString.Length();
|
|
187 |
for (TInt index=0; index<count; )
|
|
188 |
{
|
|
189 |
TInt tableIndex;
|
|
190 |
TInt c = (aDtmfString)[index++];
|
|
191 |
if (c >= '0' && c <= '9')
|
|
192 |
tableIndex = c - '0';
|
|
193 |
else if (c >= 'A' && c <= 'F')
|
|
194 |
tableIndex = c - 'A' + 10;
|
|
195 |
else if (c == '*')
|
|
196 |
tableIndex = 14;
|
|
197 |
else if (c == '#')
|
|
198 |
tableIndex = 15;
|
|
199 |
else if (c == ',') // pause ?
|
|
200 |
tableIndex = 16;
|
|
201 |
else
|
|
202 |
return KErrArgument;
|
|
203 |
|
|
204 |
TToneInfo tone;
|
|
205 |
tone.iFreq1 = KDtmfToneTable[tableIndex].iFreq1;
|
|
206 |
tone.iFreq2 = KDtmfToneTable[tableIndex].iFreq2;
|
|
207 |
|
|
208 |
c = (aDtmfString)[index++];
|
|
209 |
if (c == ' ')
|
|
210 |
tone.iDuration = KQuarterNote;
|
|
211 |
else if (c == '-')
|
|
212 |
tone.iDuration = KHalfNote;
|
|
213 |
else if (c == '+')
|
|
214 |
tone.iDuration = KEighthNote;
|
|
215 |
else if (c == '%')
|
|
216 |
tone.iDuration = KSixteenthNote;
|
|
217 |
else
|
|
218 |
return KErrArgument;
|
|
219 |
aTones.Append(tone);
|
|
220 |
}
|
|
221 |
return KErrNone;
|
|
222 |
}
|
|
223 |
|
|
224 |
/**
|
|
225 |
*
|
|
226 |
* Do the test step.
|
|
227 |
* Each test step must supply an implementation for DoTestStepL.
|
|
228 |
*
|
|
229 |
* @return "TVerdict"
|
|
230 |
* The result of the test step
|
|
231 |
*
|
|
232 |
* @xxxx
|
|
233 |
*
|
|
234 |
*/
|
|
235 |
TVerdict CTestStepTonePrepareToPlayDualTonePlay::DoTestStepL()
|
|
236 |
{
|
|
237 |
iTestStepResult = EPass;
|
|
238 |
|
|
239 |
RArray<TToneInfo> tones;
|
|
240 |
|
|
241 |
// This test plays "twinkle twinkle little star"
|
|
242 |
// by converting a DTMF sequence into an array of dualtones
|
|
243 |
// (i.e. frequency pairs) and then calling PrepareToPlayDualTone()
|
|
244 |
// for each dualtone
|
|
245 |
TInt error = GetTune(*(&KTwinkleDTMFString), tones);
|
|
246 |
if (error != KErrNone)
|
|
247 |
return EInconclusive;
|
|
248 |
|
|
249 |
for (TInt index=0; index<tones.Count(); index++)
|
|
250 |
{
|
|
251 |
TToneInfo tone = tones[index];
|
|
252 |
|
|
253 |
INFO_PRINTF4(_L("playing dual tone of %d Hz & %d Hz for %f seconds"),
|
|
254 |
tone.iFreq1, tone.iFreq2, ((TReal32)tone.iDuration)/1000000);
|
|
255 |
|
|
256 |
// if the frequency is zero, then pause i.e don't play a note
|
|
257 |
if (tone.iFreq1 != 0)
|
|
258 |
{
|
|
259 |
iTone->PrepareToPlayDualTone(tone.iFreq1, tone.iFreq2, TTimeIntervalMicroSeconds(tone.iDuration));
|
|
260 |
CActiveScheduler::Start();
|
|
261 |
|
|
262 |
if (iError != KErrNone || iTone->State() != EMdaAudioToneUtilityPrepared )
|
|
263 |
return EInconclusive;
|
|
264 |
|
|
265 |
iTone->Play();
|
|
266 |
if (iTone->State() == EMdaAudioToneUtilityPlaying)
|
|
267 |
iHasPlayed = ETrue;
|
|
268 |
CActiveScheduler::Start();
|
|
269 |
if (iError != KErrNone || !iHasPlayed)
|
|
270 |
return EFail;
|
|
271 |
iTone->CancelPrepare();
|
|
272 |
}
|
|
273 |
|
|
274 |
User::After(125000);
|
|
275 |
}
|
|
276 |
|
|
277 |
tones.Close();
|
|
278 |
|
|
279 |
INFO_PRINTF1(_L("finished with this test step"));
|
|
280 |
// test steps return a result
|
|
281 |
return iTestStepResult;
|
|
282 |
}
|
|
283 |
|