|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalTechnology |
|
22 */ |
|
23 |
|
24 #include "tsifcommonverificationstep.h" |
|
25 #include "tsifsuitedefs.h" |
|
26 #include <swi/sisregistrysession.h> |
|
27 #include <swi/sisregistrypackage.h> |
|
28 #include <ct/rcpointerarray.h> |
|
29 #include <usif/scr/scr.h> |
|
30 #include <apgcli.h> |
|
31 #include <apacmdln.h> |
|
32 |
|
33 using namespace Usif; |
|
34 |
|
35 namespace |
|
36 { |
|
37 TBool CheckPathExistenceL(const TDesC& filePath) |
|
38 { |
|
39 TBool exists = EFalse; |
|
40 |
|
41 RFs fs; |
|
42 User::LeaveIfError(fs.Connect()); |
|
43 CleanupClosePushL(fs); |
|
44 TEntry entry; |
|
45 TInt error = fs.Entry(filePath, entry); |
|
46 if (error == KErrNone) |
|
47 { |
|
48 exists = ETrue; |
|
49 } |
|
50 else if (error != KErrPathNotFound && error != KErrNotFound) |
|
51 { |
|
52 User::Leave(error); |
|
53 } |
|
54 |
|
55 CleanupStack::PopAndDestroy(&fs); |
|
56 return exists; |
|
57 } |
|
58 } |
|
59 |
|
60 CSifCommonVerificationStep::~CSifCommonVerificationStep() |
|
61 /** |
|
62 * Destructor |
|
63 */ |
|
64 { |
|
65 INFO_PRINTF1(_L("Cleanup in CSifCommonVerificationStep::~CSifCommonVerificationStep()")); |
|
66 } |
|
67 |
|
68 CSifCommonVerificationStep::CSifCommonVerificationStep() |
|
69 /** |
|
70 * Constructor |
|
71 */ |
|
72 { |
|
73 } |
|
74 |
|
75 void CSifCommonVerificationStep::ImplTestStepPreambleL() |
|
76 /** |
|
77 * @return - TVerdict code |
|
78 * Override of base class virtual |
|
79 */ |
|
80 { |
|
81 INFO_PRINTF1(_L("I am in CSifCommonVerificationStep::ImplTestStepPreambleL().")); |
|
82 } |
|
83 |
|
84 TScomoState CSifCommonVerificationStep::GetScomoStateL(TComponentId aComponentId) |
|
85 { |
|
86 RSoftwareComponentRegistry scr; |
|
87 User::LeaveIfError(scr.Connect()); |
|
88 CleanupClosePushL(scr); |
|
89 |
|
90 CComponentEntry* entry = CComponentEntry::NewLC(); |
|
91 if (!scr.GetComponentL(aComponentId, *entry)) |
|
92 { |
|
93 INFO_PRINTF1(_L("CSifCommonVerificationStep::GetScomoStateL() failed!")); |
|
94 CleanupStack::PopAndDestroy(2, &scr); |
|
95 User::Leave(KErrNotFound); |
|
96 } |
|
97 |
|
98 TScomoState scomoState = entry->ScomoState(); |
|
99 CleanupStack::PopAndDestroy(2, &scr); |
|
100 |
|
101 return scomoState; |
|
102 } |
|
103 |
|
104 void CSifCommonVerificationStep::ImplTestStepL() |
|
105 /** |
|
106 * @return - TVerdict code |
|
107 * Override of base class pure virtual |
|
108 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
109 * not leave. That being the case, the current test result value will be EPass. |
|
110 */ |
|
111 { |
|
112 INFO_PRINTF1(_L("I am in CSifCommonVerificationStep::ImplTestStepL().")); |
|
113 |
|
114 // Read the configuration from the ini file |
|
115 TBool verifyExistence = ETrue; |
|
116 if (!GetBoolFromConfig(ConfigSection(), KTe_VerifyPackageExistence, verifyExistence)) |
|
117 { |
|
118 SetTestStepResult(EFail); |
|
119 INFO_PRINTF2(_L("Failed to read %S from ini file."), &KTe_VerifyPackageExistence); |
|
120 return; |
|
121 } |
|
122 |
|
123 TInt exeReturnCode = 0; |
|
124 TInt refScomoState = 0; |
|
125 TPtrC componentName, componentVendor, executableName; |
|
126 if (!GetStringFromConfig(ConfigSection(), KTe_ComponentName, componentName) || |
|
127 !GetStringFromConfig(ConfigSection(), KTe_ComponentVendor, componentVendor) || |
|
128 (verifyExistence && !GetIntFromConfig(ConfigSection(), KTe_ScomoState, refScomoState))) |
|
129 { |
|
130 SetTestStepResult(EFail); |
|
131 INFO_PRINTF4(_L("Failed to read %S, %S or %S from ini file."), &KTe_ComponentName, &KTe_ComponentVendor, &KTe_ScomoState); |
|
132 return; |
|
133 } |
|
134 |
|
135 TBool launchExecutable = GetStringFromConfig(ConfigSection(), KTe_ExecutableName, executableName); |
|
136 if (launchExecutable && verifyExistence) |
|
137 { |
|
138 if (!GetIntFromConfig(ConfigSection(), KTe_ExecutableReturnCode, exeReturnCode)) |
|
139 { |
|
140 SetTestStepResult(EFail); |
|
141 INFO_PRINTF2(_L("Failed to read %S from ini file."), &KTe_ExecutableReturnCode); |
|
142 return; |
|
143 } |
|
144 } |
|
145 |
|
146 // Look for a component in the SCR |
|
147 TScomoState scomoState = EDeactivated; |
|
148 TBool foundInScr = EFalse; |
|
149 TComponentId componentId = FindComponentInScrL(componentName, componentVendor); |
|
150 if (componentId != 0) |
|
151 { |
|
152 foundInScr = ETrue; |
|
153 scomoState = GetScomoStateL(componentId); |
|
154 } |
|
155 |
|
156 // Look for a component in the SIS Registry |
|
157 TBool checkSisRegistry = ETrue; |
|
158 GetBoolFromConfig(ConfigSection(), KTe_CheckSisRegistry, checkSisRegistry); |
|
159 TBool foundInSisRegistry = EFalse; |
|
160 if (checkSisRegistry) |
|
161 { |
|
162 Swi::RSisRegistrySession sisRegistry; |
|
163 User::LeaveIfError(sisRegistry.Connect()); |
|
164 CleanupClosePushL(sisRegistry); |
|
165 |
|
166 RCPointerArray<Swi::CSisRegistryPackage> installedPackages; |
|
167 sisRegistry.InstalledPackagesL(installedPackages); |
|
168 CleanupClosePushL(installedPackages); |
|
169 |
|
170 const TInt numPackages = installedPackages.Count(); |
|
171 for (TInt i=0; i<numPackages; ++i) |
|
172 { |
|
173 const TDesC& name = installedPackages[i]->Name(); |
|
174 const TDesC& vendor = installedPackages[i]->Vendor(); |
|
175 if (name == componentName && vendor == componentVendor) |
|
176 { |
|
177 foundInSisRegistry = ETrue; |
|
178 break; |
|
179 } |
|
180 } |
|
181 CleanupStack::PopAndDestroy(2, &sisRegistry); |
|
182 } |
|
183 |
|
184 // Launch the executable |
|
185 TInt apaErr = KErrNone; |
|
186 TRequestStatus launchStatus; |
|
187 if (launchExecutable) |
|
188 { |
|
189 RApaLsSession apa; |
|
190 apaErr = apa.Connect(); |
|
191 if (apaErr != KErrNone) |
|
192 { |
|
193 INFO_PRINTF2(_L("Failed to connect to the application architecture server, error code: %d"), apaErr); |
|
194 User::Leave(apaErr); |
|
195 } |
|
196 CleanupClosePushL(apa); |
|
197 |
|
198 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
199 cmdLine->SetExecutableNameL(executableName); |
|
200 |
|
201 TThreadId threadId; |
|
202 apaErr = apa.StartApp(*cmdLine, threadId, &launchStatus); |
|
203 if (apaErr == KErrNone) |
|
204 { |
|
205 INFO_PRINTF3(_L("Launched: %S with error code: %d"), &executableName, launchStatus.Int()); |
|
206 User::WaitForRequest(launchStatus); |
|
207 } |
|
208 else if (apaErr != KErrNotFound) |
|
209 { |
|
210 INFO_PRINTF2(_L("Failed to call RApaLsSession::StartApp(), error code: %d"), apaErr); |
|
211 User::Leave(apaErr); |
|
212 } |
|
213 CleanupStack::PopAndDestroy(2, &apa); |
|
214 } |
|
215 |
|
216 // Look for the component's files |
|
217 TInt numDefinedFiles = 0; |
|
218 TInt numFoundFiles = 0; |
|
219 const TInt maxComponentFiles = 16; |
|
220 for (TInt i=0; i<maxComponentFiles; ++i) |
|
221 { |
|
222 // Read the name of a file |
|
223 HBufC* filePattern = HBufC::NewLC(KTe_PackageFile.iTypeLength+KMaxIntDigits); |
|
224 TPtr filePatternPtr(filePattern->Des()); |
|
225 filePatternPtr.Copy(KTe_PackageFile); |
|
226 filePatternPtr.AppendNum(i); |
|
227 TPtrC filePath; |
|
228 if (!GetStringFromConfig(ConfigSection(), *filePattern, filePath)) |
|
229 { |
|
230 CleanupStack::PopAndDestroy(filePattern); |
|
231 break; |
|
232 } |
|
233 ++numDefinedFiles; |
|
234 |
|
235 // Verify file existence |
|
236 if (CheckPathExistenceL(filePath)) |
|
237 { |
|
238 ++numFoundFiles; |
|
239 } |
|
240 |
|
241 CleanupStack::PopAndDestroy(filePattern); |
|
242 } |
|
243 |
|
244 // Calculate the test step result |
|
245 TVerdict verdict = EFail; |
|
246 if (verifyExistence) |
|
247 { |
|
248 if (foundInScr && scomoState == refScomoState && checkSisRegistry == foundInSisRegistry && numDefinedFiles == numFoundFiles) |
|
249 { |
|
250 if (launchExecutable) |
|
251 { |
|
252 if (exeReturnCode == launchStatus.Int()) |
|
253 { |
|
254 verdict = EPass; |
|
255 } |
|
256 } |
|
257 else |
|
258 { |
|
259 verdict = EPass; |
|
260 } |
|
261 } |
|
262 } |
|
263 else // verify NonExistence |
|
264 { |
|
265 if (!foundInScr && numFoundFiles == 0) |
|
266 { |
|
267 verdict = EPass; |
|
268 |
|
269 if (checkSisRegistry && foundInSisRegistry) |
|
270 { |
|
271 verdict = EFail; |
|
272 } |
|
273 if (launchExecutable && apaErr != KErrNotFound) |
|
274 { |
|
275 verdict = EFail; |
|
276 } |
|
277 } |
|
278 } |
|
279 |
|
280 SetTestStepResult(verdict); |
|
281 |
|
282 INFO_PRINTF1(_L("================== Begin Of Common Verification Steps ==================")); |
|
283 INFO_PRINTF3(_L("Verification of existence/non-existence: (%d/%d)"), verifyExistence, !verifyExistence); |
|
284 INFO_PRINTF3(_L("Component name: %S, vendor: %S"), &componentName, &componentVendor); |
|
285 INFO_PRINTF2(_L("Found in Scr = %d"), foundInScr); |
|
286 INFO_PRINTF2(_L("Found in Swi = %d"), foundInSisRegistry); |
|
287 INFO_PRINTF2(_L("Scomo state = %d"), scomoState); |
|
288 INFO_PRINTF2(_L("Exe return code = %d"), exeReturnCode); |
|
289 INFO_PRINTF3(_L("Test executable: %S launched with error code = %d"), &executableName, apaErr); |
|
290 INFO_PRINTF3(_L("Component files: defined = %d, found = %d"), numDefinedFiles, numFoundFiles); |
|
291 INFO_PRINTF1(_L("=================== End Of Common Verification Steps ===================")); |
|
292 } |
|
293 |
|
294 void CSifCommonVerificationStep::ImplTestStepPostambleL() |
|
295 /** |
|
296 * @return - TVerdict code |
|
297 * Override of base class virtual |
|
298 */ |
|
299 { |
|
300 } |