|
1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation for test cases. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32math.h> |
|
20 #include <aknsoundsystem.h> |
|
21 #include <aknappui.h> |
|
22 #include <s32mem.h> |
|
23 #include <eikkeysound.h> |
|
24 #include <avkon.rsg> |
|
25 |
|
26 #include "aknsoundserverstiftest.h" |
|
27 #include "aknsoundserversession.h" |
|
28 #include "eiksrvsoundserversession.h" |
|
29 |
|
30 // Fail code used as a default, if no error code is available. |
|
31 const TInt KDefaultFailCode = -999; |
|
32 |
|
33 // Sound server session UIDs taken from test range (0xE0000000...0xEFFFFFFF). |
|
34 const TInt KSession1Uid = 0xE2220001; |
|
35 const TInt KSession2Uid = 0xE2220002; |
|
36 |
|
37 // Fake resource ids taken from test range (0xE0000000...0xEFFFFFFF). |
|
38 #define R_STIFTEST_SOUND_CONTEXT_1 0xE1110001 |
|
39 #define R_STIFTEST_SOUND_CONTEXT_2 0xE1110002 |
|
40 |
|
41 // TestModuleIf().Printf() seems to work better with a small delay. |
|
42 const TInt KPrintDelay = 100000; |
|
43 |
|
44 // Test case names. |
|
45 _LIT(KTestCaseInit, "'Init keysound server'"); |
|
46 _LIT(KTestCasePlayKey, "'Play keysound'"); |
|
47 _LIT(KTestCasePlayKeyAsync, "'Play keysound (async)'"); |
|
48 _LIT(KTestCasePlaySid, "'Play sid'"); |
|
49 _LIT(KTestCaseStopCurrentTone, "'Stop current tone'"); |
|
50 _LIT(KTestCaseAddSids, "'Add sids'"); |
|
51 _LIT(KTestCasePushContext, "'Push context'"); |
|
52 _LIT(KTestCaseLockContext, "'Lock context'"); |
|
53 _LIT(KTestCaseCloseServer, "'Close server'"); |
|
54 |
|
55 // Generic test case texts. |
|
56 _LIT(KTestPassed, "Test case passed"); |
|
57 _LIT(KTestFailed, "Test case failed"); |
|
58 _LIT(KBegin, "Begin"); |
|
59 _LIT(KEnd, "End"); |
|
60 |
|
61 // Error texts. |
|
62 _LIT(KInitFailed, "Init() failed"); |
|
63 _LIT(KConnectFailed, "Connect() failed"); |
|
64 _LIT(KInvalidTRequestStatus, "Invalid TRequestStatus"); |
|
65 _LIT(KFirstTopContextWrong, "First TopContext() wrong"); |
|
66 _LIT(KSecondTopContextWrong, "Second TopContext() wrong"); |
|
67 _LIT(KThirdTopContextWrong, "Third TopContext() wrong"); |
|
68 _LIT(KFourthTopContextWrong, "Fourth TopContext() wrong"); |
|
69 _LIT(KFifthTopContextWrong, "Fifth TopContext() wrong"); |
|
70 _LIT(KSixthTopContextWrong, "Sixth TopContext() wrong"); |
|
71 _LIT(KInvalidReturnValue, "Return value not KErrPermissionDenied"); |
|
72 |
|
73 // Other texts |
|
74 _LIT(KPlayingKeyClick, "Playing key click"); |
|
75 _LIT(KPlayingErrorTone, "Playing error tone"); |
|
76 _LIT(KBatteryLowStopped, "Battery low stopped"); |
|
77 _LIT(KPlayingSid, "Playing sid:"); |
|
78 _LIT(KSidId, "0x%x"); |
|
79 _LIT(KPlayingFinished, "Playing finished"); |
|
80 _LIT(KPressingKey, "Pressing key:"); |
|
81 _LIT(KKeyId, "%d" ); |
|
82 _LIT(KFinished, "Finished"); |
|
83 |
|
84 // ============================ MEMBER FUNCTIONS =============================== |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CAknSoundServerStifTest::Case |
|
88 // Returns a test case by number. |
|
89 // |
|
90 // This function contains an array of all available test cases |
|
91 // i.e pair of case name and test function. If case specified by parameter |
|
92 // aCaseNumber is found from array, then that item is returned. |
|
93 // |
|
94 // The reason for this rather complicated function is to specify all the |
|
95 // test cases only in one place. It is not necessary to understand how |
|
96 // function pointers to class member functions works when adding new test |
|
97 // cases. See function body for instructions how to add new test case. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 const TCaseInfo CAknSoundServerStifTest::Case ( |
|
101 const TInt aCaseNumber ) const |
|
102 { |
|
103 /** |
|
104 * To add new test cases, implement new test case function and add new |
|
105 * line to KCases array specify the name of the case and the function |
|
106 * doing the test case |
|
107 * In practice, do following |
|
108 * 1) Make copy of existing test case function and change its name |
|
109 * and functionality. Note that the function must be added to |
|
110 * AknSoundServerStifTest.cpp file and to AknSoundServerStifTest.h |
|
111 * header file. |
|
112 * |
|
113 * 2) Add entry to following KCases array either by using: |
|
114 * |
|
115 * 2.1: FUNCENTRY or ENTRY macro |
|
116 * ENTRY macro takes two parameters: test case name and test case |
|
117 * function name. |
|
118 * |
|
119 * FUNCENTRY macro takes only test case function name as a parameter and |
|
120 * uses that as a test case name and test case function name. |
|
121 * |
|
122 * Or |
|
123 * |
|
124 * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used |
|
125 * only with OOM (Out-Of-Memory) testing! |
|
126 * |
|
127 * OOM_ENTRY macro takes five parameters: test case name, test case |
|
128 * function name, TBool which specifies is method supposed to be run using |
|
129 * OOM conditions, TInt value for first heap memory allocation failure and |
|
130 * TInt value for last heap memory allocation failure. |
|
131 * |
|
132 * OOM_FUNCENTRY macro takes test case function name as a parameter and uses |
|
133 * that as a test case name, TBool which specifies is method supposed to be |
|
134 * run using OOM conditions, TInt value for first heap memory allocation |
|
135 * failure and TInt value for last heap memory allocation failure. |
|
136 */ |
|
137 |
|
138 static TCaseInfoInternal const KCases[] = |
|
139 { |
|
140 // To add new test cases, add new items to this array |
|
141 |
|
142 // NOTE: When compiled to GCCE, there must be Classname:: |
|
143 // declaration in front of the method name, e.g. |
|
144 // CAknSoundServerStifTest::PrintTest. Otherwise the compiler |
|
145 // gives errors. |
|
146 |
|
147 // enum TKeySoundServerCommands |
|
148 // { |
|
149 // EKeySoundServerInit, TestCaseInit() |
|
150 // EKeySoundServerPlayKey, TestCasePlayKey() |
|
151 // EKeySoundServerPlaySID, TestCasePlaySid() |
|
152 // EKeySoundServerAddSIDS, TestCaseAddSidsL() |
|
153 // EKeySoundServerRemoveSIDS, None. (Command is unused and should be removed!) |
|
154 // EKeySoundServerPushContext, TestCasePushContextL() |
|
155 // EKeySoundServerPopContext, TestCasePushContextL() |
|
156 // EKeySoundServerBringToForeground, TestCasePushContextL() |
|
157 // EKeySoundServerStopCurrentTone, TestCaseStopCurrentTone() |
|
158 // EKeySoundServerLockContext, TestCaseLockContextL() |
|
159 // EKeySoundServerReleaseContext, TestCaseLockContextL() |
|
160 // EKeySoundServerCloseServer, TestCaseCloseServerL() |
|
161 // EKeySoundServerTopContext TestCasePushContextL() |
|
162 // }; |
|
163 |
|
164 ENTRY("Init keysound server", CAknSoundServerStifTest::TestCaseInit), |
|
165 ENTRY("Play keysound", CAknSoundServerStifTest::TestCasePlayKey), |
|
166 ENTRY("Play keysound (async)", CAknSoundServerStifTest::TestCasePlayKeyAsync), |
|
167 ENTRY("Play sid", CAknSoundServerStifTest::TestCasePlaySid), |
|
168 ENTRY("Stop current tone", CAknSoundServerStifTest::TestCaseStopCurrentTone), |
|
169 ENTRY("Add sids", CAknSoundServerStifTest::TestCaseAddSidsL), |
|
170 ENTRY("Push context", CAknSoundServerStifTest::TestCasePushContextL), |
|
171 ENTRY("Lock context", CAknSoundServerStifTest::TestCaseLockContextL), |
|
172 ENTRY("Close server", CAknSoundServerStifTest::TestCaseCloseServer) |
|
173 }; |
|
174 |
|
175 // Verify that case number is valid |
|
176 if( (TUint) aCaseNumber >= sizeof( KCases ) / |
|
177 sizeof( TCaseInfoInternal ) ) |
|
178 { |
|
179 // Invalid case, construct empty object |
|
180 TCaseInfo null( (const TText*) L"" ); |
|
181 null.iMethod = NULL; |
|
182 null.iIsOOMTest = EFalse; |
|
183 null.iFirstMemoryAllocation = 0; |
|
184 null.iLastMemoryAllocation = 0; |
|
185 return null; |
|
186 } |
|
187 |
|
188 // Construct TCaseInfo object and return it |
|
189 TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName ); |
|
190 tmp.iMethod = KCases[ aCaseNumber ].iMethod; |
|
191 tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest; |
|
192 tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation; |
|
193 tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation; |
|
194 return tmp; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CAknSoundServerStifTest::TestCaseInit() |
|
199 // Creates and initializes a connection to Keysound Server. |
|
200 // Test case for server command "EKeySoundServerInit". |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CAknSoundServerStifTest::TestCaseInit(TTestResult& aResult) |
|
204 { |
|
205 // Default result is fail. |
|
206 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
207 |
|
208 // Start test. |
|
209 PrintWithDelay(0, KBegin, KTestCaseInit); |
|
210 |
|
211 RAknSoundServerSession session; |
|
212 TInt err = session.Connect(); |
|
213 |
|
214 if (!err) |
|
215 { |
|
216 // The application UID should be given as a parameter for Init(). |
|
217 // However, we are already using that UID for iSoundServerSession |
|
218 // and don't want to use it twice. |
|
219 TBool init = session.Init(KSession1Uid); |
|
220 |
|
221 if(init) |
|
222 { |
|
223 // Test case passed. |
|
224 aResult.SetResult(KErrNone, KTestPassed); |
|
225 } |
|
226 else |
|
227 { |
|
228 aResult.SetResult(KDefaultFailCode, KInitFailed); |
|
229 } |
|
230 } |
|
231 else |
|
232 { |
|
233 aResult.SetResult(err, KConnectFailed); |
|
234 } |
|
235 |
|
236 session.Close(); |
|
237 |
|
238 // End test. |
|
239 PrintWithDelay(0, KEnd, KTestCaseInit); |
|
240 |
|
241 // Case was executed |
|
242 return KErrNone; |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CAknSoundServerStifTest::TestCasePlayKey() |
|
247 // Plays a keysound. |
|
248 // Test case for server command "EKeySoundServerPlayKey". |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 TInt CAknSoundServerStifTest::TestCasePlayKey(TTestResult& aResult) |
|
252 { |
|
253 // Default result is fail. |
|
254 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
255 |
|
256 // Start test. |
|
257 PrintWithDelay(0, KBegin, KTestCasePlayKey); |
|
258 |
|
259 RAknSoundServerSession session = CreateNewSessionL(KSession1Uid); |
|
260 |
|
261 // Execute step 1. |
|
262 session.KeyPressed(EStdKeyDownArrow, EFalse); |
|
263 |
|
264 PrintWithDelay(0, KNullDesC, KPlayingKeyClick); |
|
265 |
|
266 // Test case passed (unfortunately there is no means to really ensure it). |
|
267 aResult.SetResult(KErrNone, KTestPassed); |
|
268 |
|
269 session.Close(); |
|
270 |
|
271 // End test. |
|
272 PrintWithDelay(0, KEnd, KTestCasePlayKey); |
|
273 |
|
274 // Case was executed |
|
275 return KErrNone; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CAknSoundServerStifTest::TestCasePlayKeyAsync() |
|
280 // Plays a keysound asynchronously. |
|
281 // Test case for server command "EKeySoundServerPlayKey". |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 TInt CAknSoundServerStifTest::TestCasePlayKeyAsync(TTestResult& aResult) |
|
285 { |
|
286 // Default result is fail. |
|
287 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
288 |
|
289 // Start test. |
|
290 PrintWithDelay(0, KBegin, KTestCasePlayKeyAsync); |
|
291 |
|
292 // Note that REikSrvSoundServerSession is used instead of RAknSoundServerSession. |
|
293 REikSrvSoundServerSession session; |
|
294 User::LeaveIfError(session.Connect()); |
|
295 |
|
296 // Session must be initialised. |
|
297 session.Init(KSession1Uid); |
|
298 |
|
299 PrintWithDelay(0, KNullDesC, KPlayingKeyClick); |
|
300 |
|
301 TRequestStatus status; |
|
302 session.KeyPressed(EStdKeyDownArrow, status, EFalse); |
|
303 User::WaitForRequest(status); |
|
304 |
|
305 if(status.Int() == KErrNone) |
|
306 { |
|
307 // Test case passed. |
|
308 aResult.SetResult(KErrNone, KTestPassed); |
|
309 } |
|
310 else |
|
311 { |
|
312 aResult.SetResult(status.Int(), KInvalidTRequestStatus); |
|
313 } |
|
314 |
|
315 session.Close(); |
|
316 |
|
317 // End test. |
|
318 PrintWithDelay(0, KEnd, KTestCasePlayKeyAsync); |
|
319 |
|
320 // Case was executed |
|
321 return KErrNone; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CAknSoundServerStifTest::TestCasePlaySid() |
|
326 // Plays a sid. |
|
327 // Test case for server command "EKeySoundServerPlaySID". |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 TInt CAknSoundServerStifTest::TestCasePlaySid(TTestResult& aResult) |
|
331 { |
|
332 // Default result is fail. |
|
333 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
334 |
|
335 // Start test. |
|
336 PrintWithDelay(0, KBegin, KTestCasePlaySid); |
|
337 |
|
338 RAknSoundServerSession session = CreateNewSessionL(KSession1Uid); |
|
339 |
|
340 session.PlaySound(EAvkonSIDErrorTone); |
|
341 |
|
342 PrintWithDelay(0, KNullDesC, KPlayingErrorTone); |
|
343 |
|
344 // Test case passed (unfortunately there is no means to really ensure it). |
|
345 aResult.SetResult(KErrNone, KTestPassed); |
|
346 |
|
347 session.Close(); |
|
348 |
|
349 // End test. |
|
350 PrintWithDelay(0, KEnd, KTestCasePlaySid); |
|
351 |
|
352 // Case was executed |
|
353 return KErrNone; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CAknSoundServerStifTest::TestCaseStopCurrentTone() |
|
358 // Stops a playing sid. |
|
359 // Test case for server command "EKeySoundServerStopCurrentTone". |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 TInt CAknSoundServerStifTest::TestCaseStopCurrentTone(TTestResult& aResult) |
|
363 { |
|
364 // Default result is fail. |
|
365 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
366 |
|
367 // Start test. |
|
368 PrintWithDelay(0, KBegin, KTestCaseStopCurrentTone); |
|
369 |
|
370 RAknSoundServerSession session = CreateNewSessionL(KSession1Uid); |
|
371 |
|
372 session.PlaySound(EAvkonSIDBatteryLowTone); |
|
373 |
|
374 // Small delay for checking that the tone starts playing. |
|
375 User::After(300000); |
|
376 |
|
377 session.StopSound(EAvkonSIDBatteryLowTone); |
|
378 |
|
379 PrintWithDelay(0, KNullDesC, KBatteryLowStopped); |
|
380 |
|
381 // Test case passed (unfortunately there is no means to really ensure it). |
|
382 aResult.SetResult(KErrNone, KTestPassed); |
|
383 |
|
384 session.Close(); |
|
385 |
|
386 // End test. |
|
387 PrintWithDelay(0, KEnd, KTestCaseStopCurrentTone); |
|
388 |
|
389 // Case was executed |
|
390 return KErrNone; |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // CAknSoundServerStifTest::TestCaseAddSidsL() |
|
395 // Adds sids. |
|
396 // Test case for server command "EKeySoundServerAddSIDS". |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 TInt CAknSoundServerStifTest::TestCaseAddSidsL(TTestResult& aResult) |
|
400 { |
|
401 // Default result is fail. |
|
402 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
403 |
|
404 // Start test. |
|
405 PrintWithDelay(0, KBegin, KTestCaseAddSids); |
|
406 |
|
407 RAknSoundServerSession session = CreateNewSessionL(KSession1Uid); |
|
408 |
|
409 // Simulate resource reading for the following resource: |
|
410 // |
|
411 // RESOURCE AVKON_SOUND_INFO_LIST r_keysoundapp_sound_list |
|
412 // { |
|
413 // list = |
|
414 // { |
|
415 // AVKON_SOUND_INFO {sid=1; frequency=300; ms=600000;}, |
|
416 // AVKON_SOUND_INFO {sid=2; frequency=600; ms=700000;}, |
|
417 // AVKON_SOUND_INFO {sid=3; frequency=900; ms=800000;}, |
|
418 // AVKON_SOUND_INFO {sid=4; frequency=1200; ms=900000;} |
|
419 // }; |
|
420 // } |
|
421 // |
|
422 const TInt KAknResourceBufferSize = 512; |
|
423 |
|
424 // Package information to a buffer. |
|
425 CBufFlat* buffer = CBufFlat::NewL(KAknResourceBufferSize); |
|
426 CleanupStack::PushL(buffer); |
|
427 |
|
428 RBufWriteStream bufStream; |
|
429 bufStream.Open(*buffer); |
|
430 |
|
431 CleanupClosePushL(bufStream); |
|
432 |
|
433 // Take lowest 16 bits from KSession1Uid... |
|
434 TInt soundId = (KSession1Uid << 16); |
|
435 |
|
436 // Count |
|
437 bufStream.WriteUint16L(4); // count |
|
438 |
|
439 // AVKON_SOUND_INFO 1 |
|
440 bufStream.WriteUint32L(soundId + 1); // soundId |
|
441 bufStream.WriteUint16L(EAvkonLowLevelNotesPriority); // priority |
|
442 bufStream.WriteUint32L(EAknAudioPrefDefaultTone); // preference |
|
443 bufStream.WriteUint8L(1); // type 1, tone |
|
444 bufStream.WriteUint16L(300); // frequency |
|
445 bufStream.WriteUint32L(600000); // ms |
|
446 bufStream.WriteUint8L(9); // volume |
|
447 |
|
448 // AVKON_SOUND_INFO 2 |
|
449 bufStream.WriteUint32L(soundId + 2); // soundId |
|
450 bufStream.WriteUint16L(EAvkonLowLevelNotesPriority); // priority |
|
451 bufStream.WriteUint32L(EAknAudioPrefDefaultTone); // preference |
|
452 bufStream.WriteUint8L(1); // type 1, tone |
|
453 bufStream.WriteUint16L(600); // frequency |
|
454 bufStream.WriteUint32L(700000); // ms |
|
455 bufStream.WriteUint8L(9); // volume |
|
456 |
|
457 // AVKON_SOUND_INFO 3 |
|
458 bufStream.WriteUint32L(soundId + 3); // soundId |
|
459 bufStream.WriteUint16L(EAvkonLowLevelNotesPriority); // priority |
|
460 bufStream.WriteUint32L(EAknAudioPrefDefaultTone); // preference |
|
461 bufStream.WriteUint8L(1); // type 1, tone |
|
462 bufStream.WriteUint16L(900); // frequency |
|
463 bufStream.WriteUint32L(800000); // ms |
|
464 bufStream.WriteUint8L(9); // volume |
|
465 |
|
466 // AVKON_SOUND_INFO 4 |
|
467 bufStream.WriteUint32L(soundId + 4); // soundId |
|
468 bufStream.WriteUint16L(EAvkonLowLevelNotesPriority); // priority |
|
469 bufStream.WriteUint32L(EAknAudioPrefDefaultTone); // preference |
|
470 bufStream.WriteUint8L(1); // type 1, tone |
|
471 bufStream.WriteUint16L(1200); // frequency |
|
472 bufStream.WriteUint32L(900000); // ms |
|
473 bufStream.WriteUint8L(9); // volume |
|
474 |
|
475 CleanupStack::PopAndDestroy(); // bufstream close |
|
476 |
|
477 TPtr8 bufPtr = buffer->Ptr(0); |
|
478 TIpcArgs args (KSession1Uid, bufPtr.Length(), &bufPtr); |
|
479 User::LeaveIfError(session.ServerRequest(EKeySoundServerAddSIDS, args)); |
|
480 |
|
481 CleanupStack::PopAndDestroy(); // buffer |
|
482 |
|
483 // Wait for keyclick playing before starting actual test playings. |
|
484 User::After(500000); |
|
485 |
|
486 for (TInt i = 1; i < 5; i++) |
|
487 { |
|
488 session.PlaySound(soundId + i); |
|
489 TestModuleIf().Printf(0, KPlayingSid, KSidId, soundId + i); |
|
490 User::After(1000000); |
|
491 } |
|
492 |
|
493 PrintWithDelay(0, KPlayingFinished, KNullDesC); |
|
494 |
|
495 // Test case passed (unfortunately there is no means to really ensure it). |
|
496 aResult.SetResult(KErrNone, KTestPassed); |
|
497 |
|
498 session.Close(); |
|
499 |
|
500 // End test. |
|
501 PrintWithDelay(0, KEnd, KTestCaseAddSids); |
|
502 |
|
503 // Case was executed |
|
504 return KErrNone; |
|
505 } |
|
506 |
|
507 // ----------------------------------------------------------------------------- |
|
508 // CAknSoundServerStifTest::TestCasePushContextL() |
|
509 // |
|
510 // Test case for following server commands: |
|
511 // "EKeySoundServerPushContext" |
|
512 // "EKeySoundServerBringToForeground" |
|
513 // "EKeySoundServerTopContext" |
|
514 // "EKeySoundServerPopContext" |
|
515 // ----------------------------------------------------------------------------- |
|
516 // |
|
517 TInt CAknSoundServerStifTest::TestCasePushContextL(TTestResult& aResult) |
|
518 { |
|
519 // Default result is fail. |
|
520 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
521 |
|
522 // Start test. |
|
523 PrintWithDelay(0, KBegin, KTestCasePushContext); |
|
524 |
|
525 RAknSoundServerSession session = CreateNewSessionL(KSession1Uid); |
|
526 |
|
527 // Step 1 |
|
528 if (session.TopContext() != R_AVKON_DEFAULT_SKEY_LIST) |
|
529 { |
|
530 // Test case failed. |
|
531 aResult.SetResult(KDefaultFailCode, KFirstTopContextWrong); |
|
532 |
|
533 session.Close(); |
|
534 return KErrNone; |
|
535 } |
|
536 |
|
537 // Step 2 |
|
538 PushContextL(session, R_STIFTEST_SOUND_CONTEXT_1, KSession1Uid); |
|
539 |
|
540 // Step 3 |
|
541 session.BringToForeground(); |
|
542 |
|
543 // Step 4 |
|
544 if (session.TopContext() != R_STIFTEST_SOUND_CONTEXT_1) |
|
545 { |
|
546 // Test case failed. |
|
547 aResult.SetResult(KDefaultFailCode, KSecondTopContextWrong); |
|
548 |
|
549 session.Close(); |
|
550 return KErrNone; |
|
551 } |
|
552 |
|
553 // Wait for keyclick playing before starting actual test playings. |
|
554 User::After(500000); |
|
555 |
|
556 // Step 5 (simulate key presses to play sounds) |
|
557 for (TInt i = 1; i < 4; i++) |
|
558 { |
|
559 // Ascii characters '1' = 49, '2' = 50 and '3' = 51. |
|
560 session.KeyPressed(48 + i, EFalse); |
|
561 TestModuleIf().Printf(0, KPressingKey, KKeyId, i); |
|
562 User::After(1500000); |
|
563 } |
|
564 |
|
565 PrintWithDelay(0, KFinished, KNullDesC); |
|
566 |
|
567 // Step 6 |
|
568 session.PopContext(); |
|
569 |
|
570 // Step 7 |
|
571 if (session.TopContext() != R_AVKON_DEFAULT_SKEY_LIST) |
|
572 { |
|
573 // Test case failed. |
|
574 aResult.SetResult(KDefaultFailCode, KThirdTopContextWrong); |
|
575 |
|
576 session.Close(); |
|
577 return KErrNone; |
|
578 } |
|
579 |
|
580 // Test case passed. |
|
581 aResult.SetResult(KErrNone, KTestPassed); |
|
582 |
|
583 session.Close(); |
|
584 |
|
585 // Without this the keysounds of STIF application itself would get broken. |
|
586 iSoundServerSession.BringToForeground(); |
|
587 |
|
588 // End test. |
|
589 PrintWithDelay(0, KEnd, KTestCasePushContext); |
|
590 |
|
591 // Case was executed |
|
592 return KErrNone; |
|
593 } |
|
594 |
|
595 // ----------------------------------------------------------------------------- |
|
596 // CAknSoundServerStifTest::TestCaseLockContextL() |
|
597 // |
|
598 // Test case for following server commands: |
|
599 // "EKeySoundServerLockContext" |
|
600 // "EKeySoundServerReleaseContext" |
|
601 // ----------------------------------------------------------------------------- |
|
602 // |
|
603 TInt CAknSoundServerStifTest::TestCaseLockContextL(TTestResult& aResult) |
|
604 { |
|
605 // Default result is fail. |
|
606 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
607 |
|
608 // Start test. |
|
609 PrintWithDelay(0, KBegin, KTestCaseLockContext); |
|
610 |
|
611 // ------------------------------------------------------- |
|
612 // In this test case we need two keysound server sessions. |
|
613 // ------------------------------------------------------- |
|
614 RAknSoundServerSession session1 = CreateNewSessionL(KSession1Uid); |
|
615 RAknSoundServerSession session2 = CreateNewSessionL(KSession2Uid); |
|
616 |
|
617 // Step 1 |
|
618 PushContextL(session1, R_STIFTEST_SOUND_CONTEXT_1, KSession1Uid); |
|
619 |
|
620 // Step 2 |
|
621 session1.BringToForeground(); |
|
622 |
|
623 // Step 3 |
|
624 session1.LockContext(); |
|
625 |
|
626 // Step 4 |
|
627 if (session1.TopContext() != R_STIFTEST_SOUND_CONTEXT_1) |
|
628 { |
|
629 // Test case failed. |
|
630 aResult.SetResult(KDefaultFailCode, KFirstTopContextWrong); |
|
631 |
|
632 session1.Close(); |
|
633 session2.Close(); |
|
634 return KErrNone; |
|
635 } |
|
636 |
|
637 // Step 5 (change to session2) |
|
638 if (session2.TopContext() != R_STIFTEST_SOUND_CONTEXT_1) |
|
639 { |
|
640 // Test case failed. |
|
641 aResult.SetResult(KDefaultFailCode, KSecondTopContextWrong); |
|
642 |
|
643 session1.Close(); |
|
644 session2.Close(); |
|
645 return KErrNone; |
|
646 } |
|
647 |
|
648 // Step 6 |
|
649 PushContextL(session2, R_STIFTEST_SOUND_CONTEXT_2, KSession2Uid); |
|
650 |
|
651 // Step 7 |
|
652 session2.BringToForeground(); |
|
653 |
|
654 // Step 8 |
|
655 if (session2.TopContext() != R_STIFTEST_SOUND_CONTEXT_1) |
|
656 { |
|
657 // Test case failed. |
|
658 aResult.SetResult(KDefaultFailCode, KThirdTopContextWrong); |
|
659 |
|
660 session1.Close(); |
|
661 session2.Close(); |
|
662 return KErrNone; |
|
663 } |
|
664 |
|
665 // Step 9 |
|
666 session2.PopContext(); |
|
667 |
|
668 // Step 10 |
|
669 if (session2.TopContext() != R_STIFTEST_SOUND_CONTEXT_1) |
|
670 { |
|
671 // Test case failed. |
|
672 aResult.SetResult(KDefaultFailCode, KFourthTopContextWrong); |
|
673 |
|
674 session1.Close(); |
|
675 session2.Close(); |
|
676 return KErrNone; |
|
677 } |
|
678 |
|
679 // Step 11 (change back to session1) |
|
680 if (session1.TopContext() != R_STIFTEST_SOUND_CONTEXT_1) |
|
681 { |
|
682 // Test case failed. |
|
683 aResult.SetResult(KDefaultFailCode, KFifthTopContextWrong); |
|
684 |
|
685 session1.Close(); |
|
686 session2.Close(); |
|
687 return KErrNone; |
|
688 } |
|
689 |
|
690 // Step 12 |
|
691 session1.ReleaseContext(); |
|
692 |
|
693 // Step 13 |
|
694 session1.PopContext(); |
|
695 |
|
696 // Step 14 |
|
697 if (session1.TopContext() != R_AVKON_DEFAULT_SKEY_LIST) |
|
698 { |
|
699 // Test case failed. |
|
700 aResult.SetResult(KDefaultFailCode, KSixthTopContextWrong); |
|
701 |
|
702 session1.Close(); |
|
703 session2.Close(); |
|
704 return KErrNone; |
|
705 } |
|
706 |
|
707 // Test case passed. |
|
708 aResult.SetResult(KErrNone, KTestPassed); |
|
709 |
|
710 session1.Close(); |
|
711 session2.Close(); |
|
712 |
|
713 // Without this the keysounds of STIF application itself would get broken. |
|
714 iSoundServerSession.BringToForeground(); |
|
715 |
|
716 // End test. |
|
717 PrintWithDelay(0, KEnd, KTestCaseLockContext); |
|
718 |
|
719 // Case was executed |
|
720 return KErrNone; |
|
721 } |
|
722 |
|
723 // ----------------------------------------------------------------------------- |
|
724 // CAknSoundServerStifTest::TestCaseCloseServer() |
|
725 // Tries to close the keysound server. Call should fail with KErrPermissionDenied. |
|
726 // Test case for server command "EKeySoundServerCloseServer". |
|
727 // ----------------------------------------------------------------------------- |
|
728 // |
|
729 TInt CAknSoundServerStifTest::TestCaseCloseServer(TTestResult& aResult) |
|
730 { |
|
731 // Default result is fail. |
|
732 aResult.SetResult(KDefaultFailCode, KTestFailed); |
|
733 |
|
734 // Start test. |
|
735 PrintWithDelay(0, KBegin, KTestCaseCloseServer); |
|
736 |
|
737 RAknSoundServerSession session = CreateNewSessionL(KSession1Uid); |
|
738 |
|
739 // Make a direct server request. There is no method for calling close server. |
|
740 TInt err = session.ServerRequest(EKeySoundServerCloseServer, TIpcArgs()); |
|
741 |
|
742 // Only calls from eiksrvs process should be accepted, so KErrPermissionDenied |
|
743 // is the expected result. |
|
744 if (err == KErrPermissionDenied) |
|
745 { |
|
746 // Test case passed. |
|
747 aResult.SetResult(KErrNone, KTestPassed); |
|
748 } |
|
749 else |
|
750 { |
|
751 aResult.SetResult(KDefaultFailCode, KInvalidReturnValue); |
|
752 } |
|
753 |
|
754 session.Close(); |
|
755 |
|
756 // End test. |
|
757 PrintWithDelay(0, KEnd, KTestCaseCloseServer); |
|
758 |
|
759 // Case was executed |
|
760 return KErrNone; |
|
761 } |
|
762 |
|
763 // ----------------------------------------------------------------------------- |
|
764 // CAknSoundServerStifTest::CreateNewSessionL() |
|
765 // Convenience method for creating a new keysound server session. |
|
766 // ----------------------------------------------------------------------------- |
|
767 // |
|
768 RAknSoundServerSession CAknSoundServerStifTest::CreateNewSessionL(TInt aSessionUid) |
|
769 { |
|
770 RAknSoundServerSession session; |
|
771 User::LeaveIfError(session.Connect()); |
|
772 |
|
773 // Connection succeeded, call Init(). |
|
774 TInt init = session.Init(aSessionUid); |
|
775 if (!init) |
|
776 { |
|
777 // Initialisation failed. Close session and leave. |
|
778 session.Close(); |
|
779 User::Leave(KErrUnknown); |
|
780 } |
|
781 return session; |
|
782 } |
|
783 |
|
784 // ----------------------------------------------------------------------------- |
|
785 // CAknSoundServerStifTest::PushContextL() |
|
786 // Simulates resource reading and calls pushcontext for the given resource. |
|
787 // Only R_STIFTEST_SOUND_CONTEXT_1 and R_STIFTEST_SOUND_CONTEXT_1 are supported. |
|
788 // ----------------------------------------------------------------------------- |
|
789 // |
|
790 void CAknSoundServerStifTest::PushContextL(RAknSoundServerSession& aSession, |
|
791 TInt aResId, TInt aSessionUid) |
|
792 { |
|
793 switch (aResId) |
|
794 { |
|
795 case R_STIFTEST_SOUND_CONTEXT_1: |
|
796 { |
|
797 // Simulates resource reading and calls pushcontext for the following context: |
|
798 // |
|
799 // RESOURCE AVKON_SKEY_LIST r_stiftest_sound_context_1 |
|
800 // { |
|
801 // list= |
|
802 // { |
|
803 // AVKON_SKEY_INFO {key='1'; sid=EAvkonSIDReadialCompleteTone;}, |
|
804 // AVKON_SKEY_INFO {key='2'; sid=EAvkonSIDBatteryLowTone;}, |
|
805 // AVKON_SKEY_INFO {key='3'; sid=EAvkonSIDRechargeBatteryTone;} |
|
806 // }; |
|
807 // } |
|
808 // |
|
809 const TInt items = 3; |
|
810 const TInt resSize = (items * 5); |
|
811 |
|
812 CBufFlat* buffer = CBufFlat::NewL(resSize); |
|
813 CleanupStack::PushL(buffer); |
|
814 |
|
815 RBufWriteStream bufStream; |
|
816 bufStream.Open(*buffer); |
|
817 |
|
818 CleanupClosePushL(bufStream); |
|
819 |
|
820 bufStream.WriteInt16L(EAvkonSIDReadialCompleteTone); // sid |
|
821 bufStream.WriteUint16L('1'); // key |
|
822 bufStream.WriteUint8L(ESKeyTypeShort); // type |
|
823 |
|
824 bufStream.WriteInt16L(EAvkonSIDBatteryLowTone); // sid |
|
825 bufStream.WriteUint16L('2'); // key |
|
826 bufStream.WriteUint8L(ESKeyTypeShort); // type |
|
827 |
|
828 bufStream.WriteInt16L(EAvkonSIDRechargeBatteryTone); // sid |
|
829 bufStream.WriteUint16L('3'); // key |
|
830 bufStream.WriteUint8L(ESKeyTypeShort); // type |
|
831 |
|
832 CleanupStack::PopAndDestroy(); // bufstream close |
|
833 |
|
834 TPtr8 bufPtr = buffer->Ptr(0); |
|
835 TIpcArgs args (items, &bufPtr, aSessionUid, aResId); |
|
836 User::LeaveIfError(aSession.ServerRequest(EKeySoundServerPushContext, args)); |
|
837 CleanupStack::PopAndDestroy(); // buffer |
|
838 |
|
839 break; |
|
840 } |
|
841 case R_STIFTEST_SOUND_CONTEXT_2: |
|
842 { |
|
843 // Simulates resource reading and calls pushcontext for the following context: |
|
844 // |
|
845 // RESOURCE AVKON_SKEY_LIST r_stiftest_sound_context_2 |
|
846 // { |
|
847 // list= |
|
848 // { |
|
849 // AVKON_SKEY_INFO {key='1'; sid=EAvkonSIDVoiceRecordingTone;}, |
|
850 // AVKON_SKEY_INFO {key='2'; sid=EAvkonSIDVoiceRecordingStartTone;}, |
|
851 // AVKON_SKEY_INFO {key='3'; sid=EAvkonSIDVoiceRecordingStopTone;} |
|
852 // }; |
|
853 // } |
|
854 // |
|
855 const TInt items = 3; |
|
856 const TInt resSize = (items * 5); |
|
857 |
|
858 CBufFlat* buffer = CBufFlat::NewL(resSize); |
|
859 CleanupStack::PushL(buffer); |
|
860 |
|
861 RBufWriteStream bufStream; |
|
862 bufStream.Open(*buffer); |
|
863 |
|
864 CleanupClosePushL(bufStream); |
|
865 |
|
866 bufStream.WriteInt16L(EAvkonSIDVoiceRecordingTone); // sid |
|
867 bufStream.WriteUint16L('1'); // key |
|
868 bufStream.WriteUint8L(ESKeyTypeShort); // type |
|
869 |
|
870 bufStream.WriteInt16L(EAvkonSIDVoiceRecordingStartTone); // sid |
|
871 bufStream.WriteUint16L('2'); // key |
|
872 bufStream.WriteUint8L(ESKeyTypeShort); // type |
|
873 |
|
874 bufStream.WriteInt16L(EAvkonSIDVoiceRecordingStopTone); // sid |
|
875 bufStream.WriteUint16L('3'); // key |
|
876 bufStream.WriteUint8L(ESKeyTypeShort); // type |
|
877 |
|
878 CleanupStack::PopAndDestroy(); // bufstream close |
|
879 |
|
880 TPtr8 bufPtr = buffer->Ptr(0); |
|
881 TIpcArgs args (items, &bufPtr, aSessionUid, R_STIFTEST_SOUND_CONTEXT_2); |
|
882 User::LeaveIfError(aSession.ServerRequest(EKeySoundServerPushContext, args)); |
|
883 CleanupStack::PopAndDestroy(); // buffer |
|
884 |
|
885 break; |
|
886 } |
|
887 default: |
|
888 { |
|
889 break; |
|
890 } |
|
891 } |
|
892 } |
|
893 |
|
894 // ----------------------------------------------------------------------------- |
|
895 // CAknSoundServerStifTest::PrintWithDelay() |
|
896 // Convenience method for printing with delay. (Printing seems to work better |
|
897 // if a delay is used.) |
|
898 // ----------------------------------------------------------------------------- |
|
899 // |
|
900 void CAknSoundServerStifTest::PrintWithDelay(const TInt aPriority, const TDesC& aDesC1, |
|
901 const TDesC& aDesC2) |
|
902 { |
|
903 TestModuleIf().Printf(aPriority, aDesC1, aDesC2); |
|
904 User::After(KPrintDelay); |
|
905 } |
|
906 |
|
907 // End of File |