|
1 /* |
|
2 * Copyright (c) 2010 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: This file contains Hardcoded module implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <Stiftestinterface.h> |
|
20 #include <SettingServerClient.h> |
|
21 #include <sifui.h> // CSifUi |
|
22 #include "SifUiTest.h" |
|
23 |
|
24 const TInt KTestStackSize = 0x8000; // 32K stack |
|
25 const TInt KTestMinHeap = 0x4000; // 16K heap min |
|
26 const TInt KTestMaxHeap = 0x200000; // 2M heap max |
|
27 |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CSifUiTest::NewL() |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CSifUiTest* CSifUiTest::NewL() |
|
36 { |
|
37 CSifUiTest* self = new (ELeave) CSifUiTest; |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CSifUiTest::~CSifUiTest() |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CSifUiTest::~CSifUiTest() |
|
49 { |
|
50 iLog = NULL; |
|
51 delete iStdLog; |
|
52 delete iTCLog; |
|
53 iFs.Close(); |
|
54 |
|
55 if( iScheduler ) |
|
56 { |
|
57 CActiveScheduler::Install( NULL ); |
|
58 delete iScheduler; |
|
59 } |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CSifUiTest::InitL() |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 TInt CSifUiTest::InitL( TFileName& /*aIniFile*/, TBool /*aFirstTime*/ ) |
|
67 { |
|
68 return KErrNone; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CSifUiTest::GetTestCasesL() |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 TInt CSifUiTest::GetTestCasesL( const TFileName& /*aConfig*/, |
|
76 RPointerArray<TTestCaseInfo>& aTestCases ) |
|
77 { |
|
78 for( TInt index = 0; Case( index ).iMethod != NULL; ++index ) |
|
79 { |
|
80 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); |
|
81 CleanupStack::PushL( newCase ); |
|
82 newCase->iCaseNumber = index; |
|
83 newCase->iTitle.Copy( Case(index).iCaseName ); |
|
84 aTestCases.AppendL( newCase ); |
|
85 CleanupStack::Pop( newCase ); |
|
86 } |
|
87 |
|
88 return KErrNone; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CSifUiTest::RunTestCaseL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 TInt CSifUiTest::RunTestCaseL( const TInt aCaseNumber, |
|
96 const TFileName& /*aConfig*/, TTestResult& aResult ) |
|
97 { |
|
98 if( !iVersionLogged ) |
|
99 { |
|
100 SendTestModuleVersion(); |
|
101 iVersionLogged = ETrue; |
|
102 } |
|
103 |
|
104 TInt returnValue = KErrNone; |
|
105 |
|
106 TCaseInfo caseInfo = Case ( aCaseNumber ); |
|
107 if( caseInfo.iMethod != NULL ) |
|
108 { |
|
109 _LIT( KLogStartTC, "Starting testcase [%S]" ); |
|
110 iLog->Log( KLogStartTC, &caseInfo.iCaseName ); |
|
111 |
|
112 // Switch to use test case (TC) logger if necessary |
|
113 if( iAddTestCaseTitleToLogName ) |
|
114 { |
|
115 if( iTCLog ) |
|
116 { |
|
117 delete iTCLog; |
|
118 iTCLog = NULL; |
|
119 } |
|
120 |
|
121 TName title; |
|
122 TestModuleIf().GetTestCaseTitleL( title ); |
|
123 TFileName logFileName; |
|
124 logFileName.Format( KSifUiTestLogFileWithTitle, &title ); |
|
125 iTCLog = CStifLogger::NewL( KSifUiTestLogPath, logFileName ); |
|
126 iLog = iTCLog; |
|
127 } |
|
128 |
|
129 // Run test case |
|
130 iMethod = caseInfo.iMethod; |
|
131 TRAPD( err, returnValue = ( this->*iMethod )( aResult ) ); |
|
132 |
|
133 // Restore standard log and close test case logger |
|
134 if( iAddTestCaseTitleToLogName ) |
|
135 { |
|
136 iLog = iStdLog; |
|
137 delete iTCLog; |
|
138 iTCLog = NULL; |
|
139 } |
|
140 |
|
141 // Leave if the case execution failed |
|
142 User::LeaveIfError( err ); |
|
143 } |
|
144 else |
|
145 { |
|
146 returnValue = KErrNotFound; |
|
147 } |
|
148 |
|
149 // Return case execution status (not the result of the case execution) |
|
150 return returnValue; |
|
151 } |
|
152 |
|
153 //----------------------------------------------------------------------------- |
|
154 // CSifUiTest::SendTestModuleVersion |
|
155 //----------------------------------------------------------------------------- |
|
156 // |
|
157 void CSifUiTest::SendTestModuleVersion() |
|
158 { |
|
159 TVersion moduleVersion; |
|
160 moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR; |
|
161 moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR; |
|
162 moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD; |
|
163 |
|
164 TFileName moduleName; |
|
165 moduleName = _L("SifUiTest.dll"); |
|
166 |
|
167 TBool newVersionOfMethod = ETrue; |
|
168 TestModuleIf().SendTestModuleVersion( moduleVersion, moduleName, newVersionOfMethod ); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CSifUiTest::CSifUiTest() |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 CSifUiTest::CSifUiTest() |
|
176 { |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CSifUiTest::ConstructL() |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CSifUiTest::ConstructL() |
|
184 { |
|
185 User::LeaveIfError( iFs.Connect() ); |
|
186 |
|
187 RSettingServer settingsServer; |
|
188 User::LeaveIfError( settingsServer.Connect() ); |
|
189 CleanupClosePushL( settingsServer ); |
|
190 |
|
191 TLoggerSettings loggerSettings; |
|
192 User::LeaveIfError( settingsServer.GetLoggerSettings( loggerSettings ) ); |
|
193 |
|
194 CleanupStack::PopAndDestroy( &settingsServer ); |
|
195 |
|
196 iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle; |
|
197 iStdLog = CStifLogger::NewL( KSifUiTestLogPath, KSifUiTestLogFile ); |
|
198 iLog = iStdLog; |
|
199 |
|
200 _LIT( KLogStart, "SifUiTest starts" ); |
|
201 iLog->Log( KLogStart ); |
|
202 |
|
203 iVersionLogged = EFalse; |
|
204 |
|
205 if( !CActiveScheduler::Current() ) |
|
206 { |
|
207 iScheduler = new( ELeave ) CActiveScheduler; |
|
208 CActiveScheduler::Install( iScheduler ); |
|
209 } |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CSifUiTest::ErrorCodeString() |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 TPtrC CSifUiTest::ErrorCodeString( TInt aErrorCode ) const |
|
217 { |
|
218 switch( aErrorCode ) |
|
219 { |
|
220 case KErrNone: |
|
221 return _L("KErrNone"); |
|
222 case KErrNotFound: |
|
223 return _L("KErrNotFound"); |
|
224 case KErrGeneral: |
|
225 return _L("KErrGeneral"); |
|
226 case KErrCancel: |
|
227 return _L("KErrCancel"); |
|
228 case KErrNoMemory: |
|
229 return _L("KErrNoMemory"); |
|
230 case KErrNotSupported: |
|
231 return _L("KErrNotSupported"); |
|
232 case KErrArgument: |
|
233 return _L("KErrArgument"); |
|
234 case KErrTotalLossOfPrecision: |
|
235 return _L("KErrTotalLossOfPrecision"); |
|
236 case KErrBadHandle: |
|
237 return _L("KErrBadHandle"); |
|
238 case KErrOverflow: |
|
239 return _L("KErrOverflow"); |
|
240 case KErrUnderflow: |
|
241 return _L("KErrUnderflow"); |
|
242 case KErrAlreadyExists: |
|
243 return _L("KErrAlreadyExists"); |
|
244 case KErrPathNotFound: |
|
245 return _L("KErrPathNotFound"); |
|
246 case KErrDied: |
|
247 return _L("KErrDied"); |
|
248 case KErrInUse: |
|
249 return _L("KErrInUse"); |
|
250 case KErrServerTerminated: |
|
251 return _L("KErrServerTerminated"); |
|
252 case KErrServerBusy: |
|
253 return _L("KErrServerBusy"); |
|
254 case KErrCompletion: |
|
255 return _L("KErrCompletion"); |
|
256 case KErrNotReady: |
|
257 return _L("KErrNotReady"); |
|
258 case KErrUnknown: |
|
259 return _L("KErrUnknown"); |
|
260 case KErrCorrupt: |
|
261 return _L("KErrCorrupt"); |
|
262 case KErrAccessDenied: |
|
263 return _L("KErrAccessDenied"); |
|
264 case KErrLocked: |
|
265 return _L("KErrLocked"); |
|
266 case KErrWrite: |
|
267 return _L("KErrWrite"); |
|
268 case KErrDisMounted: |
|
269 return _L("KErrDisMounted"); |
|
270 case KErrEof: |
|
271 return _L("KErrEof"); |
|
272 case KErrDiskFull: |
|
273 return _L("KErrDiskFull"); |
|
274 case KErrBadDriver: |
|
275 return _L("KErrBadDriver"); |
|
276 case KErrBadName: |
|
277 return _L("KErrBadName"); |
|
278 case KErrCommsLineFail: |
|
279 return _L("KErrCommsLineFail"); |
|
280 case KErrCommsFrame: |
|
281 return _L("KErrCommsFrame"); |
|
282 case KErrCommsOverrun: |
|
283 return _L("KErrCommsOverrun"); |
|
284 case KErrCommsParity: |
|
285 return _L("KErrCommsParity"); |
|
286 case KErrTimedOut: |
|
287 return _L("KErrTimedOut"); |
|
288 case KErrCouldNotConnect: |
|
289 return _L("KErrCouldNotConnect"); |
|
290 case KErrCouldNotDisconnect: |
|
291 return _L("KErrCouldNotDisconnect"); |
|
292 case KErrDisconnected: |
|
293 return _L("KErrDisconnected"); |
|
294 case KErrBadLibraryEntryPoint: |
|
295 return _L("KErrBadLibraryEntryPoint"); |
|
296 case KErrBadDescriptor: |
|
297 return _L("KErrBadDescriptor"); |
|
298 case KErrAbort: |
|
299 return _L("KErrAbort"); |
|
300 case KErrTooBig: |
|
301 return _L("KErrTooBig"); |
|
302 case KErrDivideByZero: |
|
303 return _L("KErrDivideByZero"); |
|
304 case KErrBadPower: |
|
305 return _L("KErrBadPower"); |
|
306 case KErrDirFull: |
|
307 return _L("KErrDirFull"); |
|
308 case KErrHardwareNotAvailable: |
|
309 return _L("KErrHardwareNotAvailable"); |
|
310 case KErrSessionClosed: |
|
311 return _L("KErrSessionClosed"); |
|
312 case KErrPermissionDenied: |
|
313 return _L("KErrPermissionDenied"); |
|
314 case KErrExtensionNotSupported: |
|
315 return _L("KErrExtensionNotSupported"); |
|
316 case KErrCommsBreak: |
|
317 return _L("KErrCommsBreak"); |
|
318 case KErrNoSecureTime: |
|
319 return _L("KErrNoSecureTime"); |
|
320 } |
|
321 return _L("UNKNOWN ERROR CODE"); |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CSifUiTest::SetResult() |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 void CSifUiTest::SetResult( TTestResult& aResult, const TInt aReturnCode ) const |
|
329 { |
|
330 aResult.SetResult( aReturnCode, ErrorCodeString( aReturnCode ) ); |
|
331 } |
|
332 |
|
333 |
|
334 // ==== OTHER EXPORTED FUNCTIONS ==== |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // LibEntryL is a polymorphic Dll entry point |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 EXPORT_C CTestModuleBase* LibEntryL() |
|
341 { |
|
342 return CSifUiTest::NewL(); |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // SetRequirements handles test module parameters |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 EXPORT_C TInt SetRequirements( CTestModuleParam*& aTestModuleParam, |
|
350 TUint32& aParameterValid ) |
|
351 { |
|
352 aParameterValid = KStifTestModuleParameterChanged; |
|
353 |
|
354 CTestModuleParamVer01* param = NULL; |
|
355 TRAPD( error, param = CTestModuleParamVer01::NewL() ); |
|
356 if( !error ) |
|
357 { |
|
358 param->iTestThreadStackSize = KTestStackSize; |
|
359 param->iTestThreadMinHeap = KTestMinHeap; |
|
360 param->iTestThreadMaxHeap = KTestMaxHeap; |
|
361 aTestModuleParam = param; |
|
362 } |
|
363 |
|
364 return error; |
|
365 } |
|
366 |