contentstorage/casrv/carunningappmonitor/tsrc/t_carunningappmonitor/src/carunningappmonitortestutils.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 "cadef.h"
       
    30 #include "castorageproxy.h"
       
    31 #include "cainnerentry.h"
       
    32 #include "cainnerquery.h"
       
    33 #include "caarraycleanup.inl"
       
    34 #include "casrvplugin.h"
       
    35 
       
    36 
       
    37 #include "waitactive.h"
       
    38 #include "carunningappmonitortestutils.h"
       
    39 #include "testconsts.h"
       
    40 
       
    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 TInt CTestUtils::Copy( const TDesC& aSource, const TDesC& aDest )
       
   102     {
       
   103     return iFileManager->Copy(aSource, aDest);
       
   104     }
       
   105 
       
   106 //-----------------------------------------------------------------------
       
   107 //
       
   108 //-----------------------------------------------------------------------
       
   109 TInt CTestUtils::CopyDb()
       
   110     {
       
   111     return Copy(KTestDbSource, KTestDbDest);
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 TInt CTestUtils::LaunchApplicationL( const TUid aUid )
       
   119     {
       
   120     RWsSession wsSession;
       
   121     User::LeaveIfError( wsSession.Connect() );
       
   122     CleanupClosePushL<RWsSession>( wsSession );
       
   123 
       
   124     CAknTaskList* taskList = CAknTaskList::NewL( wsSession );
       
   125     TApaTask task = taskList->FindRootApp( aUid );
       
   126     delete taskList;
       
   127 
       
   128     if ( task.Exists() )
       
   129         {
       
   130         task.BringToForeground();
       
   131         }
       
   132     else
       
   133         {
       
   134         TApaAppInfo appInfo;
       
   135         TApaAppCapabilityBuf capabilityBuf;
       
   136         RApaLsSession appArcSession;
       
   137         User::LeaveIfError( appArcSession.Connect() );
       
   138         CleanupClosePushL<RApaLsSession>( appArcSession );
       
   139 
       
   140         User::LeaveIfError( appArcSession.GetAppInfo( appInfo, aUid ) );
       
   141         User::LeaveIfError( appArcSession.GetAppCapability( capabilityBuf, aUid ) );
       
   142 
       
   143         TApaAppCapability& caps = capabilityBuf();
       
   144         TFileName appName = appInfo.iFullName;
       
   145         CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   146         cmdLine->SetExecutableNameL( appName );
       
   147 
       
   148         if ( caps.iLaunchInBackground )
       
   149             {
       
   150             cmdLine->SetCommandL( EApaCommandBackground );
       
   151             }
       
   152         else
       
   153             {
       
   154             cmdLine->SetCommandL( EApaCommandRun );
       
   155             }
       
   156 
       
   157         User::LeaveIfError( appArcSession.StartApp( *cmdLine ) );
       
   158 
       
   159         CleanupStack::PopAndDestroy( cmdLine );
       
   160         CleanupStack::PopAndDestroy( &appArcSession );
       
   161         }
       
   162     CleanupStack::PopAndDestroy( &wsSession );
       
   163 
       
   164     //verification if app has really launched
       
   165     WaitL(2000000);
       
   166     RWsSession verWsSession;
       
   167     User::LeaveIfError( verWsSession.Connect() );
       
   168     CleanupClosePushL<RWsSession>( verWsSession );
       
   169 
       
   170     CAknTaskList* verTaskList = CAknTaskList::NewL( verWsSession );
       
   171     TApaTask verTask = verTaskList->FindRootApp( aUid );
       
   172     delete verTaskList;
       
   173 
       
   174     TInt result(KErrGeneral);
       
   175     if ( verTask.Exists() )
       
   176         {
       
   177         result = KErrNone;
       
   178         }
       
   179     CleanupStack::PopAndDestroy( &verWsSession );
       
   180     return result;
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 TInt CTestUtils::TerminateApplicationL( const TUid aUid )
       
   188     {
       
   189     TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
   190     TApaTask task = taskList.FindApp(aUid);
       
   191     if (!task.Exists()) 
       
   192         {
       
   193         return KErrNotFound; 
       
   194         }
       
   195     task.EndTask();
       
   196     WaitL(2000000);
       
   197     TApaTaskList newTaskList(CEikonEnv::Static()->WsSession());
       
   198     return newTaskList.FindApp(aUid).Exists() ? KErrGeneral : KErrNone;
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CTestUtils::WaitL(TInt aMicroSec)
       
   206     {
       
   207     CWaitActive* wait = CWaitActive::NewL();
       
   208     wait->Wait(aMicroSec);
       
   209     delete wait;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TBool CTestUtils::IsRunningL(TUid aAppUid, CCaStorageProxy& aStorage)const
       
   217     {
       
   218     TBool retVal(EFalse);
       
   219     RPointerArray<CCaInnerEntry> array;
       
   220     CleanupResetAndDestroyPushL(array);
       
   221     
       
   222     CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
       
   223     allAppQuery->SetUid(static_cast<TUint>(aAppUid.iUid));
       
   224     aStorage.GetEntriesL(allAppQuery, array);
       
   225     CleanupStack::PopAndDestroy( allAppQuery );
       
   226     
       
   227     if(0 >= array.Count())
       
   228         {
       
   229         User::Leave(KErrNotFound);
       
   230         }
       
   231     CCaInnerEntry* entry = array[0];
       
   232     if( entry->GetFlags() & ERunning )
       
   233         {
       
   234         RBuf value;
       
   235         CleanupClosePushL(value);
       
   236         value.CreateL(KCaMaxAttrValueLen);
       
   237         if( entry->FindAttribute(KCaAttrWindowGroupId, value) )
       
   238             {
       
   239             retVal = ETrue;
       
   240             }
       
   241         CleanupStack::PopAndDestroy(&value);
       
   242         }
       
   243     CleanupStack::PopAndDestroy(&array);
       
   244     return retVal;
       
   245     }