|
1 /* |
|
2 * Copyright (c) 2002-2009 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: SenUtils class member functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 // INCLUDE FILES |
|
27 #include <StifTestInterface.h> |
|
28 #include "senutilsbctest.h" |
|
29 |
|
30 // EXTERNAL DATA STRUCTURES |
|
31 //extern ?external_data; |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 //extern ?external_function( ?arg_type,?arg_type ); |
|
35 |
|
36 // CONSTANTS |
|
37 //const ?type ?constant_var = ?constant; |
|
38 |
|
39 // MACROS |
|
40 //#define ?macro ?macro_def |
|
41 |
|
42 // LOCAL CONSTANTS AND MACROS |
|
43 //const ?type ?constant_var = ?constant; |
|
44 //#define ?macro_name ?macro_def |
|
45 |
|
46 // MODULE DATA STRUCTURES |
|
47 //enum ?declaration |
|
48 //typedef ?declaration |
|
49 |
|
50 // LOCAL FUNCTION PROTOTYPES |
|
51 //?type ?function_name( ?arg_type, ?arg_type ); |
|
52 |
|
53 // FORWARD DECLARATIONS |
|
54 //class ?FORWARD_CLASSNAME; |
|
55 |
|
56 // ============================= LOCAL FUNCTIONS =============================== |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // ?function_name ?description. |
|
60 // ?description |
|
61 // Returns: ?value_1: ?description |
|
62 // ?value_n: ?description_line1 |
|
63 // ?description_line2 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 /* |
|
67 ?type ?function_name( |
|
68 ?arg_type arg, // ?description |
|
69 ?arg_type arg) // ?description |
|
70 { |
|
71 |
|
72 ?code // ?comment |
|
73 |
|
74 // ?comment |
|
75 ?code |
|
76 } |
|
77 */ |
|
78 |
|
79 // ============================ MEMBER FUNCTIONS =============================== |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CSenUtilsBCTest::CSenUtilsBCTest |
|
83 // C++ default constructor can NOT contain any code, that |
|
84 // might leave. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CSenUtilsBCTest::CSenUtilsBCTest() |
|
88 { |
|
89 |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CSenUtilsBCTest::ConstructL |
|
94 // Symbian 2nd phase constructor can leave. |
|
95 // |
|
96 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created |
|
97 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger |
|
98 // allocates memory from heap and therefore causes error situations with OOM |
|
99 // testing. For more information about STIF Logger construction, see STIF Users |
|
100 // Guide. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CSenUtilsBCTest::ConstructL() |
|
104 { |
|
105 iLog = CStifLogger::NewL( KSenUtilsLogPath, |
|
106 KSenUtilsLogFile); |
|
107 |
|
108 // Sample how to use logging |
|
109 _LIT( KLogStart, "SenUtils logging starts!" ); |
|
110 iLog->Log( KLogStart ); |
|
111 |
|
112 // if ( iXmlReader ){ |
|
113 // delete iXmlReader; |
|
114 //} |
|
115 //iXmlReader = CSenXmlReader::NewL(); |
|
116 |
|
117 } |
|
118 //----------------------------------------------------------------------------- |
|
119 // CSenUtilsBCTest::SendTestClassVersion |
|
120 // Method used to send version of test class |
|
121 //----------------------------------------------------------------------------- |
|
122 // |
|
123 void CSenUtilsBCTest::SendTestModuleVersion() |
|
124 { |
|
125 TVersion moduleVersion; |
|
126 moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR; |
|
127 moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR; |
|
128 moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD; |
|
129 |
|
130 TFileName moduleName; |
|
131 moduleName = _L("SenUtilsBCTest.dll"); |
|
132 |
|
133 |
|
134 TBool newVersionOfMethod = ETrue; |
|
135 CTestModuleIf &test=TestModuleIf(); |
|
136 test.SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod); |
|
137 test.SetBehavior(CTestModuleIf::ETestLeaksHandles); |
|
138 } |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CSenUtilsBCTest::NewL |
|
141 // Two-phased constructor. |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 CSenUtilsBCTest* CSenUtilsBCTest::NewL() |
|
145 { |
|
146 CSenUtilsBCTest* self = new (ELeave) CSenUtilsBCTest; |
|
147 |
|
148 CleanupStack::PushL( self ); |
|
149 self->ConstructL(); |
|
150 CleanupStack::Pop(); |
|
151 |
|
152 return self; |
|
153 |
|
154 } |
|
155 |
|
156 // Destructor |
|
157 CSenUtilsBCTest::~CSenUtilsBCTest() |
|
158 { |
|
159 if (iLog) delete iLog; |
|
160 //if ( iXmlReader) |
|
161 //{ |
|
162 //delete iXmlReader; |
|
163 // iXmlReader = NULL; |
|
164 // } |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CSenUtilsBCTest::InitL |
|
169 // InitL is used to initialize the Test Module. |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CSenUtilsBCTest::InitL( |
|
173 TFileName& /*aIniFile*/, |
|
174 TBool /*aFirstTime*/ ) |
|
175 { |
|
176 return KErrNone; |
|
177 |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CSenUtilsBCTest::GetTestCasesL |
|
182 // GetTestCases is used to inquire test cases from the Test Module. Test |
|
183 // cases are stored to array of test cases. The Test Framework will be |
|
184 // the owner of the data in the RPointerArray after GetTestCases return |
|
185 // and it does the memory deallocation. |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 TInt CSenUtilsBCTest::GetTestCasesL( |
|
189 const TFileName& /*aConfig*/, |
|
190 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
191 { |
|
192 |
|
193 // Loop through all test cases and create new |
|
194 // TTestCaseInfo items and append items to aTestCase array |
|
195 for( TInt i = 0; Case(i).iMethod != NULL; i++ ) |
|
196 { |
|
197 |
|
198 // Allocate new TTestCaseInfo from heap for a testcase definition. |
|
199 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
200 |
|
201 // PushL TTestCaseInfo to CleanupStack. |
|
202 CleanupStack::PushL( newCase ); |
|
203 |
|
204 // Set number for the testcase. |
|
205 // When the testcase is run, this comes as a parameter to RunTestCaseL. |
|
206 newCase->iCaseNumber = i; |
|
207 |
|
208 // Set title for the test case. This is shown in UI to user. |
|
209 newCase->iTitle.Copy( Case(i).iCaseName ); |
|
210 |
|
211 // Append TTestCaseInfo to the testcase array. After appended |
|
212 // successfully the TTestCaseInfo object is owned (and freed) |
|
213 // by the TestServer. |
|
214 User::LeaveIfError(aTestCases.Append ( newCase ) ); |
|
215 |
|
216 // Pop TTestCaseInfo from the CleanupStack. |
|
217 CleanupStack::Pop( newCase ); |
|
218 |
|
219 } |
|
220 |
|
221 return KErrNone; |
|
222 |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CSenUtilsBCTest::RunTestCaseL |
|
227 // RunTestCaseL is used to run an individual test case specified |
|
228 // by aTestCase. Test cases that can be run may be requested from |
|
229 // Test Module by GetTestCases method before calling RunTestCase. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TInt CSenUtilsBCTest::RunTestCaseL( |
|
233 const TInt aCaseNumber, |
|
234 const TFileName& /*aConfig*/, |
|
235 TTestResult& aResult ) |
|
236 { |
|
237 SendTestModuleVersion(); |
|
238 // Return value |
|
239 TInt execStatus = KErrNone; |
|
240 |
|
241 // Get the pointer to test case function |
|
242 TCaseInfo tmp = Case ( aCaseNumber ); |
|
243 iLog->Log( _L("-------------------------------------------------------------")); |
|
244 _LIT( KLogStartTC, "Starting testcase [%S]" ); |
|
245 iLog->Log( KLogStartTC, &tmp.iCaseName); |
|
246 |
|
247 // Check that case number was valid |
|
248 if ( tmp.iMethod != NULL ) |
|
249 { |
|
250 // Valid case was found, call it via function pointer |
|
251 iMethod = tmp.iMethod; |
|
252 execStatus = ( this->*iMethod )( aResult ); |
|
253 } |
|
254 else |
|
255 { |
|
256 // Valid case was not found, return error. |
|
257 execStatus = KErrNotFound; |
|
258 } |
|
259 |
|
260 // Return case execution status (not the result of the case execution) |
|
261 return execStatus; |
|
262 |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CSenUtilsBCTest::OOMTestQueryL |
|
267 // Used to check if a particular test case should be run in OOM conditions and |
|
268 // which memory allocations should fail. |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 TBool CSenUtilsBCTest::OOMTestQueryL( |
|
272 const TFileName& /* aTestCaseFile */, |
|
273 const TInt aCaseNumber, |
|
274 TOOMFailureType& /* aFailureType */, |
|
275 TInt& aFirstMemFailure, |
|
276 TInt& aLastMemFailure ) |
|
277 { |
|
278 _LIT( KLogOOMTestQueryL, "CSenUtilsBCTest::OOMTestQueryL" ); |
|
279 iLog->Log( KLogOOMTestQueryL ); |
|
280 |
|
281 aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation; |
|
282 aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation; |
|
283 |
|
284 return Case( aCaseNumber ).iIsOOMTest; |
|
285 |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CSenUtilsBCTest::OOMTestInitializeL |
|
290 // Used to perform the test environment setup for a particular OOM test case. |
|
291 // Test Modules may use the initialization file to read parameters for Test |
|
292 // Module initialization but they can also have their own configure file or |
|
293 // some other routine to initialize themselves. |
|
294 // |
|
295 // NOTE: User may add implementation for OOM test environment initialization. |
|
296 // Usually no implementation is required. |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CSenUtilsBCTest::OOMTestInitializeL( |
|
300 const TFileName& /* aTestCaseFile */, |
|
301 const TInt /* aCaseNumber */ ) |
|
302 { |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CSenUtilsBCTest::OOMHandleWarningL |
|
307 // In some cases the heap memory allocation should be skipped, either due to |
|
308 // problems in the OS code or components used by the code being tested, or even |
|
309 // inside the tested components which are implemented this way on purpose (by |
|
310 // design), so it is important to give the tester a way to bypass allocation |
|
311 // failures. |
|
312 // |
|
313 // NOTE: User may add implementation for OOM test warning handling. Usually no |
|
314 // implementation is required. |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CSenUtilsBCTest::OOMHandleWarningL( |
|
318 const TFileName& /* aTestCaseFile */, |
|
319 const TInt /* aCaseNumber */, |
|
320 TInt& /* aFailNextValue */ ) |
|
321 { |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CSenUtilsBCTest::OOMTestFinalizeL |
|
326 // Used to perform the test environment cleanup for a particular OOM test case. |
|
327 // |
|
328 // NOTE: User may add implementation for OOM test environment finalization. |
|
329 // Usually no implementation is required. |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 void CSenUtilsBCTest::OOMTestFinalizeL( |
|
333 const TFileName& /* aTestCaseFile */, |
|
334 const TInt /* aCaseNumber */ ) |
|
335 { |
|
336 } |
|
337 |
|
338 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // LibEntryL is a polymorphic Dll entry point |
|
342 // Returns: CTestModuleBase*: Pointer to Test Module object |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 EXPORT_C CTestModuleBase* LibEntryL() |
|
346 { |
|
347 return CSenUtilsBCTest::NewL(); |
|
348 |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // SetRequirements handles test module parameters(implements evolution |
|
353 // version 1 for test module's heap and stack sizes configuring). |
|
354 // Returns: TInt: Symbian error code. |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, |
|
358 TUint32& /*aParameterValid*/ ) |
|
359 { |
|
360 |
|
361 /* --------------------------------- NOTE --------------------------------- |
|
362 USER PANICS occurs in test thread creation when: |
|
363 1) "The panic occurs when the value of the stack size is negative." |
|
364 2) "The panic occurs if the minimum heap size specified is less |
|
365 than KMinHeapSize". |
|
366 KMinHeapSize: "Functions that require a new heap to be allocated will |
|
367 either panic, or will reset the required heap size to this value if |
|
368 a smaller heap size is specified". |
|
369 3) "The panic occurs if the minimum heap size specified is greater than |
|
370 the maximum size to which the heap can grow". |
|
371 Other: |
|
372 1) Make sure that your hardware or Symbian OS is supporting given sizes. |
|
373 e.g. Hardware might support only sizes that are divisible by four. |
|
374 ------------------------------- NOTE end ------------------------------- */ |
|
375 |
|
376 // Normally STIF uses default heap and stack sizes for test thread, see: |
|
377 // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize. |
|
378 // If needed heap and stack sizes can be configured here by user. Remove |
|
379 // comments and define sizes. |
|
380 |
|
381 /* |
|
382 aParameterValid = KStifTestModuleParameterChanged; |
|
383 |
|
384 CTestModuleParamVer01* param = CTestModuleParamVer01::NewL(); |
|
385 // Stack size |
|
386 param->iTestThreadStackSize= 16384; // 16K stack |
|
387 // Heap sizes |
|
388 param->iTestThreadMinHeap = 4096; // 4K heap min |
|
389 param->iTestThreadMaxHeap = 1048576;// 1M heap max |
|
390 |
|
391 aTestModuleParam = param; |
|
392 */ |
|
393 return KErrNone; |
|
394 |
|
395 } |
|
396 |
|
397 // ----------------------------------------------------------------------------- |
|
398 // E32Dll is a DLL entry point function |
|
399 // Returns: KErrNone: No error |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 #ifndef EKA2 // Hide Dll entry point to EKA2 |
|
403 GLDEF_C TInt E32Dll( |
|
404 TDllReason /*aReason*/) // Reason |
|
405 { |
|
406 return(KErrNone); |
|
407 |
|
408 } |
|
409 #endif // EKA2 |
|
410 |
|
411 // End of File |