homescreensrv_plat/context_utility_api/tsrc/src/t_ui_context_utility_api.cpp
branchRCL_3
changeset 14 15e4dd19031c
parent 12 502e5d91ad42
child 15 a0713522ab97
equal deleted inserted replaced
12:502e5d91ad42 14:15e4dd19031c
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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:  T_ui_context_utility_api class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <Stiftestinterface.h>
       
    22 #include <aknappui.h>
       
    23 #include <cfclient.h>
       
    24 #include "hgcontextutilityimpl.h"
       
    25 #include "hgcontextutility.h"
       
    26 #include "hgcontexttypes.h"
       
    27 #include "hgtestbasemacros.h"
       
    28 #include "T_ui_context_utility_api.h"
       
    29 #include "wait.h"
       
    30 #include "hgtestbasemacros.h"
       
    31 #include <cvpbkcontactmanager.h>
       
    32 #include <mvpbkcontactstore.h>
       
    33 #include <mvpbkcontactfieldtextdata.h>
       
    34 #include <mvpbkstorecontact.h>
       
    35 #include <MVPbkContactObserver.h>
       
    36 #include <MVPbkBatchOperationObserver.h>
       
    37 #include <CVPbkContactLinkArray.h>
       
    38 #include <MVPbkContactOperationBase.h>
       
    39 #include <VPbkEng.rsg>
       
    40 #include <mdesession.h>
       
    41 #include <e32math.h>
       
    42 #include <aknappui.h>
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CT_ui_context_utility_api::CT_ui_context_utility_api
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CT_ui_context_utility_api::CT_ui_context_utility_api()
       
    52     {
       
    53     iTestDllName = _L("CT_ui_context_utility_api").AllocL();
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CT_ui_context_utility_api::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 //
       
    60 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created
       
    61 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger
       
    62 // allocates memory from heap and therefore causes error situations with OOM
       
    63 // testing. For more information about STIF Logger construction, see STIF Users
       
    64 // Guide.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CT_ui_context_utility_api::ConstructL()
       
    68     {
       
    69     CHgTestBase::BaseConstructL( KT_ui_context_utility_apiLogPath,
       
    70                              KT_ui_context_utility_apiLogFile );
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CT_ui_context_utility_api::NewL
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CT_ui_context_utility_api* CT_ui_context_utility_api::NewL()
       
    79     {
       
    80     CT_ui_context_utility_api* self = new (ELeave) CT_ui_context_utility_api;
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     CleanupStack::Pop( self );
       
    84     return self;
       
    85     }
       
    86 
       
    87 // Destructor
       
    88 CT_ui_context_utility_api::~CT_ui_context_utility_api()
       
    89     {
       
    90 
       
    91     }
       
    92 
       
    93 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // LibEntryL is a polymorphic Dll entry point
       
    97 // Returns: CTestModuleBase*: Pointer to Test Module object
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 EXPORT_C CTestModuleBase* LibEntryL()
       
   101     {
       
   102     return CT_ui_context_utility_api::NewL();
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // SetRequirements handles test module parameters(implements evolution
       
   107 // version 1 for test module's heap and stack sizes configuring).
       
   108 // Returns: TInt: Symbian error code.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/,
       
   112                                 TUint32& /*aParameterValid*/ )
       
   113     {
       
   114     return KErrNone;
       
   115     }
       
   116 
       
   117 //// -----------------------------------------------------------------------------
       
   118 //// CT_ui_context_utility_api::RunTestL
       
   119 //// Method responsible for enumerating and running test cases (and also setup and teardown activities before
       
   120 //// and after each test case).
       
   121 //// -----------------------------------------------------------------------------
       
   122 TInt CT_ui_context_utility_api::RunTestL(
       
   123         CT_ui_context_utility_api::TCallReason aRunReason, 
       
   124         TInt aTestToRun, 
       
   125         RPointerArray<TTestCaseInfo>& aTestCases,
       
   126         TTestResult& aResult )
       
   127     {
       
   128     TInt _test_case_no = -1;
       
   129     //test cases, setup and teardown include
       
   130     
       
   131     
       
   132     if( aRunReason == CHgTestBase::ERunTestCase )
       
   133         {
       
   134         LoadTestCasesL(_test_case_no, aRunReason, STIF_RUN_SETUP, aTestCases, aResult);
       
   135 		LoadTestCasesL(_test_case_no, aRunReason, aTestToRun, aTestCases, aResult);
       
   136 		LoadTestCasesL(_test_case_no, aRunReason, STIF_RUN_TEARDOWN, aTestCases, aResult);
       
   137         CreateEnvL();
       
   138         _test_case_no = -1;
       
   139         TRAPD(
       
   140                 errCode, 
       
   141                 LoadTestCasesL(_test_case_no, aRunReason, STIF_RUN_SETUP, aTestCases, aResult);
       
   142                 LoadTestCasesL(_test_case_no, aRunReason, aTestToRun, aTestCases, aResult);
       
   143                 LoadTestCasesL(_test_case_no, aRunReason, STIF_RUN_TEARDOWN, aTestCases, aResult);
       
   144              )
       
   145         DestroyEnv();
       
   146         User::LeaveIfError( errCode );
       
   147         }
       
   148     else
       
   149     	{
       
   150     	LoadTestCasesL(_test_case_no, aRunReason, aTestToRun, aTestCases, aResult);
       
   151     	}
       
   152     
       
   153     return _test_case_no;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // -----------------------------------------------------------------------------
       
   158 void CT_ui_context_utility_api::CreateEnvL()
       
   159     {
       
   160     CActiveScheduler::Install ( NULL );
       
   161     ENV_cleanup = CTrapCleanup::New();
       
   162     TInt ENV_err = KErrNone;
       
   163     ENV_env = new CEikonEnv;
       
   164     if ( ENV_env ) 
       
   165         { 
       
   166         TRAP( ENV_err, ENV_env->ConstructL() ); 
       
   167         if ( ENV_err ) 
       
   168             { 
       
   169             return; 
       
   170             }
       
   171         ENV_aknAppUI = new CAknAppUi;
       
   172         if (ENV_aknAppUI)
       
   173             {
       
   174             TRAP( ENV_err, ENV_aknAppUI->BaseConstructL( CEikAppUi::ENoAppResourceFile ) ); \
       
   175             if ( ENV_err )
       
   176                 {
       
   177                 return;
       
   178                 }
       
   179             }
       
   180         }
       
   181     }
       
   182 // -----------------------------------------------------------------------------
       
   183 // -----------------------------------------------------------------------------
       
   184 void CT_ui_context_utility_api::DestroyEnv()
       
   185     {
       
   186     TInt KWait( 500000 );
       
   187     CActiveSchedulerWait*  wait = new (ELeave) CActiveSchedulerWait();
       
   188     CPeriodic*  periodic = CPeriodic::NewL( CActive::EPriorityIdle );
       
   189     periodic->Start(KWait, KWait, TCallBack( CHgTestBase::CallStop, wait ) );
       
   190     wait->Start();
       
   191     delete periodic;
       
   192     delete wait;
       
   193     
       
   194     if ( ENV_aknAppUI ) 
       
   195         { 
       
   196         ENV_aknAppUI->PrepareToExit(); 
       
   197         }
       
   198     if ( ENV_env ) 
       
   199         { 
       
   200         ENV_env->DestroyEnvironment(); 
       
   201         }
       
   202     if( ENV_cleanup )
       
   203         {
       
   204         delete ENV_cleanup;
       
   205         }
       
   206     CActiveScheduler::Install ( iActiveScheduler );
       
   207     }
       
   208 // -----------------------------------------------------------------------------
       
   209 // -----------------------------------------------------------------------------
       
   210 TInt CT_ui_context_utility_api::LoadTestCasesL(
       
   211                     TInt& _test_case_no,
       
   212                     CT_ui_context_utility_api::TCallReason aRunReason,
       
   213                     TInt aTestToRun,
       
   214                     RPointerArray<TTestCaseInfo>& aTestCases,
       
   215                     TTestResult& aResult)
       
   216     {
       
   217 #define TEST_CASES
       
   218     #include "..\src\T_ui_context_utility_api_cases.cpp"
       
   219 #undef TEST_CASES
       
   220     return KErrNone;
       
   221     }
       
   222 //  End of File