contentstorage/casrv/casatmonitor/tsrc/t_satmonitor/src/T_casatmonitor.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) 2009 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:
*
*/
/*
 * T_casatmonitor.cpp
 *
 *  Created on: 2009-09-16
 *      Author:
 */

//  CLASS HEADER


#include <ecom/ecom.h>
#include "ca2internalCRkeys.h"
#include "T_casatmonitor.h"
#include "casatmonitortestutils.h"
#include "cadef.h"
#include "waitactive.h"
#include "casrvengutils.h"
#include "castorageproxy.h"
#include "casrvmanager.h"
#include "cainnerentry.h"
#include "cainnerquery.h"
#include "caarraycleanup.inl"


const TUid KSatPluginUid = {0x20026FAE};

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaSatMonitor::WaitL(TInt aMicroSec)
{
    CWaitActive *wait = CWaitActive::NewL();
    wait->Wait(aMicroSec);
    delete wait;
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaSatMonitor::initTestCase()
{
}

void T_CaSatMonitor::cleanupTestCase()
{
}

void T_CaSatMonitor::init()
{
    iTestUtils = CTestUtils::NewL();
    iTestUtils->CopyDb();

    iStorage = CCaStorageProxy::NewL();
    //iSrvEngUtils = CCaSrvEngUtils::NewL();

    ///remember preconditions
    iTestUtils->GetRProperty(KCRUidCa, KCaSatUIName, iSatName);
    iTestUtils->GetRProperty(KCRUidCa, KCaShowSatUI, iSatVis);
    iTestUtils->WaitL(1000000);
    ///

    RBuf satName;
    satName.CleanupClosePushL();
    satName.CreateL(_L("testname_old"));
    CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
    innerEntry->SetEntryTypeNameL(KCaTypeApp);
    innerEntry->SetUid(KSatUid.iUid);
    innerEntry->SetTextL(satName);
    innerEntry->AddAttributeL(KCaAttrShortName, satName);

    iStorage->AddL(innerEntry);
    
    TInt err = iTestUtils->DefineIntRProperty(KCRUidCa, KCaShowSatUI);
    err = iTestUtils->DefineTextRProperty(KCRUidCa, KCaSatUIName);
    err = iTestUtils->SetRProperty(KCRUidCa, KCaShowSatUI, 1);
    iTestUtils->WaitL(1000000);
    iTestUtils->SetRProperty(KCRUidCa, KCaSatUIName, _L("testname_old"));
    iTestUtils->WaitL(1000000);

    CleanupStack::PopAndDestroy(innerEntry);
    CleanupStack::PopAndDestroy(&satName);
}

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaSatMonitor::cleanup()
{
    ///restore preconditions
    iTestUtils->SetRProperty(KCRUidCa, KCaSatUIName, iSatName);
    iTestUtils->SetRProperty(KCRUidCa, KCaShowSatUI, iSatVis);

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

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaSatMonitor::testSatChange()
{
    bool nonEmptySatList(false);
    bool nameMatches(false);
    TInt err(KErrNone);

    TPluginParams params;
    params.engUtils = 0;
    params.storageProxy = iStorage;

    TRAP(err,
         CCaSrvPlugin *plug = iTestUtils->LoadPluginL(KSatPluginUid, params);
         iTestUtils->WaitL(10000000);//load plugin

         RBuf newSatName;
         newSatName.CleanupClosePushL();
         newSatName.CreateL(_L("testname"));

         TInt err = iTestUtils->SetRProperty(
                        KCRUidCa, KCaSatUIName, newSatName);
         err = iTestUtils->SetRProperty(
                   KCRUidCa, KCaShowSatUI, 1);
         iTestUtils->WaitL(10000000);
         delete plug;
         CCaInnerQuery *satAppQuery = CCaInnerQuery::NewLC();
         satAppQuery->SetUid(KSatUid.iUid);
         RPointerArray<CCaInnerEntry> resultArray;
         CleanupResetAndDestroyPushL(resultArray);
         iStorage->GetEntriesL(satAppQuery, resultArray);

         nonEmptySatList = (resultArray.Count() >= 1);
         nameMatches = newSatName.Compare(resultArray[0]->GetText()) == 0;


         CleanupStack::PopAndDestroy(&resultArray);
         CleanupStack::PopAndDestroy(satAppQuery);
         CleanupStack::PopAndDestroy(&newSatName);
        );
    QCOMPARE(err, KErrNone);
    QVERIFY(nonEmptySatList);
    QVERIFY(nameMatches);
}

QTEST_MAIN(T_CaSatMonitor);