contentstorage/casrv/casatmonitor/tsrc/t_satmonitor/src/casatmonitortestutils.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 "casatmonitortestutils.h"
       
    36 #include "testconsts.h"
       
    37 
       
    38 
       
    39 //-----------------------------------------------------------------------
       
    40 // CONSTRUCTION
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CTestUtils* CTestUtils::NewL()
       
    44     {
       
    45     CTestUtils* self = CTestUtils::NewLC();
       
    46     CleanupStack::Pop();
       
    47 
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CTestUtils* CTestUtils::NewLC()
       
    56     {
       
    57     CTestUtils* self = new( ELeave ) CTestUtils();
       
    58     CleanupStack::PushL( self );
       
    59 
       
    60     self->ConstructL();
       
    61 
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Destructor (virtual by CBase)
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CTestUtils::~CTestUtils()
       
    70     {
       
    71 	iFileManager->Delete(KTestDbDest);
       
    72     delete iFileManager;    iFileManager = NULL;
       
    73     iFs.Close();
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Default constructor
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CTestUtils::CTestUtils()
       
    81     {
       
    82 
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Second phase construct
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CTestUtils::ConstructL()
       
    90     {
       
    91     User::LeaveIfError( iFs.Connect() );
       
    92     iFileManager = CFileMan::NewL( iFs );
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CTestUtils::WaitL(TInt aMicroSec)
       
   100     {
       
   101     CWaitActive* wait = CWaitActive::NewL();
       
   102     wait->Wait(aMicroSec);
       
   103     delete wait;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CTestUtils::GetRProperty
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 TInt CTestUtils::GetRProperty( TUid aCategory, TUint aKey, TDes& aValue )
       
   111     {
       
   112     return RProperty::Get( aCategory, aKey, aValue );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CTestUtils::GetRProperty
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 TInt CTestUtils::GetRProperty( TUid aCategory, TUint aKey, TInt& aValue )
       
   120     {
       
   121     return RProperty::Get( aCategory, aKey, aValue );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CTestUtils::SetRProperty
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TInt CTestUtils::SetRProperty( TUid aCategory, TUint aKey, const TDesC& aValue )
       
   129     {
       
   130     return RProperty::Set( aCategory, aKey, aValue );
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CTestUtils::SetRProperty
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 TInt CTestUtils::SetRProperty( TUid aCategory, TUint aKey, TInt aValue )
       
   138     {
       
   139     return RProperty::Set( aCategory, aKey, aValue );
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CTestUtils::DefineRProperty
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 TInt CTestUtils::DefineTextRProperty( TUid aCategory, TUint aKey )
       
   147     {
       
   148     return RProperty::Define( aCategory, aKey, RProperty::EText );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CTestUtils::DefineIntRProperty
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 TInt CTestUtils::DefineIntRProperty( TUid aCategory, TUint aKey )
       
   156     {
       
   157     return RProperty::Define( aCategory, aKey, RProperty::EInt );
       
   158     }
       
   159 
       
   160 //-----------------------------------------------------------------------
       
   161 //
       
   162 //-----------------------------------------------------------------------
       
   163 TInt CTestUtils::Copy( const TDesC& aSource, const TDesC& aDest )
       
   164     {
       
   165     return iFileManager->Copy(aSource, aDest);
       
   166     }
       
   167 
       
   168 //-----------------------------------------------------------------------
       
   169 //
       
   170 //-----------------------------------------------------------------------
       
   171 TInt CTestUtils::CopyDb()
       
   172     {
       
   173     return Copy(KTestDbSource, KTestDbDest);
       
   174     }
       
   175 
       
   176 //-----------------------------------------------------------------------
       
   177 //
       
   178 //-----------------------------------------------------------------------
       
   179 TBool CTestUtils::AppExistsInStorageL( TInt aUid, CCaStorageProxy* aStorage)
       
   180     {
       
   181     TBool exists(EFalse);
       
   182     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   183     satAppQuery->SetUid( aUid );
       
   184     RPointerArray<CCaInnerEntry> resultArray;
       
   185     CleanupResetAndDestroyPushL( resultArray );
       
   186     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   187 
       
   188     if ( resultArray.Count() )
       
   189         {
       
   190         CCaInnerEntry* dbg = resultArray[0];
       
   191         exists = ETrue;
       
   192         }
       
   193 
       
   194     CleanupStack::PopAndDestroy( &resultArray );
       
   195     CleanupStack::PopAndDestroy( satAppQuery );
       
   196 
       
   197     return exists;
       
   198     }
       
   199 
       
   200 //-----------------------------------------------------------------------
       
   201 //
       
   202 //-----------------------------------------------------------------------
       
   203 CCaInnerEntry* CTestUtils::GetAppEntryL( TInt aUid, CCaStorageProxy* aStorage)
       
   204     {
       
   205     CCaInnerEntry* entry = NULL;
       
   206     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   207     satAppQuery->SetUid( aUid );
       
   208     RPointerArray<CCaInnerEntry> resultArray;
       
   209     CleanupResetAndDestroyPushL( resultArray );
       
   210     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   211 
       
   212     if ( resultArray.Count() )
       
   213         {
       
   214         entry = resultArray[0];
       
   215         resultArray.Remove(0);
       
   216         }
       
   217 
       
   218     CleanupStack::PopAndDestroy( &resultArray );
       
   219     CleanupStack::PopAndDestroy( satAppQuery );
       
   220 
       
   221     return entry;
       
   222     }
       
   223 
       
   224 //-----------------------------------------------------------------------
       
   225 //
       
   226 //-----------------------------------------------------------------------
       
   227 TInt CTestUtils::AppsWithFlagsOffL( TInt aFlags, CCaStorageProxy* aStorage)
       
   228     {
       
   229     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   230     CDesC16ArrayFlat* appType =
       
   231                         new (ELeave) CDesC16ArrayFlat( 1 );
       
   232     CleanupStack::PushL( appType );
       
   233     appType->AppendL( KCaTypeApp );
       
   234     satAppQuery->SetEntryTypeNames( appType );
       
   235 
       
   236     satAppQuery->SetFlagsOff( aFlags );
       
   237     RPointerArray<CCaInnerEntry> resultArray;
       
   238     CleanupResetAndDestroyPushL( resultArray );
       
   239     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   240 
       
   241     TInt count = resultArray.Count();
       
   242     CleanupStack::PopAndDestroy( &resultArray );
       
   243     CleanupStack::Pop( appType );
       
   244     CleanupStack::PopAndDestroy( satAppQuery );
       
   245 
       
   246     return count;
       
   247     }
       
   248 
       
   249 
       
   250 //-----------------------------------------------------------------------
       
   251 //
       
   252 //-----------------------------------------------------------------------
       
   253 TInt CTestUtils::GetAppFlagsL( TInt aUid, CCaStorageProxy* aStorage)
       
   254     {
       
   255     TInt flags(0);
       
   256     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   257     satAppQuery->SetUid( aUid );
       
   258     RPointerArray<CCaInnerEntry> resultArray;
       
   259     CleanupResetAndDestroyPushL( resultArray );
       
   260     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   261 
       
   262     if ( resultArray.Count() )
       
   263         {
       
   264         CCaInnerEntry* dbg = resultArray[0];
       
   265         flags = resultArray[0]->GetFlags();
       
   266         }
       
   267 
       
   268     CleanupStack::PopAndDestroy( &resultArray );
       
   269     CleanupStack::PopAndDestroy( satAppQuery );
       
   270 
       
   271     return flags;
       
   272     }
       
   273 
       
   274 
       
   275 //-----------------------------------------------------------------------
       
   276 //
       
   277 //-----------------------------------------------------------------------
       
   278 void CTestUtils::RemoveAppL( TInt aUid, CCaStorageProxy* aStorage)
       
   279     {
       
   280     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   281     satAppQuery->SetUid( aUid );
       
   282     RPointerArray<CCaInnerEntry> resultArray;
       
   283     CleanupResetAndDestroyPushL( resultArray );
       
   284     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   285 
       
   286     if ( resultArray.Count() )
       
   287         {
       
   288         CCaInnerEntry* dbg = resultArray[0];
       
   289         RArray<TInt> idsToRemove;
       
   290         CleanupClosePushL(idsToRemove);
       
   291         idsToRemove.AppendL( resultArray[0]->GetId() );
       
   292         aStorage->RemoveL(idsToRemove);
       
   293         CleanupStack::PopAndDestroy( &idsToRemove );
       
   294         }
       
   295 
       
   296     CleanupStack::PopAndDestroy( &resultArray );
       
   297     CleanupStack::PopAndDestroy( satAppQuery );
       
   298     }
       
   299 
       
   300 //-----------------------------------------------------------------------
       
   301 //
       
   302 //-----------------------------------------------------------------------
       
   303 TUint CTestUtils::FingAppUidL( const TDesC& aName, CCaStorageProxy* aStorage )
       
   304     {
       
   305     CCaInnerQuery* satAppQuery = CCaInnerQuery::NewLC();
       
   306     CDesC16ArrayFlat* appType =
       
   307                         new (ELeave) CDesC16ArrayFlat( 1 );
       
   308     CleanupStack::PushL( appType );
       
   309     appType->AppendL( KCaTypeApp );
       
   310     satAppQuery->SetEntryTypeNames( appType );
       
   311 
       
   312     RPointerArray<CCaInnerEntry> resultArray;
       
   313     CleanupResetAndDestroyPushL( resultArray );
       
   314     aStorage->GetEntriesL( satAppQuery, resultArray );
       
   315 
       
   316     TUint appUid(0);
       
   317     for ( TInt i = 0; i < resultArray.Count(); i++ )
       
   318         {
       
   319         if ( resultArray[i]->GetText() == aName )
       
   320             {
       
   321             appUid = resultArray[i]->GetUid();
       
   322             }
       
   323         }
       
   324     CleanupStack::PopAndDestroy( &resultArray );
       
   325     CleanupStack::Pop( appType );
       
   326     CleanupStack::PopAndDestroy( satAppQuery );
       
   327 
       
   328     return appUid;
       
   329     }
       
   330 
       
   331 //-----------------------------------------------------------------------
       
   332 //
       
   333 //-----------------------------------------------------------------------
       
   334 CCaSrvPlugin* CTestUtils::LoadPluginL( TUid aImplUid, TPluginParams aPluginParams )
       
   335     {
       
   336     RImplInfoPtrArray infoArray;
       
   337 
       
   338     // Note that a special cleanup function is required to reset and destroy
       
   339     // all items in the array, and then close it.
       
   340     CleanupResetAndDestroyPushL( infoArray );
       
   341     CCaSrvPlugin::ListAllImplementationsL( infoArray );
       
   342 
       
   343     // Loop through each info for each implementation
       
   344     // and create and use each in turn
       
   345     CCaSrvPlugin* plug;
       
   346     for( TInt i = 0; i < infoArray.Count(); i++ )
       
   347         {
       
   348         // Slice off first sub-section in the data section
       
   349         TUid current_plugin = infoArray[i]->ImplementationUid();
       
   350         if ( current_plugin == aImplUid )
       
   351             {
       
   352             plug = CCaSrvPlugin::NewL( current_plugin, &aPluginParams );
       
   353             CleanupStack::PushL( plug );
       
   354             TInt32 key = current_plugin.iUid;
       
   355             //iPluginMap.InsertL( key, plug );
       
   356             CleanupStack::Pop( plug );
       
   357             break;
       
   358             }
       
   359         plug = NULL;
       
   360         }
       
   361     CleanupStack::PopAndDestroy( &infoArray );
       
   362     return plug;
       
   363     }
       
   364 
       
   365 
       
   366 
       
   367