|
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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class contains all test framework related parts of |
|
15 this test module. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <Stiftestinterface.h> |
|
24 #include "IMApiTest.h" |
|
25 #include <e32math.h> |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 // None |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 // None |
|
32 |
|
33 // CONSTANTS |
|
34 // None |
|
35 |
|
36 // MACROS |
|
37 // None |
|
38 |
|
39 // LOCAL CONSTANTS AND MACROS |
|
40 // None |
|
41 |
|
42 // MODULE DATA STRUCTURES |
|
43 // None |
|
44 |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 // None |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 // None |
|
50 |
|
51 // ==================== LOCAL FUNCTIONS ======================================= |
|
52 |
|
53 |
|
54 /* |
|
55 ------------------------------------------------------------------------------- |
|
56 |
|
57 DESCRIPTION |
|
58 |
|
59 This file (IMApiTest.cpp) contains all test framework related parts of |
|
60 this test module. Actual test cases are implemented in file |
|
61 IMApiTestCases.cpp. |
|
62 |
|
63 CIMApiTest is an example of test module implementation. This example |
|
64 uses hard coded test cases (i.e it does not have any test case |
|
65 configuration file). |
|
66 |
|
67 Example uses function pointers to call test cases. This provides an easy |
|
68 method to add new test cases. |
|
69 |
|
70 See function Cases in file IMApiTestCases.cpp for instructions how to |
|
71 add new test cases. It is not necessary to modify this file when adding |
|
72 new test cases. |
|
73 |
|
74 To take this module into use, add following lines to test framework |
|
75 initialisation file: |
|
76 |
|
77 # Demo module |
|
78 [New_Module] |
|
79 ModuleName= IMApiTest |
|
80 [End_Module] |
|
81 |
|
82 ------------------------------------------------------------------------------- |
|
83 */ |
|
84 |
|
85 // ================= MEMBER FUNCTIONS ========================================= |
|
86 |
|
87 /* |
|
88 ------------------------------------------------------------------------------- |
|
89 |
|
90 Class: CIMApiTest |
|
91 |
|
92 Method: CIMApiTest |
|
93 |
|
94 Description: C++ default constructor can NOT contain any code, that |
|
95 might leave. |
|
96 |
|
97 Parameters: None |
|
98 |
|
99 Return Values: None |
|
100 |
|
101 Errors/Exceptions: None |
|
102 |
|
103 Status: Approved |
|
104 |
|
105 ------------------------------------------------------------------------------- |
|
106 */ |
|
107 CIMApiTest::CIMApiTest() |
|
108 { |
|
109 } |
|
110 |
|
111 /* |
|
112 ------------------------------------------------------------------------------- |
|
113 |
|
114 Class: CIMApiTest |
|
115 |
|
116 Method: ConstructL |
|
117 |
|
118 Description: Symbian 2nd phase constructor that can leave. |
|
119 |
|
120 Note: If OOM test case uses STIF Logger, then STIF Logger must be created |
|
121 with static buffer size parameter (aStaticBufferSize). Otherwise Logger |
|
122 allocates memory from heap and therefore causes error situations with OOM |
|
123 testing. For more information about STIF Logger construction, see STIF |
|
124 Users Guide. |
|
125 |
|
126 Parameters: None |
|
127 |
|
128 Return Values: None |
|
129 |
|
130 Errors/Exceptions: None |
|
131 |
|
132 Status: Approved |
|
133 |
|
134 ------------------------------------------------------------------------------- |
|
135 */ |
|
136 void CIMApiTest::ConstructL() |
|
137 { |
|
138 // Constructing static buffer size logger, needed with OOM testing because |
|
139 // normally logger allocates memory from heap! |
|
140 iLog = CStifLogger::NewL( KIMApiTestLogPath, |
|
141 KIMApiTestLogFile, |
|
142 CStifLogger::ETxt, |
|
143 CStifLogger::EFile, |
|
144 ETrue, |
|
145 ETrue, |
|
146 ETrue, |
|
147 EFalse, |
|
148 ETrue, |
|
149 EFalse, |
|
150 100 ); |
|
151 |
|
152 // Sample how to use logging |
|
153 _LIT( KLogInfo, "IMApiTest logging starts!" ); |
|
154 iLog->Log( KLogInfo ); |
|
155 iRunner = CTestRunner::NewL(); |
|
156 } |
|
157 |
|
158 /* |
|
159 ------------------------------------------------------------------------------- |
|
160 |
|
161 Class: CIMApiTest |
|
162 |
|
163 Method: NewL |
|
164 |
|
165 Description: Two-phased constructor. Constructs new CIMApiTest |
|
166 instance and returns pointer to it. |
|
167 |
|
168 Parameters: None |
|
169 |
|
170 Return Values: CIMApiTest*: new object. |
|
171 |
|
172 Errors/Exceptions: Leaves if memory allocation fails or ConstructL leaves. |
|
173 |
|
174 Status: Approved |
|
175 |
|
176 ------------------------------------------------------------------------------- |
|
177 */ |
|
178 CIMApiTest* CIMApiTest::NewL() |
|
179 { |
|
180 CIMApiTest* self = new ( ELeave ) CIMApiTest; |
|
181 |
|
182 CleanupStack::PushL( self ); |
|
183 self->ConstructL(); |
|
184 CleanupStack::Pop(); |
|
185 |
|
186 return self; |
|
187 } |
|
188 |
|
189 /* |
|
190 ------------------------------------------------------------------------------- |
|
191 |
|
192 Class: CIMApiTest |
|
193 |
|
194 Method: ~CIMApiTest |
|
195 |
|
196 Description: Destructor. |
|
197 |
|
198 Parameters: None |
|
199 |
|
200 Return Values: None |
|
201 |
|
202 Errors/Exceptions: None |
|
203 |
|
204 Status: Approved |
|
205 |
|
206 ------------------------------------------------------------------------------- |
|
207 */ |
|
208 CIMApiTest::~CIMApiTest() |
|
209 { |
|
210 delete iLog; |
|
211 if ( iRunner ) |
|
212 delete iRunner; |
|
213 } |
|
214 |
|
215 /* |
|
216 ------------------------------------------------------------------------------- |
|
217 Class: CIMApiTest |
|
218 |
|
219 Method: InitL |
|
220 |
|
221 Description: Method for test case initialization |
|
222 |
|
223 Parameters: None |
|
224 |
|
225 Return Values: None |
|
226 |
|
227 Errors/Exceptions: None |
|
228 |
|
229 Status: Approved |
|
230 ------------------------------------------------------------------------------- |
|
231 */ |
|
232 TInt CIMApiTest::InitL( TFileName& /*aIniFile*/, |
|
233 TBool /*aFirstTime*/ ) |
|
234 { |
|
235 return KErrNone; |
|
236 |
|
237 } |
|
238 |
|
239 /* |
|
240 ------------------------------------------------------------------------------- |
|
241 |
|
242 Class: CIMApiTest |
|
243 |
|
244 Method: GetTestCases |
|
245 |
|
246 Description: GetTestCases is used to inquire test cases |
|
247 from the test module. Because this test module has hard coded test cases |
|
248 (i.e cases are not read from file), paramter aConfigFile is not used. |
|
249 |
|
250 This function loops through all cases defined in Cases() function and |
|
251 adds corresponding items to aTestCases array. |
|
252 |
|
253 Parameters: const TFileName& : in: Configuration file name. Not used |
|
254 RPointerArray<TTestCaseInfo>& aTestCases: out: |
|
255 Array of TestCases. |
|
256 |
|
257 Return Values: KErrNone: No error |
|
258 |
|
259 Errors/Exceptions: Function leaves if any memory allocation operation fails |
|
260 |
|
261 Status: Proposal |
|
262 |
|
263 ------------------------------------------------------------------------------- |
|
264 */ |
|
265 TInt CIMApiTest::GetTestCasesL( const TFileName& /*aConfig*/, |
|
266 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
267 { |
|
268 // Loop through all test cases and create new |
|
269 // TTestCaseInfo items and append items to aTestCase array |
|
270 for ( TInt i = 0; Case( i ).iMethod != NULL; i++ ) |
|
271 { |
|
272 // Allocate new TTestCaseInfo from heap for a testcase definition. |
|
273 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
274 |
|
275 // PushL TTestCaseInfo to CleanupStack. |
|
276 CleanupStack::PushL( newCase ); |
|
277 |
|
278 // Set number for the testcase. |
|
279 // When the testcase is run, this comes as a parameter to RunTestCaseL. |
|
280 newCase->iCaseNumber = i; |
|
281 |
|
282 // Set title for the test case. This is shown in UI to user. |
|
283 newCase->iTitle.Copy( Case( i ).iCaseName ); |
|
284 |
|
285 // Append TTestCaseInfo to the testcase array. After appended |
|
286 // successfully the TTestCaseInfo object is owned (and freed) |
|
287 // by the TestServer. |
|
288 User::LeaveIfError( aTestCases.Append ( newCase ) ); |
|
289 |
|
290 // Pop TTestCaseInfo from the CleanupStack. |
|
291 CleanupStack::Pop( newCase ); |
|
292 } |
|
293 |
|
294 return KErrNone; |
|
295 |
|
296 } |
|
297 |
|
298 /* |
|
299 ------------------------------------------------------------------------------- |
|
300 |
|
301 Class: CIMApiTest |
|
302 |
|
303 Method: RunTestCase |
|
304 |
|
305 Description: Run a specified testcase. |
|
306 |
|
307 Function runs a test case specified by test case number. Test case file |
|
308 parameter is not used. |
|
309 |
|
310 If case number is valid, this function runs a test case returned by |
|
311 function Cases(). |
|
312 |
|
313 Parameters: const TInt aCaseNumber: in: Testcase number |
|
314 const TFileName& : in: Configuration file name. Not used |
|
315 TTestResult& aResult: out: Testcase result |
|
316 |
|
317 Return Values: KErrNone: Testcase ran. |
|
318 KErrNotFound: Unknown testcase |
|
319 |
|
320 Errors/Exceptions: None |
|
321 |
|
322 Status: Proposal |
|
323 |
|
324 ------------------------------------------------------------------------------- |
|
325 */ |
|
326 TInt CIMApiTest::RunTestCaseL( const TInt aCaseNumber, |
|
327 const TFileName& /* aConfig */, |
|
328 TTestResult& aResult ) |
|
329 { |
|
330 // Return value |
|
331 TInt execStatus = KErrNone; |
|
332 |
|
333 // Get the pointer to test case function |
|
334 TCaseInfo tmp = Case ( aCaseNumber ); |
|
335 |
|
336 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
337 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
338 |
|
339 _LIT( KLogInfo, "Starting testcase [%S]" ); |
|
340 iLog->Log( KLogInfo, &tmp.iCaseName ); |
|
341 |
|
342 // Check that case number was valid |
|
343 if ( tmp.iMethod != NULL ) |
|
344 { |
|
345 // Valid case was found, call it via function pointer |
|
346 iMethod = tmp.iMethod; |
|
347 execStatus = ( this->*iMethod )( aResult ); |
|
348 } |
|
349 else |
|
350 { |
|
351 // Valid case was not found, return error. |
|
352 execStatus = KErrNotFound; |
|
353 } |
|
354 |
|
355 // Return case execution status (not the result of the case execution) |
|
356 return execStatus; |
|
357 |
|
358 } |
|
359 |
|
360 /* |
|
361 ------------------------------------------------------------------------------- |
|
362 |
|
363 Class: CIMApiTest |
|
364 |
|
365 Method: OOMTestQueryL |
|
366 |
|
367 Description: Checks test case information for OOM execution. |
|
368 |
|
369 Return Values: TBool |
|
370 |
|
371 Errors/Exceptions: None |
|
372 |
|
373 Status: Proposal |
|
374 |
|
375 ------------------------------------------------------------------------------- |
|
376 */ |
|
377 TBool CIMApiTest::OOMTestQueryL( const TFileName& /* aTestCaseFile */, |
|
378 const TInt aCaseNumber, |
|
379 TOOMFailureType& /* aFailureType */, |
|
380 TInt& aFirstMemFailure, |
|
381 TInt& aLastMemFailure ) |
|
382 { |
|
383 _LIT( KLogInfo, "CIMApiTest::OOMTestQueryL" ); |
|
384 iLog->Log( KLogInfo ); |
|
385 |
|
386 aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation; |
|
387 aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation; |
|
388 |
|
389 return Case( aCaseNumber ).iIsOOMTest; |
|
390 } |
|
391 |
|
392 /* |
|
393 ------------------------------------------------------------------------------- |
|
394 |
|
395 Class: CIMApiTest |
|
396 |
|
397 Method: OOMTestInitializeL |
|
398 |
|
399 Description: Used to perform the test environment setup for a particular |
|
400 OOM test case. Test Modules may use the initialization file to read |
|
401 parameters for Test Module initialization but they can also have their own |
|
402 configure file or some other routine to initialize themselves. |
|
403 |
|
404 NOTE: User may add implementation for OOM test environment initialization. |
|
405 Usually no implementation is required. |
|
406 |
|
407 Return Values: None |
|
408 |
|
409 Errors/Exceptions: None |
|
410 |
|
411 Status: Proposal |
|
412 |
|
413 ------------------------------------------------------------------------------- |
|
414 */ |
|
415 void CIMApiTest::OOMTestInitializeL( const TFileName& /* aTestCaseFile */, |
|
416 const TInt /* aCaseNumber */ ) |
|
417 { |
|
418 _LIT( KLogInfo, "CIMApiTest::OOMTestInitializeL" ); |
|
419 iLog->Log( KLogInfo ); |
|
420 |
|
421 } |
|
422 |
|
423 /* |
|
424 ------------------------------------------------------------------------------- |
|
425 |
|
426 Class: CIMApiTest |
|
427 |
|
428 Method: OOMHandleWarningL |
|
429 |
|
430 Description: Used in OOM testing to provide a way to the derived TestModule |
|
431 to handle warnings related to non-leaving or TRAPped allocations. |
|
432 |
|
433 In some cases the allocation should be skipped, either due to problems in |
|
434 the OS code or components used by the code being tested, or even inside the |
|
435 tested components which are implemented this way on purpose (by design), so |
|
436 it is important to give the tester a way to bypass allocation failures. |
|
437 |
|
438 NOTE: User may add implementation for OOM test warning handling. Usually no |
|
439 implementation is required. |
|
440 |
|
441 Return Values: None |
|
442 |
|
443 Errors/Exceptions: None |
|
444 |
|
445 Status: Proposal |
|
446 |
|
447 ------------------------------------------------------------------------------- |
|
448 */ |
|
449 void CIMApiTest::OOMHandleWarningL( const TFileName& /* aTestCaseFile */, |
|
450 const TInt /* aCaseNumber */, |
|
451 TInt& /* aFailNextValue */ ) |
|
452 { |
|
453 _LIT( KLogInfo, "CIMApiTest::OOMHandleWarningL" ); |
|
454 iLog->Log( KLogInfo ); |
|
455 |
|
456 } |
|
457 |
|
458 /* |
|
459 ------------------------------------------------------------------------------- |
|
460 |
|
461 Class: CIMApiTest |
|
462 |
|
463 Method: OOMTestFinalizeL |
|
464 |
|
465 Description: Used to perform the test environment cleanup for a particular OOM |
|
466 test case. |
|
467 |
|
468 NOTE: User may add implementation for OOM test environment finalization. |
|
469 Usually no implementation is required. |
|
470 |
|
471 Return Values: None |
|
472 |
|
473 Errors/Exceptions: None |
|
474 |
|
475 Status: Proposal |
|
476 |
|
477 ------------------------------------------------------------------------------- |
|
478 */ |
|
479 void CIMApiTest::OOMTestFinalizeL( const TFileName& /* aTestCaseFile */, |
|
480 const TInt /* aCaseNumber */ ) |
|
481 { |
|
482 _LIT( KLogInfo, "CIMApiTest::OOMTestFinalizeL" ); |
|
483 iLog->Log( KLogInfo ); |
|
484 |
|
485 } |
|
486 |
|
487 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // LibEntryL is a polymorphic Dll entry point |
|
491 // Returns: CTestModuleBase*: Pointer to Test Module object |
|
492 // ----------------------------------------------------------------------------- |
|
493 // |
|
494 EXPORT_C CTestModuleBase* LibEntryL() |
|
495 { |
|
496 return CIMApiTest::NewL(); |
|
497 |
|
498 } |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // SetRequirements handles test module parameters(implements evolution |
|
502 // version 1 for test module's heap and stack sizes configuring). |
|
503 // Returns: TInt: Symbian error code. |
|
504 // ----------------------------------------------------------------------------- |
|
505 // |
|
506 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, |
|
507 TUint32& /*aParameterValid*/ ) |
|
508 { |
|
509 |
|
510 /* --------------------------------- NOTE --------------------------------- |
|
511 USER PANICS occurs in test thread creation when: |
|
512 1) "The panic occurs when the value of the stack size is negative." |
|
513 2) "The panic occurs if the minimum heap size specified is less |
|
514 than KMinHeapSize". |
|
515 KMinHeapSize: "Functions that require a new heap to be allocated will |
|
516 either panic, or will reset the required heap size to this value if |
|
517 a smaller heap size is specified". |
|
518 3) "The panic occurs if the minimum heap size specified is greater than |
|
519 the maximum size to which the heap can grow". |
|
520 Other: |
|
521 1) Make sure that your hardware or Symbian OS is supporting given sizes. |
|
522 e.g. Hardware might support only sizes that are divisible by four. |
|
523 ------------------------------- NOTE end ------------------------------- */ |
|
524 |
|
525 // Normally STIF uses default heap and stack sizes for test thread, see: |
|
526 // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize. |
|
527 // If needed heap and stack sizes can be configured here by user. Remove |
|
528 // comments and define sizes. |
|
529 |
|
530 /* |
|
531 aParameterValid = KStifTestModuleParameterChanged; |
|
532 |
|
533 CTestModuleParamVer01* param = CTestModuleParamVer01::NewL(); |
|
534 // Stack size |
|
535 param->iTestThreadStackSize= 16384; // 16K stack |
|
536 // Heap sizes |
|
537 param->iTestThreadMinHeap = 4096; // 4K heap min |
|
538 param->iTestThreadMaxHeap = 1048576;// 1M heap max |
|
539 |
|
540 aTestModuleParam = param; |
|
541 */ |
|
542 return KErrNone; |
|
543 |
|
544 } |
|
545 |
|
546 |
|
547 // End of File |