contentstorage/casrv/cawidgetscanner/tsrc/t_cawidgetscanner/src/cawidgetscannertestutils.cpp
changeset 117 c63ee96dbe5f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/casrv/cawidgetscanner/tsrc/t_cawidgetscanner/src/cawidgetscannertestutils.cpp	Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,474 @@
+/*
+* 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 "cawidgetscannertestutils.h"
+#include "testconsts.h"
+#include "WidgetScannerUtils.h"
+#include "CaWidgetDescription.h"
+
+#include "cawidgetscannerdef.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;
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::Copy( const TDesC& aSource, const TDesC& aDest )
+    {
+    iFs.MkDirAll(aDest);
+    return iFileManager->Copy( aSource, aDest );
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::RemoveL( const TDesC& aFile )
+    {
+    return iFs.Delete( aFile );
+    }
+
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::CopyDb()
+    {
+    return Copy( KTestDbSource, KTestDbDest );
+    }
+
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::WidgetsCountL( CCaStorageProxy* aStorage )
+    {
+    TInt count(0);
+    CCaInnerQuery* widQuery = CCaInnerQuery::NewLC();
+    CDesC16ArrayFlat* appType = new (ELeave) CDesC16ArrayFlat( 1 );
+    CleanupStack::PushL( appType );
+    appType->AppendL( KCaTypeWidget );
+    widQuery->SetEntryTypeNames(appType);  
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( widQuery, resultArray );
+    
+    if ( resultArray.Count() )
+        {
+        count = resultArray.Count();
+        }
+
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::Pop( appType );
+    CleanupStack::PopAndDestroy( widQuery );
+
+    return count;
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TBool CTestUtils::WidgetExistsInStorageL( const TDesC& aAtrName, const TDesC& aValue, CCaStorageProxy* aStorage)
+    {
+    TBool exists(EFalse);
+    CCaInnerQuery* widQuery = CCaInnerQuery::NewLC();
+    CDesC16ArrayFlat* appType = new (ELeave) CDesC16ArrayFlat( 1 );
+    CleanupStack::PushL( appType );
+    appType->AppendL( KCaTypeWidget );
+    widQuery->SetEntryTypeNames(appType);  
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    RCaEntryAttrArray attrArray;
+    //CleanupResetAndDestroyPushL( attrArray );
+    aStorage->GetEntriesL( widQuery, resultArray );
+    RBuf library;
+    library.Create(KCaMaxAttrLenght);
+    
+    if ( resultArray.Count() )
+        {
+        for(int i(0); i<resultArray.Count();i++)
+            {
+            attrArray = resultArray[i]->GetAttributes();
+            attrArray.Find( aAtrName, library );
+            if(library.Length()>0 && library == aValue)
+                {
+                exists = ETrue;
+                }
+            }
+        }
+    library.Close();
+   // CleanupStack::PopAndDestroy( &attrArray );
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::Pop( appType );
+    CleanupStack::PopAndDestroy( widQuery );
+
+    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;
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+CCaWidgetDescription* CTestUtils::GetWidgetEntryL(const TDesC& aText, CCaStorageProxy* aStorage)
+    {
+    CCaWidgetDescription* widget = NULL;
+    
+    CCaInnerQuery* query = CCaInnerQuery::NewLC();
+    CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
+            KGranularityOne );
+    CleanupStack::PushL( widgetType );
+    widgetType->AppendL( KCaTypeWidget );
+    query->SetEntryTypeNames( widgetType );//transfers ownership to query
+    CleanupStack::Pop( widgetType );
+
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( query, resultArray );
+    
+    if ( resultArray.Count() )
+        {
+        for (TInt i=0; i< resultArray.Count(); i++)
+            {
+            if ( resultArray[i]->GetText() == aText )
+                {
+                widget = CCaWidgetDescription::NewLC(resultArray[i]);
+                CleanupStack::Pop( widget );
+                }
+            }
+        }
+
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::PopAndDestroy( query );
+
+    return widget;
+    }
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+TInt CTestUtils::GetWidgetFlagsL(const TDesC& aText, CCaStorageProxy* aStorage)
+    {
+    
+    TInt flags(0);
+    CCaInnerQuery* query = CCaInnerQuery::NewLC();
+    CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
+            KGranularityOne );
+    CleanupStack::PushL( widgetType );
+    widgetType->AppendL( KCaTypeWidget );
+    query->SetEntryTypeNames( widgetType );//transfers ownership to query
+    CleanupStack::Pop( widgetType );
+
+    RPointerArray<CCaInnerEntry> resultArray;
+    CleanupResetAndDestroyPushL( resultArray );
+    aStorage->GetEntriesL( query, resultArray );
+    
+    if ( resultArray.Count() )
+        {
+        for (TInt i=0; i< resultArray.Count(); i++)
+            {
+            if ( resultArray[i]->GetText() == aText )
+                {
+                
+                CCaInnerEntry* poin = resultArray[i];
+                flags = resultArray[i]->GetFlags();
+                }
+            }
+        }
+
+    CleanupStack::PopAndDestroy( &resultArray );
+    CleanupStack::PopAndDestroy( query );
+
+    return flags;
+    }
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+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::FindAppUidL( 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;
+    }
+
+// -----------------------------------------------------------------------------
+//
+TInt CTestUtils::SimpleCloseTaskL(TInt aUid)
+    {
+    RWsSession session;
+    TInt error = session.Connect();
+    TUid uidApp( TUid::Uid( aUid )) ;
+    TApaTaskList taskList( session );
+    TApaTask task = taskList.FindApp( uidApp );
+
+    if( task.Exists() )
+        {
+        task.EndTask();
+        }
+    else
+        {
+        error = KErrNotFound;
+        }
+
+    WaitL( 4000000 );
+    session.Close();
+    WaitL( 1000000  );
+
+    return error;
+    }
+
+// ----------------------------------------------------------------------------
+//
+void CTestUtils::InstallFinishedL()
+    {
+    iActiveWait->AsyncStop();
+    }
+
+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;
+    }
+
+
+
+