contentstorage/casrv/causifscanner/tsrc/t_causifscanner/src/T_caUsifScaner.cpp
author Jaakko Haukipuro (Nokia-MS/Oulu) <Jaakko.Haukipuro@nokia.com>
Thu, 16 Sep 2010 12:11:40 +0100
changeset 117 c63ee96dbe5f
permissions -rw-r--r--
Missing activityfw and taskswitcher components - fix for Bug 3670

/*
* 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 <w32std.h>
#include <apgtask.h>
#include <usif/sif/sifcommon.h>
#include <usif/sif/sif.h>

//  CLASS HEADER
#include "T_caUsifScaner.h"

//  EXTERNAL INCLUDES

#include <cadef.h>

#include "castoragefactory.h"
#include "castorageproxy.h"
#include "casrvengutils.h"
#include "causifscanner.h"
#include "causifscanner.hrh"
#include "cainnerentry.h"
#include "cainnerquery.h"
#include "caarraycleanup.inl"
#include "casrvmmchistory.h"

//  INTERNAL INCLUDES
#include "casrvtestutils.h"
#include "testconsts.h"

#include "t_cainstaller.h"

#ifdef COVERAGE_MEASUREMENT
const unsigned int TIMEOUT_FACTOR = 2;
#else
const unsigned int TIMEOUT_FACTOR = 1;
#endif

// ---------------------------------------------------------------------------
//
T_caUsifScaner::T_caUsifScaner():
    iTestUtils(NULL),
    iStorage(NULL),
    iSrvEngUtils(NULL)
{
}
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::initTestCase()
{
    if (iTestUtils == NULL) {
        TRAPD(err, iTestUtils = CTestUtils::NewL());
        QCOMPARE(err, KErrNone);
    }
    QT_TRAP_THROWING(iInstaller = T_CaInstaller::NewL());
    TRAP_IGNORE(iInstaller->InstallL(KSapiPackageFileName));
    QTest::qWait(10000);

    delete iTestUtils;
    iTestUtils = NULL;
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::init()
{
    TRAPD(err,
          iTestUtils = CTestUtils::NewL();
          iTestUtils->CopyDb();

          iStorage = CCaStorageProxy::NewL();
          iSrvEngUtils = CCaSrvEngUtils::NewL();
          
          iScr = new Usif::RSoftwareComponentRegistry;          
          User::LeaveIfError( iScr->Connect() );

          iPluginParams.storageProxy = iStorage;
          iPluginParams.engUtils = iSrvEngUtils;
          iPluginParams.softwareRegistry = iScr;
         );
    QCOMPARE(err, KErrNone);
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::cleanup()
{
    iPluginParams.storageProxy = NULL;
    iPluginParams.engUtils = NULL;
    iScr->Close();
    iPluginParams.softwareRegistry = NULL;
    
    delete iSrvEngUtils;
    iSrvEngUtils = NULL;
    delete iStorage;
    iStorage = NULL;
    delete iTestUtils;
    iTestUtils = NULL;
    delete iScr;
    iScr = NULL;
}
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::cleanupTestCase()
{
    TRAPD(err, iInstaller->UninstallL(KSapiAppFileName));
    QCOMPARE(err, KErrNone);

    delete iTestUtils;
    iTestUtils = NULL;
    
    delete iInstaller;
    REComSession::FinalClose();
}

// ---------------------------------------------------------------------------
//
void T_caUsifScaner::testNew()
{
    bool result(false);
    TRAPD(err,
          CCaUsifScanner *usifScanner = CCaUsifScanner::NewL(&iPluginParams);
          result = usifScanner != NULL;
          QTest::qWait(5000);
          delete usifScanner;
         );
    QCOMPARE(err, KErrNone);
    QVERIFY(result);
}

// ---------------------------------------------------------------------------
//
void T_caUsifScaner::testLoadPlugin()
{
    bool result(false);
    TRAPD(err, CCaSrvPlugin *plug = iTestUtils->LoadPluginL(
            TUid::Uid(KCaSrvUsifScannerPlugin), iPluginParams);
          result = plug != NULL;

          QTest::qWait(5000);
          delete plug;
         );
    QCOMPARE(err, KErrNone);
    QVERIFY(result);
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::testInstalled()
{
    bool flags(false);
    TRAPD(err,
        CCaUsifScanner *usifScaner = CCaUsifScanner::NewL(&iPluginParams);
        CleanupStack::PushL(usifScaner);
        QTest::qWait(5000);
        //visible flag update
        flags = ((iTestUtils->GetPackageFlagsL(KSapiApp, iStorage)
                & (EVisible | ERemovable) ) != FALSE);
          CleanupStack::PopAndDestroy(usifScaner);
         );
    QCOMPARE(err, KErrNone);
    QVERIFY(flags);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::testAddNewApp()
{
    bool result(false);
    TRAPD(err,
          Setup_AddNewAppL();
          CCaUsifScanner *usifScaner = CCaUsifScanner::NewL(&iPluginParams);
          CleanupStack::PushL(usifScaner);
          QTest::qWait(5000);
          // new app added
          result = ((iTestUtils->GetPackageFlagsL(KSapiApp,iStorage)
                     & (EVisible | ERemovable)) != FALSE);

          CleanupStack::PopAndDestroy(usifScaner);
         );
    QCOMPARE(err, KErrNone);
    QVERIFY(result);
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::testAddRemovable()
{
    bool result(false);
    TRAPD(err,
        Setup_AddRemovableL();
        CCaUsifScanner *usifScaner = CCaUsifScanner::NewL(&iPluginParams);
        CleanupStack::PushL(usifScaner);
        QTest::qWait(5000 * TIMEOUT_FACTOR);
        //add removable flag to installed app
        result = ((iTestUtils->GetPackageFlagsL(KSapiApp, iStorage)
                & (ERemovable | EVisible)) != FALSE);

        CleanupStack::PopAndDestroy(usifScaner);
    );
    QCOMPARE(err, KErrNone);
    QVERIFY(result);
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::testInstallNotifier()
{
    bool existsAfterInstall(false);
    TRAPD(err,
        CCaUsifScanner *usifScanner = CCaUsifScanner::NewL(&iPluginParams);
        CleanupStack::PushL(usifScanner);
        iInstaller->InstallL(KSapiPackageFileName);
        QTest::qWait(20000 * TIMEOUT_FACTOR);
        existsAfterInstall = iTestUtils->GetPackageFlagsL(KSapiApp, iStorage);
        CleanupStack::PopAndDestroy(usifScanner);
        );
    QCOMPARE(err, KErrNone);
    QVERIFY(existsAfterInstall);
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::Setup_AddNewAppL()
{
    TBool exists = iTestUtils->AppExistsInStorageL(installedUid, iStorage);
    if (exists) {
        iTestUtils->RemoveAppL(installedUid, iStorage);
        exists = iTestUtils->AppExistsInStorageL(installedUid, iStorage);
        if (exists) {
            User::Leave(KErrNotReady);
        }
    }
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_caUsifScaner::Setup_AddRemovableL()
{
    RBuf testName;
    testName.CleanupClosePushL();
    testName.CreateL(_L("Removable"));
    CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
    innerEntry->SetEntryTypeNameL(KCaTypeApp);
    innerEntry->SetUid(installedUid);
    innerEntry->SetFlags(innerEntry->GetFlags() & ~ERemovable | EVisible);
    innerEntry->SetTextL(testName);
    innerEntry->AddAttributeL(KCaAttrComponentId, _L("10"));

    iStorage->AddL(innerEntry);
    CleanupStack::PopAndDestroy(innerEntry);
    CleanupStack::PopAndDestroy(&testName);
}

QTEST_MAIN(T_caUsifScaner);

//  END OF FILE