idlefw/tsrc/ai_utilities_api/src/mt_apiaipspropertyobserver.cpp
branchRCL_3
changeset 28 053c6c7c14f3
equal deleted inserted replaced
27:2c7f27287390 28:053c6c7c14f3
       
     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 // CLASS UNDER TEST
       
    19 #include <caouserafter.h>
       
    20 #include <aiutility.h>
       
    21 #include <caipspropertyobserver.h>
       
    22 
       
    23 #include <mt_apiaipspropertyobserver.h>
       
    24 #include <digia/eunit/eunitmacros.h>
       
    25 
       
    26 const TInt KRandTestUid( 0x017000F5 );
       
    27 const TInt KRandTestKey( 0x000000FF );
       
    28 
       
    29 void ChangeKeyValueL( TInt aValue )
       
    30     {
       
    31     RProperty::Define( TUid::Uid( KRandTestUid ),
       
    32                        KRandTestKey,
       
    33                        RProperty::EInt );
       
    34                                 
       
    35     User::LeaveIfError( 
       
    36                     RProperty::Set( TUid::Uid( KRandTestUid ),
       
    37                     KRandTestKey,
       
    38                     aValue ) );
       
    39     
       
    40     }
       
    41 
       
    42 
       
    43 // CONSTRUCTION
       
    44 MT_ApiAiPSPropertyObserver* MT_ApiAiPSPropertyObserver::NewL()
       
    45     {
       
    46     MT_ApiAiPSPropertyObserver* self = MT_ApiAiPSPropertyObserver::NewLC();
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 MT_ApiAiPSPropertyObserver* MT_ApiAiPSPropertyObserver::NewLC()
       
    52     {
       
    53     MT_ApiAiPSPropertyObserver* self = new( ELeave ) MT_ApiAiPSPropertyObserver();
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     return self;
       
    57     }
       
    58 
       
    59 // Destructor (virtual by CBase)
       
    60 MT_ApiAiPSPropertyObserver::~MT_ApiAiPSPropertyObserver()
       
    61     {
       
    62 #if _BullseyeCoverage
       
    63     cov_write();
       
    64 #endif
       
    65     }
       
    66 
       
    67 // Default constructor
       
    68 MT_ApiAiPSPropertyObserver::MT_ApiAiPSPropertyObserver()
       
    69     {
       
    70     }
       
    71 
       
    72 // Second phase construct
       
    73 void MT_ApiAiPSPropertyObserver::ConstructL()
       
    74     {
       
    75     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    76     // It generates the test case table.
       
    77     CEUnitTestSuiteClass::ConstructL();
       
    78 
       
    79     ChangeKeyValueL( 5 );
       
    80     CAOUserAfter::AfterLD( 2 * 1000000 );
       
    81     }
       
    82 
       
    83 //  METHODS
       
    84 
       
    85 TInt MT_ApiAiPSPropertyObserver::HandleSystemStateChangedL(TAny* aPtr)
       
    86     {
       
    87     MT_ApiAiPSPropertyObserver* self =
       
    88         static_cast<MT_ApiAiPSPropertyObserver*>( aPtr );
       
    89     TInt value = 0;
       
    90     
       
    91     self->iPSObserver->Get(value);
       
    92 	
       
    93     if ( value == 10 )
       
    94 		{
       
    95 		self->iStateOk = ETrue;
       
    96 		}
       
    97 	
       
    98     return KErrNone;
       
    99     }
       
   100 
       
   101 void MT_ApiAiPSPropertyObserver::SetupL(  )
       
   102     {
       
   103     iPSObserver = AiUtility::CreatePSPropertyObserverL(
       
   104                 TCallBack( HandleSystemStateChangedL, this ),
       
   105                 TUid::Uid( KRandTestUid ),
       
   106                 KRandTestKey );
       
   107     }
       
   108 
       
   109 void MT_ApiAiPSPropertyObserver::Teardown(  )
       
   110     {
       
   111     Release( iPSObserver );
       
   112     }
       
   113 
       
   114 void MT_ApiAiPSPropertyObserver::TestBasicFunctionalityL(  )
       
   115     {
       
   116     MAiPSPropertyObserver* obs = NULL;
       
   117     // Test that Release(NULL) does not crash
       
   118     Release(obs);
       
   119     
       
   120     // test
       
   121     ChangeKeyValueL( 10 );
       
   122     CAOUserAfter::AfterLD( 2 * 1000000 );
       
   123     if( iStateOk )
       
   124         {
       
   125         EUNIT_ASSERT( ETrue );
       
   126         return;
       
   127         }
       
   128     EUNIT_ASSERT( EFalse );
       
   129     }
       
   130 
       
   131 void MT_ApiAiPSPropertyObserver::TestGettersL(  )
       
   132     {
       
   133     TInt err = KErrNone;
       
   134     TBuf16<100> buf16;
       
   135     TBuf8<100> buf8;
       
   136     TInt value = 0;
       
   137     err = iPSObserver->Get(buf16);
       
   138     
       
   139     EUNIT_ASSERT( err != KErrNone );
       
   140    
       
   141     err = KErrNone;
       
   142     err = iPSObserver->Get(buf8);
       
   143 
       
   144     EUNIT_ASSERT( err != KErrNone );
       
   145 
       
   146     err = iPSObserver->Get(value);
       
   147 
       
   148     EUNIT_ASSERT( err == KErrNone );
       
   149     EUNIT_ASSERT( value == 5 || value == 10 );
       
   150     }
       
   151 
       
   152 void MT_ApiAiPSPropertyObserver::TestDoCancelL(  )
       
   153     {
       
   154     iStateOk = EFalse;
       
   155     ChangeKeyValueL( 10 );
       
   156     Release(iPSObserver);
       
   157     iPSObserver = NULL;
       
   158     CAOUserAfter::AfterLD( 2 * 1000000 );
       
   159     if( !iStateOk ) // make sure that the change was cancelled
       
   160         {
       
   161         EUNIT_ASSERT( ETrue );
       
   162         return;
       
   163         }
       
   164     EUNIT_ASSERT( EFalse );
       
   165     }
       
   166 
       
   167 //  TEST TABLE
       
   168 
       
   169 EUNIT_BEGIN_TEST_TABLE(
       
   170     MT_ApiAiPSPropertyObserver,
       
   171     "Unit test suite for MAiContentItemIterator implementation returned from AiUtility::CreateContentItemArrayIteratorL",
       
   172     "CAiContentItemArrayIterator" )
       
   173 
       
   174 EUNIT_TEST(
       
   175     "Test one",
       
   176     "MAiContentItemIterator",
       
   177     "All",
       
   178     "FUNCTIONALITY",
       
   179     SetupL, TestBasicFunctionalityL, Teardown)
       
   180 
       
   181 EUNIT_TEST(
       
   182     "Test one",
       
   183     "MAiContentItemIterator",
       
   184     "All",
       
   185     "FUNCTIONALITY",
       
   186     SetupL, TestGettersL, Teardown)
       
   187 
       
   188 EUNIT_TEST(
       
   189     "Test one",
       
   190     "MAiContentItemIterator",
       
   191     "All",
       
   192     "FUNCTIONALITY",
       
   193     SetupL, TestDoCancelL, Teardown)
       
   194 
       
   195 EUNIT_END_TEST_TABLE
       
   196 
       
   197 //  END OF FILE