|
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 CEmergencyCallTests class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32math.h> |
|
22 #include "EmergencyCallTests.h" |
|
23 #include <CPhCltEmergencyCall.h> |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 //extern ?external_data; |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 //extern ?external_function( ?arg_type,?arg_type ); |
|
30 |
|
31 // CONSTANTS |
|
32 //const ?type ?constant_var = ?constant; |
|
33 _LIT(KPhoneNumber1, "112"); |
|
34 _LIT(KPhoneNumber2, "050123456#112"); |
|
35 // MACROS |
|
36 //#define ?macro ?macro_def |
|
37 |
|
38 // LOCAL CONSTANTS AND MACROS |
|
39 //const ?type ?constant_var = ?constant; |
|
40 //#define ?macro_name ?macro_def |
|
41 |
|
42 // MODULE DATA STRUCTURES |
|
43 //enum ?declaration |
|
44 //typedef ?declaration |
|
45 |
|
46 // LOCAL FUNCTION PROTOTYPES |
|
47 //?type ?function_name( ?arg_type, ?arg_type ); |
|
48 |
|
49 // FORWARD DECLARATIONS |
|
50 //class ?FORWARD_CLASSNAME; |
|
51 |
|
52 // ============================= LOCAL FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // ?function_name ?description. |
|
56 // ?description |
|
57 // Returns: ?value_1: ?description |
|
58 // ?value_n: ?description_line1 |
|
59 // ?description_line2 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 /* |
|
63 ?type ?function_name( |
|
64 ?arg_type arg, // ?description |
|
65 ?arg_type arg) // ?description |
|
66 { |
|
67 |
|
68 ?code // ?comment |
|
69 |
|
70 // ?comment |
|
71 ?code |
|
72 } |
|
73 */ |
|
74 |
|
75 // ============================ MEMBER FUNCTIONS =============================== |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CEmergencyCallTests::Case |
|
79 // Returns a test case by number. |
|
80 // |
|
81 // This function contains an array of all available test cases |
|
82 // i.e pair of case name and test function. If case specified by parameter |
|
83 // aCaseNumber is found from array, then that item is returned. |
|
84 // |
|
85 // The reason for this rather complicated function is to specify all the |
|
86 // test cases only in one place. It is not necessary to understand how |
|
87 // function pointers to class member functions works when adding new test |
|
88 // cases. See function body for instructions how to add new test case. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 const TCaseInfo CEmergencyCallTests::Case ( |
|
92 const TInt aCaseNumber ) const |
|
93 { |
|
94 |
|
95 /** |
|
96 * To add new test cases, implement new test case function and add new |
|
97 * line to KCases array specify the name of the case and the function |
|
98 * doing the test case |
|
99 * In practice, do following |
|
100 * 1) Make copy of existing test case function and change its name |
|
101 * and functionality. Note that the function must be added to |
|
102 * EmergencyCallTests.cpp file and to EmergencyCallTests.h |
|
103 * header file. |
|
104 * |
|
105 * 2) Add entry to following KCases array either by using: |
|
106 * |
|
107 * 2.1: FUNCENTRY or ENTRY macro |
|
108 * ENTRY macro takes two parameters: test case name and test case |
|
109 * function name. |
|
110 * |
|
111 * FUNCENTRY macro takes only test case function name as a parameter and |
|
112 * uses that as a test case name and test case function name. |
|
113 * |
|
114 * Or |
|
115 * |
|
116 * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used |
|
117 * only with OOM (Out-Of-Memory) testing! |
|
118 * |
|
119 * OOM_ENTRY macro takes five parameters: test case name, test case |
|
120 * function name, TBool which specifies is method supposed to be run using |
|
121 * OOM conditions, TInt value for first heap memory allocation failure and |
|
122 * TInt value for last heap memory allocation failure. |
|
123 * |
|
124 * OOM_FUNCENTRY macro takes test case function name as a parameter and uses |
|
125 * that as a test case name, TBool which specifies is method supposed to be |
|
126 * run using OOM conditions, TInt value for first heap memory allocation |
|
127 * failure and TInt value for last heap memory allocation failure. |
|
128 */ |
|
129 |
|
130 static TCaseInfoInternal const KCases[] = |
|
131 { |
|
132 // To add new test cases, add new items to this array |
|
133 |
|
134 // NOTE: When compiled to GCCE, there must be Classname:: |
|
135 // declaration in front of the method name, e.g. |
|
136 // CEmergencyCallTests::PrintTest. Otherwise the compiler |
|
137 // gives errors. |
|
138 ENTRY( "CPhCltEmergencyCall::NewL", ConstructionTest ), |
|
139 ENTRY( "CPhCltEmergencyCall::IsEmergencyPhoneNumber", IsEmergencyPhoneNumber ), |
|
140 ENTRY( "CPhCltEmergencyCall::FindEmergencyPhoneNumber", FindEmergencyPhoneNumber ), |
|
141 ENTRY( "CPhCltEmergencyCall::DialEmergencyCall", DialEmergencyCall ), |
|
142 ENTRY( "CPhCltEmergencyCall::IsEmergencyPhoneNumber2", IsEmergencyPhoneNumber2 ), |
|
143 ENTRY( "CPhCltEmergencyCall::FindEmergencyPhoneNumber", FindEmergencyPhoneNumber2 ), |
|
144 //ENTRY( "Loop test", CEmergencyCallTests::LoopTest ), |
|
145 // Example how to use OOM functionality |
|
146 //OOM_ENTRY( "Loop test with OOM", CEmergencyCallTests::LoopTest, ETrue, 2, 3), |
|
147 //OOM_FUNCENTRY( CEmergencyCallTests::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 // CEmergencyCallTests::PrintTest |
|
175 // Simple printing to UI test. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CEmergencyCallTests::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 // CEmergencyCallTests::LoopTest |
|
206 // Another printing to UI test. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TInt CEmergencyCallTests::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 // ----------------------------------------------------------------------------- |
|
242 // Construction test |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 TInt CEmergencyCallTests::ConstructionTest( |
|
246 TTestResult& aResult ) |
|
247 { |
|
248 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
249 CActiveScheduler::Install( scheduler ); |
|
250 CleanupStack::PushL( scheduler ); |
|
251 CPhCltEmergencyCall* handler = CPhCltEmergencyCall::NewL( this ); |
|
252 delete handler; |
|
253 CleanupStack::PopAndDestroy( scheduler ); |
|
254 |
|
255 _LIT( KDescription, "NewL passed" ); |
|
256 aResult.SetResult( KErrNone, KDescription ); |
|
257 |
|
258 return KErrNone; |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // HandleEmergencyDialL test |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CEmergencyCallTests::HandleEmergencyDialL( const TInt aStatus ) |
|
266 { |
|
267 |
|
268 } |
|
269 |
|
270 |
|
271 //----------------------------------------------------------------------------- |
|
272 // CEmergencyCallTests::IsEmergencyPhoneNumber |
|
273 //----------------------------------------------------------------------------- |
|
274 // |
|
275 TInt CEmergencyCallTests::IsEmergencyPhoneNumber( TTestResult& aResult ) |
|
276 { |
|
277 |
|
278 TBuf<32> number(KPhoneNumber1); |
|
279 TBool value; |
|
280 |
|
281 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
282 CActiveScheduler::Install( scheduler ); |
|
283 CleanupStack::PushL( scheduler ); |
|
284 CPhCltEmergencyCall* handler = CPhCltEmergencyCall::NewL( this ); |
|
285 handler->IsEmergencyPhoneNumber( number, value ); |
|
286 delete handler; |
|
287 CleanupStack::PopAndDestroy( scheduler ); |
|
288 |
|
289 if ( value ) |
|
290 { |
|
291 _LIT( KDescription, "IsEmergencyPhoneNumber passed" ); |
|
292 aResult.SetResult( KErrNone, KDescription ); |
|
293 return KErrNone; |
|
294 } |
|
295 else |
|
296 { |
|
297 _LIT( KDescription, "IsEmergencyPhoneNumber failed" ); |
|
298 aResult.SetResult( KErrGeneral, KDescription ); |
|
299 return KErrGeneral; |
|
300 } |
|
301 |
|
302 } |
|
303 |
|
304 //----------------------------------------------------------------------------- |
|
305 // CEmergencyCallTests::IsEmergencyPhoneNumber2 |
|
306 // This case testes that, if phone number is set to 050123456#112, |
|
307 // it should not be detected as emergency number |
|
308 //----------------------------------------------------------------------------- |
|
309 // |
|
310 TInt CEmergencyCallTests::IsEmergencyPhoneNumber2( TTestResult& aResult ) |
|
311 { |
|
312 |
|
313 TBuf<32> number(KPhoneNumber2); |
|
314 TBool value; |
|
315 |
|
316 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
317 CActiveScheduler::Install( scheduler ); |
|
318 CleanupStack::PushL( scheduler ); |
|
319 CPhCltEmergencyCall* handler = CPhCltEmergencyCall::NewL( this ); |
|
320 handler->IsEmergencyPhoneNumber( number, value ); |
|
321 delete handler; |
|
322 CleanupStack::PopAndDestroy( scheduler ); |
|
323 |
|
324 if ( value == EFalse ) |
|
325 { |
|
326 _LIT( KDescription, "IsEmergencyPhoneNumber passed" ); |
|
327 aResult.SetResult( KErrNone, KDescription ); |
|
328 return KErrNone; |
|
329 } |
|
330 else |
|
331 { |
|
332 _LIT( KDescription, "IsEmergencyPhoneNumber failed" ); |
|
333 aResult.SetResult( KErrGeneral, KDescription ); |
|
334 return KErrGeneral; |
|
335 } |
|
336 |
|
337 } |
|
338 |
|
339 //----------------------------------------------------------------------------- |
|
340 // CEmergencyCallTests::FindEmergencyPhoneNumber |
|
341 //----------------------------------------------------------------------------- |
|
342 // |
|
343 TInt CEmergencyCallTests::FindEmergencyPhoneNumber(TTestResult& aResult ) |
|
344 { |
|
345 |
|
346 TBuf<32> number(KPhoneNumber1); |
|
347 TBool value; |
|
348 |
|
349 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
350 CActiveScheduler::Install( scheduler ); |
|
351 CleanupStack::PushL( scheduler ); |
|
352 CPhCltEmergencyCall* handler = CPhCltEmergencyCall::NewL( this ); |
|
353 handler->FindEmergencyPhoneNumber( number, value ); |
|
354 delete handler; |
|
355 CleanupStack::PopAndDestroy( scheduler ); |
|
356 |
|
357 if ( value ) |
|
358 { |
|
359 _LIT( KDescription, "FindEmergencyPhoneNumber passed" ); |
|
360 aResult.SetResult( KErrNone, KDescription ); |
|
361 return KErrNone; |
|
362 } |
|
363 else |
|
364 { |
|
365 _LIT( KDescription, "FindEmergencyPhoneNumber failed" ); |
|
366 aResult.SetResult( KErrGeneral, KDescription ); |
|
367 return KErrGeneral; |
|
368 } |
|
369 } |
|
370 |
|
371 //----------------------------------------------------------------------------- |
|
372 // CEmergencyCallTests::FindEmergencyPhoneNumber |
|
373 //----------------------------------------------------------------------------- |
|
374 // |
|
375 TInt CEmergencyCallTests::FindEmergencyPhoneNumber2(TTestResult& aResult ) |
|
376 { |
|
377 |
|
378 TBuf<32> number(KPhoneNumber2); |
|
379 TBool value; |
|
380 |
|
381 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
382 CActiveScheduler::Install( scheduler ); |
|
383 CleanupStack::PushL( scheduler ); |
|
384 CPhCltEmergencyCall* handler = CPhCltEmergencyCall::NewL( this ); |
|
385 handler->FindEmergencyPhoneNumber( number, value ); |
|
386 delete handler; |
|
387 CleanupStack::PopAndDestroy( scheduler ); |
|
388 |
|
389 if ( value == EFalse ) |
|
390 { |
|
391 _LIT( KDescription, "FindEmergencyPhoneNumber passed" ); |
|
392 aResult.SetResult( KErrNone, KDescription ); |
|
393 return KErrNone; |
|
394 } |
|
395 else |
|
396 { |
|
397 _LIT( KDescription, "FindEmergencyPhoneNumber failed" ); |
|
398 aResult.SetResult( KErrGeneral, KDescription ); |
|
399 return KErrGeneral; |
|
400 } |
|
401 } |
|
402 |
|
403 //----------------------------------------------------------------------------- |
|
404 // CEmergencyCallTests::DialEmergencyCall |
|
405 //----------------------------------------------------------------------------- |
|
406 // |
|
407 TInt CEmergencyCallTests::DialEmergencyCall(TTestResult& aResult ) |
|
408 { |
|
409 |
|
410 TBuf<32> number(KPhoneNumber1); |
|
411 TBool value; |
|
412 |
|
413 CActiveScheduler* scheduler = new( ELeave )CActiveScheduler(); |
|
414 CActiveScheduler::Install( scheduler ); |
|
415 CleanupStack::PushL( scheduler ); |
|
416 CPhCltEmergencyCall* handler = CPhCltEmergencyCall::NewL( this ); |
|
417 handler->DialEmergencyCallL( number ); |
|
418 delete handler; |
|
419 CleanupStack::PopAndDestroy( scheduler ); |
|
420 |
|
421 _LIT( KDescription, "DialEmergencyCall passed" ); |
|
422 aResult.SetResult( KErrNone, KDescription ); |
|
423 |
|
424 return KErrNone; |
|
425 |
|
426 } |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 // ----------------------------------------------------------------------------- |
|
433 // ?classname::?member_function |
|
434 // ?implementation_description |
|
435 // (other items were commented in a header). |
|
436 // ----------------------------------------------------------------------------- |
|
437 // |
|
438 /* |
|
439 ?type ?classname::?member_function( |
|
440 ?arg_type arg, |
|
441 ?arg_type arg ) |
|
442 { |
|
443 |
|
444 ?code |
|
445 |
|
446 } |
|
447 */ |
|
448 |
|
449 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // ?function_name implements... |
|
453 // ?implementation_description. |
|
454 // Returns: ?value_1: ?description |
|
455 // ?value_n: ?description |
|
456 // ?description |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 /* |
|
460 ?type ?function_name( |
|
461 ?arg_type arg, // ?description |
|
462 ?arg_type arg ) // ?description |
|
463 { |
|
464 |
|
465 ?code |
|
466 |
|
467 } |
|
468 */ |
|
469 // End of File |