contentstorage/casrv/casatmonitor/tsrc/t_satmonitor/src/casatmonitortestutils.cpp
changeset 117 c63ee96dbe5f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/casrv/casatmonitor/tsrc/t_satmonitor/src/casatmonitortestutils.cpp	Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,367 @@
+/*
+* 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: 
+*
+*/
+
+#include <W32STD.H>
+#include <e32property.h>
+#include <cadef.h>
+#include <badesca.h>
+#include <apgtask.h>
+#include <AknTaskList.h>
+#include <apgcli.h>
+#include <APACMDLN.h>
+#include <EIKENV.h>
+
+
+#include "castorageproxy.h"
+#include "cainnerentry.h"
+#include "cainnerquery.h"
+#include "caarraycleanup.inl"
+#include "casrvplugin.h"
+#include "waitactive.h"
+#include "casatmonitortestutils.h"
+#include "testconsts.h"
+
+
+//-----------------------------------------------------------------------
+// CONSTRUCTION
+// ---------------------------------------------------------------------------
+//
+CTestUtils* CTestUtils::NewL()
+    {
+    CTestUtils* self = CTestUtils::NewLC();
+    CleanupStack::Pop();
+
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+CTestUtils* CTestUtils::NewLC()
+    {
+    CTestUtils* self = new( ELeave ) CTestUtils();
+    CleanupStack::PushL( self );
+
+    self->ConstructL();
+
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
+// Destructor (virtual by CBase)
+// ---------------------------------------------------------------------------
+//
+CTestUtils::~CTestUtils()
+    {
+	iFileManager->Delete(KTestDbDest);
+    delete iFileManager;    iFileManager = NULL;
+    iFs.Close();
+    }
+
+// ---------------------------------------------------------------------------
+// Default constructor
+// ---------------------------------------------------------------------------
+//
+CTestUtils::CTestUtils()
+    {
+
+    }
+
+// ---------------------------------------------------------------------------
+// Second phase construct
+// ---------------------------------------------------------------------------
+//
+void CTestUtils::ConstructL()
+    {
+    User::LeaveIfError( iFs.Connect() );
+    iFileManager = CFileMan::NewL( iFs );
+    }
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void CTestUtils::WaitL(TInt aMicroSec)
+    {
+    CWaitActive* wait = CWaitActive::NewL();
+    wait->Wait(aMicroSec);
+    delete wait;
+    }
+
+// ---------------------------------------------------------------------------
+// CTestUtils::GetRProperty
+// ---------------------------------------------------------------------------
+//
+TInt CTestUtils::GetRProperty( TUid aCategory, TUint aKey, TDes& aValue )
+    {
+    return RProperty::Get( aCategory, aKey, aValue );
+    }
+
+// ---------------------------------------------------------------------------
+// CTestUtils::GetRProperty
+// ---------------------------------------------------------------------------
+//
+TInt CTestUtils::GetRProperty( TUid aCategory, TUint aKey, TInt& aValue )
+    {
+    return RProperty::Get( aCategory, aKey, aValue );
+    }
+
+// ---------------------------------------------------------------------------
+// CTestUtils::SetRProperty
+// ---------------------------------------------------------------------------
+//
+TInt CTestUtils::SetRProperty( TUid aCategory, TUint aKey, const TDesC& aValue )
+    {
+    return RProperty::Set( aCategory, aKey, aValue );
+    }
+
+// ---------------------------------------------------------------------------
+// CTestUtils::SetRProperty
+// ---------------------------------------------------------------------------
+//
+TInt CTestUtils::SetRProperty( TUid aCategory, TUint aKey, TInt aValue )
+    {
+    return RProperty::Set( aCategory, aKey, aValue );
+    }
+
+// ---------------------------------------------------------------------------
+// CTestUtils::DefineRProperty
+// ---------------------------------------------------------------------------
+//
+TInt CTestUtils::DefineTextRProperty( TUid aCategory, TUint aKey )
+    {
+    return RProperty::Define( aCategory, aKey, RProperty::EText );
+    }
+
+// ---------------------------------------------------------------------------
+// CTestUtils::DefineIntRProperty
+// ---------------------------------------------------------------------------
+//
+TInt CTestUtils::DefineIntRProperty( TUid aCategory, TUint aKey )
+    {
+    return RProperty::Define( aCategory, aKey, RProperty::EInt );
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::Copy( const TDesC& aSource, const TDesC& aDest )
+    {
+    return iFileManager->Copy(aSource, aDest);
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::CopyDb()
+    {
+    return Copy(KTestDbSource, KTestDbDest);
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TBool CTestUtils::AppExistsInStorageL( TInt aUid, CCaStorageProxy* aStorage)
+    {
+    TBool exists(EFalse);
+    CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
+    satAppQuery->SetUid( aUid );
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( satAppQuery, resultArray );
+
+    if ( resultArray.Count() )
+        {
+        CCaInnerEntry* dbg = resultArray[0];
+        exists = ETrue;
+        }
+
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::PopAndDestroy( satAppQuery );
+
+    return exists;
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+CCaInnerEntry* CTestUtils::GetAppEntryL( TInt aUid, CCaStorageProxy* aStorage)
+    {
+    CCaInnerEntry* entry = NULL;
+    CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
+    satAppQuery->SetUid( aUid );
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( satAppQuery, resultArray );
+
+    if ( resultArray.Count() )
+        {
+        entry = resultArray[0];
+        resultArray.Remove(0);
+        }
+
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::PopAndDestroy( satAppQuery );
+
+    return entry;
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::AppsWithFlagsOffL( TInt aFlags, CCaStorageProxy* aStorage)
+    {
+    CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
+    CDesC16ArrayFlat* appType =
+                        new (ELeave) CDesC16ArrayFlat( 1 );
+    CleanupStack::PushL( appType );
+    appType->AppendL( KCaTypeApp );
+    satAppQuery->SetEntryTypeNames( appType );
+
+    satAppQuery->SetFlagsOff( aFlags );
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( satAppQuery, resultArray );
+
+    TInt count = resultArray.Count();
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::Pop( appType );
+    CleanupStack::PopAndDestroy( satAppQuery );
+
+    return count;
+    }
+
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::GetAppFlagsL( TInt aUid, CCaStorageProxy* aStorage)
+    {
+    TInt flags(0);
+    CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
+    satAppQuery->SetUid( aUid );
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( satAppQuery, resultArray );
+
+    if ( resultArray.Count() )
+        {
+        CCaInnerEntry* dbg = resultArray[0];
+        flags = resultArray[0]->GetFlags();
+        }
+
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::PopAndDestroy( satAppQuery );
+
+    return flags;
+    }
+
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+void CTestUtils::RemoveAppL( TInt aUid, CCaStorageProxy* aStorage)
+    {
+    CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
+    satAppQuery->SetUid( aUid );
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( satAppQuery, resultArray );
+
+    if ( resultArray.Count() )
+        {
+        CCaInnerEntry* dbg = resultArray[0];
+        RArray<TInt> idsToRemove;
+        CleanupClosePushL(idsToRemove);
+        idsToRemove.AppendL( resultArray[0]->GetId() );
+        aStorage->RemoveL(idsToRemove);
+        CleanupStack::PopAndDestroy( &idsToRemove );
+        }
+
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::PopAndDestroy( satAppQuery );
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TUint CTestUtils::FingAppUidL( const TDesC& aName, CCaStorageProxy* aStorage )
+    {
+    CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
+    CDesC16ArrayFlat* appType =
+                        new (ELeave) CDesC16ArrayFlat( 1 );
+    CleanupStack::PushL( appType );
+    appType->AppendL( KCaTypeApp );
+    satAppQuery->SetEntryTypeNames( appType );
+
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( satAppQuery, resultArray );
+
+    TUint appUid(0);
+    for ( TInt i = 0; i < resultArray.Count(); i++ )
+        {
+        if ( resultArray[i]->GetText() == aName )
+            {
+            appUid = resultArray[i]->GetUid();
+            }
+        }
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::Pop( appType );
+    CleanupStack::PopAndDestroy( satAppQuery );
+
+    return appUid;
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+CCaSrvPlugin* CTestUtils::LoadPluginL( TUid aImplUid, TPluginParams aPluginParams )
+    {
+    RImplInfoPtrArray infoArray;
+
+    // Note that a special cleanup function is required to reset and destroy
+    // all items in the array, and then close it.
+    CleanupResetAndDestroyPushL( infoArray );
+    CCaSrvPlugin::ListAllImplementationsL( infoArray );
+
+    // Loop through each info for each implementation
+    // and create and use each in turn
+    CCaSrvPlugin* plug;
+    for( TInt i = 0; i < infoArray.Count(); i++ )
+        {
+        // Slice off first sub-section in the data section
+        TUid current_plugin = infoArray[i]->ImplementationUid();
+        if ( current_plugin == aImplUid )
+            {
+            plug = CCaSrvPlugin::NewL( current_plugin, &aPluginParams );
+            CleanupStack::PushL( plug );
+            TInt32 key = current_plugin.iUid;
+            //iPluginMap.InsertL( key, plug );
+            CleanupStack::Pop( plug );
+            break;
+            }
+        plug = NULL;
+        }
+    CleanupStack::PopAndDestroy( &infoArray );
+    return plug;
+    }
+
+
+
+