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