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