|
1 /* |
|
2 * Copyright (c) 2002 - 2007 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 "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: WebUtilsBCTest class member functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <Stiftestinterface.h> |
|
22 #include "WebUtilsBCTest.h" |
|
23 |
|
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 |
|
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 // CWebUtilsBCTest::CWebUtilsBCTest |
|
77 // C++ default constructor can NOT contain any code, that |
|
78 // might leave. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CWebUtilsBCTest::CWebUtilsBCTest() |
|
82 { |
|
83 |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CWebUtilsBCTest::ConstructL |
|
88 // Symbian 2nd phase constructor can leave. |
|
89 // |
|
90 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created |
|
91 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger |
|
92 // allocates memory from heap and therefore causes error situations with OOM |
|
93 // testing. For more information about STIF Logger construction, see STIF Users |
|
94 // Guide. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CWebUtilsBCTest::ConstructL() |
|
98 { |
|
99 iLog = CStifLogger::NewL( KWebUtilsBCTestLogPath, |
|
100 KWebUtilsBCTestLogFile); |
|
101 |
|
102 |
|
103 iUserAgent = CUserAgent::NewL(); |
|
104 |
|
105 // Sample how to use logging |
|
106 _LIT( KLogStart, "WebUtilsBCTest logging starts!" ); |
|
107 iLog->Log( KLogStart ); |
|
108 |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CWebUtilsBCTest::NewL |
|
113 // Two-phased constructor. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CWebUtilsBCTest* CWebUtilsBCTest::NewL() |
|
117 { |
|
118 CWebUtilsBCTest* self = new (ELeave) CWebUtilsBCTest; |
|
119 |
|
120 CleanupStack::PushL( self ); |
|
121 self->ConstructL(); |
|
122 CleanupStack::Pop(); |
|
123 |
|
124 return self; |
|
125 |
|
126 } |
|
127 |
|
128 // Destructor |
|
129 CWebUtilsBCTest::~CWebUtilsBCTest() |
|
130 { |
|
131 delete iUserAgent; |
|
132 delete iLog; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CWebUtilsBCTest::InitL |
|
137 // InitL is used to initialize the Test Module. |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CWebUtilsBCTest::InitL( |
|
141 TFileName& /*aIniFile*/, |
|
142 TBool /*aFirstTime*/ ) |
|
143 { |
|
144 return KErrNone; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CWebUtilsBCTest::GetTestCasesL |
|
149 // GetTestCases is used to inquire test cases from the Test Module. Test |
|
150 // cases are stored to array of test cases. The Test Framework will be |
|
151 // the owner of the data in the RPointerArray after GetTestCases return |
|
152 // and it does the memory deallocation. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CWebUtilsBCTest::GetTestCasesL( |
|
156 const TFileName& /*aConfig*/, |
|
157 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
158 { |
|
159 |
|
160 // Loop through all test cases and create new |
|
161 // TTestCaseInfo items and append items to aTestCase array |
|
162 for( TInt i = 0; Case(i).iMethod != NULL; i++ ) |
|
163 { |
|
164 |
|
165 // Allocate new TTestCaseInfo from heap for a testcase definition. |
|
166 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
167 |
|
168 // PushL TTestCaseInfo to CleanupStack. |
|
169 CleanupStack::PushL( newCase ); |
|
170 |
|
171 // Set number for the testcase. |
|
172 // When the testcase is run, this comes as a parameter to RunTestCaseL. |
|
173 newCase->iCaseNumber = i; |
|
174 |
|
175 // Set title for the test case. This is shown in UI to user. |
|
176 newCase->iTitle.Copy( Case(i).iCaseName ); |
|
177 |
|
178 // Append TTestCaseInfo to the testcase array. After appended |
|
179 // successfully the TTestCaseInfo object is owned (and freed) |
|
180 // by the TestServer. |
|
181 User::LeaveIfError(aTestCases.Append ( newCase ) ); |
|
182 |
|
183 // Pop TTestCaseInfo from the CleanupStack. |
|
184 CleanupStack::Pop( newCase ); |
|
185 |
|
186 } |
|
187 |
|
188 return KErrNone; |
|
189 |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CWebUtilsBCTest::RunTestCaseL |
|
194 // RunTestCaseL is used to run an individual test case specified |
|
195 // by aTestCase. Test cases that can be run may be requested from |
|
196 // Test Module by GetTestCases method before calling RunTestCase. |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 TInt CWebUtilsBCTest::RunTestCaseL( |
|
200 const TInt aCaseNumber, |
|
201 const TFileName& /*aConfig*/, |
|
202 TTestResult& aResult ) |
|
203 { |
|
204 |
|
205 // Return value |
|
206 TInt execStatus = KErrNone; |
|
207 |
|
208 // Get the pointer to test case function |
|
209 TCaseInfo tmp = Case ( aCaseNumber ); |
|
210 |
|
211 _LIT( KLogStartTC, "Starting testcase [%S]" ); |
|
212 iLog->Log( KLogStartTC, &tmp.iCaseName); |
|
213 |
|
214 // Check that case number was valid |
|
215 if ( tmp.iMethod != NULL ) |
|
216 { |
|
217 // Valid case was found, call it via function pointer |
|
218 iMethod = tmp.iMethod; |
|
219 execStatus = ( this->*iMethod )( aResult ); |
|
220 } |
|
221 else |
|
222 { |
|
223 // Valid case was not found, return error. |
|
224 execStatus = KErrNotFound; |
|
225 } |
|
226 |
|
227 // Return case execution status (not the result of the case execution) |
|
228 return execStatus; |
|
229 |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CWebUtilsBCTest::OOMTestQueryL |
|
234 // Used to check if a particular test case should be run in OOM conditions and |
|
235 // which memory allocations should fail. |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 TBool CWebUtilsBCTest::OOMTestQueryL( |
|
239 const TFileName& /* aTestCaseFile */, |
|
240 const TInt aCaseNumber, |
|
241 TOOMFailureType& /* aFailureType */, |
|
242 TInt& aFirstMemFailure, |
|
243 TInt& aLastMemFailure ) |
|
244 { |
|
245 _LIT( KLogOOMTestQueryL, "CWebUtilsBCTest::OOMTestQueryL" ); |
|
246 iLog->Log( KLogOOMTestQueryL ); |
|
247 |
|
248 aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation; |
|
249 aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation; |
|
250 |
|
251 return Case( aCaseNumber ).iIsOOMTest; |
|
252 |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CWebUtilsBCTest::OOMTestInitializeL |
|
257 // Used to perform the test environment setup for a particular OOM test case. |
|
258 // Test Modules may use the initialization file to read parameters for Test |
|
259 // Module initialization but they can also have their own configure file or |
|
260 // some other routine to initialize themselves. |
|
261 // |
|
262 // NOTE: User may add implementation for OOM test environment initialization. |
|
263 // Usually no implementation is required. |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CWebUtilsBCTest::OOMTestInitializeL( |
|
267 const TFileName& /* aTestCaseFile */, |
|
268 const TInt /* aCaseNumber */ ) |
|
269 { |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CWebUtilsBCTest::OOMHandleWarningL |
|
274 // In some cases the heap memory allocation should be skipped, either due to |
|
275 // problems in the OS code or components used by the code being tested, or even |
|
276 // inside the tested components which are implemented this way on purpose (by |
|
277 // design), so it is important to give the tester a way to bypass allocation |
|
278 // failures. |
|
279 // |
|
280 // NOTE: User may add implementation for OOM test warning handling. Usually no |
|
281 // implementation is required. |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 void CWebUtilsBCTest::OOMHandleWarningL( |
|
285 const TFileName& /* aTestCaseFile */, |
|
286 const TInt /* aCaseNumber */, |
|
287 TInt& /* aFailNextValue */ ) |
|
288 { |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CWebUtilsBCTest::OOMTestFinalizeL |
|
293 // Used to perform the test environment cleanup for a particular OOM test case. |
|
294 // |
|
295 // NOTE: User may add implementation for OOM test environment finalization. |
|
296 // Usually no implementation is required. |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CWebUtilsBCTest::OOMTestFinalizeL( |
|
300 const TFileName& /* aTestCaseFile */, |
|
301 const TInt /* aCaseNumber */ ) |
|
302 { |
|
303 } |
|
304 |
|
305 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // LibEntryL is a polymorphic Dll entry point |
|
309 // Returns: CTestModuleBase*: Pointer to Test Module object |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C CTestModuleBase* LibEntryL() |
|
313 { |
|
314 return CWebUtilsBCTest::NewL(); |
|
315 |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // SetRequirements handles test module parameters(implements evolution |
|
320 // version 1 for test module's heap and stack sizes configuring). |
|
321 // Returns: TInt: Symbian error code. |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, |
|
325 TUint32& /*aParameterValid*/ ) |
|
326 { |
|
327 |
|
328 /* --------------------------------- NOTE --------------------------------- |
|
329 USER PANICS occurs in test thread creation when: |
|
330 1) "The panic occurs when the value of the stack size is negative." |
|
331 2) "The panic occurs if the minimum heap size specified is less |
|
332 than KMinHeapSize". |
|
333 KMinHeapSize: "Functions that require a new heap to be allocated will |
|
334 either panic, or will reset the required heap size to this value if |
|
335 a smaller heap size is specified". |
|
336 3) "The panic occurs if the minimum heap size specified is greater than |
|
337 the maximum size to which the heap can grow". |
|
338 Other: |
|
339 1) Make sure that your hardware or Symbian OS is supporting given sizes. |
|
340 e.g. Hardware might support only sizes that are divisible by four. |
|
341 ------------------------------- NOTE end ------------------------------- */ |
|
342 |
|
343 // Normally STIF uses default heap and stack sizes for test thread, see: |
|
344 // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize. |
|
345 // If needed heap and stack sizes can be configured here by user. Remove |
|
346 // comments and define sizes. |
|
347 |
|
348 /* |
|
349 aParameterValid = KStifTestModuleParameterChanged; |
|
350 |
|
351 CTestModuleParamVer01* param = CTestModuleParamVer01::NewL(); |
|
352 // Stack size |
|
353 param->iTestThreadStackSize= 16384; // 16K stack |
|
354 // Heap sizes |
|
355 param->iTestThreadMinHeap = 4096; // 4K heap min |
|
356 param->iTestThreadMaxHeap = 1048576;// 1M heap max |
|
357 |
|
358 aTestModuleParam = param; |
|
359 */ |
|
360 return KErrNone; |
|
361 |
|
362 } |
|
363 |
|
364 |
|
365 // End of File |