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