|
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: Implementation of CCommandHandlerTests. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32math.h> |
|
22 #include "CommandHandlerTests.h" |
|
23 #include <CPhCltCommandHandler.h> |
|
24 // EXTERNAL DATA STRUCTURES |
|
25 //extern ?external_data; |
|
26 |
|
27 // EXTERNAL FUNCTION PROTOTYPES |
|
28 //extern ?external_function( ?arg_type,?arg_type ); |
|
29 |
|
30 // CONSTANTS |
|
31 //const ?type ?constant_var = ?constant; |
|
32 _LIT(KPhoneNumber1, "111"); |
|
33 // MACROS |
|
34 //#define ?macro ?macro_def |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 //const ?type ?constant_var = ?constant; |
|
38 //#define ?macro_name ?macro_def |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 //enum ?declaration |
|
42 //typedef ?declaration |
|
43 |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 //?type ?function_name( ?arg_type, ?arg_type ); |
|
46 |
|
47 // FORWARD DECLARATIONS |
|
48 //class ?FORWARD_CLASSNAME; |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // ?function_name ?description. |
|
54 // ?description |
|
55 // Returns: ?value_1: ?description |
|
56 // ?value_n: ?description_line1 |
|
57 // ?description_line2 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 /* |
|
61 ?type ?function_name( |
|
62 ?arg_type arg, // ?description |
|
63 ?arg_type arg) // ?description |
|
64 { |
|
65 |
|
66 ?code // ?comment |
|
67 |
|
68 // ?comment |
|
69 ?code |
|
70 } |
|
71 */ |
|
72 |
|
73 // ============================ MEMBER FUNCTIONS =============================== |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CCommandHandlerTests::Case |
|
77 // Returns a test case by number. |
|
78 // |
|
79 // This function contains an array of all available test cases |
|
80 // i.e pair of case name and test function. If case specified by parameter |
|
81 // aCaseNumber is found from array, then that item is returned. |
|
82 // |
|
83 // The reason for this rather complicated function is to specify all the |
|
84 // test cases only in one place. It is not necessary to understand how |
|
85 // function pointers to class member functions works when adding new test |
|
86 // cases. See function body for instructions how to add new test case. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 const TCaseInfo CCommandHandlerTests::Case ( |
|
90 const TInt aCaseNumber ) const |
|
91 { |
|
92 |
|
93 /** |
|
94 * To add new test cases, implement new test case function and add new |
|
95 * line to KCases array specify the name of the case and the function |
|
96 * doing the test case |
|
97 * In practice, do following |
|
98 * 1) Make copy of existing test case function and change its name |
|
99 * and functionality. Note that the function must be added to |
|
100 * CommandHandlerTests.cpp file and to CommandHandlerTests.h |
|
101 * header file. |
|
102 * |
|
103 * 2) Add entry to following KCases array either by using: |
|
104 * |
|
105 * 2.1: FUNCENTRY or ENTRY macro |
|
106 * ENTRY macro takes two parameters: test case name and test case |
|
107 * function name. |
|
108 * |
|
109 * FUNCENTRY macro takes only test case function name as a parameter and |
|
110 * uses that as a test case name and test case function name. |
|
111 * |
|
112 * Or |
|
113 * |
|
114 * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used |
|
115 * only with OOM (Out-Of-Memory) testing! |
|
116 * |
|
117 * OOM_ENTRY macro takes five parameters: test case name, test case |
|
118 * function name, TBool which specifies is method supposed to be run using |
|
119 * OOM conditions, TInt value for first heap memory allocation failure and |
|
120 * TInt value for last heap memory allocation failure. |
|
121 * |
|
122 * OOM_FUNCENTRY macro takes test case function name as a parameter and uses |
|
123 * that as a test case name, TBool which specifies is method supposed to be |
|
124 * run using OOM conditions, TInt value for first heap memory allocation |
|
125 * failure and TInt value for last heap memory allocation failure. |
|
126 */ |
|
127 |
|
128 static TCaseInfoInternal const KCases[] = |
|
129 { |
|
130 // To add new test cases, add new items to this array |
|
131 |
|
132 // NOTE: When compiled to GCCE, there must be Classname:: |
|
133 // declaration in front of the method name, e.g. |
|
134 // CCommandHandlerTests::PrintTest. Otherwise the compiler |
|
135 // gives errors. |
|
136 |
|
137 //FUNCENTRY( CCommandHandlerTests::PrintTest ), |
|
138 ENTRY( "CPhCltCommandHandler::NewL", Construction ), |
|
139 ENTRY( "CPhCltCommandHandler::Atd", Atd ), |
|
140 ENTRY( "CPhCltCommandHandler::Chup", Chup ), |
|
141 ENTRY( "CPhCltCommandHandler::Ata", Ata ), |
|
142 ENTRY( "CPhCltCommandHandler::Vts", Vts ), |
|
143 ENTRY( "CPhCltCommandHandler::MuteRingingTone", MuteRingingTone ), |
|
144 |
|
145 // Example how to use OOM functionality |
|
146 //OOM_ENTRY( "Loop test with OOM", CCommandHandlerTests::LoopTest, ETrue, 2, 3), |
|
147 //OOM_FUNCENTRY( CCommandHandlerTests::PrintTest, ETrue, 1, 3 ), |
|
148 }; |
|
149 |
|
150 // Verify that case number is valid |
|
151 if( (TUint) aCaseNumber >= sizeof( KCases ) / |
|
152 sizeof( TCaseInfoInternal ) ) |
|
153 { |
|
154 // Invalid case, construct empty object |
|
155 TCaseInfo null( (const TText*) L"" ); |
|
156 null.iMethod = NULL; |
|
157 null.iIsOOMTest = EFalse; |
|
158 null.iFirstMemoryAllocation = 0; |
|
159 null.iLastMemoryAllocation = 0; |
|
160 return null; |
|
161 } |
|
162 |
|
163 // Construct TCaseInfo object and return it |
|
164 TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName ); |
|
165 tmp.iMethod = KCases[ aCaseNumber ].iMethod; |
|
166 tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest; |
|
167 tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation; |
|
168 tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation; |
|
169 return tmp; |
|
170 |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CCommandHandlerTests::PrintTest |
|
175 // Simple printing to UI test. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CCommandHandlerTests::PrintTest( |
|
179 TTestResult& aResult ) |
|
180 { |
|
181 /* Simple print test */ |
|
182 _LIT( KPrintTest, "PrintTest" ); |
|
183 _LIT( KEnter, "Enter" ); |
|
184 _LIT( KOnGoing, "On-going" ); |
|
185 _LIT( KExit, "Exit" ); |
|
186 |
|
187 TestModuleIf().Printf( 0, KPrintTest, KEnter ); |
|
188 |
|
189 TestModuleIf().Printf( 1, KPrintTest, KOnGoing ); |
|
190 |
|
191 TestModuleIf().Printf( 0, KPrintTest, KExit ); |
|
192 |
|
193 // Test case passed |
|
194 |
|
195 // Sets test case result and description(Maximum size is KStifMaxResultDes) |
|
196 _LIT( KDescription, "PrintTest passed" ); |
|
197 aResult.SetResult( KErrNone, KDescription ); |
|
198 |
|
199 // Case was executed |
|
200 return KErrNone; |
|
201 |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CCommandHandlerTests::LoopTest |
|
206 // Another printing to UI test. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TInt CCommandHandlerTests::LoopTest( TTestResult& aResult ) |
|
210 { |
|
211 |
|
212 /* Simple print and wait loop */ |
|
213 _LIT( KState, "State" ); |
|
214 _LIT( KLooping, "Looping" ); |
|
215 |
|
216 TestModuleIf().Printf( 0, KState, KLooping ); |
|
217 |
|
218 _LIT( KRunning, "Running" ); |
|
219 _LIT( KLoop, "%d" ); |
|
220 for( TInt i=0; i<10; i++) |
|
221 { |
|
222 TestModuleIf().Printf( 1, KRunning, KLoop, i); |
|
223 User::After( 1000000 ); |
|
224 } |
|
225 |
|
226 _LIT( KFinished, "Finished" ); |
|
227 TestModuleIf().Printf( 0, KState, KFinished ); |
|
228 |
|
229 // Test case passed |
|
230 |
|
231 // Sets test case result and description(Maximum size is KStifMaxResultDes) |
|
232 _LIT( KDescription, "LoopTest passed" ); |
|
233 aResult.SetResult( KErrNone, KDescription ); |
|
234 |
|
235 // Case was executed |
|
236 return KErrNone; |
|
237 |
|
238 } |
|
239 |
|
240 //----------------------------------------------------------------------------- |
|
241 // CCommandHandlerTests::Construction |
|
242 //----------------------------------------------------------------------------- |
|
243 // |
|
244 TInt CCommandHandlerTests::Construction( TTestResult& aResult ) |
|
245 { |
|
246 TPhCltComHandCommandParameters Param; |
|
247 Param.iTelNumber = KPhoneNumber1; |
|
248 TRequestStatus iStatus; |
|
249 |
|
250 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
251 CActiveScheduler::Install( scheduler ); |
|
252 CleanupStack::PushL( scheduler ); |
|
253 |
|
254 CPhCltCommandHandler* handler = CPhCltCommandHandler::NewL(); |
|
255 delete handler; |
|
256 CleanupStack::PopAndDestroy( scheduler ); |
|
257 |
|
258 _LIT( KDescription, "NewL Done" ); |
|
259 aResult.SetResult( KErrNone, KDescription ); |
|
260 |
|
261 return KErrNone; |
|
262 |
|
263 } |
|
264 |
|
265 //----------------------------------------------------------------------------- |
|
266 // CCommandHandlerTests::Atd |
|
267 //----------------------------------------------------------------------------- |
|
268 // |
|
269 TInt CCommandHandlerTests::Atd( TTestResult& aResult ) |
|
270 { |
|
271 TPhCltComHandCommandParameters Param; |
|
272 Param.iTelNumber = KPhoneNumber1; |
|
273 TRequestStatus iStatus; |
|
274 |
|
275 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
276 CActiveScheduler::Install( scheduler ); |
|
277 CleanupStack::PushL( scheduler ); |
|
278 |
|
279 CPhCltCommandHandler* handler = CPhCltCommandHandler::NewL(); |
|
280 |
|
281 handler->Atd( iStatus, Param.iTelNumber ); |
|
282 User::WaitForRequest( iStatus ); |
|
283 |
|
284 delete handler; |
|
285 CleanupStack::PopAndDestroy( scheduler ); |
|
286 |
|
287 _LIT( KDescription, "Atd Done" ); |
|
288 aResult.SetResult( iStatus.Int(), KDescription ); |
|
289 |
|
290 return iStatus.Int(); |
|
291 |
|
292 } |
|
293 |
|
294 //----------------------------------------------------------------------------- |
|
295 // CCommandHandlerTests::Chup |
|
296 //----------------------------------------------------------------------------- |
|
297 // |
|
298 TInt CCommandHandlerTests::Chup( TTestResult& aResult ) |
|
299 { |
|
300 TPhCltComHandCommandParameters Param; |
|
301 Param.iTelNumber = KPhoneNumber1; |
|
302 TRequestStatus iStatus; |
|
303 |
|
304 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
305 CActiveScheduler::Install( scheduler ); |
|
306 CleanupStack::PushL( scheduler ); |
|
307 |
|
308 CPhCltCommandHandler* handler = CPhCltCommandHandler::NewL(); |
|
309 |
|
310 handler->Chup( iStatus ); |
|
311 User::WaitForRequest( iStatus ); |
|
312 |
|
313 delete handler; |
|
314 CleanupStack::PopAndDestroy( scheduler ); |
|
315 |
|
316 _LIT( KDescription, "Chup Done" ); |
|
317 aResult.SetResult( iStatus.Int(), KDescription ); |
|
318 |
|
319 return iStatus.Int(); |
|
320 |
|
321 } |
|
322 |
|
323 //----------------------------------------------------------------------------- |
|
324 // CCommandHandlerTests::Ata |
|
325 //----------------------------------------------------------------------------- |
|
326 // |
|
327 TInt CCommandHandlerTests::Ata( TTestResult& aResult ) |
|
328 { |
|
329 |
|
330 TRequestStatus iStatus; |
|
331 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
332 CActiveScheduler::Install( scheduler ); |
|
333 CleanupStack::PushL( scheduler ); |
|
334 |
|
335 CPhCltCommandHandler* handler = CPhCltCommandHandler::NewL(); |
|
336 |
|
337 handler->Ata( iStatus ); |
|
338 User::WaitForRequest( iStatus ); |
|
339 |
|
340 delete handler; |
|
341 CleanupStack::PopAndDestroy( scheduler ); |
|
342 |
|
343 _LIT( KDescription, "Ata Done" ); |
|
344 aResult.SetResult( iStatus.Int(), KDescription ); |
|
345 |
|
346 return iStatus.Int(); |
|
347 |
|
348 } |
|
349 |
|
350 //----------------------------------------------------------------------------- |
|
351 // CCommandHandlerTests::Chld |
|
352 //----------------------------------------------------------------------------- |
|
353 // |
|
354 TInt CCommandHandlerTests::Chld( TTestResult& aResult ) |
|
355 { |
|
356 |
|
357 TRequestStatus iStatus; |
|
358 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
359 CActiveScheduler::Install( scheduler ); |
|
360 CleanupStack::PushL( scheduler ); |
|
361 |
|
362 CPhCltCommandHandler* handler = CPhCltCommandHandler::NewL(); |
|
363 |
|
364 handler->Chld( iStatus, EPhCltChldZero, 0 ); |
|
365 User::WaitForRequest( iStatus ); |
|
366 |
|
367 delete handler; |
|
368 CleanupStack::PopAndDestroy( scheduler ); |
|
369 |
|
370 _LIT( KDescription, "Chld Done" ); |
|
371 aResult.SetResult( iStatus.Int(), KDescription ); |
|
372 |
|
373 return iStatus.Int(); |
|
374 |
|
375 } |
|
376 |
|
377 //----------------------------------------------------------------------------- |
|
378 // CCommandHandlerTests::Vts |
|
379 //----------------------------------------------------------------------------- |
|
380 // |
|
381 |
|
382 TInt CCommandHandlerTests::Vts( TTestResult& aResult ) |
|
383 { |
|
384 |
|
385 TPhCltComHandCommandParameters Param; |
|
386 |
|
387 TRequestStatus iStatus; |
|
388 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
389 CActiveScheduler::Install( scheduler ); |
|
390 CleanupStack::PushL( scheduler ); |
|
391 |
|
392 CPhCltCommandHandler* handler = CPhCltCommandHandler::NewL(); |
|
393 |
|
394 handler->Vts(iStatus, Param.iDtmfTone, EPhCltDtmfNotUsed ); |
|
395 User::WaitForRequest( iStatus ); |
|
396 |
|
397 delete handler; |
|
398 CleanupStack::PopAndDestroy( scheduler ); |
|
399 |
|
400 _LIT( KDescription, "Chld Done" ); |
|
401 aResult.SetResult( iStatus.Int(), KDescription ); |
|
402 |
|
403 return iStatus.Int(); |
|
404 |
|
405 } |
|
406 |
|
407 //----------------------------------------------------------------------------- |
|
408 // TestCPhCltCommandHandler::MuteMicrophone |
|
409 //----------------------------------------------------------------------------- |
|
410 // |
|
411 TInt CCommandHandlerTests::MuteMicrophone( TTestResult& aResult ) |
|
412 { |
|
413 |
|
414 // TBD, somehow does not work in this environment, |
|
415 // ->User::WaitForRequest( iStatus ) jams |
|
416 return KErrNone; |
|
417 } |
|
418 |
|
419 //----------------------------------------------------------------------------- |
|
420 // TestCPhCltCommandHandler::CancelAsyncRequest |
|
421 //----------------------------------------------------------------------------- |
|
422 // |
|
423 TInt CCommandHandlerTests::CancelAsyncRequest( TTestResult& aResult ) |
|
424 { |
|
425 // TBD |
|
426 return KErrNone; |
|
427 } |
|
428 |
|
429 //----------------------------------------------------------------------------- |
|
430 // CCommandHandlerTests::MuteRingingTone |
|
431 //----------------------------------------------------------------------------- |
|
432 // |
|
433 TInt CCommandHandlerTests::MuteRingingTone( TTestResult& aResult ) |
|
434 { |
|
435 |
|
436 TRequestStatus iStatus; |
|
437 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
438 CActiveScheduler::Install( scheduler ); |
|
439 CleanupStack::PushL( scheduler ); |
|
440 |
|
441 CPhCltCommandHandler* handler = CPhCltCommandHandler::NewL(); |
|
442 |
|
443 handler->MuteRingingTone( iStatus ); |
|
444 |
|
445 User::WaitForRequest( iStatus ); |
|
446 |
|
447 delete handler; |
|
448 CleanupStack::PopAndDestroy( scheduler ); |
|
449 |
|
450 _LIT( KDescription, "MuteRingingTone Done" ); |
|
451 aResult.SetResult( iStatus.Int(), KDescription ); |
|
452 |
|
453 return iStatus.Int(); |
|
454 } |
|
455 |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // ?classname::?member_function |
|
459 // ?implementation_description |
|
460 // (other items were commented in a header). |
|
461 // ----------------------------------------------------------------------------- |
|
462 // |
|
463 /* |
|
464 ?type ?classname::?member_function( |
|
465 ?arg_type arg, |
|
466 ?arg_type arg ) |
|
467 { |
|
468 |
|
469 ?code |
|
470 |
|
471 } |
|
472 */ |
|
473 |
|
474 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
475 |
|
476 // ----------------------------------------------------------------------------- |
|
477 // ?function_name implements... |
|
478 // ?implementation_description. |
|
479 // Returns: ?value_1: ?description |
|
480 // ?value_n: ?description |
|
481 // ?description |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 /* |
|
485 ?type ?function_name( |
|
486 ?arg_type arg, // ?description |
|
487 ?arg_type arg ) // ?description |
|
488 { |
|
489 |
|
490 ?code |
|
491 |
|
492 } |
|
493 */ |
|
494 // End of File |