|
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 // Checks for notifications when application list changes.\n |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @test |
|
23 @internalComponent - Internal Symbian test code |
|
24 */ |
|
25 |
|
26 #include <f32file.h> |
|
27 #include <fbs.h> |
|
28 #include <apaid.h> |
|
29 #include <apgaplst.h> |
|
30 #include <apaflrec.h> |
|
31 #include <apgcli.h> |
|
32 #include <apacmdln.h> |
|
33 #include <apsserv.h> |
|
34 #include <apfrec.h> |
|
35 #include <datastor.h> |
|
36 #include <apgicnfl.h> |
|
37 #include <apasvst.h> |
|
38 #include <apgnotif.h> |
|
39 #include <e32test.h> |
|
40 |
|
41 #include "appfwk_test_utils.h" |
|
42 #include "T_NotifStep.h" |
|
43 |
|
44 |
|
45 /** |
|
46 |
|
47 Overridden from virtual method MApaAppListServObserver::HandleAppListEvent(). |
|
48 This method is used to receive notification for change in application list.\n |
|
49 |
|
50 */ |
|
51 void CTestObserver::HandleAppListEvent(TInt /*aEvent*/) |
|
52 { |
|
53 |
|
54 iNotified++; |
|
55 if (iNotifier) |
|
56 iNotifier->Cancel(); |
|
57 CActiveScheduler::Stop(); |
|
58 } |
|
59 |
|
60 /** |
|
61 Auxiliary Fn for Test Case ID T-NotifStep-TestAppNotificationL |
|
62 |
|
63 Copy a registration resource file in the path "c:\private\10003a3f\import\apps" . |
|
64 */ |
|
65 void CT_NotifStep::CreateAppL(const TDesC& aAppName) |
|
66 { |
|
67 TFileName appFullName; |
|
68 TFileName appTargetName; |
|
69 CFileMan* fileManager = CFileMan::NewL(iFs); |
|
70 CleanupStack::PushL(fileManager); |
|
71 appFullName.Format(_L("z:\\ApparcTest\\%S_reg.RSC"),&aAppName); |
|
72 appTargetName.Format(_L("C:\\Private\\10003a3f\\Import\\apps\\%S_reg.Rsc"), &aAppName); |
|
73 INFO_PRINTF2(_L("copying the file: %S"), &appTargetName); |
|
74 TInt ret = fileManager->Copy (appFullName, appTargetName, CFileMan::ERecurse); |
|
75 TEST(ret==KErrNone); |
|
76 CleanupStack::PopAndDestroy(fileManager); |
|
77 } |
|
78 |
|
79 /** |
|
80 Auxiliary Fn for Test Case ID T-NotifStep-TestAppNotificationL |
|
81 Delete a registration resource file from the path "c:\private\10003a3f\import\apps" . |
|
82 */ |
|
83 void CT_NotifStep::DeleteAppL(const TDesC& aAppName) |
|
84 { |
|
85 TFileName appFullName; |
|
86 CFileMan* fileManager = CFileMan::NewL(iFs); |
|
87 CleanupStack::PushL(fileManager); |
|
88 appFullName.Format(_L("C:\\Private\\10003a3f\\Import\\apps\\%S_reg.Rsc"),&aAppName); |
|
89 |
|
90 INFO_PRINTF2(_L("Deleting the file: %S"), &appFullName); |
|
91 TRequestStatus status; |
|
92 TTime tempTime(0); // added tempTime to avoid asynch CFileMan::Attribs request completing with KErrArgument |
|
93 TEST(fileManager->Attribs(appFullName,0,KEntryAttReadOnly, tempTime, CFileMan::ERecurse, status)==KErrNone); |
|
94 User::WaitForRequest(status); |
|
95 TEST(status.Int() == KErrNone); |
|
96 TInt ret = fileManager->Delete(appFullName, CFileMan::ERecurse); |
|
97 TEST(ret==KErrNone); |
|
98 CleanupStack::PopAndDestroy(fileManager); |
|
99 } |
|
100 |
|
101 /** |
|
102 @SYMTestCaseID T-NotifStep-TestAppNotificationL |
|
103 |
|
104 @SYMPREQ REQ1087, PCHY-5L3RDW |
|
105 |
|
106 @SYMTestCaseDesc Test whether notification is received from CApaAppListNotifier |
|
107 whenever application list changes. |
|
108 |
|
109 @SYMTestPriority High |
|
110 |
|
111 @SYMTestStatus Implemented |
|
112 |
|
113 @SYMTestActions The method creates an object of user-defined observer CTestObserver |
|
114 and creates a CApaAppListNotifier active object which is associated to the |
|
115 observer. It then starts the active scheduler and adds a new application or deletes |
|
116 an application from the application list. To ensure that notifications are received on |
|
117 change in application list HandleAppListEvent() method which is derived |
|
118 from interface class MApaAppListServObserver is observed.\n |
|
119 API Calls:\n |
|
120 CApaAppListNotifier::NewL(MApaAppListServObserver* aObserver, TPriority aPriority)\n |
|
121 |
|
122 @SYMTestExpectedResults On deletion of the app the notification for change in |
|
123 the application list is received. |
|
124 |
|
125 */ |
|
126 void CT_NotifStep::TestAppNotificationL() |
|
127 { |
|
128 // Force the applist to be updated |
|
129 //To ensure that server has time to count all applications in the system |
|
130 RPointerArray<TDesC> dummy; |
|
131 User::LeaveIfError(iSession.ForceRegistration(dummy)); |
|
132 |
|
133 TInt theAppCount = 0; |
|
134 TInt theErr1 = iSession.AppCount(theAppCount); |
|
135 TEST(theErr1==KErrNone); |
|
136 |
|
137 INFO_PRINTF2(_L("The number of applications : %d"), theAppCount); |
|
138 |
|
139 CTestObserver* obs=new(ELeave) CTestObserver(); |
|
140 CleanupStack::PushL(obs); |
|
141 CApaAppListNotifier* notif=CApaAppListNotifier::NewL(obs,CActive::EPriorityHigh); |
|
142 CleanupStack::PushL(notif); |
|
143 obs->iNotifier=notif; |
|
144 INFO_PRINTF1(_L("Creating and deleting apps for notification")); |
|
145 CreateAppL(_L("AAA")); |
|
146 |
|
147 CActiveScheduler::Start(); |
|
148 |
|
149 TInt theAppCount1 = 0; |
|
150 theErr1 = iSession.AppCount(theAppCount1); |
|
151 TEST((theAppCount1 - 1) == theAppCount); |
|
152 INFO_PRINTF2(_L("The number of applications : %d"), theAppCount1); |
|
153 CleanupStack::PopAndDestroy(notif); |
|
154 |
|
155 notif = CApaAppListNotifier::NewL(obs,CActive::EPriorityHigh); |
|
156 CleanupStack::PushL(notif); |
|
157 obs->iNotifier = notif; |
|
158 INFO_PRINTF1(_L("Deleting the application")); |
|
159 DeleteAppL(_L("AAA")); |
|
160 |
|
161 CActiveScheduler::Start(); |
|
162 |
|
163 CleanupStack::PopAndDestroy(notif); |
|
164 User::LeaveIfError(iSession.ForceRegistration(dummy)); |
|
165 theErr1 = iSession.AppCount(theAppCount1); |
|
166 TEST(theErr1==KErrNone); |
|
167 TEST(theAppCount1 == theAppCount); |
|
168 |
|
169 INFO_PRINTF2(_L("The number of applications : %d"), theAppCount1); |
|
170 TEST(obs->iNotified>0); |
|
171 |
|
172 INFO_PRINTF2(_L("Received %d notifications"),obs->iNotified); |
|
173 CleanupStack::PopAndDestroy(obs); |
|
174 } |
|
175 |
|
176 void CT_NotifStep::ModifyIconFileTimeStamp() |
|
177 { |
|
178 _LIT(KMbmIconFile, "c:\\resource\\apps\\tupgradeiconapp.mbm"); |
|
179 _LIT(KTestIconFile, "c:\\TestUpgradeIcon\\tupgradeiconapp.mbm"); |
|
180 _LIT(KTestIconFileTempPath, "c:\\TestUpgradeIcon\\"); |
|
181 |
|
182 // Create KMbmIconFileTempPath |
|
183 TInt ret = iUtils.CreateDirectoryL(KTestIconFileTempPath); |
|
184 TEST(ret == KErrNone || ret == KErrAlreadyExists); |
|
185 INFO_PRINTF1(_L("Copy icon file from C: drive to temp path")); |
|
186 ret = iUtils.CopyFileL(KMbmIconFile, KTestIconFileTempPath); |
|
187 |
|
188 INFO_PRINTF1(_L("Modify timestamp of the icon file")); |
|
189 TTime modifiedTime(0); |
|
190 modifiedTime.HomeTime(); |
|
191 ret = iFs.SetModified(KTestIconFile, modifiedTime); |
|
192 TEST(ret==KErrNone); |
|
193 ret = iUtils.SetReadOnly(KTestIconFile, 0); |
|
194 TEST(ret==KErrNone); |
|
195 INFO_PRINTF2(_L("Replace the modified icon file in C: drive (%S)"), &KMbmIconFile); |
|
196 ret = iUtils.CopyFileL(KTestIconFile, KMbmIconFile); |
|
197 // wait 5 seconds to finish re-scan |
|
198 User::After(5*1000000); |
|
199 TEST(ret==KErrNone); |
|
200 } |
|
201 |
|
202 /** |
|
203 @SYMTestCaseID T-NotifStep-TTestIconFileNotificationL |
|
204 |
|
205 @SYMPREQ PDEF102804 |
|
206 |
|
207 @SYMTestCaseDesc Test whether notification is received from CApaAppListNotifier whenever the application icon file is changed |
|
208 |
|
209 @SYMTestPriority High |
|
210 |
|
211 @SYMTestStatus Implemented |
|
212 |
|
213 @SYMTestActions Modify the application icon file in a temporary location. Move icon file to a location specified in the resource file. |
|
214 |
|
215 @SYMTestExpectedResults A notification is recieved when the updated icon file is replaced to a location specified in the resource file. |
|
216 */ |
|
217 void CT_NotifStep::TestIconFileNotificationL() |
|
218 { |
|
219 // Force the applist to be updated |
|
220 //To ensure that server has time to count all applications in the system |
|
221 RPointerArray<TDesC> dummy; |
|
222 User::LeaveIfError(iSession.ForceRegistration(dummy)); |
|
223 |
|
224 // Create observer |
|
225 CTestObserver* obs = new(ELeave) CTestObserver(); |
|
226 CleanupStack::PushL(obs); |
|
227 CApaAppListNotifier* notif = CApaAppListNotifier::NewL(obs, CActive::EPriorityHigh); |
|
228 CleanupStack::PushL(notif); |
|
229 obs->iNotifier=notif; |
|
230 |
|
231 // Change the timestamp of the icon file |
|
232 INFO_PRINTF1(_L("Modifying the icon file...attempt to check it's notified")); |
|
233 ModifyIconFileTimeStamp(); |
|
234 |
|
235 CActiveScheduler::Start(); |
|
236 |
|
237 CleanupStack::PopAndDestroy(notif); |
|
238 // Test if notification is recieved. |
|
239 TEST(obs->iNotified > 0); |
|
240 if (obs->iNotified > 0) |
|
241 { |
|
242 INFO_PRINTF2(_L("Received %d notifications"),obs->iNotified); |
|
243 } |
|
244 |
|
245 CleanupStack::PopAndDestroy(obs); //obs |
|
246 } |
|
247 |
|
248 CT_NotifStep::~CT_NotifStep() |
|
249 /** |
|
250 Destructor |
|
251 */ |
|
252 { |
|
253 delete iScheduler; |
|
254 } |
|
255 |
|
256 CT_NotifStep::CT_NotifStep() |
|
257 /** |
|
258 Constructor |
|
259 */ |
|
260 { |
|
261 // Call base class method to set up the human readable name for logging |
|
262 SetTestStepName(KT_NotifStep); |
|
263 } |
|
264 |
|
265 TVerdict CT_NotifStep::doTestStepL() |
|
266 /** |
|
267 @return - TVerdict code |
|
268 Override of base class virtual |
|
269 */ |
|
270 { |
|
271 INFO_PRINTF1(_L("Testing Apparc...T_Notif")); |
|
272 |
|
273 TInt ret = FbsStartup(); |
|
274 TEST(ret==KErrNone); |
|
275 ret=RFbsSession::Connect(); |
|
276 TEST(ret==KErrNone); |
|
277 // start an active scheduler |
|
278 iScheduler=new(ELeave) CActiveScheduler(); |
|
279 CActiveScheduler::Install(iScheduler); |
|
280 |
|
281 TEST(KErrNone == iFs.Connect()); |
|
282 TEST(KErrNone == iSession.Connect()); |
|
283 TEST(KErrNone == iUtils.Connect()); |
|
284 |
|
285 // run the testcode (inside an alloc heaven harness) |
|
286 __UHEAP_MARK; |
|
287 #if defined (__WINSCW__) |
|
288 INFO_PRINTF1(_L("T-NotifStep-TTestIconFileNotificationL Test Started...")); |
|
289 TRAP(ret,TestIconFileNotificationL()); |
|
290 TEST(ret==KErrNone); |
|
291 INFO_PRINTF2(_L("TestIconFileNotificationL() finished with return code '%d'\n"), ret); |
|
292 #endif |
|
293 INFO_PRINTF1(_L("T-NotifStep-TestAppNotificationL Test Started...")); |
|
294 TRAP(ret,TestAppNotificationL()); |
|
295 TEST(ret==KErrNone); |
|
296 INFO_PRINTF2(_L("TestAppNotificationL() finished with return code '%d'\n"), ret); |
|
297 __UHEAP_MARKEND; |
|
298 |
|
299 iUtils.Close(); |
|
300 iSession.Close(); |
|
301 iFs.Close(); |
|
302 RFbsSession::Disconnect(); |
|
303 INFO_PRINTF1(_L("T_Notif Completed.")); |
|
304 return TestStepResult(); |
|
305 } |