/*
* Copyright (c) 2004 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 <e32cmn.h>
#include <w32std.h>
#include <apgtask.h>
#include <usif/sif/sifcommon.h>
#include <usif/sif/sif.h>
#include <QScopedPointer>
// CLASS HEADER
#include "T_casrvAppScaner.h"
// EXTERNAL INCLUDES
#include <cadef.h>
#include "castoragefactory.h"
#include "castorageproxy.h"
#include "casrvengutils.h"
#include "casrvappscanner.h"
#include "caappscannerhandler.h"
#include "cainnerentry.h"
#include "cainnerquery.h"
#include "caarraycleanup.inl"
#include "casrvmmchistory.h"
#include "t_cainstaller.h"
// INTERNAL INCLUDES
#include "casrvtestutils.h"
#include "testconsts.h"
#ifdef COVERAGE_MEASUREMENT
const double TIMEOUT_FACTOR = 1.2;
#else
const double TIMEOUT_FACTOR = 1.0;
#endif
template <typename RClass>
struct RClassDeleter
{
static inline void cleanup(RClass *ptr)
{
ptr->Close();
}
};
typedef RClassDeleter< RPointerArray<CCaInnerEntry> > RInnerEntryArrayDeleter;
typedef QScopedPointer< RPointerArray<CCaInnerEntry>, RInnerEntryArrayDeleter >
InnerEntryRArrayPointer;
typedef RClassDeleter< RBuf > RBufDeleter;
typedef QScopedPointer< RBuf, RBufDeleter >
RBufPointer;
using namespace Usif;
const TUid KAppScannerHandlerPluginUid = {0x20026FAF};
void T_casrvAppScaner::initTestCase()
{
if (iTestUtils == NULL) {
TRAPD(err, iTestUtils = CTestUtils::NewL());
QCOMPARE(err, KErrNone);
}
QT_TRAP_THROWING(iInstaller = T_CaInstaller::NewL());
iTestUtils->CopyMmcHistory();
delete iTestUtils;
iTestUtils = NULL;
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::init()
{
TRAPD(err,
iTestUtils = CTestUtils::NewL();
iTestUtils->CopyDb();
iStorage = CCaStorageProxy::NewL();
iSrvEngUtils = CCaSrvEngUtils::NewL();
iScr = new Usif::RSoftwareComponentRegistry;
User::LeaveIfError(iScr->Connect());
);
QCOMPARE(err, KErrNone);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::cleanup()
{
delete iSrvEngUtils;
iSrvEngUtils = NULL;
delete iStorage;
iStorage = NULL;
delete iTestUtils;
iTestUtils = NULL;
iScr->Close();
delete iScr;
iScr = NULL;
}
void T_casrvAppScaner::cleanupTestCase()
{
Usif::TComponentId wrtComponentId(0);
TRAP_IGNORE(wrtComponentId =
iInstaller->GetComponentIdForAppIdL(KWRTAppId));
TRAP_IGNORE(iInstaller->UninstallL(wrtComponentId));
Usif::TComponentId wrtMiniViewComponentId(0);
TRAP_IGNORE(wrtMiniViewComponentId =
iInstaller->GetComponentIdForAppIdL(KWRTMiniViewAppId));
TRAP_IGNORE(iInstaller->UninstallL(wrtMiniViewComponentId));
REComSession::FinalClose();
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_UninstalledL()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(notInstalledUid);
innerEntry->SetFlags(EVisible);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
T_casrvAppScaner::T_casrvAppScaner():
iTestUtils(NULL),
iStorage(NULL),
iSrvEngUtils(NULL),
iScr(NULL)
{
}
void T_casrvAppScaner::testHandler_LoadPlugin()
{
TPluginParams params;
params.engUtils = iSrvEngUtils;
params.storageProxy = iStorage;
params.softwareRegistry = iScr;
bool result(false);
TRAPD(err,
CCaSrvPlugin *plug = iTestUtils->LoadPluginL(KAppScannerHandlerPluginUid, params);
result = plug != NULL;
delete plug;
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testHandler_New()
{
TPluginParams params;
params.engUtils = iSrvEngUtils;
params.storageProxy = iStorage;
params.softwareRegistry = iScr;
bool result(false);
TRAPD(err,
CCaAppScannerHandler *appScanerHandler = CCaAppScannerHandler::NewL(¶ms);
result = appScanerHandler != NULL;
delete appScanerHandler;
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testNew()
{
bool result(false);
TRAPD(err,
Usif::RSoftwareComponentRegistry scr;
User::LeaveIfError(scr.Connect());
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr,*iSrvEngUtils);
result = appScanner != NULL;
scr.Close();
delete appScanner;
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testUninstalled()
{
bool exists(false);
bool is_missing(false);
TRAPD(err,
Setup_UninstalledL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//visible flag update
exists = iTestUtils->AppExistsInStorageL(notInstalledUid,
iStorage) == TRUE;
is_missing = (iTestUtils->GetAppFlagsL(notInstalledUid, iStorage)
& EMissing) == TRUE;
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(exists);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testInstalled()
{
bool result(false);
TRAPD(err,
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//visible flag update
result = ((iTestUtils->GetAppFlagsL(systemApp, iStorage)
& EVisible) != FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testAddNewApp()
{
bool result(false);
TRAPD(err,
Setup_AddNewAppL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
// new app added
result = ((iTestUtils->GetAppFlagsL(systemApp,iStorage)
& EVisible) != FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testNoUpdate()
{
bool result(false);
TRAPD(err,
Setup_NoUpdateL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//no flag update
result = ((iTestUtils->GetAppFlagsL(systemApp, iStorage)
& EVisible) != FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testRemoveMmcApp()
{
bool exist(false);
TInt flags(0);
TRAPD(err,
Setup_RemoveMmcAppL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//remove mmc attr
exist = iTestUtils->AppExistsInStorageL(notInstalledUid, iStorage);
flags = iTestUtils->GetAppFlagsL(notInstalledUid, iStorage);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
TBool visible(ETrue);
visible = flags & EVisible;
QVERIFY(!visible);
QVERIFY(exist);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testRemoveMmcAttr()
{
bool entryExists(false);
bool noMmcAttr(false);
TRAPD(err,
Setup_RemoveMmcAttrL();
iInstaller->InstallL(KSapiPackageFileName);
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//remove mmc attr
CCaInnerEntry *entry = iTestUtils->GetAppEntryL(installedUid, iStorage);
entryExists = entry != NULL;
CleanupStack::PushL(entry);
RBuf value;
value.CleanupClosePushL();
value.CreateL(KCaMassStorage);
if (entryExists) {
noMmcAttr = (entry->FindAttribute(KCaAttrMmcId, value) == FALSE);
}
CleanupStack::PopAndDestroy(&value);
CleanupStack::PopAndDestroy(entry);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(entryExists);
QVERIFY(noMmcAttr);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testSetCWRTAppL()
{
RSoftwareInstall sif;
CleanupClosePushL( sif );
User::LeaveIfError( sif.Connect() );
// Install the component
_LIT16( KSmokeTestUnsigned, "c:\\testing\\data\\t_caappscanner\\installs\\SmokeTestUnsigned.wgt" );
COpaqueNamedParams* arguments;
COpaqueNamedParams* results;
arguments = COpaqueNamedParams::NewLC();
results = COpaqueNamedParams::NewLC();
arguments->AddIntL( KSifInParam_InstallSilently, 1 );
TRequestStatus status;
sif.Install( KSmokeTestUnsigned, *arguments, *results, status, EFalse );
User::WaitForRequest( status );
User::LeaveIfError( status.Int() );
CleanupStack::PopAndDestroy( results );
// Install the component
_LIT16( KAccuWeather, "c:\\testing\\data\\t_caappscanner\\installs\\AccuWeather_W3C.wgt" );
results = COpaqueNamedParams::NewLC();
TRequestStatus status2;
sif.Install( KAccuWeather, *arguments, *results, status2, EFalse );
User::WaitForRequest( status2 );
User::LeaveIfError( status2.Int() );
CleanupStack::PopAndDestroy( results );
CleanupStack::PopAndDestroy( arguments );
// Disconnect from the SIF server
CleanupStack::PopAndDestroy( &sif );
QScopedPointer<CCaSrvAppScanner> appScanner;
QT_TRAP_THROWING(appScanner.reset(CCaSrvAppScanner::NewL(
*iStorage, *iScr, *iSrvEngUtils)));
QVERIFY(!appScanner.isNull());
QTest::qWait(7000 * TIMEOUT_FACTOR);
//remove mmc attr
QScopedPointer<CCaInnerEntry> entry;
TInt wrtUid(0);
TRAP_IGNORE( wrtUid = iTestUtils->FindAppUidL(KWrtAppName, iStorage));
TRAPD(err, entry.reset(iTestUtils->GetAppEntryL(wrtUid, iStorage)));
QCOMPARE(err, KErrNone);
QVERIFY(!entry.isNull());
QCOMPARE(err, KErrNone);
QTest::qWait(7000 * TIMEOUT_FACTOR);
TInt wrtMiniViewUid(0);
TRAP_IGNORE( wrtMiniViewUid =
iTestUtils->FindAppUidL( KWrtMiniViewAppName, iStorage ));
TRAP(err, entry.reset(iTestUtils->GetAppEntryL(wrtMiniViewUid, iStorage)));
QCOMPARE(err, KErrNone);
QVERIFY(!entry.isNull());
bool exists(false);
bool match(false);
TRAP(err,
RBuf value;
value.CleanupClosePushL();
value.CreateL(KCaMaxAttrLenght);
exists = (entry->FindAttribute(KCaAttrAppWidgetUri, value) != 0);
match = (value == KCaAttrAppWidgetUriCWRTValue);
CleanupStack::PopAndDestroy(&value);
);
QCOMPARE(err, KErrNone);
QVERIFY(exists);
QVERIFY(match);
exists = false;
TRAP(err,
RBuf value;
value.CleanupClosePushL();
value.CreateL(KCaMaxAttrLenght);
exists = (entry->FindAttribute(KCaAttrAppWidgetParamWebAppId, value) != 0);
CleanupStack::PopAndDestroy(&value);
);
QCOMPARE(err, KErrNone);
QVERIFY(exists);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testRemoveMissingFlag()
{
bool result(false);
TRAPD(err,
Setup_RemoveMissingFlagL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//remove missing flag
result = (iTestUtils->AppExistsInStorageL(notInstalledUid,
iStorage) != FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testRemoveMissingFlag01()
{
bool exists(false);
bool noMissingFlag(false);
TRAPD(err,
Setup_RemoveMissingFlag01L();
iInstaller->InstallL(KSapiPackageFileName);
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//remove missing flag
exists = ((iTestUtils->GetAppFlagsL(
installedUid, iStorage) & EVisible) != FALSE);
noMissingFlag =((iTestUtils->GetAppFlagsL(
installedUid, iStorage) & EMissing) == FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(exists);
QVERIFY(noMissingFlag);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testAddMissingFlag()
{
bool result(false);
TRAPD(err,
Setup_AddMissingFlagL();
QTest::qWait(1000);
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//Add missing flag
result = (iTestUtils->GetAppFlagsL(notInstalledUid, iStorage)
& EMissing) != FALSE;
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testSatApp()
{
bool visibleFlag(false);
bool missingFlag(false);
TRAPD(err,
Setup_SatAppL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//sat app should not be updated by app scanner
visibleFlag = ((iTestUtils->GetAppFlagsL(
KSatUid.iUid, iStorage) & EVisible) != FALSE);
missingFlag = ((iTestUtils->GetAppFlagsL(
KSatUid.iUid, iStorage) & EMissing) != FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(visibleFlag);
QVERIFY(missingFlag);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testHsApp()
{
bool visibleFlag;
TRAPD(err,
Setup_HsAppL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//HS app should not be updated by app scanner
visibleFlag = ((iTestUtils->GetAppFlagsL(
KHsAppUid.iUid, iStorage) & EVisible) != FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(!visibleFlag);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testAddRemovable()
{
bool result(false);
TRAPD(err,
Setup_AddRemovableL();
iInstaller->InstallL(KSapiPackageFileName);
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
//add removable flag to not visible app
result = ((iTestUtils->GetAppFlagsL(
installedUid, iStorage) & ERemovable) != FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testRemoveRemovable()
{
bool result(false);
TRAPD(err,
Setup_RemoveRemovableL();
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000);
//remove removable flag to not visible app
result = ((iTestUtils->GetAppFlagsL(systemApp, iStorage)
& ERemovable) == FALSE);
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testRunError()
{
bool result(false);
TRAPD(err,
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
result = (!appScanner->RunError(1));
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testInstallNotifier()
{
bool existsBeforeUninstall(false);
bool existsAfterUninstall(false);
QScopedPointer<CCaSrvAppScanner> appScanner;
QT_TRAP_THROWING(appScanner.reset(CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils)))
//test
TInt err(KErrNone);
TRAP(err, iInstaller->InstallL(KSapiPackageFileName))
QCOMPARE(err, KErrNone);
QTest::qWait(7000 * TIMEOUT_FACTOR);
TComponentId componentId(0);
TRAP(err, componentId = iInstaller->GetComponentIdL(installedUid));
QCOMPARE(err, KErrNone);
TRAP(err, existsBeforeUninstall = (iTestUtils->ComponentExistsInStorageL(
componentId, iStorage) != FALSE));
QCOMPARE(err, KErrNone);
TRAP(err, iInstaller->UninstallL(componentId))
QCOMPARE(err, KErrNone);
QTest::qWait(7000 * TIMEOUT_FACTOR);
TRAP(err, existsAfterUninstall = (iTestUtils->ComponentExistsInStorageL(
componentId, iStorage) != FALSE))
QCOMPARE(err, KErrNone);
QVERIFY(existsBeforeUninstall);
QVERIFY(existsAfterUninstall);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testDownloadCollectionAdd()
{
cleanup();
init();
TInt countAfterInstall(0);
TInt countBeforeInstall(0);
bool existsAfterInstall(false);
QScopedPointer<CCaSrvAppScanner> appScanner;
QT_TRAP_THROWING(appScanner.reset(CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils)))
// ensure the application is not installed
TComponentId unComponentId;
TRAP_IGNORE(unComponentId = iInstaller->GetComponentIdL(installedUid))
if( unComponentId > 0 )
{
TRAP_IGNORE(iInstaller->UninstallL(unComponentId));
}
RPointerArray<CCaInnerEntry> array;
InnerEntryRArrayPointer resultArray(&array);
QScopedPointer<CDesC16ArrayFlat> appType;
QT_TRAP_THROWING(appType.reset(new(ELeave) CDesC16ArrayFlat(1)));
TRAPD(error, appType->AppendL(KCaTypeApp));
QCOMPARE(error, KErrNone);
QScopedPointer<CCaInnerQuery> query;
TRAP(error, query.reset(CCaInnerQuery::NewL()));
QCOMPARE(error, KErrNone);
query->SetEntryTypeNames(appType.take());
QTest::qWait(20000 * TIMEOUT_FACTOR);
TInt dcID(0);
TRAP(error, dcID = appScanner->GetCollectionDownloadIdL());
QCOMPARE(error, KErrNone);
query->SetParentId(dcID);
query->SetFlagsOn(EVisible);
query->SetFlagsOff(EMissing);
TRAP(error, iStorage->GetEntriesL(query.data(), *resultArray));
QCOMPARE(error, KErrNone);
countBeforeInstall = resultArray->Count();
TRAP(error, iInstaller->InstallL(KSapiPackageFileName));
QCOMPARE(error, KErrNone);
QTest::qWait(20000 * TIMEOUT_FACTOR);
TComponentId componentId(0);
TRAP(error, componentId = iInstaller->GetComponentIdL(installedUid));
QCOMPARE(error, KErrNone);
TRAP(error, iStorage->GetEntriesL(query.data(), *resultArray));
QCOMPARE(error, KErrNone);
countAfterInstall = resultArray->Count();
existsAfterInstall = (iTestUtils->ComponentExistsInStorageL(
componentId, iStorage));
TRAP(error, iInstaller->UninstallL(componentId));
QCOMPARE(error, KErrNone);
QVERIFY(countAfterInstall == countBeforeInstall + 1);
QVERIFY(existsAfterInstall);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testDownloadCollectionUpdate()
{
TInt countAfterInstall(0);
TInt countBeforeInstall(0);
bool existsAfterInstall(false);
TComponentId unComponentId;
TRAP_IGNORE(unComponentId = iInstaller->GetComponentIdL(installedUid))
if( unComponentId > 0 )
{
TRAP_IGNORE(iInstaller->UninstallL(unComponentId));
}
QScopedPointer<CCaSrvAppScanner> appScanner;
QT_TRAP_THROWING(appScanner.reset(CCaSrvAppScanner::NewL(*iStorage,*iScr,
*iSrvEngUtils)))
QTest::qWait(7000 * TIMEOUT_FACTOR);
RPointerArray<CCaInnerEntry> array;
InnerEntryRArrayPointer resultArray(&array);
QScopedPointer<CDesC16ArrayFlat> appType;
QT_TRAP_THROWING(appType.reset(new(ELeave) CDesC16ArrayFlat(1)))
TRAPD(err, appType->AppendL(KCaTypeApp))
QCOMPARE(err, KErrNone);
QScopedPointer<CCaInnerQuery> query;
QT_TRAP_THROWING(query.reset(CCaInnerQuery::NewL()));
query->SetEntryTypeNames(appType.take());
TRAP(err, query->SetParentId(appScanner->GetCollectionDownloadIdL()));
QCOMPARE(err, KErrNone);
query->SetFlagsOn(EVisible);
query->SetFlagsOff(EMissing);
TRAP(err, iStorage->GetEntriesL(query.data(), *resultArray))
QCOMPARE(err, KErrNone);
countBeforeInstall = resultArray->Count();
resultArray->Reset();
TRAP(err, iInstaller->InstallL(KSapiPackageFileName))
QCOMPARE(err, KErrNone);
TRAP(err, iInstaller->InstallL(KSapiPackageFileName))
QCOMPARE(err, KErrNone);
QTest::qWait(20000 * TIMEOUT_FACTOR);
TComponentId componentId(0);
TRAP(err, componentId = iInstaller->GetComponentIdL(installedUid));
QCOMPARE(err, KErrNone);
TRAP(err, iStorage->GetEntriesL(query.data(), *resultArray))
QCOMPARE(err, KErrNone);
countAfterInstall = resultArray->Count();
TRAP(err, existsAfterInstall =
(iTestUtils->ComponentExistsInStorageL(
componentId, iStorage) != FALSE));
QCOMPARE(err, KErrNone);
TRAP(err, iInstaller->UninstallL(componentId))
QCOMPARE(err, KErrNone);
QVERIFY(countAfterInstall == countBeforeInstall + 1);
QVERIFY(existsAfterInstall);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testDownloadCollectionRemove()
{
TInt countBeforeInstall(0);
TInt countAfterInstall(0);
TInt countAfterRemove(0);
bool existsAfterInstall(false);
// ensure the application is not installed
TComponentId unComponentId;
TRAP_IGNORE(unComponentId = iInstaller->GetComponentIdL(installedUid))
if( unComponentId > 0 )
{
TRAP_IGNORE(iInstaller->UninstallL(unComponentId));
}
QScopedPointer<CCaSrvAppScanner> appScanner;
QT_TRAP_THROWING(appScanner.reset(CCaSrvAppScanner::NewL(*iStorage,*iScr,
*iSrvEngUtils)))
QTest::qWait(7000 * TIMEOUT_FACTOR);
RPointerArray<CCaInnerEntry> array;
InnerEntryRArrayPointer resultArray(&array);
QScopedPointer<CDesC16ArrayFlat> appType;
TRAPD(error, appType.reset(new(ELeave) CDesC16ArrayFlat(1)));
QCOMPARE(error, KErrNone);
QScopedPointer<CCaInnerQuery> query;
TRAP(error, query.reset(CCaInnerQuery::NewL()));
QCOMPARE(error, KErrNone);
appType->AppendL(KCaTypeApp);
query->SetEntryTypeNames(appType.take());
TInt dcID(0);
TRAP(error, dcID = appScanner->GetCollectionDownloadIdL());
QCOMPARE(error, KErrNone);
query->SetParentId(dcID);
query->SetFlagsOn(EVisible);
query->SetFlagsOff(EMissing);
TRAP(error, iStorage->GetEntriesL(query.data(), *resultArray));
QCOMPARE(error, KErrNone);
countBeforeInstall = resultArray->Count();
TRAP(error, iInstaller->InstallL(KSapiPackageFileName));
QCOMPARE(error, KErrNone);
QTest::qWait(20000 * TIMEOUT_FACTOR);
TComponentId componentId(0);
TRAP(error, componentId = iInstaller->GetComponentIdL(installedUid));
QCOMPARE(error, KErrNone);
TRAP(error, iStorage->GetEntriesL(query.data(), *resultArray));
QCOMPARE(error, KErrNone);
countAfterInstall = resultArray->Count();
if (countAfterInstall >= 1) {
TRAP(error, appScanner->RemoveEntryFromDownloadedL(
(*resultArray)[countAfterInstall-1]->GetId()));
QCOMPARE(error, KErrNone);
}
RPointerArray<CCaInnerEntry> arrayA;
InnerEntryRArrayPointer resultArrayA(&arrayA);
TRAP(error, iStorage->GetEntriesL(query.data(), *resultArrayA));
QCOMPARE(error, KErrNone);
countAfterRemove = resultArrayA->Count();
TRAP(error, existsAfterInstall =
iTestUtils->ComponentExistsInStorageL(componentId, iStorage));
QCOMPARE(error, KErrNone);
TRAP(error, iInstaller->UninstallL(componentId));
QCOMPARE(error, KErrNone);
QVERIFY(countAfterInstall == countBeforeInstall + 1);
QVERIFY(countBeforeInstall == countAfterRemove);
QVERIFY(existsAfterInstall);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testCreatePredefinedCollection()
{
_LIT16( KPredefinedCollection, "Predefined" );
TInt predefinedCollectionId( 0 );
TRAPD(err,
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
// create predefined collection
predefinedCollectionId = appScanner->CreatePredefinedCollectionL(
KPredefinedCollection );
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE( err, KErrNone );
// clean db after test
if (predefinedCollectionId) {
RArray<TInt> idsToRemove;
CleanupClosePushL(idsToRemove);
TRAP(err, idsToRemove.AppendL( predefinedCollectionId );
iStorage->RemoveL(idsToRemove));
CleanupStack::PopAndDestroy( &idsToRemove );
}
QCOMPARE(err, KErrNone);
QVERIFY(predefinedCollectionId); // all collection id from db
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testGetAllCollectionIdL()
{
TInt allCollectionId(0);
const TInt referenceAllCollectionId(1);
TRAPD(err,
CCaSrvAppScanner *appScanner = CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils);
CleanupStack::PushL(appScanner);
QTest::qWait(7000 * TIMEOUT_FACTOR);
// get all collection id
allCollectionId = appScanner->GetAllCollectionIdL();
CleanupStack::PopAndDestroy(appScanner);
);
QCOMPARE( err, KErrNone );
QCOMPARE( allCollectionId, referenceAllCollectionId );
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testUpdateComponentIdL()
{
TBool updatedWhenNotExists = EFalse;
TBool updatedAfterInstall = EFalse;
TBool updatedWhenNoChange = EFalse;
RBuf actualComponentId;
RBufPointer actualComponentIdPointer(&actualComponentId);
TBool componentIdAttributeFoundWhenNotExists = EFalse;
TBool componentIdAttributeFoundAfterInstall = EFalse;
// create app scanner to test
QScopedPointer<CCaSrvAppScanner> appScanner;
QT_TRAP_THROWING(appScanner.reset(CCaSrvAppScanner::NewL(*iStorage,
*iScr, *iSrvEngUtils)))
QScopedPointer<CCaInnerEntry> entry;
QT_TRAP_THROWING(entry.reset(CCaInnerEntry::NewL()))
// case 1: pass non existing application description
entry->SetUid(0);
TRAPD(err, updatedWhenNotExists =
appScanner->UpdateComponentIdL(*entry))
QCOMPARE(err, KErrNone);
TRAP(err, actualComponentIdPointer->CreateL(KCaMaxAttrValueLen))
QCOMPARE(err, KErrNone);
componentIdAttributeFoundWhenNotExists =
entry->FindAttribute(KCaComponentId, *actualComponentIdPointer);
// case 2: add component id once application is installed
// ensure the application is not installed
TComponentId unComponentId;
TRAP_IGNORE(unComponentId = iInstaller->GetComponentIdL(installedUid))
if( unComponentId > 0 )
{
TRAP_IGNORE(iInstaller->UninstallL(unComponentId));
}
TRAP(err, iInstaller->InstallL(KSapiPackageFileName))
QCOMPARE(err, KErrNone);
TComponentId componentId(0);
TRAP(err, componentId = iInstaller->GetComponentIdL(installedUid));
QCOMPARE(err, KErrNone);
entry->SetUid(installedUid);
TRAP(err, updatedAfterInstall =
appScanner->UpdateComponentIdL(*entry));
QCOMPARE(err, KErrNone);
actualComponentIdPointer->Close();
TRAP(err, actualComponentIdPointer->CreateL(KCaMaxAttrValueLen))
QCOMPARE(err, KErrNone);
componentIdAttributeFoundAfterInstall =
entry->FindAttribute(KCaComponentId, *actualComponentIdPointer);
// case 3: update for application which has component id not changed
TRAP(err, updatedWhenNoChange =
appScanner->UpdateComponentIdL(*entry))
QCOMPARE(err, KErrNone);
QVERIFY(!updatedWhenNotExists);
QVERIFY(!componentIdAttributeFoundWhenNotExists);
QVERIFY(updatedAfterInstall);
QVERIFY(componentIdAttributeFoundAfterInstall);
QVERIFY(!updatedWhenNoChange);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testSave()
{
bool result(false);
TRAPD(err,
RFs fs;
User::LeaveIfError(fs.Connect());
{
CCaSrvMmcHistory* mmcHist = CCaSrvMmcHistory::NewL();
CleanupStack::PushL( mmcHist );
mmcHist->InsertL(1);
mmcHist->SaveL(fs, _L("c:\\testing\\data\\t_caappscanner\\testmmchist"));
CleanupStack::PopAndDestroy( mmcHist );
mmcHist = CCaSrvMmcHistory::NewL();
CleanupStack::PushL( mmcHist );
mmcHist->LoadL(fs, _L("c:\\testing\\data\\t_caappscanner\\testmmchist"));
result = (mmcHist->Find(1) != KErrNotFound);
CleanupStack::PopAndDestroy( mmcHist );
}
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::testInsert()
{
bool result(false);
TRAPD(err,
CCaSrvMmcHistory* mmcHist = CCaSrvMmcHistory::NewL();
CleanupStack::PushL( mmcHist );
mmcHist->InsertL(1);
result = (mmcHist->Find(1) != KErrNotFound);
CleanupStack::PopAndDestroy( mmcHist );
);
QCOMPARE(err, KErrNone);
QVERIFY(result);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_AddNewAppL()
{
TBool exists = iTestUtils->AppExistsInStorageL(systemApp, iStorage);
if (exists) {
iTestUtils->RemoveAppL(systemApp, iStorage);
exists = iTestUtils->AppExistsInStorageL(systemApp, iStorage);
if (exists) {
User::Leave(KErrNotReady);
}
}
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_NoUpdateL()
{
TInt flags(KErrNotFound);
CCaInnerQuery *satAppQuery = CCaInnerQuery::NewLC();
satAppQuery->SetUid(systemApp);
RPointerArray<CCaInnerEntry> resultArray;
CleanupResetAndDestroyPushL(resultArray);
iStorage->GetEntriesL(satAppQuery, resultArray);
if (resultArray.Count()) {
CCaInnerEntry *innerEntry = resultArray[0];
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(systemApp);
innerEntry->SetFlags(innerEntry->GetFlags() | EVisible);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
CleanupStack::PopAndDestroy(&resultArray);
CleanupStack::PopAndDestroy(satAppQuery);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_RemoveMmcAppL()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(notInstalledUid);
innerEntry->SetFlags(EVisible);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
innerEntry->AddAttributeL(KCaAttrMmcId, KCaMassStorage);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_RemoveMmcAttrL()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(installedUid);
innerEntry->SetFlags(EVisible);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
innerEntry->AddAttributeL(KCaAttrMmcId, KCaMassStorage);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_RemoveMissingFlagL()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(notInstalledUid);
innerEntry->SetFlags(EVisible | EMissing);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_RemoveMissingFlag01L()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(installedUid);
innerEntry->SetFlags(EVisible | EMissing);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_AddMissingFlagL()
{
iTestUtils->CopyMmcHistory();
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(notInstalledUid);
innerEntry->SetFlags(EVisible);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
innerEntry->AddAttributeL(KCaAttrMmcId, KMmcIdValue);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_SatAppL()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(KSatUid.iUid);
innerEntry->SetFlags(EVisible | EMissing);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_HsAppL()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("HsApplication"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(KHsAppUid.iUid);
innerEntry->SetFlags(0);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_AddRemovableL()
{
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(installedUid);
innerEntry->SetFlags(innerEntry->GetFlags() & ~ERemovable | EVisible);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_casrvAppScaner::Setup_RemoveRemovableL()
{
TInt flags(KErrNotFound);
CCaInnerQuery *satAppQuery = CCaInnerQuery::NewLC();
satAppQuery->SetUid(systemApp);
RPointerArray<CCaInnerEntry> resultArray;
CleanupResetAndDestroyPushL(resultArray);
iStorage->GetEntriesL(satAppQuery, resultArray);
if (resultArray.Count()) {
CCaInnerEntry *innerEntry = resultArray[0];
RBuf testName;
testName.CleanupClosePushL();
testName.CreateL(_L("testname_old"));
innerEntry->SetEntryTypeNameL(KCaTypeApp);
innerEntry->SetUid(systemApp);
innerEntry->SetFlags(innerEntry->GetFlags() | ERemovable);
innerEntry->SetTextL(testName);
innerEntry->AddAttributeL(KCaAttrShortName, testName);
iStorage->AddL(innerEntry);
CleanupStack::PopAndDestroy(&testName);
}
CleanupStack::PopAndDestroy(&resultArray);
CleanupStack::PopAndDestroy(satAppQuery);
}
void T_casrvAppScaner::testSetJavaAppL()
{
RSoftwareInstall sif;
CleanupClosePushL( sif );
User::LeaveIfError( sif.Connect() );
// Install the component
_LIT16( KHelloWorldJarPath, "c:\\testing\\data\\t_caappscanner\\HelloWorld.jar" );
COpaqueNamedParams* arguments = NULL;
COpaqueNamedParams* results = NULL;
arguments = COpaqueNamedParams::NewLC();
results = COpaqueNamedParams::NewLC();
arguments->AddIntL( KSifInParam_InstallSilently, 1 );
TRequestStatus status;
sif.Install( KHelloWorldJarPath, *arguments, *results, status, EFalse );
User::WaitForRequest( status );
User::LeaveIfError( status.Int() );
CleanupStack::PopAndDestroy( results );
CleanupStack::PopAndDestroy( arguments );
// Disconnect from the SIF server
CleanupStack::PopAndDestroy( &sif );
QScopedPointer<CCaSrvAppScanner> appScanner;
QT_TRAP_THROWING(appScanner.reset(CCaSrvAppScanner::NewL(
*iStorage, *iScr, *iSrvEngUtils)));
QVERIFY(!appScanner.isNull());
QTest::qWait(7000 * TIMEOUT_FACTOR);
QScopedPointer<CCaInnerEntry> entry;
TInt javaUid(0);
TRAP_IGNORE( javaUid = iTestUtils->FindAppUidL(KJavaAppName, iStorage));
TRAPD(err, entry.reset(iTestUtils->GetAppEntryL(javaUid, iStorage)));
QCOMPARE(err, KErrNone);
QVERIFY(!entry.isNull());
QCOMPARE(err, KErrNone);
bool exists(false);
bool match(false);
TRAP(err,
RBuf value;
value.CleanupClosePushL();
value.CreateL(KCaMaxAttrLenght);
exists = (entry->FindAttribute(KCaAttrAppType, value) != 0);
match = (value == KCaAttrAppTypeValueJava);
CleanupStack::PopAndDestroy(&value);
);
QCOMPARE(err, KErrNone);
QVERIFY(exists);
QVERIFY(match);
}
QTEST_MAIN(T_casrvAppScaner);
// END OF FILE