|
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: CIsvTelephonyTest class member functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <Stiftestinterface.h> |
|
22 #include <StifParser.h> |
|
23 #include "IsvTelephonyTest.h" |
|
24 #include "IsvTelephonyTestEngine.h" |
|
25 #include "IsvTelephonyTestParser.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CIsvTelephonyTest::CIsvTelephonyTest |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CIsvTelephonyTest::CIsvTelephonyTest() |
|
36 { |
|
37 iMessageOption = EMessagesLogAndUi; |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CIsvTelephonyTest::ConstructL |
|
42 // Symbian 2nd phase constructor can leave. |
|
43 // |
|
44 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created |
|
45 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger |
|
46 // allocates memory from heap and therefore causes error situations with OOM |
|
47 // testing. For more information about STIF Logger construction, see STIF Users |
|
48 // Guide. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CIsvTelephonyTest::ConstructL() |
|
52 { |
|
53 iLogger = CStifLogger::NewL( |
|
54 KIsvTelephonyTestLogPath, |
|
55 KIsvTelephonyTestLogFile ); |
|
56 |
|
57 iTestScheduler = new (ELeave) CActiveScheduler; |
|
58 CActiveScheduler::Install( iTestScheduler ); |
|
59 |
|
60 iTestEngine = CIsvTelephonyTestEngine::NewL(); |
|
61 iTestParser = CIsvTelephonyTestParser::NewL( *this ); |
|
62 } |
|
63 //----------------------------------------------------------------------------- |
|
64 // CIsvTelephonyTest::SendTestClassVersion |
|
65 // Method used to send version of test class |
|
66 //----------------------------------------------------------------------------- |
|
67 // |
|
68 void CIsvTelephonyTest::SendTestModuleVersion() |
|
69 { |
|
70 TVersion moduleVersion; |
|
71 moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR; |
|
72 moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR; |
|
73 moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD; |
|
74 |
|
75 TFileName moduleName; |
|
76 moduleName = _L("IsvTelephonyTest.dll"); |
|
77 |
|
78 |
|
79 TBool newVersionOfMethod = ETrue; |
|
80 CTestModuleIf &test=TestModuleIf(); |
|
81 test.SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod); |
|
82 test.SetBehavior(CTestModuleIf::ETestLeaksHandles); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CIsvTelephonyTest::NewL |
|
87 // Two-phased constructor. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CIsvTelephonyTest* CIsvTelephonyTest::NewL() |
|
91 { |
|
92 CIsvTelephonyTest* self = new (ELeave) CIsvTelephonyTest; |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL(); |
|
95 CleanupStack::Pop(); |
|
96 return self; |
|
97 } |
|
98 |
|
99 // Destructor |
|
100 CIsvTelephonyTest::~CIsvTelephonyTest() |
|
101 { |
|
102 iDTMFTones.Close(); |
|
103 delete iTestParser; |
|
104 delete iTestEngine; |
|
105 delete iTestScheduler; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CIsvTelephonyTest::InitL |
|
110 // InitL is used to initialize the Test Module. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TInt CIsvTelephonyTest::InitL( |
|
114 TFileName& aIniFile, |
|
115 TBool /*aFirstTime*/ ) |
|
116 { |
|
117 TInt result( KErrNone ); |
|
118 |
|
119 CStifParser* parser = CStifParser::NewL( KNullDesC, aIniFile ); |
|
120 CleanupStack::PushL( parser ); |
|
121 |
|
122 CStifSectionParser* section = parser->SectionL( |
|
123 KInitIsvTelephonyTestSectionStart, |
|
124 KInitSectionEnd ); |
|
125 CStifItemParser *item; |
|
126 TPtrC parsePtr; |
|
127 |
|
128 // Initialise variables from IsvTelephonyTest ini file |
|
129 if( section ) |
|
130 { |
|
131 // Phone number 1 |
|
132 item = section->GetItemLineL( KInitMoPhoneNumber1 ); |
|
133 result = item->GetString( KInitMoPhoneNumber1, parsePtr ); |
|
134 if( KErrNone == result ) |
|
135 { |
|
136 iTelNumber1.Copy( parsePtr ); |
|
137 } |
|
138 // Phone number 2 |
|
139 item = section->GetItemLineL( KInitMoPhoneNumber2 ); |
|
140 result = item->GetString( KInitMoPhoneNumber2, parsePtr ); |
|
141 if( KErrNone == result ) |
|
142 { |
|
143 iTelNumber2.Copy( parsePtr ); |
|
144 } |
|
145 // Id restrict (CLIR) |
|
146 item = section->GetItemLineL( KInitIdRestrict ); |
|
147 result = item->GetString( KInitIdRestrict, parsePtr ); |
|
148 if( KErrNone == result ) |
|
149 { |
|
150 if( parsePtr.Compare(KInitEIdRestrictDefault) == 0 ) |
|
151 { |
|
152 iIdRestrict = CTelephony::EIdRestrictDefault; |
|
153 } |
|
154 else if( parsePtr.Compare(KInitESendMyId) == 0 ) |
|
155 { |
|
156 iIdRestrict = CTelephony::ESendMyId; |
|
157 } |
|
158 else if( parsePtr.Compare(KInitEDontSendMyId) == 0 ) |
|
159 { |
|
160 iIdRestrict = CTelephony::EDontSendMyId; |
|
161 } |
|
162 } |
|
163 // Phone line |
|
164 item = section->GetItemLineL( KInitPhoneLine ); |
|
165 result = item->GetString( KInitPhoneLine, parsePtr ); |
|
166 if( KErrNone == result ) |
|
167 { |
|
168 if( parsePtr.Compare(KInitEVoiceLine) == 0 ) |
|
169 { |
|
170 iPhoneLine = CTelephony::EVoiceLine; |
|
171 } |
|
172 else if( parsePtr.Compare(KInitEDataLine) == 0 ) |
|
173 { |
|
174 iPhoneLine = CTelephony::EDataLine; |
|
175 } |
|
176 else if( parsePtr.Compare(KInitEFaxLine) == 0 ) |
|
177 { |
|
178 iPhoneLine = CTelephony::EFaxLine; |
|
179 } |
|
180 } |
|
181 // DTMF tones |
|
182 item = section->GetItemLineL( KInitDTMFTones ); |
|
183 result = item->GetString( KInitDTMFTones, parsePtr ); |
|
184 if( KErrNone == result ) |
|
185 { |
|
186 iDTMFTones.Create( parsePtr ); |
|
187 } |
|
188 } |
|
189 |
|
190 CleanupStack::PopAndDestroy( parser ); // parser |
|
191 |
|
192 return result; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CIsvTelephonyTest::GetTestCasesL |
|
197 // GetTestCases is used to inquire test cases from the Test Module. Test |
|
198 // cases are stored to array of test cases. The Test Framework will be |
|
199 // the owner of the data in the RPointerArray after GetTestCases return |
|
200 // and it does the memory deallocation. |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CIsvTelephonyTest::GetTestCasesL( |
|
204 const TFileName& /*aConfig*/, |
|
205 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
206 { |
|
207 // Loop through all test cases and create new |
|
208 // TTestCaseInfo items and append items to aTestCase array |
|
209 for( TInt i = 0; Case(i).iMethod != NULL; i++ ) |
|
210 { |
|
211 // Allocate new TTestCaseInfo from heap for a testcase definition. |
|
212 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
213 |
|
214 // PushL TTestCaseInfo to CleanupStack. |
|
215 CleanupStack::PushL( newCase ); |
|
216 |
|
217 // Set number for the testcase. |
|
218 // When the testcase is run, this comes as a parameter to RunTestCaseL. |
|
219 newCase->iCaseNumber = i; |
|
220 |
|
221 // Set title for the test case. This is shown in UI to user. |
|
222 newCase->iTitle.Copy( Case(i).iCaseName ); |
|
223 |
|
224 // Append TTestCaseInfo to the testcase array. After appended |
|
225 // successfully the TTestCaseInfo object is owned (and freed) |
|
226 // by the TestServer. |
|
227 User::LeaveIfError(aTestCases.Append ( newCase ) ); |
|
228 |
|
229 // Pop TTestCaseInfo from the CleanupStack. |
|
230 CleanupStack::Pop( newCase ); |
|
231 } |
|
232 |
|
233 return KErrNone; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CIsvTelephonyTest::RunTestCaseL |
|
238 // RunTestCaseL is used to run an individual test case specified |
|
239 // by aTestCase. Test cases that can be run may be requested from |
|
240 // Test Module by GetTestCases method before calling RunTestCase. |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 TInt CIsvTelephonyTest::RunTestCaseL( |
|
244 const TInt aCaseNumber, |
|
245 const TFileName& /*aConfig*/, |
|
246 TTestResult& aResult ) |
|
247 { |
|
248 SendTestModuleVersion(); |
|
249 // Return value |
|
250 TInt execStatus = KErrNone; |
|
251 |
|
252 // Get the pointer to test case function |
|
253 TCaseInfo tmp = Case ( aCaseNumber ); |
|
254 |
|
255 // Write test case start messages to log |
|
256 iLogger->WriteDelimiter(); |
|
257 _LIT( KLogStartTC, "Starting testcase [%S]" ); |
|
258 iLogger->Log( KLogStartTC, &tmp.iCaseName); |
|
259 |
|
260 // Check that case number was valid |
|
261 if ( tmp.iMethod != NULL ) |
|
262 { |
|
263 // Valid case was found, call it via function pointer |
|
264 iMethod = tmp.iMethod; |
|
265 execStatus = ( this->*iMethod )( aResult ); |
|
266 } |
|
267 else |
|
268 { |
|
269 // Valid case was not found, return error. |
|
270 execStatus = KErrNotFound; |
|
271 } |
|
272 |
|
273 // Print result to log/Stif UI |
|
274 if( KErrNone == aResult.iResult ) |
|
275 { |
|
276 PrintMessage( KResultPASS() ); |
|
277 } |
|
278 else |
|
279 { |
|
280 PrintMessage( KResultFAIL() ); |
|
281 TBuf<KMessageHandlerMaxMessageSize> buffer; |
|
282 buffer.Copy( KErrorCode ); |
|
283 buffer.AppendNum( aResult.iResult ); |
|
284 PrintMessage( buffer ); |
|
285 } |
|
286 |
|
287 // If STIF Ui printing is used then a UI flush is needed after each test case |
|
288 if( EMessagesUi == iMessageOption || |
|
289 EMessagesLogAndUi == iMessageOption ) |
|
290 { |
|
291 TestModuleIf().Printf( iStifUiLineCounter, KNullDesC, KNullDesC ); |
|
292 iStifUiLineCounter = 0; |
|
293 } |
|
294 |
|
295 // Return case execution status (not the result of the case execution) |
|
296 return execStatus; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CIsvTelephonyTest::OOMTestQueryL |
|
301 // Used to check if a particular test case should be run in OOM conditions and |
|
302 // which memory allocations should fail. |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 TBool CIsvTelephonyTest::OOMTestQueryL( |
|
306 const TFileName& /* aTestCaseFile */, |
|
307 const TInt aCaseNumber, |
|
308 TOOMFailureType& /* aFailureType */, |
|
309 TInt& aFirstMemFailure, |
|
310 TInt& aLastMemFailure ) |
|
311 { |
|
312 aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation; |
|
313 aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation; |
|
314 |
|
315 return Case( aCaseNumber ).iIsOOMTest; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CIsvTelephonyTest::OOMTestInitializeL |
|
320 // Used to perform the test environment setup for a particular OOM test case. |
|
321 // Test Modules may use the initialization file to read parameters for Test |
|
322 // Module initialization but they can also have their own configure file or |
|
323 // some other routine to initialize themselves. |
|
324 // |
|
325 // NOTE: User may add implementation for OOM test environment initialization. |
|
326 // Usually no implementation is required. |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CIsvTelephonyTest::OOMTestInitializeL( |
|
330 const TFileName& /* aTestCaseFile */, |
|
331 const TInt /* aCaseNumber */ ) |
|
332 { |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CIsvTelephonyTest::OOMHandleWarningL |
|
337 // In some cases the heap memory allocation should be skipped, either due to |
|
338 // problems in the OS code or components used by the code being tested, or even |
|
339 // inside the tested components which are implemented this way on purpose (by |
|
340 // design), so it is important to give the tester a way to bypass allocation |
|
341 // failures. |
|
342 // |
|
343 // NOTE: User may add implementation for OOM test warning handling. Usually no |
|
344 // implementation is required. |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void CIsvTelephonyTest::OOMHandleWarningL( |
|
348 const TFileName& /* aTestCaseFile */, |
|
349 const TInt /* aCaseNumber */, |
|
350 TInt& /* aFailNextValue */ ) |
|
351 { |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CIsvTelephonyTest::OOMTestFinalizeL |
|
356 // Used to perform the test environment cleanup for a particular OOM test case. |
|
357 // |
|
358 // NOTE: User may add implementation for OOM test environment finalization. |
|
359 // Usually no implementation is required. |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 void CIsvTelephonyTest::OOMTestFinalizeL( |
|
363 const TFileName& /* aTestCaseFile */, |
|
364 const TInt /* aCaseNumber */ ) |
|
365 { |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CIsvTelephonyTest::PrintMessage |
|
370 // Implements MIsvTelephonyTestMessageHandler messaging interface. |
|
371 // Message is output to file log or to STIF Ui. |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 void CIsvTelephonyTest::PrintMessage( const TDesC& aMessage ) |
|
375 { |
|
376 switch( iMessageOption ) |
|
377 { |
|
378 case EMessagesLog: |
|
379 iLogger->Log( aMessage ); |
|
380 break; |
|
381 case EMessagesUi: |
|
382 TestModuleIf().Printf( iStifUiLineCounter, KNullDesC, aMessage ); |
|
383 iStifUiLineCounter++; |
|
384 break; |
|
385 case EMessagesLogAndUi: |
|
386 iLogger->Log( aMessage ); |
|
387 TestModuleIf().Printf( iStifUiLineCounter, KNullDesC, aMessage ); |
|
388 iStifUiLineCounter++; |
|
389 break; |
|
390 case EMessagesOff: |
|
391 break; |
|
392 default: |
|
393 break; |
|
394 } |
|
395 } |
|
396 |
|
397 // ----------------------------------------------------------------------------- |
|
398 // CIsvTelephonyTest::PrintMessage |
|
399 // Implements MIsvTelephonyTestMessageHandler messaging interface. |
|
400 // Message is output to file log or to STIF Ui. |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 void CIsvTelephonyTest::PrintMessage( TRefByValue<const TDesC> aMessage,... ) |
|
404 { |
|
405 switch( iMessageOption ) |
|
406 { |
|
407 case EMessagesLog: |
|
408 iLogger->Log( aMessage ); |
|
409 break; |
|
410 case EMessagesUi: |
|
411 TestModuleIf().Printf( iStifUiLineCounter, KNullDesC, aMessage ); |
|
412 iStifUiLineCounter++; |
|
413 break; |
|
414 case EMessagesLogAndUi: |
|
415 iLogger->Log( aMessage ); |
|
416 TestModuleIf().Printf( iStifUiLineCounter, KNullDesC, aMessage ); |
|
417 iStifUiLineCounter++; |
|
418 break; |
|
419 case EMessagesOff: |
|
420 break; |
|
421 default: |
|
422 break; |
|
423 } |
|
424 } |
|
425 |
|
426 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // LibEntryL is a polymorphic Dll entry point |
|
430 // Returns: CTestModuleBase*: Pointer to Test Module object |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 EXPORT_C CTestModuleBase* LibEntryL() |
|
434 { |
|
435 return CIsvTelephonyTest::NewL(); |
|
436 } |
|
437 |
|
438 // ----------------------------------------------------------------------------- |
|
439 // SetRequirements handles test module parameters(implements evolution |
|
440 // version 1 for test module's heap and stack sizes configuring). |
|
441 // Returns: TInt: Symbian error code. |
|
442 // ----------------------------------------------------------------------------- |
|
443 // |
|
444 EXPORT_C TInt SetRequirements( |
|
445 CTestModuleParam*& /*aTestModuleParam*/, |
|
446 TUint32& /*aParameterValid*/ ) |
|
447 { |
|
448 return KErrNone; |
|
449 } |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // E32Dll is a DLL entry point function |
|
453 // Returns: KErrNone: No error |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 #ifndef EKA2 // Hide Dll entry point to EKA2 |
|
457 GLDEF_C TInt E32Dll( |
|
458 TDllReason /*aReason*/) // Reason |
|
459 { |
|
460 return(KErrNone); |
|
461 } |
|
462 #endif // EKA2 |
|
463 |
|
464 // End of File |