|
1 /* |
|
2 * Copyright (c) 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: This file contains testclass implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <StifTestInterface.h> |
|
20 #include "RfsTestModule.h" |
|
21 #include <SettingServerClient.h> |
|
22 #include <e32svr.h> |
|
23 #include <StifParser.h> |
|
24 |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 //extern ?external_data; |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 //extern ?external_function( ?arg_type,?arg_type ); |
|
31 |
|
32 // CONSTANTS |
|
33 //const ?type ?constant_var = ?constant; |
|
34 namespace |
|
35 { |
|
36 // Filename of a test RFS script |
|
37 _LIT( KLitTestScriptFile, "z:\\data\\coreappuistestdata\\rfs_testscript0.txt" ); |
|
38 |
|
39 _LIT( KLitTestScriptFileNotFound, "z:\\data\\coreappuistestdata\\thisfileisnotfound.yes"); |
|
40 |
|
41 // Simple RFS script, no error |
|
42 _LIT( KLitTestScriptDesc, "CD C:\\system\\data\\"); |
|
43 |
|
44 // Simple RFS script with syntax error |
|
45 _LIT( KLitTestScriptDescErr, "CerrorD C:\\system\\data\\"); |
|
46 } |
|
47 |
|
48 // MACROS |
|
49 //#define ?macro ?macro_def |
|
50 |
|
51 // LOCAL CONSTANTS AND MACROS |
|
52 //const ?type ?constant_var = ?constant; |
|
53 //#define ?macro_name ?macro_def |
|
54 |
|
55 // MODULE DATA STRUCTURES |
|
56 //enum ?declaration |
|
57 //typedef ?declaration |
|
58 |
|
59 // LOCAL FUNCTION PROTOTYPES |
|
60 //?type ?function_name( ?arg_type, ?arg_type ); |
|
61 |
|
62 // FORWARD DECLARATIONS |
|
63 //class ?FORWARD_CLASSNAME; |
|
64 |
|
65 // ============================= LOCAL FUNCTIONS =============================== |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // ?function_name ?description. |
|
69 // ?description |
|
70 // Returns: ?value_1: ?description |
|
71 // ?value_n: ?description_line1 |
|
72 // ?description_line2 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 /* |
|
76 ?type ?function_name( |
|
77 ?arg_type arg, // ?description |
|
78 ?arg_type arg) // ?description |
|
79 { |
|
80 |
|
81 ?code // ?comment |
|
82 |
|
83 // ?comment |
|
84 ?code |
|
85 } |
|
86 */ |
|
87 |
|
88 // ============================ MEMBER FUNCTIONS =============================== |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CRfsTestModule::CRfsTestModule |
|
92 // C++ default constructor can NOT contain any code, that |
|
93 // might leave. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CRfsTestModule::CRfsTestModule( |
|
97 CTestModuleIf& aTestModuleIf ): |
|
98 CScriptBase( aTestModuleIf ) |
|
99 { |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CRfsTestModule::ConstructL |
|
104 // Symbian 2nd phase constructor can leave. |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CRfsTestModule::ConstructL() |
|
108 { |
|
109 //Read logger settings to check whether test case name is to be |
|
110 //appended to log file name. |
|
111 RSettingServer settingServer; |
|
112 TInt ret = settingServer.Connect(); |
|
113 if(ret != KErrNone) |
|
114 { |
|
115 User::Leave(ret); |
|
116 } |
|
117 // Struct to StifLogger settigs. |
|
118 TLoggerSettings loggerSettings; |
|
119 // Parse StifLogger defaults from STIF initialization file. |
|
120 ret = settingServer.GetLoggerSettings(loggerSettings); |
|
121 if(ret != KErrNone) |
|
122 { |
|
123 User::Leave(ret); |
|
124 } |
|
125 // Close Setting server session |
|
126 settingServer.Close(); |
|
127 |
|
128 TFileName logFileName; |
|
129 |
|
130 if(loggerSettings.iAddTestCaseTitle) |
|
131 { |
|
132 TName title; |
|
133 TestModuleIf().GetTestCaseTitleL(title); |
|
134 logFileName.Format(KRfsTestModuleLogFileWithTitle, &title); |
|
135 } |
|
136 else |
|
137 { |
|
138 logFileName.Copy(KRfsTestModuleLogFile); |
|
139 } |
|
140 |
|
141 iLog = CStifLogger::NewL( KRfsTestModuleLogPath, |
|
142 logFileName, |
|
143 CStifLogger::ETxt, |
|
144 CStifLogger::EFile, |
|
145 EFalse ); |
|
146 |
|
147 SendTestClassVersion(); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CRfsTestModule::NewL |
|
152 // Two-phased constructor. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 CRfsTestModule* CRfsTestModule::NewL( |
|
156 CTestModuleIf& aTestModuleIf ) |
|
157 { |
|
158 CRfsTestModule* self = new (ELeave) CRfsTestModule( aTestModuleIf ); |
|
159 |
|
160 CleanupStack::PushL( self ); |
|
161 self->ConstructL(); |
|
162 CleanupStack::Pop(); |
|
163 |
|
164 return self; |
|
165 |
|
166 } |
|
167 |
|
168 void CRfsTestModule::Delete() |
|
169 { |
|
170 |
|
171 } |
|
172 |
|
173 // Destructor |
|
174 CRfsTestModule::~CRfsTestModule() |
|
175 { |
|
176 |
|
177 // Delete resources allocated from test methods |
|
178 Delete(); |
|
179 |
|
180 // Delete logger |
|
181 delete iLog; |
|
182 |
|
183 } |
|
184 |
|
185 //----------------------------------------------------------------------------- |
|
186 // CRfsTestModule::SendTestClassVersion |
|
187 // Method used to send version of test class |
|
188 //----------------------------------------------------------------------------- |
|
189 // |
|
190 void CRfsTestModule::SendTestClassVersion() |
|
191 { |
|
192 TVersion moduleVersion; |
|
193 moduleVersion.iMajor = TEST_CLASS_VERSION_MAJOR; |
|
194 moduleVersion.iMinor = TEST_CLASS_VERSION_MINOR; |
|
195 moduleVersion.iBuild = TEST_CLASS_VERSION_BUILD; |
|
196 |
|
197 TFileName moduleName; |
|
198 moduleName = _L("RfsTestModule.dll"); |
|
199 |
|
200 TBool newVersionOfMethod = ETrue; |
|
201 TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod); |
|
202 } |
|
203 |
|
204 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // LibEntryL is a polymorphic Dll entry point. |
|
208 // Returns: CScriptBase: New CScriptBase derived object |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C CScriptBase* LibEntryL( |
|
212 CTestModuleIf& aTestModuleIf ) // Backpointer to STIF Test Framework |
|
213 { |
|
214 |
|
215 return ( CScriptBase* ) CRfsTestModule::NewL( aTestModuleIf ); |
|
216 |
|
217 } |
|
218 |
|
219 |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CRfsTestModule::RunMethodL |
|
223 // Run specified method. Contains also table of test mothods and their names. |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 TInt CRfsTestModule::RunMethodL( |
|
227 CStifItemParser& aItem ) |
|
228 { |
|
229 |
|
230 static TStifFunctionInfo const KFunctions[] = |
|
231 { |
|
232 // Copy this line for every implemented function. |
|
233 // First string is the function name used in TestScripter script file. |
|
234 // Second is the actual implementation member function. |
|
235 //ENTRY( "Example", CRfsTestModule::ExampleL ), |
|
236 |
|
237 // CRfsHandler test cases |
|
238 ENTRY( "TestCRfsHandlerL", CRfsTestModule::TestCRfsHandlerL ), |
|
239 ENTRY( "SetupL", CRfsTestModule::SetupL ), |
|
240 ENTRY( "Teardown", CRfsTestModule::Teardown ), |
|
241 ENTRY( "SpecialSetupL", CRfsTestModule::SpecialSetupL ), |
|
242 ENTRY( "SpecialTeardown", CRfsTestModule::SpecialTeardown ), |
|
243 ENTRY( "TestActivateRfsLL", CRfsTestModule::TestActivateRfsLL ), |
|
244 ENTRY( "TestCancelL", CRfsTestModule::TestCancelL ), |
|
245 |
|
246 // RRfsClient test cases |
|
247 ENTRY( "RRfsClientSetupL", CRfsTestModule::RRfsClientSetupL ), |
|
248 ENTRY( "RRfsClientTeardown", CRfsTestModule::RRfsClientTeardown ), |
|
249 ENTRY( "TestConnectAndCloseL", CRfsTestModule::TestConnectAndCloseL ), |
|
250 ENTRY( "TestPerformRfsNormalL", CRfsTestModule::TestPerformRfsNormalL ), |
|
251 ENTRY( "TestPerformRfsDeepL", CRfsTestModule::TestPerformRfsDeepL ), |
|
252 ENTRY( "TestPerformPostEikonRfsL", CRfsTestModule::TestPerformPostEikonRfsL ), |
|
253 ENTRY( "TestPerformPostEikonRfsDeepL", CRfsTestModule::TestPerformPostEikonRfsDeepL ), |
|
254 ENTRY( "TestRunScriptInDescriptorNoErrorL", CRfsTestModule::TestRunScriptInDescriptorNoErrorL ), |
|
255 ENTRY( "TestRunScriptInDescriptorSyntaxErrorL", CRfsTestModule::TestRunScriptInDescriptorSyntaxErrorL ), |
|
256 ENTRY( "TestRunScriptInFileNoErrorL", CRfsTestModule::TestRunScriptInFileNoErrorL ), |
|
257 ENTRY( "TestRunScriptInFileNotFoundL", CRfsTestModule::TestRunScriptInFileNotFoundL ), |
|
258 |
|
259 //ADD NEW ENTRY HERE |
|
260 // [test cases entries] - Do not remove |
|
261 |
|
262 }; |
|
263 |
|
264 const TInt count = sizeof( KFunctions ) / |
|
265 sizeof( TStifFunctionInfo ); |
|
266 |
|
267 return RunInternalL( KFunctions, count, aItem ); |
|
268 |
|
269 } |
|
270 // Test Methods |
|
271 TInt CRfsTestModule::SetupL(CStifItemParser& /*aItem*/) |
|
272 { |
|
273 RDebug::Print(_L("Entered SetupL")); |
|
274 iCRfsHandler = new( ELeave ) CRfsHandler; |
|
275 STIF_ASSERT_NOT_NULL(iCRfsHandler); |
|
276 return KErrNone; |
|
277 } |
|
278 |
|
279 TInt CRfsTestModule::Teardown(CStifItemParser& /*aItem*/) |
|
280 { |
|
281 RDebug::Print(_L("Entered Teardown")); |
|
282 delete iCRfsHandler; |
|
283 iCRfsHandler = NULL; |
|
284 return KErrNone; |
|
285 } |
|
286 |
|
287 TInt CRfsTestModule::SpecialSetupL(CStifItemParser& /*aItem*/) |
|
288 { |
|
289 RDebug::Print(_L("Entered SpecialSetupL")); |
|
290 iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
291 STIF_ASSERT_NOT_NULL(iPeriodic); |
|
292 return KErrNone; |
|
293 } |
|
294 |
|
295 |
|
296 TInt CRfsTestModule::SpecialTeardown( CStifItemParser& /*aItem*/) |
|
297 { |
|
298 RDebug::Print(_L("Entered SpecialTeardown")); |
|
299 if ( iPeriodic ) |
|
300 { |
|
301 iPeriodic->Cancel(); |
|
302 } |
|
303 delete iPeriodic; |
|
304 return KErrNone; |
|
305 } |
|
306 |
|
307 TInt CRfsTestModule::TestCRfsHandlerL(CStifItemParser& /*aItem*/ ) |
|
308 { |
|
309 RDebug::Print(_L("Entered TestCRfsHandlerL")); |
|
310 CRfsHandler* handler = new( ELeave ) CRfsHandler; |
|
311 STIF_ASSERT_NOT_NULL(handler); |
|
312 delete handler; |
|
313 return KErrNone; |
|
314 } |
|
315 |
|
316 TInt CRfsTestModule::TestActivateRfsLL( CStifItemParser& /*aItem*/ ) |
|
317 { |
|
318 RDebug::Print(_L("Entered TestActivateRfsLL")); |
|
319 if ( !iPeriodic->IsActive() ) |
|
320 { |
|
321 iPeriodic->Start( 4000000, 1000000, TCallBack( SimulateRightSoftkey, static_cast<TAny*>( this ) ) ); |
|
322 } |
|
323 |
|
324 TRAPD(err, iCRfsHandler->ActivateRfsL( ERfsNormal )); |
|
325 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
326 return KErrNone; |
|
327 } |
|
328 |
|
329 TInt CRfsTestModule::TestCancelL( CStifItemParser& /*aItem*/ ) |
|
330 { |
|
331 RDebug::Print(_L("Entered TestCancelL")); |
|
332 iCRfsHandler->Cancel( ); |
|
333 return KErrNone; |
|
334 } |
|
335 |
|
336 TInt CRfsTestModule::SimulateRightSoftkey( TAny* aPtr) |
|
337 { |
|
338 RDebug::Print(_L("Entered SimulateRightSoftkey")); |
|
339 CRfsTestModule* instL = static_cast<CRfsTestModule*>( aPtr ); |
|
340 instL->DoSimulateRightL(); |
|
341 return KErrNone; |
|
342 } |
|
343 |
|
344 void CRfsTestModule::DoSimulateRightL() |
|
345 { |
|
346 RDebug::Print(_L("Entered DoSimulateRightL")); |
|
347 TKeyEvent event; |
|
348 event.iCode = EKeyCBA2; |
|
349 event.iScanCode = 0; |
|
350 event.iRepeats = 0; |
|
351 event.iModifiers = 0; |
|
352 |
|
353 TWsEvent wsEvent; |
|
354 *( wsEvent.Key() ) = event; |
|
355 wsEvent.SetType( EEventKey ); |
|
356 wsEvent.SetTimeNow(); |
|
357 |
|
358 RDebug::Print(_L("Entered DoSimulateRightL--2")); |
|
359 RWsSession* ws = &CCoeEnv::Static()->WsSession(); |
|
360 |
|
361 TInt wgId = ws->GetFocusWindowGroup(); |
|
362 RDebug::Print(_L("DoSimulateRightL: window focus group id = %d"),wgId); |
|
363 |
|
364 ws->SendEventToWindowGroup( wgId, wsEvent ); |
|
365 |
|
366 iPeriodic->Cancel(); |
|
367 RDebug::Print(_L("Leaving DoSimulateRightL")); |
|
368 } |
|
369 |
|
370 |
|
371 //RRfsClient functions |
|
372 TInt CRfsTestModule::RRfsClientSetupL( CStifItemParser& /*aItem*/ ) |
|
373 { |
|
374 RDebug::Print(_L("Entered RRfsClientSetupL")); |
|
375 TInt err = iRRfsClient.Connect(); |
|
376 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
377 return KErrNone; |
|
378 } |
|
379 |
|
380 TInt CRfsTestModule::RRfsClientTeardown( CStifItemParser& /*aItem*/ ) |
|
381 { |
|
382 RDebug::Print(_L("Entered RRfsClientTeardown")); |
|
383 iRRfsClient.Close(); |
|
384 return KErrNone; |
|
385 } |
|
386 |
|
387 TInt CRfsTestModule::TestConnectAndCloseL( CStifItemParser& /*aItem*/ ) |
|
388 { |
|
389 RDebug::Print(_L("Entered TestConnectAndCloseL")); |
|
390 RRfsClient client; |
|
391 TInt err = client.Connect(); |
|
392 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
393 client.Close(); |
|
394 return KErrNone; |
|
395 } |
|
396 |
|
397 TInt CRfsTestModule::TestPerformRfsNormalL( CStifItemParser& /*aItem*/ ) |
|
398 { |
|
399 RDebug::Print(_L("Entered TestPerformRfsNormalL")); |
|
400 TInt err = iRRfsClient.PerformRfs( ERfsNormal ); |
|
401 RDebug::Print(_L("TestPerformRfsNormalL: iRRfsClient.PerformRfs returns with err = %d"), err); |
|
402 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
403 return KErrNone; |
|
404 } |
|
405 |
|
406 TInt CRfsTestModule::TestPerformRfsDeepL( CStifItemParser& /*aItem*/ ) |
|
407 { |
|
408 RDebug::Print(_L("Entered TestPerformRfsDeepL")); |
|
409 TInt err = iRRfsClient.PerformRfs( ERfsDeep ); |
|
410 RDebug::Print(_L("TestPerformRfsDeepL: iRRfsClient.PerformRfs returns with err = %d"), err); |
|
411 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
412 return KErrNone; |
|
413 } |
|
414 |
|
415 TInt CRfsTestModule::TestPerformPostEikonRfsL( CStifItemParser& /*aItem*/ ) |
|
416 { |
|
417 RDebug::Print(_L("Entered TestPerformPostEikonRfsL")); |
|
418 TInt err = iRRfsClient.PerformPostEikonRfs( ERfsNormal ); |
|
419 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
420 return KErrNone; |
|
421 } |
|
422 |
|
423 TInt CRfsTestModule::TestPerformPostEikonRfsDeepL( CStifItemParser& /*aItem*/ ) |
|
424 { |
|
425 RDebug::Print(_L("Entered TestPerformPostEikonRfsDeepL")); |
|
426 TInt err = iRRfsClient.PerformPostEikonRfs( ERfsDeep ); |
|
427 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
428 return KErrNone; |
|
429 } |
|
430 |
|
431 TInt CRfsTestModule::TestRunScriptInDescriptorNoErrorL( CStifItemParser& /*aItem*/ ) |
|
432 { |
|
433 RDebug::Print(_L("Entered TestRunScriptInDescriptorNoErrorL")); |
|
434 TInt err = iRRfsClient.RunScriptInDescriptor( KLitTestScriptDesc ); |
|
435 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
436 return KErrNone; |
|
437 } |
|
438 |
|
439 TInt CRfsTestModule::TestRunScriptInDescriptorSyntaxErrorL( CStifItemParser& /*aItem*/ ) |
|
440 { |
|
441 RDebug::Print(_L("Entered TestRunScriptInDescriptorSyntaxErrorL")); |
|
442 TInt err = iRRfsClient.RunScriptInDescriptor( KLitTestScriptDescErr ); |
|
443 STIF_ASSERT_EQUALS( KErrGeneral, err ); |
|
444 return KErrNone; |
|
445 } |
|
446 |
|
447 TInt CRfsTestModule::TestRunScriptInFileNoErrorL( CStifItemParser& /*aItem*/ ) |
|
448 { |
|
449 RDebug::Print(_L("Entered TestRunScriptInFileNoErrorL")); |
|
450 TInt err = iRRfsClient.RunScriptInFile( KLitTestScriptFile ); |
|
451 RDebug::Print(_L("TestRunScriptInFileNoErrorL: iRRfsClient.RunScriptInFile returns with err = %d"), err); |
|
452 STIF_ASSERT_EQUALS( KErrNone, err ); |
|
453 return KErrNone; |
|
454 } |
|
455 |
|
456 TInt CRfsTestModule::TestRunScriptInFileNotFoundL( CStifItemParser& /*aItem*/ ) |
|
457 { |
|
458 RDebug::Print(_L("Entered TestRunScriptInFileNotFoundL")); |
|
459 TInt err = iRRfsClient.RunScriptInFile( KLitTestScriptFileNotFound ); |
|
460 RDebug::Print(_L("TestRunScriptInFileNotFoundL: iRRfsClient.RunScriptInFile returns with err = %d"), err); |
|
461 STIF_ASSERT_EQUALS( KErrNotFound, err ); |
|
462 return KErrNone; |
|
463 } |
|
464 |
|
465 // End of File |