--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/casoftwareregistry/tsrc/t_casoftwareregistry/src/t_casoftwareregistry.cpp Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,468 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+#include <HbParameterLengthLimiter>
+#include <HbExtendedLocale>
+#include "casoftwareregistry.h"
+#include "casoftwareregistry_p.h"
+
+#include "t_casoftwareregistry.h"
+
+#ifdef Q_OS_SYMBIAN
+#include <e32base.h>
+#include <e32def.h>
+#undef SYMBIAN_ENABLE_SPLIT_HEADERS
+#include <usif/scr/scr.h>
+#include <usif/scr/screntries.h>
+
+#include <usif/sif/sif.h>
+#include <usif/scr/scr.h>
+
+#include <xqconversions.h>
+using namespace Usif;
+#include <caarraycleanup.inl>
+#endif
+
+T_CaSoftwareRegistry::T_CaSoftwareRegistry():
+ mSoftwareRegistry(NULL)
+{
+}
+
+void T_CaSoftwareRegistry::cleanup()
+{
+
+}
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void T_CaSoftwareRegistry::initTestCase()
+{
+
+}
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void T_CaSoftwareRegistry::testSoftwareRegistryCreate()
+{
+
+ QVERIFY(CaSoftwareRegistry::create());
+ QSharedPointer<CaSoftwareRegistry> scr = CaSoftwareRegistry::create();
+ QVERIFY(CaSoftwareRegistry::create().data() == scr.data());
+}
+
+#ifdef Q_OS_SYMBIAN
+
+void T_CaSoftwareRegistry::testExtractingDetailsFromEntry()
+{
+ // set up expexted values..
+ _LIT(KName, "appname");
+ _LIT(KVendor, "xxx");
+
+ TDriveList installedDrives;
+
+ QString expectedDrives;
+
+ const TInt driveListLen(installedDrives.Length());
+ for (TInt i( 0 ); i < driveListLen; ++i) {
+ if (i == 3 || i == 4) {
+ installedDrives[i] = '\1';
+ expectedDrives = expectedDrives.append(QChar('A'+ i)).append(":");
+ } else {
+ installedDrives[i] = '\0';
+ }
+ }
+
+ _LIT(KVersion, "ver 1.1");
+ _LIT(KSwType, "software type");
+ const TInt64 KSize = 2048; // i.e 2k
+
+ // definition below are provided just to satisfy CComponentEntry::NewL
+ _LIT(KGlobalId, "");
+ TBool KRemovable(EFalse);
+ TScomoState KScomoState;
+ TComponentId KId;
+ _LIT(KInstallTime, "");
+ TBool KDrmProtected(EFalse);
+ TBool KHidden(EFalse);
+ TBool KKnownRevoked(EFalse);
+ TBool KOriginVerified(EFalse);
+
+
+ QScopedPointer<CComponentEntry> entry;
+
+ QT_TRAP_THROWING(entry.reset(
+ CComponentEntry::NewL(
+ KId,
+ KName,
+ KVendor,
+ KSwType,
+ KGlobalId,
+ KRemovable,
+ KSize,
+ KScomoState,
+ installedDrives,
+ KVersion,
+ KInstallTime,
+ KDrmProtected,
+ KHidden,
+ KKnownRevoked,
+ KOriginVerified)
+ )
+ );
+
+ CaSoftwareRegistryPrivate scr(NULL);
+ CaSoftwareRegistry::DetailMap detailMap = scr.entryDetailsL(*entry);
+
+ QCOMPARE(detailMap.size(), 6);
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentNameKey()],
+ XQConversions::s60DescToQString(KName));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentVersionKey()],
+ XQConversions::s60DescToQString(KVersion));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentVendorKey()],
+ XQConversions::s60DescToQString(KVendor));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentDriveInfoKey()],
+ expectedDrives);
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentSizeKey()],
+ QString(HbParameterLengthLimiter("txt_applib_dialog_l1_kb")
+ .arg(QString().setNum(static_cast<double>(KSize / 1024)))));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentTypeKey()],
+ XQConversions::s60DescToQString(KSwType));
+
+ for (TInt i( 0 ); i < driveListLen; ++i) {
+ installedDrives[i]= '\0';
+ }
+
+ QT_TRAP_THROWING(entry.reset(
+ CComponentEntry::NewL(
+ KId,
+ _L(""), // name
+ _L(""), // vendor
+ _L(""), // sw type
+ KGlobalId,
+ KRemovable,
+ 0, // size
+ KScomoState,
+ installedDrives,
+ _L(""), // version
+ KInstallTime,
+ KDrmProtected,
+ KHidden,
+ KKnownRevoked,
+ KOriginVerified)
+ )
+ );
+
+ detailMap = scr.entryDetailsL(*entry);
+
+ QCOMPARE(detailMap.size(), 6);
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentNameKey()],
+ QString(""));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentVersionKey()],
+ QString(""));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentVendorKey()],
+ QString(""));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentDriveInfoKey()],
+ QString(""));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentSizeKey()],
+ QString(HbParameterLengthLimiter("txt_applib_dialog_l1_kb")
+ .arg(QString().setNum(
+ static_cast<double>(0)))));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentTypeKey()],
+ QString(""));
+}
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void T_CaSoftwareRegistry::testExtractingDetailsFromJavaEntry()
+{
+ static const int javaUid = 270026627;
+
+ Usif::RSoftwareInstall sif;
+ CleanupClosePushL( sif );
+ User::LeaveIfError( sif.Connect() );
+
+ // Install the component
+ _LIT16( KMIDPTestIconsJadPath, "c:\\testing\\data\\t_casoftwareregistry\\installs\\MIDPTestIcons.jad" );
+ Usif::COpaqueNamedParams* arguments = NULL;
+ Usif::COpaqueNamedParams* results = NULL;
+ arguments = Usif::COpaqueNamedParams::NewLC();
+ results = Usif::COpaqueNamedParams::NewLC();
+ arguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 );
+ TRequestStatus status;
+ sif.Install( KMIDPTestIconsJadPath, *arguments, *results, status, EFalse );
+ User::WaitForRequest( status );
+ User::LeaveIfError( status.Int() );
+
+ CleanupStack::PopAndDestroy( results );
+
+ int componentId(0);
+ TRAPD(err,
+ RSoftwareComponentRegistry scr;
+ CleanupClosePushL(scr);
+ User::LeaveIfError(scr.Connect());
+ componentId = scr.GetComponentIdForAppL(TUid::Uid(javaUid));
+ CleanupStack::PopAndDestroy(&scr);
+ );
+ QCOMPARE(err, KErrNone);
+ QVERIFY(componentId != 0);
+
+ QSharedPointer<CaSoftwareRegistry> scr = CaSoftwareRegistry::create();
+ CaSoftwareRegistry::DetailMap detailMap = scr->entryDetails(componentId);
+
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentTypeKey()],
+ QString("java"));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentProtectionDomainKey()],
+ QString("txt_java_inst_setlabel_cert_domain_val_untrusted_third_party,javaapplicationinstaller"));
+ QCOMPARE(detailMap[CaSoftwareRegistry::componentDescriptionKey()],
+ QString("Testing support for several icon formats"));
+
+ TComponentId localComponentId( componentId );
+ results = Usif::COpaqueNamedParams::NewLC();
+ TRequestStatus status2;
+ sif.Uninstall( localComponentId, *arguments, *results, status2 );
+ User::WaitForRequest( status2 );
+ User::LeaveIfError( status2.Int() );
+
+ CleanupStack::PopAndDestroy( results );
+ CleanupStack::PopAndDestroy( arguments );
+ // Disconnect from the SIF server
+ CleanupStack::PopAndDestroy( &sif );
+}
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void T_CaSoftwareRegistry::testUninstallDetails()
+{
+ static const int javaUid = 270026627;
+
+ Usif::RSoftwareInstall sif;
+ CleanupClosePushL( sif );
+ User::LeaveIfError( sif.Connect() );
+
+ // Install the component
+ _LIT16( KMIDPTestIconsJadPath, "c:\\testing\\data\\t_casoftwareregistry\\installs\\MIDPTestIcons.jad" );
+ Usif::COpaqueNamedParams* arguments = NULL;
+ Usif::COpaqueNamedParams* results = NULL;
+ arguments = Usif::COpaqueNamedParams::NewLC();
+ results = Usif::COpaqueNamedParams::NewLC();
+ arguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 );
+ TRequestStatus status;
+ sif.Install( KMIDPTestIconsJadPath, *arguments, *results, status, EFalse );
+ User::WaitForRequest( status );
+ User::LeaveIfError( status.Int() );
+
+ CleanupStack::PopAndDestroy( results );
+
+ QSharedPointer<CaSoftwareRegistry> registry = CaSoftwareRegistry::create();
+ QVERIFY(registry);
+ QString componentName;
+ QStringList appUids;
+ QString confirmationMessage;
+ int componentId(0);
+ TRAPD(err,
+ RSoftwareComponentRegistry scr;
+ CleanupClosePushL(scr);
+ User::LeaveIfError(scr.Connect());
+ componentId = scr.GetComponentIdForAppL(TUid::Uid(javaUid));
+ CleanupStack::PopAndDestroy(&scr);
+ );
+ QCOMPARE(err, KErrNone);
+ bool success = registry->getUninstallDetails(
+ componentId, componentName, appUids, confirmationMessage);
+ QVERIFY(success);
+ QCOMPARE(componentName, QString("MIDP Test Icon"));
+ QCOMPARE(confirmationMessage, QString("This is delete confirm text...."));
+ QCOMPARE(appUids.length(), 12);
+ QVERIFY(appUids.contains(QString::number(javaUid)));
+
+ TComponentId localComponentId( componentId );
+ results = Usif::COpaqueNamedParams::NewLC();
+ TRequestStatus status2;
+ sif.Uninstall( localComponentId, *arguments, *results, status2 );
+ User::WaitForRequest( status2 );
+ User::LeaveIfError( status2.Int() );
+
+ CleanupStack::PopAndDestroy( results );
+ CleanupStack::PopAndDestroy( arguments );
+ // Disconnect from the SIF server
+ CleanupStack::PopAndDestroy( &sif );
+}
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void T_CaSoftwareRegistry::testGetLogEntries()
+{
+ RSoftwareComponentRegistry scr;
+ CleanupClosePushL(scr);
+ User::LeaveIfError(scr.Connect());
+
+ RPointerArray<CScrLogEntry> logEntries;
+ CleanupResetAndDestroyPushL( logEntries );
+
+ scr.RetrieveLogEntriesL(logEntries);
+
+ QSharedPointer<CaSoftwareRegistry> registry
+ = CaSoftwareRegistry::create();
+ QList<CaSoftwareRegistry::DetailMap> logMap
+ = registry->retrieveLogEntries();
+ // 50 log items or less - ui spec
+ TInt lastLog(0);
+ const int maxLogsCount = 20;
+ if (logEntries.Count() > maxLogsCount) {
+ lastLog = logEntries.Count() - maxLogsCount;
+ }
+ // iteration through most recent log to the last
+ for (TInt i = logEntries.Count() - 1; i >= lastLog; i--) {
+ CScrLogEntry* entry = logEntries[i];
+ QString iComponentName = XQConversions::s60DescToQString(
+ entry->ComponentName());
+ QString iVersion = XQConversions::s60DescToQString(
+ entry->ComponentVersion());
+
+ TTime iRecordTime = entry->OperationTime();
+ TDateTime dt = iRecordTime.DateTime();
+ QDate date(dt.Year(), dt.Month()+1, dt.Day()+1);
+ HbExtendedLocale hbLoc;
+ QString strDateTime = hbLoc.format(date, r_qtn_date_usual_with_zero);
+
+ TScrComponentOperationType iOpType = entry->OperationType();
+ QString opType;
+ switch (iOpType) {
+ case EScrCompInstall:
+ opType = CaSoftwareRegistry::componentInstallValue();
+ break;
+ case EScrCompUnInstall:
+ opType = CaSoftwareRegistry::componentUninstallValue();
+ break;
+ case EScrCompUpgrade:
+ opType = CaSoftwareRegistry::componentUpgradeValue();
+ break;
+ case EScrCompHidden:
+ opType = CaSoftwareRegistry::componentHiddenValue();
+ break;
+ }
+
+ QCOMPARE(iComponentName,
+ logMap[(logEntries.Count() - 1) - i].value(CaSoftwareRegistry::componentNameKey()));
+ QCOMPARE(iVersion,
+ logMap[(logEntries.Count() - 1) - i].value(CaSoftwareRegistry::componentVersionKey()));
+ QCOMPARE(strDateTime,
+ logMap[(logEntries.Count() - 1) - i].value(CaSoftwareRegistry::componentTimeKey()));
+ QCOMPARE(opType,
+ logMap[(logEntries.Count() - 1) - i].value(
+ CaSoftwareRegistry::componentOperationTypeKey()));
+ }
+ CleanupStack::PopAndDestroy( &logEntries );
+ CleanupStack::PopAndDestroy(&scr);
+}
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void T_CaSoftwareRegistry::testApplicationsUids()
+{
+ static const int javaUid = 270026627;
+
+ Usif::RSoftwareInstall sif;
+ CleanupClosePushL( sif );
+ User::LeaveIfError( sif.Connect() );
+
+ // Install the component
+ _LIT16( KMIDPTestIconsJadPath, "c:\\testing\\data\\t_casoftwareregistry\\installs\\MIDPTestIcons.jad" );
+ Usif::COpaqueNamedParams* arguments = NULL;
+ Usif::COpaqueNamedParams* results = NULL;
+ arguments = Usif::COpaqueNamedParams::NewLC();
+ results = Usif::COpaqueNamedParams::NewLC();
+ arguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 );
+ TRequestStatus status;
+ sif.Install( KMIDPTestIconsJadPath, *arguments, *results, status, EFalse );
+ User::WaitForRequest( status );
+ User::LeaveIfError( status.Int() );
+
+ CleanupStack::PopAndDestroy( results );
+
+
+ QSharedPointer<CaSoftwareRegistry> registry = CaSoftwareRegistry::create();
+ QVERIFY(registry);
+ QStringList appUids;
+ int componentId(0);
+ TRAPD(err,
+ RSoftwareComponentRegistry scr;
+ CleanupClosePushL(scr);
+ User::LeaveIfError(scr.Connect());
+ componentId = scr.GetComponentIdForAppL(TUid::Uid(javaUid));
+ CleanupStack::PopAndDestroy(&scr);
+ );
+ QCOMPARE(err, KErrNone);
+ bool success = registry->getApplicationsUids(componentId, appUids);
+ QVERIFY(success);
+ QCOMPARE(appUids.length(), 12);
+ QVERIFY(appUids.contains(QString::number(javaUid)));
+
+ TComponentId localComponentId( componentId );
+ results = Usif::COpaqueNamedParams::NewLC();
+ TRequestStatus status2;
+ sif.Uninstall( localComponentId, *arguments, *results, status2 );
+ User::WaitForRequest( status2 );
+ User::LeaveIfError( status2.Int() );
+
+ CleanupStack::PopAndDestroy( results );
+ CleanupStack::PopAndDestroy( arguments );
+ // Disconnect from the SIF server
+ CleanupStack::PopAndDestroy( &sif );
+}
+
+#endif // Q_OS_SYMBIAN
+
+void T_CaSoftwareRegistry::testEntryDetails()
+{
+ const int componentId = 0; // not reffering to any application
+ QSharedPointer<CaSoftwareRegistry> scr = CaSoftwareRegistry::create();
+ CaSoftwareRegistry::DetailMap detailMap = scr->entryDetails(componentId);
+
+ QCOMPARE(detailMap, CaSoftwareRegistry::DetailMap());
+}
+
+void T_CaSoftwareRegistry::testUninstallDetailsBadComponentId()
+{
+ QSharedPointer<CaSoftwareRegistry> registry = CaSoftwareRegistry::create();
+ QVERIFY(registry);
+ QString componentName;
+ QStringList appUids;
+ QString confirmationMessage;
+ registry->getUninstallDetails(0, componentName, appUids, confirmationMessage);
+ QCOMPARE(componentName, QString());
+ QCOMPARE(confirmationMessage, QString());
+ QCOMPARE(appUids.length(), 0);
+}
+
+void T_CaSoftwareRegistry::testCreateUninstallNotifier()
+ {
+ CaUninstallNotifier* notifier = CaSoftwareRegistry::create()->createUninstallNotifier();
+ QVERIFY(notifier);
+ }
+QTEST_MAIN(T_CaSoftwareRegistry)
+