|
1 /* |
|
2 * Copyright (c) 2010 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 "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 #include <HbParameterLengthLimiter> |
|
18 #include <HbExtendedLocale> |
|
19 #include "casoftwareregistry.h" |
|
20 #include "casoftwareregistry_p.h" |
|
21 |
|
22 #include "t_casoftwareregistry.h" |
|
23 |
|
24 #ifdef Q_OS_SYMBIAN |
|
25 #include <e32base.h> |
|
26 #include <e32def.h> |
|
27 #undef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
28 #include <usif/scr/scr.h> |
|
29 #include <usif/scr/screntries.h> |
|
30 |
|
31 #include <usif/sif/sif.h> |
|
32 #include <usif/scr/scr.h> |
|
33 |
|
34 #include <xqconversions.h> |
|
35 using namespace Usif; |
|
36 #include <caarraycleanup.inl> |
|
37 #endif |
|
38 |
|
39 T_CaSoftwareRegistry::T_CaSoftwareRegistry(): |
|
40 mSoftwareRegistry(NULL) |
|
41 { |
|
42 } |
|
43 |
|
44 void T_CaSoftwareRegistry::cleanup() |
|
45 { |
|
46 |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 void T_CaSoftwareRegistry::initTestCase() |
|
53 { |
|
54 |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void T_CaSoftwareRegistry::testSoftwareRegistryCreate() |
|
62 { |
|
63 |
|
64 QVERIFY(CaSoftwareRegistry::create()); |
|
65 QSharedPointer<CaSoftwareRegistry> scr = CaSoftwareRegistry::create(); |
|
66 QVERIFY(CaSoftwareRegistry::create().data() == scr.data()); |
|
67 } |
|
68 |
|
69 #ifdef Q_OS_SYMBIAN |
|
70 |
|
71 void T_CaSoftwareRegistry::testExtractingDetailsFromEntry() |
|
72 { |
|
73 // set up expexted values.. |
|
74 _LIT(KName, "appname"); |
|
75 _LIT(KVendor, "xxx"); |
|
76 |
|
77 TDriveList installedDrives; |
|
78 |
|
79 QString expectedDrives; |
|
80 |
|
81 const TInt driveListLen(installedDrives.Length()); |
|
82 for (TInt i( 0 ); i < driveListLen; ++i) { |
|
83 if (i == 3 || i == 4) { |
|
84 installedDrives[i] = '\1'; |
|
85 expectedDrives = expectedDrives.append(QChar('A'+ i)).append(":"); |
|
86 } else { |
|
87 installedDrives[i] = '\0'; |
|
88 } |
|
89 } |
|
90 |
|
91 _LIT(KVersion, "ver 1.1"); |
|
92 _LIT(KSwType, "software type"); |
|
93 const TInt64 KSize = 2048; // i.e 2k |
|
94 |
|
95 // definition below are provided just to satisfy CComponentEntry::NewL |
|
96 _LIT(KGlobalId, ""); |
|
97 TBool KRemovable(EFalse); |
|
98 TScomoState KScomoState; |
|
99 TComponentId KId; |
|
100 _LIT(KInstallTime, ""); |
|
101 TBool KDrmProtected(EFalse); |
|
102 TBool KHidden(EFalse); |
|
103 TBool KKnownRevoked(EFalse); |
|
104 TBool KOriginVerified(EFalse); |
|
105 |
|
106 |
|
107 QScopedPointer<CComponentEntry> entry; |
|
108 |
|
109 QT_TRAP_THROWING(entry.reset( |
|
110 CComponentEntry::NewL( |
|
111 KId, |
|
112 KName, |
|
113 KVendor, |
|
114 KSwType, |
|
115 KGlobalId, |
|
116 KRemovable, |
|
117 KSize, |
|
118 KScomoState, |
|
119 installedDrives, |
|
120 KVersion, |
|
121 KInstallTime, |
|
122 KDrmProtected, |
|
123 KHidden, |
|
124 KKnownRevoked, |
|
125 KOriginVerified) |
|
126 ) |
|
127 ); |
|
128 |
|
129 CaSoftwareRegistryPrivate scr(NULL); |
|
130 CaSoftwareRegistry::DetailMap detailMap = scr.entryDetailsL(*entry); |
|
131 |
|
132 QCOMPARE(detailMap.size(), 6); |
|
133 QCOMPARE(detailMap[CaSoftwareRegistry::componentNameKey()], |
|
134 XQConversions::s60DescToQString(KName)); |
|
135 QCOMPARE(detailMap[CaSoftwareRegistry::componentVersionKey()], |
|
136 XQConversions::s60DescToQString(KVersion)); |
|
137 QCOMPARE(detailMap[CaSoftwareRegistry::componentVendorKey()], |
|
138 XQConversions::s60DescToQString(KVendor)); |
|
139 QCOMPARE(detailMap[CaSoftwareRegistry::componentDriveInfoKey()], |
|
140 expectedDrives); |
|
141 QCOMPARE(detailMap[CaSoftwareRegistry::componentSizeKey()], |
|
142 QString(HbParameterLengthLimiter("txt_applib_dialog_l1_kb") |
|
143 .arg(QString().setNum(static_cast<double>(KSize / 1024))))); |
|
144 QCOMPARE(detailMap[CaSoftwareRegistry::componentTypeKey()], |
|
145 XQConversions::s60DescToQString(KSwType)); |
|
146 |
|
147 for (TInt i( 0 ); i < driveListLen; ++i) { |
|
148 installedDrives[i]= '\0'; |
|
149 } |
|
150 |
|
151 QT_TRAP_THROWING(entry.reset( |
|
152 CComponentEntry::NewL( |
|
153 KId, |
|
154 _L(""), // name |
|
155 _L(""), // vendor |
|
156 _L(""), // sw type |
|
157 KGlobalId, |
|
158 KRemovable, |
|
159 0, // size |
|
160 KScomoState, |
|
161 installedDrives, |
|
162 _L(""), // version |
|
163 KInstallTime, |
|
164 KDrmProtected, |
|
165 KHidden, |
|
166 KKnownRevoked, |
|
167 KOriginVerified) |
|
168 ) |
|
169 ); |
|
170 |
|
171 detailMap = scr.entryDetailsL(*entry); |
|
172 |
|
173 QCOMPARE(detailMap.size(), 6); |
|
174 QCOMPARE(detailMap[CaSoftwareRegistry::componentNameKey()], |
|
175 QString("")); |
|
176 QCOMPARE(detailMap[CaSoftwareRegistry::componentVersionKey()], |
|
177 QString("")); |
|
178 QCOMPARE(detailMap[CaSoftwareRegistry::componentVendorKey()], |
|
179 QString("")); |
|
180 QCOMPARE(detailMap[CaSoftwareRegistry::componentDriveInfoKey()], |
|
181 QString("")); |
|
182 QCOMPARE(detailMap[CaSoftwareRegistry::componentSizeKey()], |
|
183 QString(HbParameterLengthLimiter("txt_applib_dialog_l1_kb") |
|
184 .arg(QString().setNum( |
|
185 static_cast<double>(0))))); |
|
186 QCOMPARE(detailMap[CaSoftwareRegistry::componentTypeKey()], |
|
187 QString("")); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void T_CaSoftwareRegistry::testExtractingDetailsFromJavaEntry() |
|
195 { |
|
196 static const int javaUid = 270026627; |
|
197 |
|
198 Usif::RSoftwareInstall sif; |
|
199 CleanupClosePushL( sif ); |
|
200 User::LeaveIfError( sif.Connect() ); |
|
201 |
|
202 // Install the component |
|
203 _LIT16( KMIDPTestIconsJadPath, "c:\\testing\\data\\t_casoftwareregistry\\installs\\MIDPTestIcons.jad" ); |
|
204 Usif::COpaqueNamedParams* arguments = NULL; |
|
205 Usif::COpaqueNamedParams* results = NULL; |
|
206 arguments = Usif::COpaqueNamedParams::NewLC(); |
|
207 results = Usif::COpaqueNamedParams::NewLC(); |
|
208 arguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 ); |
|
209 TRequestStatus status; |
|
210 sif.Install( KMIDPTestIconsJadPath, *arguments, *results, status, EFalse ); |
|
211 User::WaitForRequest( status ); |
|
212 User::LeaveIfError( status.Int() ); |
|
213 |
|
214 CleanupStack::PopAndDestroy( results ); |
|
215 |
|
216 int componentId(0); |
|
217 TRAPD(err, |
|
218 RSoftwareComponentRegistry scr; |
|
219 CleanupClosePushL(scr); |
|
220 User::LeaveIfError(scr.Connect()); |
|
221 componentId = scr.GetComponentIdForAppL(TUid::Uid(javaUid)); |
|
222 CleanupStack::PopAndDestroy(&scr); |
|
223 ); |
|
224 QCOMPARE(err, KErrNone); |
|
225 QVERIFY(componentId != 0); |
|
226 |
|
227 QSharedPointer<CaSoftwareRegistry> scr = CaSoftwareRegistry::create(); |
|
228 CaSoftwareRegistry::DetailMap detailMap = scr->entryDetails(componentId); |
|
229 |
|
230 QCOMPARE(detailMap[CaSoftwareRegistry::componentTypeKey()], |
|
231 QString("java")); |
|
232 QCOMPARE(detailMap[CaSoftwareRegistry::componentProtectionDomainKey()], |
|
233 QString("txt_java_inst_setlabel_cert_domain_val_untrusted_third_party,javaapplicationinstaller")); |
|
234 QCOMPARE(detailMap[CaSoftwareRegistry::componentDescriptionKey()], |
|
235 QString("Testing support for several icon formats")); |
|
236 |
|
237 TComponentId localComponentId( componentId ); |
|
238 results = Usif::COpaqueNamedParams::NewLC(); |
|
239 TRequestStatus status2; |
|
240 sif.Uninstall( localComponentId, *arguments, *results, status2 ); |
|
241 User::WaitForRequest( status2 ); |
|
242 User::LeaveIfError( status2.Int() ); |
|
243 |
|
244 CleanupStack::PopAndDestroy( results ); |
|
245 CleanupStack::PopAndDestroy( arguments ); |
|
246 // Disconnect from the SIF server |
|
247 CleanupStack::PopAndDestroy( &sif ); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void T_CaSoftwareRegistry::testUninstallDetails() |
|
255 { |
|
256 static const int javaUid = 270026627; |
|
257 |
|
258 Usif::RSoftwareInstall sif; |
|
259 CleanupClosePushL( sif ); |
|
260 User::LeaveIfError( sif.Connect() ); |
|
261 |
|
262 // Install the component |
|
263 _LIT16( KMIDPTestIconsJadPath, "c:\\testing\\data\\t_casoftwareregistry\\installs\\MIDPTestIcons.jad" ); |
|
264 Usif::COpaqueNamedParams* arguments = NULL; |
|
265 Usif::COpaqueNamedParams* results = NULL; |
|
266 arguments = Usif::COpaqueNamedParams::NewLC(); |
|
267 results = Usif::COpaqueNamedParams::NewLC(); |
|
268 arguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 ); |
|
269 TRequestStatus status; |
|
270 sif.Install( KMIDPTestIconsJadPath, *arguments, *results, status, EFalse ); |
|
271 User::WaitForRequest( status ); |
|
272 User::LeaveIfError( status.Int() ); |
|
273 |
|
274 CleanupStack::PopAndDestroy( results ); |
|
275 |
|
276 QSharedPointer<CaSoftwareRegistry> registry = CaSoftwareRegistry::create(); |
|
277 QVERIFY(registry); |
|
278 QString componentName; |
|
279 QStringList appUids; |
|
280 QString confirmationMessage; |
|
281 int componentId(0); |
|
282 TRAPD(err, |
|
283 RSoftwareComponentRegistry scr; |
|
284 CleanupClosePushL(scr); |
|
285 User::LeaveIfError(scr.Connect()); |
|
286 componentId = scr.GetComponentIdForAppL(TUid::Uid(javaUid)); |
|
287 CleanupStack::PopAndDestroy(&scr); |
|
288 ); |
|
289 QCOMPARE(err, KErrNone); |
|
290 bool success = registry->getUninstallDetails( |
|
291 componentId, componentName, appUids, confirmationMessage); |
|
292 QVERIFY(success); |
|
293 QCOMPARE(componentName, QString("MIDP Test Icon")); |
|
294 QCOMPARE(confirmationMessage, QString("This is delete confirm text....")); |
|
295 QCOMPARE(appUids.length(), 12); |
|
296 QVERIFY(appUids.contains(QString::number(javaUid))); |
|
297 |
|
298 TComponentId localComponentId( componentId ); |
|
299 results = Usif::COpaqueNamedParams::NewLC(); |
|
300 TRequestStatus status2; |
|
301 sif.Uninstall( localComponentId, *arguments, *results, status2 ); |
|
302 User::WaitForRequest( status2 ); |
|
303 User::LeaveIfError( status2.Int() ); |
|
304 |
|
305 CleanupStack::PopAndDestroy( results ); |
|
306 CleanupStack::PopAndDestroy( arguments ); |
|
307 // Disconnect from the SIF server |
|
308 CleanupStack::PopAndDestroy( &sif ); |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 void T_CaSoftwareRegistry::testGetLogEntries() |
|
316 { |
|
317 RSoftwareComponentRegistry scr; |
|
318 CleanupClosePushL(scr); |
|
319 User::LeaveIfError(scr.Connect()); |
|
320 |
|
321 RPointerArray<CScrLogEntry> logEntries; |
|
322 CleanupResetAndDestroyPushL( logEntries ); |
|
323 |
|
324 scr.RetrieveLogEntriesL(logEntries); |
|
325 |
|
326 QSharedPointer<CaSoftwareRegistry> registry |
|
327 = CaSoftwareRegistry::create(); |
|
328 QList<CaSoftwareRegistry::DetailMap> logMap |
|
329 = registry->retrieveLogEntries(); |
|
330 // 50 log items or less - ui spec |
|
331 TInt lastLog(0); |
|
332 const int maxLogsCount = 20; |
|
333 if (logEntries.Count() > maxLogsCount) { |
|
334 lastLog = logEntries.Count() - maxLogsCount; |
|
335 } |
|
336 // iteration through most recent log to the last |
|
337 for (TInt i = logEntries.Count() - 1; i >= lastLog; i--) { |
|
338 CScrLogEntry* entry = logEntries[i]; |
|
339 QString iComponentName = XQConversions::s60DescToQString( |
|
340 entry->ComponentName()); |
|
341 QString iVersion = XQConversions::s60DescToQString( |
|
342 entry->ComponentVersion()); |
|
343 |
|
344 TTime iRecordTime = entry->OperationTime(); |
|
345 TDateTime dt = iRecordTime.DateTime(); |
|
346 QDate date(dt.Year(), dt.Month()+1, dt.Day()+1); |
|
347 HbExtendedLocale hbLoc; |
|
348 QString strDateTime = hbLoc.format(date, r_qtn_date_usual_with_zero); |
|
349 |
|
350 TScrComponentOperationType iOpType = entry->OperationType(); |
|
351 QString opType; |
|
352 switch (iOpType) { |
|
353 case EScrCompInstall: |
|
354 opType = CaSoftwareRegistry::componentInstallValue(); |
|
355 break; |
|
356 case EScrCompUnInstall: |
|
357 opType = CaSoftwareRegistry::componentUninstallValue(); |
|
358 break; |
|
359 case EScrCompUpgrade: |
|
360 opType = CaSoftwareRegistry::componentUpgradeValue(); |
|
361 break; |
|
362 case EScrCompHidden: |
|
363 opType = CaSoftwareRegistry::componentHiddenValue(); |
|
364 break; |
|
365 } |
|
366 |
|
367 QCOMPARE(iComponentName, |
|
368 logMap[(logEntries.Count() - 1) - i].value(CaSoftwareRegistry::componentNameKey())); |
|
369 QCOMPARE(iVersion, |
|
370 logMap[(logEntries.Count() - 1) - i].value(CaSoftwareRegistry::componentVersionKey())); |
|
371 QCOMPARE(strDateTime, |
|
372 logMap[(logEntries.Count() - 1) - i].value(CaSoftwareRegistry::componentTimeKey())); |
|
373 QCOMPARE(opType, |
|
374 logMap[(logEntries.Count() - 1) - i].value( |
|
375 CaSoftwareRegistry::componentOperationTypeKey())); |
|
376 } |
|
377 CleanupStack::PopAndDestroy( &logEntries ); |
|
378 CleanupStack::PopAndDestroy(&scr); |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void T_CaSoftwareRegistry::testApplicationsUids() |
|
386 { |
|
387 static const int javaUid = 270026627; |
|
388 |
|
389 Usif::RSoftwareInstall sif; |
|
390 CleanupClosePushL( sif ); |
|
391 User::LeaveIfError( sif.Connect() ); |
|
392 |
|
393 // Install the component |
|
394 _LIT16( KMIDPTestIconsJadPath, "c:\\testing\\data\\t_casoftwareregistry\\installs\\MIDPTestIcons.jad" ); |
|
395 Usif::COpaqueNamedParams* arguments = NULL; |
|
396 Usif::COpaqueNamedParams* results = NULL; |
|
397 arguments = Usif::COpaqueNamedParams::NewLC(); |
|
398 results = Usif::COpaqueNamedParams::NewLC(); |
|
399 arguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 ); |
|
400 TRequestStatus status; |
|
401 sif.Install( KMIDPTestIconsJadPath, *arguments, *results, status, EFalse ); |
|
402 User::WaitForRequest( status ); |
|
403 User::LeaveIfError( status.Int() ); |
|
404 |
|
405 CleanupStack::PopAndDestroy( results ); |
|
406 |
|
407 |
|
408 QSharedPointer<CaSoftwareRegistry> registry = CaSoftwareRegistry::create(); |
|
409 QVERIFY(registry); |
|
410 QStringList appUids; |
|
411 int componentId(0); |
|
412 TRAPD(err, |
|
413 RSoftwareComponentRegistry scr; |
|
414 CleanupClosePushL(scr); |
|
415 User::LeaveIfError(scr.Connect()); |
|
416 componentId = scr.GetComponentIdForAppL(TUid::Uid(javaUid)); |
|
417 CleanupStack::PopAndDestroy(&scr); |
|
418 ); |
|
419 QCOMPARE(err, KErrNone); |
|
420 bool success = registry->getApplicationsUids(componentId, appUids); |
|
421 QVERIFY(success); |
|
422 QCOMPARE(appUids.length(), 12); |
|
423 QVERIFY(appUids.contains(QString::number(javaUid))); |
|
424 |
|
425 TComponentId localComponentId( componentId ); |
|
426 results = Usif::COpaqueNamedParams::NewLC(); |
|
427 TRequestStatus status2; |
|
428 sif.Uninstall( localComponentId, *arguments, *results, status2 ); |
|
429 User::WaitForRequest( status2 ); |
|
430 User::LeaveIfError( status2.Int() ); |
|
431 |
|
432 CleanupStack::PopAndDestroy( results ); |
|
433 CleanupStack::PopAndDestroy( arguments ); |
|
434 // Disconnect from the SIF server |
|
435 CleanupStack::PopAndDestroy( &sif ); |
|
436 } |
|
437 |
|
438 #endif // Q_OS_SYMBIAN |
|
439 |
|
440 void T_CaSoftwareRegistry::testEntryDetails() |
|
441 { |
|
442 const int componentId = 0; // not reffering to any application |
|
443 QSharedPointer<CaSoftwareRegistry> scr = CaSoftwareRegistry::create(); |
|
444 CaSoftwareRegistry::DetailMap detailMap = scr->entryDetails(componentId); |
|
445 |
|
446 QCOMPARE(detailMap, CaSoftwareRegistry::DetailMap()); |
|
447 } |
|
448 |
|
449 void T_CaSoftwareRegistry::testUninstallDetailsBadComponentId() |
|
450 { |
|
451 QSharedPointer<CaSoftwareRegistry> registry = CaSoftwareRegistry::create(); |
|
452 QVERIFY(registry); |
|
453 QString componentName; |
|
454 QStringList appUids; |
|
455 QString confirmationMessage; |
|
456 registry->getUninstallDetails(0, componentName, appUids, confirmationMessage); |
|
457 QCOMPARE(componentName, QString()); |
|
458 QCOMPARE(confirmationMessage, QString()); |
|
459 QCOMPARE(appUids.length(), 0); |
|
460 } |
|
461 |
|
462 void T_CaSoftwareRegistry::testCreateUninstallNotifier() |
|
463 { |
|
464 CaUninstallNotifier* notifier = CaSoftwareRegistry::create()->createUninstallNotifier(); |
|
465 QVERIFY(notifier); |
|
466 } |
|
467 QTEST_MAIN(T_CaSoftwareRegistry) |
|
468 |