|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // The following test cases test the funtionality of RuleBased plugins framework. |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include <apacmdln.h> |
|
26 #include "..\tef\tRuleBasedApps\RuleBasedUID.H" //The UID'S for the 4 applications used during testing |
|
27 #include "T_RuleBasedLaunchingStep.h" |
|
28 #include <APGICNFL.H> |
|
29 #include "testableapalssession.h" |
|
30 |
|
31 const TUint KNonNativeApplicationType = 0x10207f90; |
|
32 const TUint KNonNativeApplication = 0xA0000B6E; |
|
33 |
|
34 _LIT(KLitNativeExecutable, "z:\\sys\\bin\\TNNAPP2.EXE"); |
|
35 _LIT(KLitLogicalExecutableA, "c:\\A.NNAPP2"); // this file never actually needs to exist |
|
36 _LIT8(KLitMimeTypeA, "x-epoc/a-nnapp2"); |
|
37 |
|
38 CTRuleBasedLaunchingStep::CTRuleBasedLaunchingStep() |
|
39 { |
|
40 // Call base class method to set up the human readable name for logging |
|
41 SetTestStepName(KT_RuleBasedLaunchingStep); |
|
42 } |
|
43 |
|
44 CTRuleBasedLaunchingStep::~CTRuleBasedLaunchingStep() |
|
45 { |
|
46 iWs.Close(); |
|
47 iFs.Close(); |
|
48 } |
|
49 |
|
50 void CTRuleBasedLaunchingStep::ExecuteL() |
|
51 { |
|
52 RTestableApaLsSession theLs; |
|
53 User::LeaveIfError(theLs.Connect()); |
|
54 CleanupClosePushL(theLs); |
|
55 |
|
56 //DONT_CHECK since app list is updated |
|
57 HEAP_TEST_LS_SESSION(theLs, 0, DONT_CHECK, TestLaunchNonNativeApplicationForRuleBasedL(theLs), NO_CLEANUP); |
|
58 //DONT_CHECK since result is unstable |
|
59 HEAP_TEST_LS_SESSION(theLs, 0, DONT_CHECK, LaunchAppTests1L(theLs), theLs.FlushRecognitionCache() ); |
|
60 HEAP_TEST_LS_SESSION(theLs, 0, 0, LaunchAppTests2L(theLs), theLs.FlushRecognitionCache() ); |
|
61 HEAP_TEST_LS_SESSION(theLs, 0, 0, LaunchAppTests3L(theLs), theLs.FlushRecognitionCache() ); |
|
62 HEAP_TEST_LS_SESSION(theLs, 0, 0, LaunchAppTests4L(theLs), theLs.FlushRecognitionCache() ); |
|
63 HEAP_TEST_LS_SESSION(theLs, 0, 0, LaunchAppTests5L(theLs), theLs.FlushRecognitionCache() ); |
|
64 HEAP_TEST_LS_SESSION(theLs, 0, 0, LaunchAppTests6L(theLs), theLs.FlushRecognitionCache() ); |
|
65 |
|
66 CleanupStack::PopAndDestroy(&theLs); |
|
67 } |
|
68 |
|
69 LOCAL_C void DeregisterNonNativeForRuleBased(TAny* aApparcServer) |
|
70 { |
|
71 RApaLsSession& apparcServer = *static_cast<RApaLsSession*>(aApparcServer); |
|
72 TRAP_IGNORE(apparcServer.PrepareNonNativeApplicationsUpdatesL()); |
|
73 TRAP_IGNORE(apparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KNonNativeApplication))); |
|
74 TRAP_IGNORE(apparcServer.CommitNonNativeApplicationsUpdatesL()); |
|
75 TRAP_IGNORE(apparcServer.DeregisterNonNativeApplicationTypeL(TUid::Uid(KNonNativeApplicationType))); |
|
76 } |
|
77 |
|
78 void CTRuleBasedLaunchingStep::TestLaunchNonNativeApplicationForRuleBasedL(RApaLsSession& aApparcServer) |
|
79 { |
|
80 INFO_PRINTF1(_L("TestLaunchNonNativeApplicationForRuleBasedL...")); |
|
81 |
|
82 // make sure we're starting from a clean sheet |
|
83 aApparcServer.PrepareNonNativeApplicationsUpdatesL(); |
|
84 aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KNonNativeApplication)); |
|
85 aApparcServer.CommitNonNativeApplicationsUpdatesL(); |
|
86 aApparcServer.DeregisterNonNativeApplicationTypeL(TUid::Uid(KNonNativeApplicationType)); |
|
87 CleanupStack::PushL(TCleanupItem(DeregisterNonNativeForRuleBased, &aApparcServer)); |
|
88 |
|
89 aApparcServer.RegisterNonNativeApplicationTypeL(TUid::Uid(KNonNativeApplicationType), KLitNativeExecutable); |
|
90 |
|
91 CApaRegistrationResourceFileWriter* const registrationResourceFileWriter = CApaRegistrationResourceFileWriter::NewL(TUid::Uid(KNonNativeApplication), KLitLogicalExecutableA, TApaAppCapability::ENonNative); |
|
92 CleanupStack::PushL(registrationResourceFileWriter); |
|
93 registrationResourceFileWriter->AddDataTypeL(KDataTypePriorityNormal, KLitMimeTypeA); |
|
94 |
|
95 CApaCommandLine* const commandLineForNonNativeApp = CApaCommandLine::NewLC(); |
|
96 commandLineForNonNativeApp->SetExecutableNameL(KLitLogicalExecutableA); |
|
97 |
|
98 INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() ")); |
|
99 aApparcServer.PrepareNonNativeApplicationsUpdatesL(); |
|
100 aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KNonNativeApplicationType), EDriveC, *registrationResourceFileWriter, NULL, NULL); |
|
101 aApparcServer.CommitNonNativeApplicationsUpdatesL(); |
|
102 |
|
103 // Since NonNative application will be launched inspite of Rule saying it should not be launched |
|
104 INFO_PRINTF1(_L("Testing launching of a NonNativeApp...")); |
|
105 TEST(aApparcServer.StartApp(*commandLineForNonNativeApp) == KErrCancel); |
|
106 |
|
107 INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() ")); |
|
108 aApparcServer.PrepareNonNativeApplicationsUpdatesL(); |
|
109 aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KNonNativeApplication)); |
|
110 aApparcServer.CommitNonNativeApplicationsUpdatesL(); |
|
111 |
|
112 // clean-up |
|
113 CleanupStack::PopAndDestroy(3); |
|
114 } |
|
115 |
|
116 /** |
|
117 @SYMTestCaseID APPFWK-APPARC-0023 |
|
118 @SYMPREQ PREQ1122 |
|
119 @SYMTestCaseDesc Rule Based Launching of Applications |
|
120 @SYMTestPriority High |
|
121 @SYMTestStatus Implemented |
|
122 |
|
123 @SYMTestActions The test utilises 4 test applications that simply display the appication name. |
|
124 Each application is launched and closed in sequence. |
|
125 |
|
126 @SYMTestExpectedResults The test verifies that each application can be opened and closed normally. |
|
127 */ |
|
128 void CTRuleBasedLaunchingStep::LaunchAppTests1L(RApaLsSession& aLs) |
|
129 { |
|
130 INFO_PRINTF1(_L("Test case 1 started")); |
|
131 |
|
132 // App1 is launched and closed |
|
133 TEST(AppLaunchedL(aLs, KUidApp1) == KErrNone); |
|
134 TEST(AppClosed(KUidApp1) == KErrNone); |
|
135 |
|
136 // App2 is launched and closed |
|
137 TEST(AppLaunchedL(aLs, KUidApp2) == KErrNone); |
|
138 TEST(AppClosed(KUidApp2) == KErrNone); |
|
139 |
|
140 // App3 is launched and closed |
|
141 TEST(AppLaunchedL(aLs, KUidApp3) == KErrNone); |
|
142 TEST(AppClosed(KUidApp3) == KErrNone); |
|
143 |
|
144 // App4 is launched and closed |
|
145 TEST(AppLaunchedL(aLs, KUidApp4) == KErrNone); |
|
146 TEST(AppClosed(KUidApp4) == KErrNone); |
|
147 |
|
148 // Close all apps |
|
149 ClosedAllTestApp(); |
|
150 |
|
151 INFO_PRINTF1(_L("Test case 1 finished")); |
|
152 } |
|
153 |
|
154 /** |
|
155 @SYMTestCaseID APPFWK-APPARC-0024 |
|
156 @SYMPREQ PREQ1122 |
|
157 @SYMTestCaseDesc Rule Based Launching of Applications |
|
158 @SYMTestPriority High |
|
159 @SYMTestStatus Implemented |
|
160 |
|
161 @SYMTestActions The test utilises 3 test applications that simply display the appication name. |
|
162 The test utilises a single plugin that implements 2 rules. |
|
163 Only the first rule is executed(Launching App3 closes App1). |
|
164 |
|
165 @SYMTestExpectedResults The test verifies that that when an application is launched, |
|
166 the rule based mechanism is invoked and only the corresponding rule executed. |
|
167 |
|
168 */ |
|
169 void CTRuleBasedLaunchingStep::LaunchAppTests2L(RApaLsSession& aLs) |
|
170 { |
|
171 INFO_PRINTF1(_L("Test case 2 started")); |
|
172 |
|
173 TEST(AppLaunchedL(aLs, KUidApp1) == KErrNone); |
|
174 TEST(AppLaunchedL(aLs, KUidApp2) == KErrNone); |
|
175 TEST(AppLaunchedL(aLs, KUidApp3) == KErrNone); |
|
176 |
|
177 TApaTaskList taskList(iWs); |
|
178 |
|
179 //Wait 2sec for App1 to be closed |
|
180 User::After(2 * 1000000); |
|
181 |
|
182 // App1 should be closed when App3 is launched |
|
183 const TApaTask task1 = taskList.FindApp(KUidApp1); |
|
184 TEST(!task1.Exists()); |
|
185 const TApaTask task2 = taskList.FindApp(KUidApp2); |
|
186 TEST(task2.Exists()); |
|
187 const TApaTask task3 = taskList.FindApp(KUidApp3); |
|
188 TEST(task3.Exists()); |
|
189 |
|
190 // Close all apps |
|
191 ClosedAllTestApp(); |
|
192 |
|
193 INFO_PRINTF1(_L("Test case 2 finished")); |
|
194 } |
|
195 |
|
196 /** |
|
197 @SYMTestCaseID APPFWK-APPARC-0025 |
|
198 @SYMPREQ PREQ1122 |
|
199 @SYMTestCaseDesc Rule Based Launching of Applications |
|
200 @SYMTestPriority High |
|
201 @SYMTestStatus Implemented |
|
202 |
|
203 @SYMTestActions The test utilises 2 test applications that simply display the appication name. |
|
204 Only the first rule is executed(A running App3 prevents App1 launching). |
|
205 Only the second rule is executed(App1 cannot launch if App3 is running). |
|
206 |
|
207 @SYMTestExpectedResults The test verifies that multiple rules can be implemented in a single plugin and |
|
208 only the correct rule is executed. |
|
209 |
|
210 */ |
|
211 void CTRuleBasedLaunchingStep::LaunchAppTests3L(RApaLsSession& aLs) |
|
212 { |
|
213 INFO_PRINTF1(_L("Test case 3 started")); |
|
214 |
|
215 // App1 cannot be launched if App3 is running |
|
216 TEST(AppLaunchedL(aLs, KUidApp2) == KErrNone); |
|
217 TEST(AppLaunchedL(aLs, KUidApp3) == KErrNone); |
|
218 TEST(AppLaunchedL(aLs, KUidApp1) == KErrCancel); |
|
219 |
|
220 TApaTaskList taskList(iWs); |
|
221 |
|
222 const TApaTask task1 = taskList.FindApp(KUidApp1); |
|
223 TEST(!task1.Exists()); |
|
224 const TApaTask task2 = taskList.FindApp(KUidApp2); |
|
225 TEST(task2.Exists()); |
|
226 const TApaTask task3 = taskList.FindApp(KUidApp3); |
|
227 TEST(task3.Exists()); |
|
228 |
|
229 // Close all apps |
|
230 ClosedAllTestApp(); |
|
231 |
|
232 INFO_PRINTF1(_L("Test case 3 finished")); |
|
233 } |
|
234 |
|
235 /** |
|
236 @SYMTestCaseID APPFWK-APPARC-0026 |
|
237 @SYMPREQ PREQ1122 |
|
238 @SYMTestCaseDesc Rule Based Launching of Applications |
|
239 @SYMTestPriority High |
|
240 @SYMTestStatus Implemented |
|
241 |
|
242 @SYMTestActions The test utilises 3 test applications that simply display the appication name. |
|
243 The test utilises 2 plugins. |
|
244 Rules from both plugins are executed. |
|
245 Plugin1 (Launching App4 closes App2) |
|
246 Plugin2 (Launching App4 closes App3) |
|
247 |
|
248 @SYMTestExpectedResults The test verifies that multiple rules can be implemented in multiple plugins and |
|
249 only the correct rules are executed. |
|
250 */ |
|
251 void CTRuleBasedLaunchingStep::LaunchAppTests4L(RApaLsSession& aLs) |
|
252 { |
|
253 INFO_PRINTF1(_L("Test case 4 started")); |
|
254 |
|
255 // App2 and App3 are closed if App4 is launched |
|
256 TEST(AppLaunchedL(aLs, KUidApp3) == KErrNone); |
|
257 TEST(AppLaunchedL(aLs, KUidApp2) == KErrNone); |
|
258 TEST(AppLaunchedL(aLs, KUidApp4) == KErrNone); |
|
259 |
|
260 TApaTaskList taskList(iWs); |
|
261 |
|
262 //Wait 2sec for App2 and App3 to be closed |
|
263 User::After(2 * 1000000); |
|
264 |
|
265 const TApaTask task2 = taskList.FindApp(KUidApp2); |
|
266 TEST(!task2.Exists()); |
|
267 const TApaTask task3 = taskList.FindApp(KUidApp3); |
|
268 TEST(!task3.Exists()); |
|
269 const TApaTask task4 = taskList.FindApp(KUidApp4); |
|
270 TEST(task4.Exists()); |
|
271 |
|
272 // Close all apps |
|
273 ClosedAllTestApp(); |
|
274 |
|
275 INFO_PRINTF1(_L("Test case 4 finished")); |
|
276 } |
|
277 |
|
278 /** |
|
279 @SYMTestCaseID APPFWK-APPARC-0027 |
|
280 @SYMPREQ PREQ1122 |
|
281 @SYMTestCaseDesc Rule Based Launching of Applications |
|
282 @SYMTestPriority High |
|
283 @SYMTestStatus Implemented |
|
284 |
|
285 @SYMTestActions The test cases is similar to APPFWK-APPARC-0025 but it launching applications |
|
286 via associated documents. |
|
287 |
|
288 @SYMTestExpectedResults The test verifies that multiple rules can be implemented in a single plugin and |
|
289 only the correct rule is executed. |
|
290 |
|
291 */ |
|
292 void CTRuleBasedLaunchingStep::LaunchAppTests5L(RApaLsSession& aLs) |
|
293 { |
|
294 INFO_PRINTF1(_L("Test case 5 started")); |
|
295 |
|
296 // App1 cannot be launched if App3 is running |
|
297 TEST(LaunchAppFromAssociatedDocument(aLs, KUidApp2) == KErrNone); |
|
298 TEST(LaunchAppFromAssociatedDocument(aLs, KUidApp3) == KErrNone); |
|
299 // Wait 2sec for App2 and App3 to be closed |
|
300 User::After(2 * 1000000); |
|
301 TEST(LaunchAppFromAssociatedDocument(aLs, KUidApp1) == KErrCancel); |
|
302 |
|
303 TApaTaskList taskList(iWs); |
|
304 |
|
305 const TApaTask task1 = taskList.FindApp(KUidApp1); |
|
306 TEST(!task1.Exists()); |
|
307 const TApaTask task2 = taskList.FindApp(KUidApp2); |
|
308 TEST(task2.Exists()); |
|
309 const TApaTask task3 = taskList.FindApp(KUidApp3); |
|
310 TEST(task3.Exists()); |
|
311 |
|
312 // Close all apps |
|
313 ClosedAllTestApp(); |
|
314 |
|
315 INFO_PRINTF1(_L("Test case 5 finished")); |
|
316 } |
|
317 |
|
318 /** |
|
319 @SYMTestCaseID APPFWK-APPARC-0028 |
|
320 @SYMPREQ PREQ1122 |
|
321 @SYMTestCaseDesc Rule Based Launching of Applications |
|
322 @SYMTestPriority High |
|
323 @SYMTestStatus Implemented |
|
324 |
|
325 @SYMTestActions The test case launches an applications where file name defined whether without extension or |
|
326 disk drive, or as non system path. |
|
327 |
|
328 @SYMTestExpectedResults Rule based framework has to process this name correctly and apply pre-defined rules. |
|
329 |
|
330 */ |
|
331 void CTRuleBasedLaunchingStep::LaunchAppTests6L(RApaLsSession& aLs) |
|
332 { |
|
333 INFO_PRINTF1(_L("Test case 6 started")); |
|
334 |
|
335 TPtrC arFileName[] = { _L("tRuleBasedApp1.exe"), |
|
336 _L("\\sys\\bin\\tRuleBasedApp1.exe"), |
|
337 _L("\\nonsys\\bin\\tRuleBasedApp1.exe"), |
|
338 _L("\\sys\\bin\\tRuleBasedApp1"), |
|
339 _L("tRuleBasedApp1"), |
|
340 }; |
|
341 TInt sizeOfFileNameArray = sizeof(arFileName) / sizeof(arFileName[0]); |
|
342 |
|
343 for(TInt ii = 0; ii < sizeOfFileNameArray; ii++) |
|
344 { |
|
345 TEST(LaunchAppFromAssociatedDocument(aLs, KUidApp3) == KErrNone); |
|
346 TEST(AppLaunchedL(aLs, arFileName[ii]) == KErrCancel); |
|
347 |
|
348 TApaTaskList taskList(iWs); |
|
349 |
|
350 const TApaTask task1 = taskList.FindApp(KUidApp1); |
|
351 TEST(!task1.Exists()); |
|
352 const TApaTask task3 = taskList.FindApp(KUidApp3); |
|
353 TEST(task3.Exists()); |
|
354 if(task1.Exists() || !task3.Exists()) |
|
355 { |
|
356 INFO_PRINTF2(_L("The name %S is not recognized by rule based plug-ins as a valid"), &arFileName[ii]); |
|
357 } |
|
358 |
|
359 // Close all apps |
|
360 ClosedAllTestApp(); |
|
361 } |
|
362 |
|
363 INFO_PRINTF1(_L("Test case 6 finished")); |
|
364 } |
|
365 |
|
366 /** |
|
367 The function is used to launch an app whose UID is supplied as its second input parameter. |
|
368 The function returns KErrNone upon success, KErrGeneral otherwise. |
|
369 */ |
|
370 TInt CTRuleBasedLaunchingStep::AppLaunchedL(RApaLsSession& aLs, const TUid& aAppUid) |
|
371 { |
|
372 TApaAppInfo info; |
|
373 TFileName fileName; |
|
374 aLs.GetAppInfo(info,aAppUid); |
|
375 //Wait 0.5sec for function to complete |
|
376 User::After(500000); |
|
377 fileName = info.iFullName; |
|
378 CApaCommandLine* cmdLn = CApaCommandLine::NewLC(); |
|
379 cmdLn->SetExecutableNameL(fileName); |
|
380 TInt result = aLs.StartApp(*cmdLn); |
|
381 //Wait 0.5sec for App to start |
|
382 User::After(500000); |
|
383 CleanupStack::PopAndDestroy(cmdLn); |
|
384 return result; |
|
385 } |
|
386 |
|
387 /** |
|
388 The function is used to launch an application using full file name as param. |
|
389 */ |
|
390 TInt CTRuleBasedLaunchingStep::AppLaunchedL(RApaLsSession& aLs, const TDesC& aAppFullFileName) |
|
391 { |
|
392 CApaCommandLine* cmdLn = CApaCommandLine::NewLC(); |
|
393 cmdLn->SetExecutableNameL(aAppFullFileName); |
|
394 TInt result = aLs.StartApp(*cmdLn); |
|
395 //Wait 0.5sec for App to start |
|
396 User::After(500000); |
|
397 CleanupStack::PopAndDestroy(cmdLn); |
|
398 return result; |
|
399 } |
|
400 |
|
401 /** |
|
402 The function is used to launch an application via dummy document associated with this application. |
|
403 */ |
|
404 TInt CTRuleBasedLaunchingStep::LaunchAppFromAssociatedDocument(RApaLsSession& aLs,const TUid& aAppUid) |
|
405 { |
|
406 TDataType theDataType(aAppUid); |
|
407 TThreadId theThreadId; |
|
408 TInt result = aLs.StartDocument(KNullDesC, theDataType, theThreadId); |
|
409 //Wait 2sec for App to start |
|
410 User::After(2 * 1000000); |
|
411 return result; |
|
412 } |
|
413 |
|
414 /** |
|
415 The function is used to close an app whose UID is supplied as the input parameter. |
|
416 The function returns KerrNone upon success, KErrGeneral othewise. |
|
417 */ |
|
418 TInt CTRuleBasedLaunchingStep::AppClosed(TUid AppUid) |
|
419 { |
|
420 TInt result = KErrNone; |
|
421 TApaTaskList taskList(iWs); |
|
422 TApaTask task1 = taskList.FindApp(AppUid); |
|
423 if(task1.Exists()) |
|
424 { |
|
425 task1.EndTask(); |
|
426 //Wait 0.5sec for the App to close |
|
427 User::After(500000); |
|
428 |
|
429 const TApaTask task2 = taskList.FindApp(AppUid); |
|
430 if (task2.Exists()) |
|
431 { |
|
432 result = KErrGeneral; |
|
433 } |
|
434 } |
|
435 return result; |
|
436 } |
|
437 |
|
438 /** The function close all test applications */ |
|
439 void CTRuleBasedLaunchingStep::ClosedAllTestApp() |
|
440 { |
|
441 AppClosed(KUidApp1); |
|
442 AppClosed(KUidApp2); |
|
443 AppClosed(KUidApp3); |
|
444 AppClosed(KUidApp4); |
|
445 } |
|
446 |
|
447 TVerdict CTRuleBasedLaunchingStep::doTestStepL() |
|
448 { |
|
449 INFO_PRINTF1(_L("TRuleBasedLaunchingStep test started....")); |
|
450 |
|
451 User::LeaveIfError(FbsStartup()); |
|
452 TInt ret=RFbsSession::Connect(); |
|
453 |
|
454 User::LeaveIfError(iFs.Connect()); |
|
455 User::LeaveIfError(iWs.Connect()); |
|
456 |
|
457 TEST(ret==KErrNone); |
|
458 __UHEAP_MARK; |
|
459 TRAPD(err, ExecuteL()); |
|
460 TEST(err == KErrNone); |
|
461 INFO_PRINTF2(_L("execute tests ended with return value '%d'"), err); |
|
462 __UHEAP_MARKEND; |
|
463 |
|
464 RFbsSession::Disconnect(); |
|
465 INFO_PRINTF1(_L(".... TRuleBasedLaunchingStep test finished!!")); |
|
466 return TestStepResult(); |
|
467 } |