|
1 // Copyright (c) 2006-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 // This contains CTestAppLoaderTaskRunning |
|
15 // |
|
16 // |
|
17 |
|
18 // USER includes |
|
19 #include "TestAppLoaderTaskRunning.h" |
|
20 |
|
21 // EPOC includes |
|
22 #include <w32std.h> |
|
23 #include <coemain.h> |
|
24 #include <apgtask.h> |
|
25 #include <apgcli.h> |
|
26 #include <apgwgnam.H> |
|
27 |
|
28 /*@{*/ |
|
29 /// Parameters |
|
30 _LIT(KProgram, "program"); |
|
31 |
|
32 /// Log messages |
|
33 _LIT(KLogTask, "Caption '%S'."); |
|
34 |
|
35 /// Error messages |
|
36 _LIT(KErrCode, "Error %d"); |
|
37 _LIT(KErrMissingParameter, "Misssing Parameter %S"); |
|
38 _LIT(KErrTaskNotFound, "Task '%S' not found"); |
|
39 /*@}*/ |
|
40 |
|
41 // constructor |
|
42 CTestAppLoaderTaskRunning::CTestAppLoaderTaskRunning() |
|
43 : CTestAppLoaderBase() |
|
44 { |
|
45 SetTestStepName(_L("TaskRunning")); |
|
46 } |
|
47 |
|
48 // Each test step must supply a implementation for doTestStepL |
|
49 enum TVerdict CTestAppLoaderTaskRunning::doTestStepL( void ) |
|
50 { |
|
51 // Printing to the console and log file |
|
52 INFO_PRINTF1(_L("TEST-> TASK RUNNING")); |
|
53 |
|
54 TPtrC program; |
|
55 if ( !GetStringFromConfig(ConfigSection(), KProgram, program) ) |
|
56 { |
|
57 ERR_PRINTF2(KErrMissingParameter, &KProgram()); |
|
58 SetTestStepResult(EFail); |
|
59 } |
|
60 else |
|
61 { |
|
62 RApaLsSession apaLsSession; |
|
63 User::LeaveIfError(apaLsSession.Connect()); |
|
64 CleanupClosePushL(apaLsSession); |
|
65 User::LeaveIfError(apaLsSession.GetAllApps()); |
|
66 |
|
67 RWsSession ws; |
|
68 User::LeaveIfError(ws.Connect()); |
|
69 CleanupClosePushL(ws); |
|
70 |
|
71 TInt numWindowGroups = ws.NumWindowGroups(); |
|
72 CArrayFixFlat<TInt>* windowGroupList = new(ELeave) CArrayFixFlat<TInt>(numWindowGroups); |
|
73 CleanupStack::PushL(windowGroupList); |
|
74 |
|
75 // Populate array with current group list ids |
|
76 User::LeaveIfError(ws.WindowGroupList(windowGroupList)); |
|
77 |
|
78 CApaWindowGroupName* windowGroupName = CApaWindowGroupName::NewLC(ws); |
|
79 |
|
80 /* Note: we use windowGroupList->Count() instead of numWindowGroups, as in the middle of the |
|
81 * update the list could change in length (or worse, be reduced) thus producing an out of bounds |
|
82 * error if numWindowGroups were used |
|
83 */ |
|
84 TBool searching=ETrue; |
|
85 for ( TInt i=0; (i<windowGroupList->Count()) && searching; ++i ) |
|
86 { |
|
87 TInt wgId = windowGroupList->At(i); |
|
88 windowGroupName->ConstructFromWgIdL(wgId); |
|
89 |
|
90 TUid appUid = windowGroupName->AppUid(); |
|
91 |
|
92 TApaAppInfo appInfo; |
|
93 HBufC* appCaption = NULL; |
|
94 // Some applications, like midlets, may not provide any info |
|
95 if (apaLsSession.GetAppInfo(appInfo, appUid) == KErrNone) |
|
96 { |
|
97 appCaption = appInfo.iCaption.AllocL(); |
|
98 } |
|
99 else |
|
100 { |
|
101 appCaption = windowGroupName->Caption().AllocL(); |
|
102 } |
|
103 CleanupStack::PushL(appCaption); |
|
104 |
|
105 // Only list 'visible' applications |
|
106 if ( appCaption->Length() ) |
|
107 { |
|
108 TPtrC caption=*appCaption; |
|
109 INFO_PRINTF2(KLogTask, &caption); |
|
110 |
|
111 if ( program.CompareC(caption)==0 ) |
|
112 { |
|
113 searching=EFalse; |
|
114 TApaTask task(ws); |
|
115 task.SetWgId(wgId); |
|
116 if (!task.Exists()) |
|
117 { |
|
118 ERR_PRINTF2(KErrTaskNotFound, &program); |
|
119 SetTestStepResult(EFail); |
|
120 } |
|
121 } |
|
122 } |
|
123 CleanupStack::Pop(1, appCaption); // taskEntry, appCaption |
|
124 } |
|
125 |
|
126 if ( searching ) |
|
127 { |
|
128 ERR_PRINTF2(KErrTaskNotFound, &program); |
|
129 SetTestStepResult(EFail); |
|
130 } |
|
131 CleanupStack::PopAndDestroy(4, &apaLsSession); // windowGroupName, windowGroupList |
|
132 } |
|
133 |
|
134 // test steps return a result |
|
135 return TestStepResult(); |
|
136 } |