contentstorage/casrv/cawidgetscanner/tsrc/t_cawidgetscanner/src/cawidgetscannertestutils.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <W32STD.H>
       
    19 #include <e32property.h>
       
    20 #include <cadef.h>
       
    21 #include <badesca.h>
       
    22 #include <apgtask.h>
       
    23 #include <AknTaskList.h>
       
    24 #include <apgcli.h>
       
    25 #include <APACMDLN.h>
       
    26 #include <EIKENV.h>
       
    27 
       
    28 
       
    29 #include "castorageproxy.h"
       
    30 #include "cainnerentry.h"
       
    31 #include "cainnerquery.h"
       
    32 #include "caarraycleanup.inl"
       
    33 #include "casrvplugin.h"
       
    34 #include "waitactive.h"
       
    35 #include "cawidgetscannertestutils.h"
       
    36 #include "testconsts.h"
       
    37 #include "WidgetScannerUtils.h"
       
    38 #include "CaWidgetDescription.h"
       
    39 
       
    40 #include "cawidgetscannerdef.h"
       
    41 
       
    42 //-----------------------------------------------------------------------
       
    43 // CONSTRUCTION
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CTestUtils* CTestUtils::NewL()
       
    47     {
       
    48     CTestUtils* self = CTestUtils::NewLC();
       
    49     CleanupStack::Pop();
       
    50 
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CTestUtils* CTestUtils::NewLC()
       
    59     {
       
    60     CTestUtils* self = new( ELeave ) CTestUtils();
       
    61     CleanupStack::PushL( self );
       
    62 
       
    63     self->ConstructL();
       
    64 
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Destructor (virtual by CBase)
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CTestUtils::~CTestUtils()
       
    73     {
       
    74     iFileManager->Delete(KTestDbDest);
       
    75     delete iFileManager;    iFileManager = NULL;
       
    76     iFs.Close();
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Default constructor
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CTestUtils::CTestUtils()
       
    84     {
       
    85 
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // Second phase construct
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CTestUtils::ConstructL()
       
    93     {
       
    94     User::LeaveIfError( iFs.Connect() );
       
    95     iFileManager = CFileMan::NewL( iFs );
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CTestUtils::WaitL(TInt aMicroSec)
       
   103     {
       
   104     CWaitActive* wait = CWaitActive::NewL();
       
   105     wait->Wait(aMicroSec);
       
   106     delete wait;
       
   107     }
       
   108 
       
   109 //-----------------------------------------------------------------------
       
   110 //
       
   111 //-----------------------------------------------------------------------
       
   112 TInt CTestUtils::Copy( const TDesC& aSource, const TDesC& aDest )
       
   113     {
       
   114     iFs.MkDirAll(aDest);
       
   115     return iFileManager->Copy( aSource, aDest );
       
   116     }
       
   117 
       
   118 //-----------------------------------------------------------------------
       
   119 //
       
   120 //-----------------------------------------------------------------------
       
   121 TInt CTestUtils::RemoveL( const TDesC& aFile )
       
   122     {
       
   123     return iFs.Delete( aFile );
       
   124     }
       
   125 
       
   126 
       
   127 //-----------------------------------------------------------------------
       
   128 //
       
   129 //-----------------------------------------------------------------------
       
   130 TInt CTestUtils::CopyDb()
       
   131     {
       
   132     return Copy( KTestDbSource, KTestDbDest );
       
   133     }
       
   134 
       
   135 
       
   136 //-----------------------------------------------------------------------
       
   137 //
       
   138 //-----------------------------------------------------------------------
       
   139 TInt CTestUtils::WidgetsCountL( CCaStorageProxy* aStorage )
       
   140     {
       
   141     TInt count(0);
       
   142     CCaInnerQuery* widQuery = CCaInnerQuery::NewLC();
       
   143     CDesC16ArrayFlat* appType = new (ELeave) CDesC16ArrayFlat( 1 );
       
   144     CleanupStack::PushL( appType );
       
   145     appType->AppendL( KCaTypeWidget );
       
   146     widQuery->SetEntryTypeNames(appType);  
       
   147     RPointerArray<CCaInnerEntry> resultArray;
       
   148     CleanupResetAndDestroyPushL( resultArray );
       
   149     aStorage->GetEntriesL( widQuery, resultArray );
       
   150     
       
   151     if ( resultArray.Count() )
       
   152         {
       
   153         count = resultArray.Count();
       
   154         }
       
   155 
       
   156     CleanupStack::PopAndDestroy( &resultArray );
       
   157     CleanupStack::Pop( appType );
       
   158     CleanupStack::PopAndDestroy( widQuery );
       
   159 
       
   160     return count;
       
   161     }
       
   162 
       
   163 //-----------------------------------------------------------------------
       
   164 //
       
   165 //-----------------------------------------------------------------------
       
   166 TBool CTestUtils::WidgetExistsInStorageL( const TDesC& aAtrName, const TDesC& aValue, CCaStorageProxy* aStorage)
       
   167     {
       
   168     TBool exists(EFalse);
       
   169     CCaInnerQuery* widQuery = CCaInnerQuery::NewLC();
       
   170     CDesC16ArrayFlat* appType = new (ELeave) CDesC16ArrayFlat( 1 );
       
   171     CleanupStack::PushL( appType );
       
   172     appType->AppendL( KCaTypeWidget );
       
   173     widQuery->SetEntryTypeNames(appType);  
       
   174     RPointerArray<CCaInnerEntry> resultArray;
       
   175     CleanupResetAndDestroyPushL( resultArray );
       
   176     RCaEntryAttrArray attrArray;
       
   177     //CleanupResetAndDestroyPushL( attrArray );
       
   178     aStorage->GetEntriesL( widQuery, resultArray );
       
   179     RBuf library;
       
   180     library.Create(KCaMaxAttrLenght);
       
   181     
       
   182     if ( resultArray.Count() )
       
   183         {
       
   184         for(int i(0); i<resultArray.Count();i++)
       
   185             {
       
   186             attrArray = resultArray[i]->GetAttributes();
       
   187             attrArray.Find( aAtrName, library );
       
   188             if(library.Length()>0 && library == aValue)
       
   189                 {
       
   190                 exists = ETrue;
       
   191                 }
       
   192             }
       
   193         }
       
   194     library.Close();
       
   195    // CleanupStack::PopAndDestroy( &attrArray );
       
   196     CleanupStack::PopAndDestroy( &resultArray );
       
   197     CleanupStack::Pop( appType );
       
   198     CleanupStack::PopAndDestroy( widQuery );
       
   199 
       
   200     return exists;
       
   201     }
       
   202 
       
   203 //-----------------------------------------------------------------------
       
   204 //
       
   205 //-----------------------------------------------------------------------
       
   206 CCaInnerEntry* CTestUtils::GetAppEntryL( TInt aUid, CCaStorageProxy* aStorage)
       
   207     {
       
   208     CCaInnerEntry* entry = NULL;
       
   209     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   210     satAppQuery->SetUid( aUid );
       
   211     RPointerArray<CCaInnerEntry> resultArray;
       
   212     CleanupResetAndDestroyPushL( resultArray );
       
   213     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   214 
       
   215     if ( resultArray.Count() )
       
   216         {
       
   217         entry = resultArray[0];
       
   218         resultArray.Remove(0);
       
   219         }
       
   220 
       
   221     CleanupStack::PopAndDestroy( &resultArray );
       
   222     CleanupStack::PopAndDestroy( satAppQuery );
       
   223 
       
   224     return entry;
       
   225     }
       
   226 
       
   227 //-----------------------------------------------------------------------
       
   228 //
       
   229 //-----------------------------------------------------------------------
       
   230 CCaWidgetDescription* CTestUtils::GetWidgetEntryL(const TDesC& aText, CCaStorageProxy* aStorage)
       
   231     {
       
   232     CCaWidgetDescription* widget = NULL;
       
   233     
       
   234     CCaInnerQuery* query = CCaInnerQuery::NewLC();
       
   235     CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
       
   236             KGranularityOne );
       
   237     CleanupStack::PushL( widgetType );
       
   238     widgetType->AppendL( KCaTypeWidget );
       
   239     query->SetEntryTypeNames( widgetType );//transfers ownership to query
       
   240     CleanupStack::Pop( widgetType );
       
   241 
       
   242     RPointerArray<CCaInnerEntry> resultArray;
       
   243     CleanupResetAndDestroyPushL( resultArray );
       
   244     aStorage->GetEntriesL( query, resultArray );
       
   245     
       
   246     if ( resultArray.Count() )
       
   247         {
       
   248         for (TInt i=0; i< resultArray.Count(); i++)
       
   249             {
       
   250             if ( resultArray[i]->GetText() == aText )
       
   251                 {
       
   252                 widget = CCaWidgetDescription::NewLC(resultArray[i]);
       
   253                 CleanupStack::Pop( widget );
       
   254                 }
       
   255             }
       
   256         }
       
   257 
       
   258     CleanupStack::PopAndDestroy( &resultArray );
       
   259     CleanupStack::PopAndDestroy( query );
       
   260 
       
   261     return widget;
       
   262     }
       
   263 
       
   264 //-----------------------------------------------------------------------
       
   265 //
       
   266 //-----------------------------------------------------------------------
       
   267 TInt CTestUtils::GetWidgetFlagsL(const TDesC& aText, CCaStorageProxy* aStorage)
       
   268     {
       
   269     
       
   270     TInt flags(0);
       
   271     CCaInnerQuery* query = CCaInnerQuery::NewLC();
       
   272     CDesC16ArrayFlat* widgetType = new ( ELeave ) CDesC16ArrayFlat(
       
   273             KGranularityOne );
       
   274     CleanupStack::PushL( widgetType );
       
   275     widgetType->AppendL( KCaTypeWidget );
       
   276     query->SetEntryTypeNames( widgetType );//transfers ownership to query
       
   277     CleanupStack::Pop( widgetType );
       
   278 
       
   279     RPointerArray<CCaInnerEntry> resultArray;
       
   280     CleanupResetAndDestroyPushL( resultArray );
       
   281     aStorage->GetEntriesL( query, resultArray );
       
   282     
       
   283     if ( resultArray.Count() )
       
   284         {
       
   285         for (TInt i=0; i< resultArray.Count(); i++)
       
   286             {
       
   287             if ( resultArray[i]->GetText() == aText )
       
   288                 {
       
   289                 
       
   290                 CCaInnerEntry* poin = resultArray[i];
       
   291                 flags = resultArray[i]->GetFlags();
       
   292                 }
       
   293             }
       
   294         }
       
   295 
       
   296     CleanupStack::PopAndDestroy( &resultArray );
       
   297     CleanupStack::PopAndDestroy( query );
       
   298 
       
   299     return flags;
       
   300     }
       
   301 //-----------------------------------------------------------------------
       
   302 //
       
   303 //-----------------------------------------------------------------------
       
   304 TInt CTestUtils::AppsWithFlagsOffL( TInt aFlags, CCaStorageProxy* aStorage)
       
   305     {
       
   306     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   307     CDesC16ArrayFlat* appType =
       
   308                         new (ELeave) CDesC16ArrayFlat( 1 );
       
   309     CleanupStack::PushL( appType );
       
   310     appType->AppendL( KCaTypeApp );
       
   311     satAppQuery->SetEntryTypeNames( appType );
       
   312 
       
   313     satAppQuery->SetFlagsOff( aFlags );
       
   314     RPointerArray<CCaInnerEntry> resultArray;
       
   315     CleanupResetAndDestroyPushL( resultArray );
       
   316     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   317 
       
   318     TInt count = resultArray.Count();
       
   319     CleanupStack::PopAndDestroy( &resultArray );
       
   320     CleanupStack::Pop( appType );
       
   321     CleanupStack::PopAndDestroy( satAppQuery );
       
   322 
       
   323     return count;
       
   324     }
       
   325 
       
   326 
       
   327 //-----------------------------------------------------------------------
       
   328 //
       
   329 //-----------------------------------------------------------------------
       
   330 TInt CTestUtils::GetAppFlagsL( TInt aUid, CCaStorageProxy* aStorage)
       
   331     {
       
   332     TInt flags(0);
       
   333     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   334     satAppQuery->SetUid( aUid );
       
   335     RPointerArray<CCaInnerEntry> resultArray;
       
   336     CleanupResetAndDestroyPushL( resultArray );
       
   337     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   338 
       
   339     if ( resultArray.Count() )
       
   340         {
       
   341         CCaInnerEntry* dbg = resultArray[0];
       
   342         flags = resultArray[0]->GetFlags();
       
   343         }
       
   344 
       
   345     CleanupStack::PopAndDestroy( &resultArray );
       
   346     CleanupStack::PopAndDestroy( satAppQuery );
       
   347 
       
   348     return flags;
       
   349     }
       
   350 
       
   351 
       
   352 //-----------------------------------------------------------------------
       
   353 //
       
   354 //-----------------------------------------------------------------------
       
   355 void CTestUtils::RemoveAppL( TInt aUid, CCaStorageProxy* aStorage)
       
   356     {
       
   357     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   358     satAppQuery->SetUid( aUid );
       
   359     RPointerArray<CCaInnerEntry> resultArray;
       
   360     CleanupResetAndDestroyPushL( resultArray );
       
   361     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   362 
       
   363     if ( resultArray.Count() )
       
   364         {
       
   365         CCaInnerEntry* dbg = resultArray[0];
       
   366         RArray<TInt> idsToRemove;
       
   367         CleanupClosePushL(idsToRemove);
       
   368         idsToRemove.AppendL( resultArray[0]->GetId() );
       
   369         aStorage->RemoveL(idsToRemove);
       
   370         CleanupStack::PopAndDestroy( &idsToRemove );
       
   371         }
       
   372 
       
   373     CleanupStack::PopAndDestroy( &resultArray );
       
   374     CleanupStack::PopAndDestroy( satAppQuery );
       
   375     }
       
   376 
       
   377 
       
   378 
       
   379 
       
   380 TUint CTestUtils::FindAppUidL( const TDesC& aName, CCaStorageProxy* aStorage )
       
   381     {
       
   382     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   383     CDesC16ArrayFlat* appType =
       
   384                         new (ELeave) CDesC16ArrayFlat( 1 );
       
   385     CleanupStack::PushL( appType );
       
   386     appType->AppendL( KCaTypeApp );
       
   387     satAppQuery->SetEntryTypeNames( appType );
       
   388 
       
   389     RPointerArray<CCaInnerEntry> resultArray;
       
   390     CleanupResetAndDestroyPushL( resultArray );
       
   391     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   392 
       
   393     TUint appUid(0);
       
   394     for ( TInt i = 0; i < resultArray.Count(); i++ )
       
   395         {
       
   396         if ( resultArray[i]->GetText() == aName )
       
   397             {
       
   398             appUid = resultArray[i]->GetUid();
       
   399             }
       
   400         }
       
   401     CleanupStack::PopAndDestroy( &resultArray );
       
   402     CleanupStack::Pop( appType );
       
   403     CleanupStack::PopAndDestroy( satAppQuery );
       
   404 
       
   405     return appUid;
       
   406     }
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 TInt CTestUtils::SimpleCloseTaskL(TInt aUid)
       
   411     {
       
   412     RWsSession session;
       
   413     TInt error = session.Connect();
       
   414     TUid uidApp( TUid::Uid( aUid )) ;
       
   415     TApaTaskList taskList( session );
       
   416     TApaTask task = taskList.FindApp( uidApp );
       
   417 
       
   418     if( task.Exists() )
       
   419         {
       
   420         task.EndTask();
       
   421         }
       
   422     else
       
   423         {
       
   424         error = KErrNotFound;
       
   425         }
       
   426 
       
   427     WaitL( 4000000 );
       
   428     session.Close();
       
   429     WaitL( 1000000  );
       
   430 
       
   431     return error;
       
   432     }
       
   433 
       
   434 // ----------------------------------------------------------------------------
       
   435 //
       
   436 void CTestUtils::InstallFinishedL()
       
   437     {
       
   438     iActiveWait->AsyncStop();
       
   439     }
       
   440 
       
   441 CCaSrvPlugin* CTestUtils::LoadPluginL( TUid aImplUid, TPluginParams* aPluginParams )
       
   442     {
       
   443     RImplInfoPtrArray infoArray;
       
   444 
       
   445     // Note that a special cleanup function is required to reset and destroy
       
   446     // all items in the array, and then close it.
       
   447     CleanupResetAndDestroyPushL( infoArray );
       
   448     CCaSrvPlugin::ListAllImplementationsL( infoArray );
       
   449 
       
   450     // Loop through each info for each implementation
       
   451     // and create and use each in turn
       
   452     CCaSrvPlugin* plug;
       
   453     for( TInt i = 0; i < infoArray.Count(); i++ )
       
   454         {
       
   455         // Slice off first sub-section in the data section
       
   456         TUid current_plugin = infoArray[i]->ImplementationUid();
       
   457         if ( current_plugin == aImplUid )
       
   458             {
       
   459             plug = CCaSrvPlugin::NewL( current_plugin, aPluginParams );
       
   460             CleanupStack::PushL( plug );
       
   461             TInt32 key = current_plugin.iUid;
       
   462             //iPluginMap.InsertL( key, plug );
       
   463             CleanupStack::Pop( plug );
       
   464             break;
       
   465             }
       
   466         plug = NULL;
       
   467         }
       
   468     CleanupStack::PopAndDestroy( &infoArray );
       
   469     return plug;
       
   470     }
       
   471 
       
   472 
       
   473 
       
   474