idlefw/tsrc/framework/ut_aifw/ut_aiecomobserver/src/ut_aiecomobserver.cpp
branchRCL_3
changeset 110 2c7f27287390
equal deleted inserted replaced
101:9e077f9a342c 110:2c7f27287390
       
     1 /*
       
     2 * Copyright (c) 2004 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: EUnit unit test class for CAiStateProvider
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <e32base.h>
       
    20 #include <e32cmn.h> 
       
    21 #include <digia/eunit/eunitmacros.h>
       
    22 #include <digia/eunit/teunitassertioninfo.h>
       
    23 
       
    24 // User includes
       
    25 #include "ut_aiecomobserver.h"
       
    26 
       
    27 #include "aiecomobserver.h"
       
    28 
       
    29 // Constants
       
    30 
       
    31 
       
    32 // ======== LOCAL FUNCTIONS ========
       
    33     
       
    34 // ======== MEMBER FUNCTIONS =======
       
    35 // ----------------------------------------------------------------------------
       
    36 // UT_AiEcomObserver::NewL()
       
    37 //
       
    38 // ----------------------------------------------------------------------------
       
    39 //
       
    40 UT_AiEcomObserver* UT_AiEcomObserver::NewL()
       
    41     {
       
    42     UT_AiEcomObserver* self = UT_AiEcomObserver::NewLC();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // UT_AiEcomObserver::NewLC()
       
    49 //
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 UT_AiEcomObserver* UT_AiEcomObserver::NewLC()
       
    53     {
       
    54     UT_AiEcomObserver* self = new ( ELeave ) UT_AiEcomObserver();
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // UT_AiEcomObserver::~UT_AiEcomObserver()
       
    62 //
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 UT_AiEcomObserver::~UT_AiEcomObserver()
       
    66     {    
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // UT_AiEcomObserver::UT_AiEcomObserver()
       
    71 //
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 UT_AiEcomObserver::UT_AiEcomObserver()
       
    75     {
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // UT_AiEcomObserver::ConstructL()
       
    80 //
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 void UT_AiEcomObserver::ConstructL()
       
    84     {
       
    85     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    86     // It generates the test case table.
       
    87     CEUnitTestSuiteClass::ConstructL();
       
    88     }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // UT_AiEcomObserver::SetupL()
       
    92 //
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 void UT_AiEcomObserver::SetupL()
       
    96     {
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // UT_AiEcomObserver::Teardown()
       
   101 //
       
   102 // ----------------------------------------------------------------------------
       
   103 //
       
   104 void UT_AiEcomObserver::Teardown()
       
   105     {
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // UT_AiEcomObserver::NotifyEcomRegistryChanged()
       
   110 //
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 void UT_AiEcomObserver::NotifyEcomRegistryChanged()
       
   114     {
       
   115     iNotificationReceived = ETrue;
       
   116     
       
   117     iWait->AsyncStop();
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // UT_AiEcomObserver::TestStartObserveL()
       
   122 //
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 void UT_AiEcomObserver::TestStartObserveL()
       
   126     {
       
   127     CAiEcomObserver* observer = CAiEcomObserver::NewLC();
       
   128     
       
   129     EUNIT_ASSERT_EQUALS( observer->iEComSession.Handle() != 0, ETrue );
       
   130     EUNIT_ASSERT_EQUALS( observer->IsAdded(), ETrue );
       
   131     EUNIT_ASSERT_EQUALS( observer->IsActive(), ETrue );
       
   132     EUNIT_ASSERT_EQUALS( observer->iObservers.Count(), 0 );
       
   133     
       
   134     CleanupStack::PopAndDestroy( observer );
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // UT_AiEcomObserver::TestAddObserverL()
       
   139 //
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 void UT_AiEcomObserver::TestAddObserverL()
       
   143     {
       
   144     CAiEcomObserver* observer = CAiEcomObserver::NewLC();
       
   145 
       
   146     observer->AddObserverL( NULL );
       
   147     
       
   148     EUNIT_ASSERT_EQUALS( observer->iObservers.Count(), 0 );
       
   149     
       
   150     observer->AddObserverL( this );       
       
   151     
       
   152     EUNIT_ASSERT_EQUALS( observer->iObservers.Count(), 1 );
       
   153     EUNIT_ASSERT_EQUALS( observer->iObservers[0] == this, ETrue );
       
   154     
       
   155     CleanupStack::PopAndDestroy( observer );    
       
   156     }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // UT_AiEcomObserver::TestNotifyObserverL()
       
   160 //
       
   161 // ----------------------------------------------------------------------------
       
   162 //
       
   163 void UT_AiEcomObserver::TestNotifyObserverL()
       
   164     {
       
   165     iNotificationReceived = EFalse;
       
   166 
       
   167     iWait = new ( ELeave ) CActiveSchedulerWait;
       
   168            
       
   169     CAiEcomObserver* observer = CAiEcomObserver::NewLC();
       
   170 
       
   171     observer->AddObserverL( this );       
       
   172 
       
   173     EUNIT_ASSERT_EQUALS( observer->IsAdded(), ETrue );
       
   174     EUNIT_ASSERT_EQUALS( observer->IsActive(), ETrue );
       
   175     
       
   176     TRequestStatus* stat( &observer->iStatus );
       
   177     
       
   178     User::RequestComplete( stat, KErrNone );
       
   179                    
       
   180     iWait->Start();
       
   181 
       
   182     delete iWait;
       
   183     iWait = NULL;
       
   184         
       
   185     EUNIT_ASSERT_EQUALS( iNotificationReceived, ETrue );
       
   186 
       
   187     // Ensure observer is active again
       
   188     EUNIT_ASSERT_EQUALS( observer->IsAdded(), ETrue );
       
   189     EUNIT_ASSERT_EQUALS( observer->IsActive(), ETrue );        
       
   190         
       
   191     CleanupStack::PopAndDestroy( observer );        
       
   192     }
       
   193 
       
   194 //------------------------------------------------------------------------------
       
   195 // Test case table
       
   196 //
       
   197 //------------------------------------------------------------------------------
       
   198 //
       
   199 EUNIT_BEGIN_TEST_TABLE(
       
   200     UT_AiEcomObserver,
       
   201     "Unit test suite for CAiEcomObserver",
       
   202     "UNIT" )
       
   203 
       
   204     EUNIT_TEST(
       
   205         "Start observe",
       
   206         "CAiEcomObserver",
       
   207         "",
       
   208         "FUNCTIONALITY",
       
   209         SetupL, TestStartObserveL, Teardown )
       
   210         
       
   211     EUNIT_TEST(
       
   212         "Add observer",
       
   213         "CAiEcomObserver",
       
   214         "",
       
   215         "FUNCTIONALITY",
       
   216         SetupL, TestAddObserverL, Teardown )
       
   217 
       
   218     EUNIT_TEST(
       
   219         "notify Observer",
       
   220         "CAiEcomObserver",
       
   221         "",
       
   222         "FUNCTIONALITY",
       
   223         SetupL, TestNotifyObserverL, Teardown )
       
   224 
       
   225 EUNIT_END_TEST_TABLE
       
   226 
       
   227 // End of file