|
1 /* |
|
2 * Copyright (c) 2002 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32math.h> |
|
21 #include <e32base.h> |
|
22 #include <s32mem.h> |
|
23 #include <e32property.h> |
|
24 #include <tspclientmapper.h> |
|
25 #include <e32property.h> |
|
26 #include "tspclientTestModule.h" |
|
27 #include "tspclientmapperprivatepskeys.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 //extern ?external_data; |
|
31 |
|
32 // EXTERNAL FUNCTION PROTOTYPES |
|
33 //extern ?external_function( ?arg_type,?arg_type ); |
|
34 |
|
35 // CONSTANTS |
|
36 _LIT( KEnter, "Enter" ); |
|
37 _LIT( KOnGoing, "On-going" ); |
|
38 _LIT( KExit, "Exit" ); |
|
39 |
|
40 // MACROS |
|
41 //#define ?macro ?macro_def |
|
42 |
|
43 // LOCAL CONSTANTS AND MACROS |
|
44 const TProcessId iProcessId0( 0 ); |
|
45 const TProcessId iProcessId1( 1 ); |
|
46 const TProcessId iProcessId2( 2 ); |
|
47 //const ?type ?constant_var = ?constant; |
|
48 //#define ?macro_name ?macro_def |
|
49 |
|
50 // MODULE DATA STRUCTURES |
|
51 //enum ?declaration |
|
52 //typedef ?declaration |
|
53 |
|
54 // LOCAL FUNCTION PROTOTYPES |
|
55 //?type ?function_name( ?arg_type, ?arg_type ); |
|
56 |
|
57 // FORWARD DECLARATIONS |
|
58 //class ?FORWARD_CLASSNAME; |
|
59 |
|
60 // ============================= LOCAL FUNCTIONS =============================== |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // ?function_name ?description. |
|
64 // ?description |
|
65 // Returns: ?value_1: ?description |
|
66 // ?value_n: ?description_line1 |
|
67 // ?description_line2 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 /* |
|
71 ?type ?function_name( |
|
72 ?arg_type arg, // ?description |
|
73 ?arg_type arg) // ?description |
|
74 { |
|
75 |
|
76 ?code // ?comment |
|
77 |
|
78 // ?comment |
|
79 ?code |
|
80 } |
|
81 */ |
|
82 |
|
83 // ============================ MEMBER FUNCTIONS =============================== |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CAccMonitoringTestModule::Case |
|
87 // Returns a test case by number. |
|
88 // |
|
89 // This function contains an array of all available test cases |
|
90 // i.e pair of case name and test function. If case specified by parameter |
|
91 // aCaseNumber is found from array, then that item is returned. |
|
92 // |
|
93 // The reason for this rather complicated function is to specify all the |
|
94 // test cases only in one place. It is not necessary to understand how |
|
95 // function pointers to class member functions works when adding new test |
|
96 // cases. See function body for instructions how to add new test case. |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 const TCaseInfo CTspClientTestModule::Case ( |
|
100 const TInt aCaseNumber ) const |
|
101 { |
|
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 * headsetTestModule.cpp file and to headsetTestModule.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 ENTRY( "Set a process id playing", SetProcessIdPlayingL ), |
|
142 ENTRY( "Set and move a process id playing", SetAndMoveProcessIdPlayingL ), |
|
143 ENTRY( "Set and remove a process id playing", SetAndRemoveProcessIdPlayingL ), |
|
144 ENTRY( "Set two and set first process id playing", SetTwoAndSetFirstProcessIdPlayingL ), |
|
145 ENTRY( "Set a process id registered", SetProcessIdRegisteredL ), |
|
146 ENTRY( "Set and move a process id registered", SetAndMoveProcessIdRegisteredL ), |
|
147 ENTRY( "Set and remove a process id registered", SetAndRemoveProcessIdRegisteredL ), |
|
148 ENTRY( "Set two and set first process id registered", SetTwoAndSetFirstProcessIdRegisteredL ), |
|
149 ENTRY( "Set a process id stopped", SetProcessIdStoppedL ), |
|
150 ENTRY( "Set and move a process id stopped", SetAndMoveProcessIdStoppedL ), |
|
151 ENTRY( "Set and remove a process id stopped", SetAndRemoveProcessIdStoppedL ), |
|
152 ENTRY( "Set two and set first process id stopped", SetTwoAndSetFirstProcessIdStoppedL ), |
|
153 ENTRY( "Check out of range", CheckOutOfRangeL ), |
|
154 ENTRY( "AddAPI Usage from Multiple Threads Simultaneously", MultiThreadTestSyncL ), |
|
155 }; |
|
156 |
|
157 // Verify that case number is valid |
|
158 if( (TUint) aCaseNumber >= sizeof( KCases ) / |
|
159 sizeof( TCaseInfoInternal ) ) |
|
160 { |
|
161 // Invalid case, construct empty object |
|
162 TCaseInfo null( (const TText*) L"" ); |
|
163 null.iMethod = NULL; |
|
164 null.iIsOOMTest = EFalse; |
|
165 null.iFirstMemoryAllocation = 0; |
|
166 null.iLastMemoryAllocation = 0; |
|
167 return null; |
|
168 } |
|
169 |
|
170 // Construct TCaseInfo object and return it |
|
171 TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName ); |
|
172 tmp.iMethod = KCases[ aCaseNumber ].iMethod; |
|
173 tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest; |
|
174 tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation; |
|
175 tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation; |
|
176 |
|
177 return tmp; |
|
178 |
|
179 } |
|
180 |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CAccMonitoringTestModule::AccMonitorTestNoL |
|
184 // A simple test which creates an instance of the CAccMonitor and uses |
|
185 // GetConnectedAccessoriesL method. Expected result is KErrNotFound since no |
|
186 // accessories are connected. |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CTspClientTestModule::SetProcessIdPlayingL( |
|
190 TTestResult& aResult ) |
|
191 { |
|
192 // Create an instance of the CAccMonitor |
|
193 TInt err( KErrGeneral ); |
|
194 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
195 |
|
196 mapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
197 |
|
198 CleanupStack::PopAndDestroy( mapper ); |
|
199 |
|
200 RArray< TProcessId > array; |
|
201 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
202 |
|
203 if( array[ 0 ] == iProcessId1 ) |
|
204 { |
|
205 err = KErrNone; |
|
206 } |
|
207 |
|
208 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
209 |
|
210 mapper1->RemoveTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
211 |
|
212 CleanupStack::PopAndDestroy( mapper1 ); |
|
213 |
|
214 array.Reset(); |
|
215 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
216 if( !CheckArrayZero( array ) ) |
|
217 { |
|
218 User::Leave( KErrGeneral ); |
|
219 } |
|
220 |
|
221 // Case was executed |
|
222 return err; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CTspClientTestModule::ResetRegisteredClients |
|
227 // Reset registered client array to avoid other registered clients than |
|
228 // test code to affect test cases. |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CTspClientTestModule::ResetRegisteredClients() |
|
232 { |
|
233 TFixedArray< TProcessId, 10 > array; |
|
234 TPckg< TFixedArray< TProcessId, 10 > > buf( array ); |
|
235 const TProcessId processIdNull( 0 ); |
|
236 for( TInt i = 0; i != 10; i++ ) |
|
237 { |
|
238 array[ i ] = processIdNull; |
|
239 } |
|
240 |
|
241 RProperty::Set( |
|
242 KTspClientMapperProperty, |
|
243 KTspClientMapperKeyRegistered, |
|
244 buf ); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CAccMonitoringTestModule::AccMonitorTestMultiL |
|
249 // A test to connect multiple accessories and then getting the information from |
|
250 // Accessory Monitoring API. The information is then checked to be correct. |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 TInt CTspClientTestModule::SetAndMoveProcessIdPlayingL( |
|
254 TTestResult& aResult ) |
|
255 { |
|
256 TInt err( KErrGeneral ); |
|
257 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
258 |
|
259 ResetRegisteredClients(); |
|
260 mapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
261 mapper->SetTspTargetClientToOtherType( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
262 |
|
263 CleanupStack::PopAndDestroy( mapper ); |
|
264 |
|
265 RArray< TProcessId > array; |
|
266 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
267 |
|
268 if( array[ 0 ] != iProcessId1 ) |
|
269 { |
|
270 User::Leave( err ); |
|
271 } |
|
272 else |
|
273 { |
|
274 err = KErrNone; |
|
275 } |
|
276 RArray< TProcessId > array2; |
|
277 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array2 ); |
|
278 if( array2[ 0 ] != iProcessId0 ) |
|
279 { |
|
280 User::Leave( err ); |
|
281 } |
|
282 else |
|
283 { |
|
284 err = KErrNone; |
|
285 } |
|
286 |
|
287 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
288 |
|
289 mapper1->RemoveTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
290 |
|
291 CleanupStack::PopAndDestroy( mapper1 ); |
|
292 |
|
293 array.Reset(); |
|
294 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
295 if( !CheckArrayZero( array ) ) |
|
296 { |
|
297 User::Leave( KErrGeneral ); |
|
298 } |
|
299 |
|
300 // Case was executed |
|
301 return err; |
|
302 |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CAccMonitoringTestModule::TestHasAccessoryCapa |
|
307 // In this test a wired headset is connected and then the information is fetched |
|
308 // from the API. |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 TInt CTspClientTestModule::SetAndRemoveProcessIdPlayingL( |
|
312 TTestResult& aResult ) |
|
313 { |
|
314 TInt err( KErrGeneral ); |
|
315 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
316 |
|
317 mapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
318 mapper->RemoveTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
319 |
|
320 CleanupStack::PopAndDestroy( mapper ); |
|
321 |
|
322 RArray< TProcessId > array; |
|
323 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
324 |
|
325 if( array[ 0 ] == iProcessId0 ) |
|
326 { |
|
327 err = KErrNone; |
|
328 } |
|
329 |
|
330 if( !CheckArrayZero( array ) ) |
|
331 { |
|
332 User::Leave( KErrGeneral ); |
|
333 } |
|
334 |
|
335 // Case was executed |
|
336 return err; |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CAccMonitoringTestModule::TestHasAccessoryCapa |
|
341 // In this test a wired headset is connected and then the information is fetched |
|
342 // from the API. |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 TInt CTspClientTestModule::SetTwoAndSetFirstProcessIdPlayingL( |
|
346 TTestResult& aResult ) |
|
347 { |
|
348 TInt err( KErrGeneral ); |
|
349 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
350 |
|
351 mapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
352 mapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId2 ); |
|
353 mapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
354 |
|
355 CleanupStack::PopAndDestroy( mapper ); |
|
356 |
|
357 RArray< TProcessId > array; |
|
358 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
359 |
|
360 if( ( array[ 0 ] == iProcessId1 ) && ( array[ 2 ] == iProcessId0 ) ) |
|
361 { |
|
362 err = KErrNone; |
|
363 } |
|
364 |
|
365 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
366 |
|
367 mapper1->RemoveTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
368 mapper1->RemoveTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId2 ); |
|
369 |
|
370 CleanupStack::PopAndDestroy( mapper1 ); |
|
371 |
|
372 array.Reset(); |
|
373 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
374 if( !CheckArrayZero( array ) ) |
|
375 { |
|
376 User::Leave( KErrGeneral ); |
|
377 } |
|
378 |
|
379 // Case was executed |
|
380 return err; |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CAccMonitoringTestModule::AccMonitorTestNoL |
|
385 // A simple test which creates an instance of the CAccMonitor and uses |
|
386 // GetConnectedAccessoriesL method. Expected result is KErrNotFound since no |
|
387 // accessories are connected. |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 TInt CTspClientTestModule::SetProcessIdRegisteredL( |
|
391 TTestResult& aResult ) |
|
392 { |
|
393 // Create an instance of the CAccMonitor |
|
394 TInt err( KErrGeneral ); |
|
395 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
396 |
|
397 ResetRegisteredClients(); |
|
398 mapper->SetTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
399 |
|
400 CleanupStack::PopAndDestroy( mapper ); |
|
401 |
|
402 RArray< TProcessId > array; |
|
403 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
404 |
|
405 if( array[ 0 ] == iProcessId1 ) |
|
406 { |
|
407 err = KErrNone; |
|
408 } |
|
409 |
|
410 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
411 |
|
412 mapper1->RemoveTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
413 |
|
414 CleanupStack::PopAndDestroy( mapper1 ); |
|
415 |
|
416 array.Reset(); |
|
417 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
418 if( !CheckArrayZero( array ) ) |
|
419 { |
|
420 User::Leave( KErrGeneral ); |
|
421 } |
|
422 |
|
423 // Case was executed |
|
424 return err; |
|
425 } |
|
426 |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // CAccMonitoringTestModule::AccMonitorTestMultiL |
|
430 // A test to connect multiple accessories and then getting the information from |
|
431 // Accessory Monitoring API. The information is then checked to be correct. |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 TInt CTspClientTestModule::SetAndMoveProcessIdRegisteredL( |
|
435 TTestResult& aResult ) |
|
436 { |
|
437 TInt err( KErrGeneral ); |
|
438 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
439 |
|
440 ResetRegisteredClients(); |
|
441 mapper->SetTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
442 mapper->SetTspTargetClientToOtherType( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
443 |
|
444 CleanupStack::PopAndDestroy( mapper ); |
|
445 |
|
446 RArray< TProcessId > array; |
|
447 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
448 |
|
449 if( array[ 0 ] != iProcessId1 ) |
|
450 { |
|
451 User::Leave( err ); |
|
452 } |
|
453 else |
|
454 { |
|
455 err = KErrNone; |
|
456 } |
|
457 RArray< TProcessId > array2; |
|
458 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array2 ); |
|
459 if( array2[ 0 ] != iProcessId0 ) |
|
460 { |
|
461 User::Leave( err ); |
|
462 } |
|
463 else |
|
464 { |
|
465 err = KErrNone; |
|
466 } |
|
467 |
|
468 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
469 |
|
470 mapper1->RemoveTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
471 |
|
472 CleanupStack::PopAndDestroy( mapper1 ); |
|
473 |
|
474 array.Reset(); |
|
475 CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
476 if( !CheckArrayZero( array ) ) |
|
477 { |
|
478 User::Leave( KErrGeneral ); |
|
479 } |
|
480 |
|
481 // Case was executed |
|
482 return err; |
|
483 |
|
484 } |
|
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // CAccMonitoringTestModule::TestHasAccessoryCapa |
|
488 // In this test a wired headset is connected and then the information is fetched |
|
489 // from the API. |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 TInt CTspClientTestModule::SetAndRemoveProcessIdRegisteredL( |
|
493 TTestResult& aResult ) |
|
494 { |
|
495 TInt err( KErrGeneral ); |
|
496 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
497 |
|
498 ResetRegisteredClients(); |
|
499 mapper->SetTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
500 mapper->RemoveTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
501 |
|
502 CleanupStack::PopAndDestroy( mapper ); |
|
503 |
|
504 RArray< TProcessId > array; |
|
505 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
506 |
|
507 if( array[ 0 ] == iProcessId0 ) |
|
508 { |
|
509 err = KErrNone; |
|
510 } |
|
511 |
|
512 array.Reset(); |
|
513 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
514 if( !CheckArrayZero( array ) ) |
|
515 { |
|
516 User::Leave( KErrGeneral ); |
|
517 } |
|
518 |
|
519 // Case was executed |
|
520 return err; |
|
521 } |
|
522 |
|
523 // ----------------------------------------------------------------------------- |
|
524 // CAccMonitoringTestModule::TestHasAccessoryCapa |
|
525 // In this test a wired headset is connected and then the information is fetched |
|
526 // from the API. |
|
527 // ----------------------------------------------------------------------------- |
|
528 // |
|
529 TInt CTspClientTestModule::SetTwoAndSetFirstProcessIdRegisteredL( |
|
530 TTestResult& aResult ) |
|
531 { |
|
532 TInt err( KErrGeneral ); |
|
533 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
534 |
|
535 ResetRegisteredClients(); |
|
536 mapper->SetTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
537 mapper->SetTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId2 ); |
|
538 mapper->SetTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
539 |
|
540 CleanupStack::PopAndDestroy( mapper ); |
|
541 |
|
542 RArray< TProcessId > array; |
|
543 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
544 |
|
545 if( ( array[ 0 ] == iProcessId1 ) && ( array[ 2 ] == iProcessId0 ) ) |
|
546 { |
|
547 err = KErrNone; |
|
548 } |
|
549 |
|
550 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
551 |
|
552 mapper1->RemoveTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
553 mapper1->RemoveTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId2 ); |
|
554 |
|
555 CleanupStack::PopAndDestroy( mapper1 ); |
|
556 |
|
557 array.Reset(); |
|
558 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
559 if( !CheckArrayZero( array ) ) |
|
560 { |
|
561 User::Leave( KErrGeneral ); |
|
562 } |
|
563 |
|
564 // Case was executed |
|
565 return err; |
|
566 } |
|
567 |
|
568 // ----------------------------------------------------------------------------- |
|
569 // CAccMonitoringTestModule::AccMonitorTestNoL |
|
570 // A simple test which creates an instance of the CAccMonitor and uses |
|
571 // GetConnectedAccessoriesL method. Expected result is KErrNotFound since no |
|
572 // accessories are connected. |
|
573 // ----------------------------------------------------------------------------- |
|
574 // |
|
575 TInt CTspClientTestModule::SetProcessIdStoppedL( |
|
576 TTestResult& aResult ) |
|
577 { |
|
578 // Create an instance of the CAccMonitor |
|
579 TInt err( KErrGeneral ); |
|
580 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
581 |
|
582 mapper->SetTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
583 |
|
584 CleanupStack::PopAndDestroy( mapper ); |
|
585 |
|
586 RArray< TProcessId > array; |
|
587 CheckTspTargetClients( CTspClientMapper::EStoppedClients, array ); |
|
588 |
|
589 if( array[ 0 ] == iProcessId1 ) |
|
590 { |
|
591 err = KErrNone; |
|
592 } |
|
593 |
|
594 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
595 |
|
596 mapper1->RemoveTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
597 |
|
598 CleanupStack::PopAndDestroy( mapper1 ); |
|
599 |
|
600 array.Reset(); |
|
601 CheckTspTargetClients( CTspClientMapper::EStoppedClients, array ); |
|
602 if( !CheckArrayZero( array ) ) |
|
603 { |
|
604 User::Leave( KErrGeneral ); |
|
605 } |
|
606 |
|
607 // Case was executed |
|
608 return err; |
|
609 } |
|
610 |
|
611 |
|
612 // ----------------------------------------------------------------------------- |
|
613 // CAccMonitoringTestModule::AccMonitorTestMultiL |
|
614 // A test to connect multiple accessories and then getting the information from |
|
615 // Accessory Monitoring API. The information is then checked to be correct. |
|
616 // ----------------------------------------------------------------------------- |
|
617 // |
|
618 TInt CTspClientTestModule::SetAndMoveProcessIdStoppedL( |
|
619 TTestResult& aResult ) |
|
620 { |
|
621 TInt err( KErrGeneral ); |
|
622 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
623 |
|
624 ResetRegisteredClients(); |
|
625 mapper->SetTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
626 mapper->SetTspTargetClientToOtherType( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
627 |
|
628 CleanupStack::PopAndDestroy( mapper ); |
|
629 |
|
630 RArray< TProcessId > array; |
|
631 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
632 |
|
633 if( array[ 0 ] != iProcessId1 ) |
|
634 { |
|
635 User::Leave( err ); |
|
636 } |
|
637 else |
|
638 { |
|
639 err = KErrNone; |
|
640 } |
|
641 RArray< TProcessId > array2; |
|
642 CheckTspTargetClients( CTspClientMapper::EStoppedClients, array2 ); |
|
643 if( array2[ 0 ] != iProcessId0 ) |
|
644 { |
|
645 User::Leave( err ); |
|
646 } |
|
647 else |
|
648 { |
|
649 err = KErrNone; |
|
650 } |
|
651 |
|
652 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
653 |
|
654 mapper1->RemoveTspTargetClient( CTspClientMapper::ERegisteredClients, iProcessId1 ); |
|
655 |
|
656 CleanupStack::PopAndDestroy( mapper1 ); |
|
657 |
|
658 array.Reset(); |
|
659 CheckTspTargetClients( CTspClientMapper::ERegisteredClients, array ); |
|
660 if( !CheckArrayZero( array ) ) |
|
661 { |
|
662 User::Leave( KErrGeneral ); |
|
663 } |
|
664 |
|
665 // Case was executed |
|
666 return err; |
|
667 |
|
668 } |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // CAccMonitoringTestModule::TestHasAccessoryCapa |
|
672 // In this test a wired headset is connected and then the information is fetched |
|
673 // from the API. |
|
674 // ----------------------------------------------------------------------------- |
|
675 // |
|
676 TInt CTspClientTestModule::SetAndRemoveProcessIdStoppedL( |
|
677 TTestResult& aResult ) |
|
678 { |
|
679 TInt err( KErrGeneral ); |
|
680 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
681 |
|
682 mapper->SetTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
683 mapper->RemoveTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
684 |
|
685 CleanupStack::PopAndDestroy( mapper ); |
|
686 |
|
687 RArray< TProcessId > array; |
|
688 CheckTspTargetClients( CTspClientMapper::EStoppedClients, array ); |
|
689 |
|
690 if( array[ 0 ] == iProcessId0 ) |
|
691 { |
|
692 err = KErrNone; |
|
693 } |
|
694 |
|
695 array.Reset(); |
|
696 CheckTspTargetClients( CTspClientMapper::EStoppedClients, array ); |
|
697 if( !CheckArrayZero( array ) ) |
|
698 { |
|
699 User::Leave( KErrGeneral ); |
|
700 } |
|
701 |
|
702 // Case was executed |
|
703 return err; |
|
704 } |
|
705 |
|
706 // ----------------------------------------------------------------------------- |
|
707 // CAccMonitoringTestModule::TestHasAccessoryCapa |
|
708 // In this test a wired headset is connected and then the information is fetched |
|
709 // from the API. |
|
710 // ----------------------------------------------------------------------------- |
|
711 // |
|
712 TInt CTspClientTestModule::SetTwoAndSetFirstProcessIdStoppedL( |
|
713 TTestResult& aResult ) |
|
714 { |
|
715 TInt err( KErrGeneral ); |
|
716 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
717 |
|
718 mapper->SetTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
719 mapper->SetTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId2 ); |
|
720 mapper->SetTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
721 |
|
722 CleanupStack::PopAndDestroy( mapper ); |
|
723 |
|
724 RArray< TProcessId > array; |
|
725 CheckTspTargetClients( CTspClientMapper::EStoppedClients, array ); |
|
726 |
|
727 if( ( array[ 0 ] == iProcessId1 ) && ( array[ 2 ] == iProcessId0 ) ) |
|
728 { |
|
729 err = KErrNone; |
|
730 } |
|
731 |
|
732 CTspClientMapper* mapper1 = CTspClientMapper::NewLC(); |
|
733 |
|
734 mapper1->RemoveTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId1 ); |
|
735 mapper1->RemoveTspTargetClient( CTspClientMapper::EStoppedClients, iProcessId2 ); |
|
736 |
|
737 CleanupStack::PopAndDestroy( mapper1 ); |
|
738 |
|
739 array.Reset(); |
|
740 CheckTspTargetClients( CTspClientMapper::EStoppedClients, array ); |
|
741 if( !CheckArrayZero( array ) ) |
|
742 { |
|
743 User::Leave( KErrGeneral ); |
|
744 } |
|
745 |
|
746 // Case was executed |
|
747 return err; |
|
748 } |
|
749 |
|
750 // ----------------------------------------------------------------------------- |
|
751 // CAccMonitoringTestModule::TestHasAccessoryCapa |
|
752 // In this test a wired headset is connected and then the information is fetched |
|
753 // from the API. |
|
754 // ----------------------------------------------------------------------------- |
|
755 // |
|
756 TInt CTspClientTestModule::CheckOutOfRangeL( |
|
757 TTestResult& aResult ) |
|
758 { |
|
759 TInt err( KErrNone ); |
|
760 |
|
761 CTspClientMapper* mapper = CTspClientMapper::NewL(); |
|
762 |
|
763 err = mapper->SetTspTargetClientToOtherType( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
764 if( err != KErrNotFound ) |
|
765 { |
|
766 User::Leave( KErrGeneral ); |
|
767 } |
|
768 |
|
769 err = mapper->RemoveTspTargetClient( CTspClientMapper::EPlayingClients, iProcessId1 ); |
|
770 if( err != KErrNotFound ) |
|
771 { |
|
772 User::Leave( KErrGeneral ); |
|
773 } |
|
774 else |
|
775 { |
|
776 err = KErrNone; |
|
777 } |
|
778 |
|
779 delete mapper; |
|
780 |
|
781 return err; |
|
782 } |
|
783 |
|
784 // ----------------------------------------------------------------------------- |
|
785 // CTspClientMapperImpl::GetTspTargetClientsL |
|
786 // Provides implementation of this (TSP) interface. |
|
787 // (other items were commented in a header). |
|
788 // ----------------------------------------------------------------------------- |
|
789 // |
|
790 TInt CTspClientTestModule::CheckTspTargetClients( |
|
791 TInt aMappingType, |
|
792 RArray< TProcessId >& aPidArray |
|
793 ) |
|
794 { |
|
795 TInt returnErr( KErrNone ); |
|
796 if( aMappingType > CTspClientMapper::EStoppedClients ) |
|
797 { |
|
798 returnErr = KErrNotSupported; |
|
799 } |
|
800 TFixedArray< TProcessId, 10 > array; |
|
801 TPckgBuf< TFixedArray< TProcessId, 10 > > buf( array ); |
|
802 //COM_TRACE_1( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() aMappingType = %d", aMappingType ); |
|
803 TInt count( 0 ); |
|
804 |
|
805 if( aMappingType == CTspClientMapper::EPlayingClients ) |
|
806 { |
|
807 //COM_TRACE_( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() - Getting playing clients" ); |
|
808 returnErr = RProperty::Get( |
|
809 KTspClientMapperProperty, |
|
810 KTspClientMapperKeyPlaying, |
|
811 buf ); |
|
812 //COM_TRACE_1( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() playing clients count = %d", buf().Count() ); |
|
813 count = buf().Count(); |
|
814 } |
|
815 if( aMappingType == CTspClientMapper::ERegisteredClients ) |
|
816 { |
|
817 //COM_TRACE_( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() - Getting registered clients" ); |
|
818 returnErr = RProperty::Get( |
|
819 KTspClientMapperProperty, |
|
820 KTspClientMapperKeyRegistered, |
|
821 buf ); |
|
822 //COM_TRACE_1( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() registered clients count = %d", buf().Count() ); |
|
823 count = buf().Count(); |
|
824 } |
|
825 if( aMappingType == CTspClientMapper::EStoppedClients ) |
|
826 { |
|
827 //COM_TRACE_( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() - Getting stopped clients" ); |
|
828 returnErr = RProperty::Get( |
|
829 KTspClientMapperProperty, |
|
830 KTspClientMapperKeyStopped, |
|
831 buf ); |
|
832 //COM_TRACE_1( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() stopped clients count = %d", buf().Count() ); |
|
833 count = buf().Count(); |
|
834 } |
|
835 |
|
836 for( TInt i = 0; i != count; i++ ) |
|
837 { |
|
838 //COM_TRACE_1( "[TspClientMapperImpl] CTspClientMapperImpl::GetTspTargetClientsL() first client's Pid = %d", (TInt)buf().operator[]( i ) ); |
|
839 aPidArray.Append( buf().operator[]( i ) ); |
|
840 } |
|
841 |
|
842 return returnErr; |
|
843 |
|
844 } |
|
845 |
|
846 // ----------------------------------------------------------------------------- |
|
847 // CTspClientMapperImpl::GetTspTargetClientsL |
|
848 // Provides implementation of this (TSP) interface. |
|
849 // (other items were commented in a header). |
|
850 // ----------------------------------------------------------------------------- |
|
851 // |
|
852 TBool CTspClientTestModule::CheckArrayZero( RArray< TProcessId >& aPidArray ) |
|
853 { |
|
854 TBool ret( ETrue ); |
|
855 for( TInt i = 0; aPidArray.Count() != i; i++ ) |
|
856 { |
|
857 TProcessId pid = aPidArray[ i ]; |
|
858 if( aPidArray[ i ] != iProcessId0 ) |
|
859 { |
|
860 ret = EFalse; |
|
861 } |
|
862 } |
|
863 return ret; |
|
864 } |
|
865 |
|
866 // --------------------------------------------------------- |
|
867 // CTspClientTestModule::MultiThreadTestSyncL |
|
868 // This Test creates a child thread and tests the TSPClientMapper API usage from two threads simultaneously. |
|
869 // --------------------------------------------------------- |
|
870 TInt CTspClientTestModule::MultiThreadTestSyncL( TTestResult& /*aResult*/ ) |
|
871 { |
|
872 StartThreadFunctionL (); |
|
873 |
|
874 TInt err = DoSyncLockTestL ( iProcessId1 ); |
|
875 return err; |
|
876 } |
|
877 |
|
878 |
|
879 // --------------------------------------------------------- |
|
880 // CTspClientTestModule::StartThreadFunctionL |
|
881 // --------------------------------------------------------- |
|
882 void CTspClientTestModule::StartThreadFunctionL() |
|
883 { |
|
884 RThread thread; |
|
885 User::LeaveIfError( thread.Create( |
|
886 KNullDesC, ThreadEntryFunction, KDefaultStackSize, NULL, this ) ); |
|
887 thread.SetPriority( EPriorityNormal ); |
|
888 thread.Resume(); |
|
889 thread.Close(); |
|
890 } |
|
891 |
|
892 // --------------------------------------------------------- |
|
893 // CTspClientTestModule::ThreadEntryFunction |
|
894 // --------------------------------------------------------- |
|
895 TInt CTspClientTestModule::ThreadEntryFunction( TAny* /*aPtr*/ ) |
|
896 { |
|
897 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
898 if ( !cleanup ) |
|
899 return KErrNoMemory; |
|
900 |
|
901 TInt err = KErrNone; |
|
902 TRAP ( err, DoSyncLockTestL ( iProcessId2 ) ); |
|
903 |
|
904 delete cleanup; |
|
905 |
|
906 return KErrNone; |
|
907 } |
|
908 |
|
909 // --------------------------------------------------------- |
|
910 // CTspClientTestModule::DoSyncLockTestL |
|
911 // --------------------------------------------------------- |
|
912 TInt CTspClientTestModule::DoSyncLockTestL ( TProcessId aProcessId ) |
|
913 { |
|
914 // Create an instance of the CAccMonitor |
|
915 TInt err( KErrGeneral ); |
|
916 CTspClientMapper* mapper = CTspClientMapper::NewLC(); |
|
917 |
|
918 mapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, aProcessId ); |
|
919 |
|
920 CleanupStack::PopAndDestroy( mapper ); |
|
921 |
|
922 RArray< TProcessId > array; |
|
923 err = CheckTspTargetClients( CTspClientMapper::EPlayingClients, array ); |
|
924 |
|
925 if( array[ 0 ] == aProcessId ) |
|
926 { |
|
927 err = KErrNone; |
|
928 } |
|
929 return err; |
|
930 } |
|
931 |
|
932 |
|
933 // End of file |