|
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 "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: CAknSoundServerStifTest implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <stiftestinterface.h> |
|
20 #include "aknsoundserverstiftest.h" |
|
21 #include <settingserverclient.h> |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CAknSoundServerStifTest::CAknSoundServerStifTest |
|
27 // C++ default constructor can NOT contain any code, that |
|
28 // might leave. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CAknSoundServerStifTest::CAknSoundServerStifTest() |
|
32 { |
|
33 } |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CAknSoundServerStifTest::ConstructL |
|
37 // Symbian 2nd phase constructor can leave. |
|
38 // |
|
39 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created |
|
40 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger |
|
41 // allocates memory from heap and therefore causes error situations with OOM |
|
42 // testing. For more information about STIF Logger construction, see STIF Users |
|
43 // Guide. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CAknSoundServerStifTest::ConstructL() |
|
47 { |
|
48 // Initialise a permanent session to keysound server. |
|
49 User::LeaveIfError(iSoundServerSession.Connect()); |
|
50 TInt init = iSoundServerSession.Init(KDllUid); |
|
51 if (!init) |
|
52 { |
|
53 User::Leave(KErrUnknown); |
|
54 } |
|
55 |
|
56 //Read logger settings to check whether test case name is to be |
|
57 //appended to log file name. |
|
58 RSettingServer settingServer; |
|
59 TInt ret = settingServer.Connect(); |
|
60 if(ret != KErrNone) |
|
61 { |
|
62 User::Leave(ret); |
|
63 } |
|
64 // Struct to StifLogger settigs. |
|
65 TLoggerSettings loggerSettings; |
|
66 // Parse StifLogger defaults from STIF initialization file. |
|
67 ret = settingServer.GetLoggerSettings(loggerSettings); |
|
68 if(ret != KErrNone) |
|
69 { |
|
70 User::Leave(ret); |
|
71 } |
|
72 // Close Setting server session |
|
73 settingServer.Close(); |
|
74 iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle; |
|
75 |
|
76 iStdLog = CStifLogger::NewL( KAknSoundServerStifTestLogPath, |
|
77 KAknSoundServerStifTestLogFile); |
|
78 iLog = iStdLog; |
|
79 |
|
80 // Sample how to use logging |
|
81 _LIT( KLogStart, "AknSoundServerStifTest logging starts!" ); |
|
82 iLog->Log( KLogStart ); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CAknSoundServerStifTest::NewL |
|
87 // Two-phased constructor. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CAknSoundServerStifTest* CAknSoundServerStifTest::NewL() |
|
91 { |
|
92 CAknSoundServerStifTest* self = new (ELeave) CAknSoundServerStifTest; |
|
93 |
|
94 CleanupStack::PushL( self ); |
|
95 self->ConstructL(); |
|
96 CleanupStack::Pop(); |
|
97 |
|
98 return self; |
|
99 } |
|
100 |
|
101 // Destructor |
|
102 CAknSoundServerStifTest::~CAknSoundServerStifTest() |
|
103 { |
|
104 iLog = NULL; |
|
105 delete iStdLog; |
|
106 iStdLog = NULL; |
|
107 delete iTCLog; |
|
108 iTCLog = NULL; |
|
109 |
|
110 // Closes the connection to keysound server. |
|
111 iSoundServerSession.Close(); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CAknSoundServerStifTest::InitL |
|
116 // InitL is used to initialize the Test Module. |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 TInt CAknSoundServerStifTest::InitL( |
|
120 TFileName& /*aIniFile*/, |
|
121 TBool /*aFirstTime*/ ) |
|
122 { |
|
123 return KErrNone; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CAknSoundServerStifTest::GetTestCasesL |
|
128 // GetTestCases is used to inquire test cases from the Test Module. Test |
|
129 // cases are stored to array of test cases. The Test Framework will be |
|
130 // the owner of the data in the RPointerArray after GetTestCases return |
|
131 // and it does the memory deallocation. |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CAknSoundServerStifTest::GetTestCasesL( |
|
135 const TFileName& /*aConfig*/, |
|
136 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
137 { |
|
138 // Loop through all test cases and create new |
|
139 // TTestCaseInfo items and append items to aTestCase array |
|
140 for( TInt i = 0; Case(i).iMethod != NULL; i++ ) |
|
141 { |
|
142 // Allocate new TTestCaseInfo from heap for a testcase definition. |
|
143 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
144 |
|
145 // PushL TTestCaseInfo to CleanupStack. |
|
146 CleanupStack::PushL( newCase ); |
|
147 |
|
148 // Set number for the testcase. |
|
149 // When the testcase is run, this comes as a parameter to RunTestCaseL. |
|
150 newCase->iCaseNumber = i; |
|
151 |
|
152 // Set title for the test case. This is shown in UI to user. |
|
153 newCase->iTitle.Copy( Case(i).iCaseName ); |
|
154 |
|
155 // Append TTestCaseInfo to the testcase array. After appended |
|
156 // successfully the TTestCaseInfo object is owned (and freed) |
|
157 // by the TestServer. |
|
158 User::LeaveIfError(aTestCases.Append ( newCase ) ); |
|
159 |
|
160 // Pop TTestCaseInfo from the CleanupStack. |
|
161 CleanupStack::Pop( newCase ); |
|
162 } |
|
163 |
|
164 return KErrNone; |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CAknSoundServerStifTest::RunTestCaseL |
|
169 // RunTestCaseL is used to run an individual test case specified |
|
170 // by aTestCase. Test cases that can be run may be requested from |
|
171 // Test Module by GetTestCases method before calling RunTestCase. |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 TInt CAknSoundServerStifTest::RunTestCaseL( |
|
175 const TInt aCaseNumber, |
|
176 const TFileName& /*aConfig*/, |
|
177 TTestResult& aResult ) |
|
178 { |
|
179 // Return value |
|
180 TInt execStatus = KErrNone; |
|
181 |
|
182 // Get the pointer to test case function |
|
183 TCaseInfo tmp = Case ( aCaseNumber ); |
|
184 |
|
185 _LIT( KLogStartTC, "Starting testcase [%S]" ); |
|
186 iLog->Log( KLogStartTC, &tmp.iCaseName); |
|
187 |
|
188 // Check that case number was valid |
|
189 if ( tmp.iMethod != NULL ) |
|
190 { |
|
191 //Open new log file with test case title in file name |
|
192 if(iAddTestCaseTitleToLogName) |
|
193 { |
|
194 //Delete test case logger if exists |
|
195 if(iTCLog) |
|
196 { |
|
197 delete iTCLog; |
|
198 iTCLog = NULL; |
|
199 } |
|
200 |
|
201 TFileName logFileName; |
|
202 TName title; |
|
203 TestModuleIf().GetTestCaseTitleL(title); |
|
204 |
|
205 logFileName.Format(KAknSoundServerStifTestLogFileWithTitle, &title); |
|
206 |
|
207 iTCLog = CStifLogger::NewL(KAknSoundServerStifTestLogPath, |
|
208 logFileName); |
|
209 iLog = iTCLog; |
|
210 } |
|
211 |
|
212 // Valid case was found, call it via function pointer |
|
213 iMethod = tmp.iMethod; |
|
214 //execStatus = ( this->*iMethod )( aResult ); |
|
215 TRAPD(err, execStatus = ( this->*iMethod )( aResult )); |
|
216 if(iAddTestCaseTitleToLogName) |
|
217 { |
|
218 //Restore standard log and destroy test case logger |
|
219 iLog = iStdLog; |
|
220 delete iTCLog; //Close test case log |
|
221 iTCLog = NULL; |
|
222 } |
|
223 User::LeaveIfError(err); |
|
224 } |
|
225 else |
|
226 { |
|
227 // Valid case was not found, return error. |
|
228 execStatus = KErrNotFound; |
|
229 } |
|
230 |
|
231 // Return case execution status (not the result of the case execution) |
|
232 return execStatus; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CAknSoundServerStifTest::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 CAknSoundServerStifTest::OOMTestQueryL( |
|
242 const TFileName& /* aTestCaseFile */, |
|
243 const TInt aCaseNumber, |
|
244 TOOMFailureType& /* aFailureType */, |
|
245 TInt& aFirstMemFailure, |
|
246 TInt& aLastMemFailure ) |
|
247 { |
|
248 _LIT( KLogOOMTestQueryL, "CAknSoundServerStifTest::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 // CAknSoundServerStifTest::OOMTestInitializeL |
|
259 // Used to perform the test environment setup for a particular OOM test case. |
|
260 // Test Modules may use the initialization file to read parameters for Test |
|
261 // Module initialization but they can also have their own configure file or |
|
262 // some other routine to initialize themselves. |
|
263 // |
|
264 // NOTE: User may add implementation for OOM test environment initialization. |
|
265 // Usually no implementation is required. |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CAknSoundServerStifTest::OOMTestInitializeL( |
|
269 const TFileName& /* aTestCaseFile */, |
|
270 const TInt /* aCaseNumber */ ) |
|
271 { |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CAknSoundServerStifTest::OOMHandleWarningL |
|
276 // In some cases the heap memory allocation should be skipped, either due to |
|
277 // problems in the OS code or components used by the code being tested, or even |
|
278 // inside the tested components which are implemented this way on purpose (by |
|
279 // design), so it is important to give the tester a way to bypass allocation |
|
280 // failures. |
|
281 // |
|
282 // NOTE: User may add implementation for OOM test warning handling. Usually no |
|
283 // implementation is required. |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CAknSoundServerStifTest::OOMHandleWarningL( |
|
287 const TFileName& /* aTestCaseFile */, |
|
288 const TInt /* aCaseNumber */, |
|
289 TInt& /* aFailNextValue */ ) |
|
290 { |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CAknSoundServerStifTest::OOMTestFinalizeL |
|
295 // Used to perform the test environment cleanup for a particular OOM test case. |
|
296 // |
|
297 // NOTE: User may add implementation for OOM test environment finalization. |
|
298 // Usually no implementation is required. |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CAknSoundServerStifTest::OOMTestFinalizeL( |
|
302 const TFileName& /* aTestCaseFile */, |
|
303 const TInt /* aCaseNumber */ ) |
|
304 { |
|
305 } |
|
306 |
|
307 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // LibEntryL is a polymorphic Dll entry point |
|
311 // Returns: CTestModuleBase*: Pointer to Test Module object |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 EXPORT_C CTestModuleBase* LibEntryL() |
|
315 { |
|
316 return CAknSoundServerStifTest::NewL(); |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // SetRequirements handles test module parameters(implements evolution |
|
321 // version 1 for test module's heap and stack sizes configuring). |
|
322 // Returns: TInt: Symbian error code. |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, |
|
326 TUint32& /*aParameterValid*/ ) |
|
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 // End of File |