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