|
1 /* |
|
2 * Copyright (c) 2008-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 the License "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: |
|
15 * tswisstep.cpp |
|
16 * UPS test step implementation |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 */ |
|
26 |
|
27 |
|
28 #include <e32std.h> |
|
29 #include "tupsstep.h" |
|
30 #include "testutilclient.h" |
|
31 #include <test/testexecutelog.h> |
|
32 #include <swi/launcher.h> |
|
33 #include "swi/sisregistryentry.h" |
|
34 #include "swi/sisregistrysession.h" |
|
35 #include "swi/sisregistrypackage.h" |
|
36 #include "cleanuputils.h" |
|
37 |
|
38 using namespace Swi; |
|
39 using namespace Swi::Test; |
|
40 |
|
41 // |
|
42 // CUpsInstallStep |
|
43 // |
|
44 |
|
45 CUpsInstallStep::~CUpsInstallStep() |
|
46 { |
|
47 delete iUi; |
|
48 } |
|
49 |
|
50 |
|
51 CUpsInstallStep::CUpsInstallStep(TInstallType aInstallType) |
|
52 : iInstallType(aInstallType) |
|
53 { |
|
54 // Call base class method to set up the human readable name for logging |
|
55 SetTestStepName(KUpsInstallStep); |
|
56 } |
|
57 |
|
58 /** |
|
59 * Override of base class virtual. Prepares for the test run of SWIS |
|
60 * @return TVerdict code |
|
61 */ |
|
62 TVerdict CUpsInstallStep::doTestStepPreambleL() |
|
63 { |
|
64 // get step parameters |
|
65 TPtrC str; |
|
66 if (!GetStringFromConfig(ConfigSection(), _L("sis"), str)) |
|
67 { |
|
68 ERR_PRINTF1(_L("Missing SIS file name")); |
|
69 SetTestStepResult(EFail); |
|
70 } |
|
71 else |
|
72 { |
|
73 iSisFileName.Copy(str); |
|
74 if (!GetStringFromConfig(ConfigSection(), _L("script"), str)) |
|
75 { |
|
76 ERR_PRINTF1(_L("Missing XML file name")); |
|
77 SetTestStepResult(EFail); |
|
78 } |
|
79 else |
|
80 { |
|
81 iXmlFileName.Copy(str); |
|
82 INFO_PRINTF3(_L("Installing '%S' using script '%S'"), |
|
83 &iSisFileName, &iXmlFileName); |
|
84 // create UI handler with default entries |
|
85 iUi = CUIScriptAdaptor::NewL(iXmlFileName, Logger()); |
|
86 } |
|
87 } |
|
88 |
|
89 return TestStepResult(); |
|
90 } |
|
91 |
|
92 /** |
|
93 * Override of base class pure virtual |
|
94 * Demonstrates reading configuration parameters fom an ini file section |
|
95 * @return TVerdict code |
|
96 */ |
|
97 TVerdict CUpsInstallStep::doTestStepL() |
|
98 { |
|
99 INFO_PRINTF1(KUpsInstallStep); |
|
100 |
|
101 // launch the installation |
|
102 CInstallPrefs* prefs = CInstallPrefs::NewLC(); |
|
103 |
|
104 TInt err = DoInstallL(*prefs); |
|
105 INFO_PRINTF2(_L("DoInstallL returned %d"), err); |
|
106 if (err != KErrNone) |
|
107 { |
|
108 // Can't set error to KErrServerBusy, or Testexecute will retry. |
|
109 SetTestStepResult((err != KErrServerBusy)? static_cast<TVerdict>(err) : EFail); |
|
110 } |
|
111 CleanupStack::PopAndDestroy(prefs); |
|
112 return TestStepResult(); |
|
113 } |
|
114 |
|
115 TInt CUpsInstallStep::DoInstallL(CInstallPrefs& aInstallPrefs) |
|
116 { |
|
117 switch (iInstallType) |
|
118 { |
|
119 case EUseFileName: |
|
120 return Launcher::Install(*iUi, iSisFileName, aInstallPrefs); |
|
121 } |
|
122 |
|
123 // Shouldn't get here |
|
124 return KErrGeneral; |
|
125 } |
|
126 |
|
127 /** |
|
128 * Override of base class virtual |
|
129 * @return TVerdict code |
|
130 */ |
|
131 TVerdict CUpsInstallStep::doTestStepPostambleL() |
|
132 { |
|
133 /* if((TestStepResult() == EPass)) |
|
134 { |
|
135 RSisRegistrySession registrySession; |
|
136 User::LeaveIfError(registrySession.Connect()); |
|
137 CleanupClosePushL(registrySession); |
|
138 |
|
139 RSisRegistryEntry registryEntry; |
|
140 TInt error=registryEntry.Open(registrySession, iUid); |
|
141 if(error != KErrNone) |
|
142 { |
|
143 ERR_PRINTF2(_L("RSisRegistrySession::Open failed error=%d\n"), error); |
|
144 SetTestStepResult(EFail); |
|
145 } |
|
146 else |
|
147 { |
|
148 CleanupClosePushL(registryEntry); |
|
149 |
|
150 TInt userDrive =0; |
|
151 TRAP(error, userDrive = registryEntry.SelectedDriveL()); |
|
152 if((error != KErrNone) || (userDrive != iExpectedUserDrive)) |
|
153 { |
|
154 ERR_PRINTF4(_L("SelectedDriveL err=%d, userDrive expected %d got %d\n"), |
|
155 error, iExpectedUserDrive, userDrive); |
|
156 SetTestStepResult(EFail); |
|
157 } |
|
158 else |
|
159 { |
|
160 INFO_PRINTF2(_L("SelectedDriveL userDrive = %d OK\n"), userDrive); |
|
161 } |
|
162 |
|
163 CleanupStack::PopAndDestroy(®istryEntry); |
|
164 } |
|
165 CleanupStack::PopAndDestroy(®istrySession); |
|
166 }*/ |
|
167 |
|
168 return TestStepResult(); |
|
169 } |
|
170 |
|
171 // |
|
172 // CSwisUninstallStep |
|
173 // |
|
174 |
|
175 CUpsUninstallStep::~CUpsUninstallStep() |
|
176 { |
|
177 delete iUi; |
|
178 } |
|
179 |
|
180 CUpsUninstallStep::CUpsUninstallStep(TUninstallType aType) |
|
181 : iType(aType) |
|
182 { |
|
183 // Call base class method to set up the human readable name for logging |
|
184 SetTestStepName(KUpsUnInstallStep); |
|
185 } |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 /** |
|
191 * Override of base class virtual. Prepares for the test run of SWIS |
|
192 * @return TVerdict code |
|
193 */ |
|
194 TVerdict CUpsUninstallStep::doTestStepPreambleL() |
|
195 { |
|
196 INFO_PRINTF1(_L("CUpsUninstallStep::doTestStepPreambleL")); |
|
197 // get step parameters |
|
198 |
|
199 TPtrC str; |
|
200 if (!GetStringFromConfig(ConfigSection(), _L("script"), str)) |
|
201 { |
|
202 ERR_PRINTF1(_L("Missing XML file name")); |
|
203 SetTestStepResult(EFail); |
|
204 return EFail; |
|
205 } |
|
206 iXmlFileName.Copy(str); |
|
207 TInt uid=0; |
|
208 |
|
209 if (!GetHexFromConfig(ConfigSection(), _L("uid"), uid)) |
|
210 { |
|
211 ERR_PRINTF1(_L("Missing uid")); |
|
212 SetTestStepResult(EFail); |
|
213 return EFail; |
|
214 } |
|
215 |
|
216 iUid.iUid=uid; |
|
217 |
|
218 if (iType == EByPackage) |
|
219 { |
|
220 TPtrC vendorName; |
|
221 if (!GetStringFromConfig(ConfigSection(), _L("vendorName"), vendorName)) |
|
222 { |
|
223 ERR_PRINTF1(_L("Missing Vendor Name")); |
|
224 SetTestStepResult(EFail); |
|
225 return EFail; |
|
226 } |
|
227 iVendorName.Set(vendorName); |
|
228 |
|
229 TPtrC packageName; |
|
230 if (!GetStringFromConfig(ConfigSection(), _L("packageName"), packageName)) |
|
231 { |
|
232 ERR_PRINTF1(_L("Missing Package Name")); |
|
233 SetTestStepResult(EFail); |
|
234 return EFail; |
|
235 } |
|
236 iPackageName.Set(packageName); |
|
237 |
|
238 |
|
239 INFO_PRINTF5(_L("Uninstalling %D, %S, %S using script '%S'"), |
|
240 iUid.iUid, &iPackageName, &iVendorName, &iXmlFileName); |
|
241 // create UI handler with default entries |
|
242 iUi = CUIScriptAdaptor::NewL(iXmlFileName, Logger()); |
|
243 } |
|
244 else if (iType== EByUid) |
|
245 { |
|
246 INFO_PRINTF3(_L("Uninstalling '%D' using script '%S'"), |
|
247 iUid.iUid, &iXmlFileName); |
|
248 // create UI handler with default entries |
|
249 iUi = CUIScriptAdaptor::NewL(iXmlFileName, Logger()); |
|
250 } |
|
251 |
|
252 return TestStepResult(); |
|
253 } |
|
254 |
|
255 /** |
|
256 * Override of base class pure virtual |
|
257 * Demonstrates reading configuration parameters fom an ini file section |
|
258 * @return TVerdict code |
|
259 */ |
|
260 |
|
261 TInt CUpsUninstallStep::DoUninstallL() |
|
262 { |
|
263 TInt error = KErrNotFound; |
|
264 |
|
265 if (iType == EByUid) |
|
266 { |
|
267 // launch the installation |
|
268 return Launcher::Uninstall(*iUi, iUid); |
|
269 } |
|
270 else if (iType == EByPackage) |
|
271 { |
|
272 |
|
273 TInt err = KErrNotFound; |
|
274 // Go through list of packages from base package to get augmentations. |
|
275 CSisRegistryPackage* uninstallPackage=CSisRegistryPackage::NewLC(iUid, iPackageName, iVendorName); |
|
276 |
|
277 RSisRegistrySession registrySession; |
|
278 User::LeaveIfError(registrySession.Connect()); |
|
279 CleanupClosePushL(registrySession); |
|
280 |
|
281 RSisRegistryEntry registryEntry; |
|
282 |
|
283 User::LeaveIfError(registryEntry.Open(registrySession, iUid)); |
|
284 CleanupClosePushL(registryEntry); |
|
285 |
|
286 CSisRegistryPackage* package=registryEntry.PackageL(); |
|
287 CleanupStack::PushL(package); |
|
288 |
|
289 if (*package == *uninstallPackage) |
|
290 { |
|
291 err = -1; |
|
292 err=Launcher::Uninstall(*iUi, *package); |
|
293 } |
|
294 else |
|
295 { |
|
296 // check augmenations |
|
297 RPointerArray<CSisRegistryPackage> augmentationPackages; |
|
298 CleanupResetAndDestroy<RPointerArray<CSisRegistryPackage> >::PushL(augmentationPackages); |
|
299 |
|
300 registryEntry.AugmentationsL(augmentationPackages); |
|
301 for (TInt i=0; i < augmentationPackages.Count(); ++i) |
|
302 { |
|
303 if (*augmentationPackages[i] == *uninstallPackage) |
|
304 { |
|
305 err=User::LeaveIfError(Launcher::Uninstall(*iUi, *augmentationPackages[i])); |
|
306 break; |
|
307 } |
|
308 } |
|
309 CleanupStack::PopAndDestroy(&augmentationPackages); |
|
310 } |
|
311 |
|
312 CleanupStack::PopAndDestroy(3, ®istrySession); |
|
313 CleanupStack::PopAndDestroy(uninstallPackage); |
|
314 error = err; |
|
315 } |
|
316 return error; |
|
317 } |
|
318 |
|
319 TVerdict CUpsUninstallStep::doTestStepL() |
|
320 { |
|
321 INFO_PRINTF1(KUpsUnInstallStep); |
|
322 |
|
323 TInt err = DoUninstallL(); |
|
324 INFO_PRINTF2(_L("DoUninstallL returned %d"), err); |
|
325 if (err != KErrNone) |
|
326 { |
|
327 // Can't set error to KErrServerBusy, or Testexecute will retry. |
|
328 SetTestStepResult((err != KErrServerBusy)? static_cast<TVerdict>(err) : EFail); |
|
329 } |
|
330 return TestStepResult(); |
|
331 } |
|
332 |
|
333 /** |
|
334 * Override of base class virtual |
|
335 * @return TVerdict code |
|
336 */ |
|
337 TVerdict CUpsUninstallStep::doTestStepPostambleL() |
|
338 { |
|
339 return TestStepResult(); |
|
340 } |
|
341 |
|
342 // End of file |