mmsharing/mmshengine/tsrc/ut_engine/src/ut_muspropertywatch.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     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 
       
    19 //  INTERNAL INCLUDES
       
    20 #include "ut_muspropertywatch.h"
       
    21 #include "muspropertywatch.h"
       
    22 
       
    23 #include "mussessionproperties.h"
       
    24 
       
    25 //  SYSTEM INCLUDES
       
    26 #include <eunitmacros.h>
       
    27 #include <e32property.h>
       
    28 
       
    29 using namespace NMusSessionApi;
       
    30 
       
    31 const TInt KMusUiTestKey = 1100;
       
    32 const TInt KMusUiTestPropertyReadInteger = 200;
       
    33 _LIT( KMusUiTestPropertyReadDesc, "testread" ); 
       
    34 TUid KMusUiDummyUid = { 1000 }; // Unit testing dummy
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 UT_CMusPropertyWatch* UT_CMusPropertyWatch::NewL()
       
    41     {
       
    42     UT_CMusPropertyWatch* self = UT_CMusPropertyWatch::NewLC();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 UT_CMusPropertyWatch* UT_CMusPropertyWatch::NewLC()
       
    53     {
       
    54     UT_CMusPropertyWatch* self = new( ELeave ) UT_CMusPropertyWatch();
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 UT_CMusPropertyWatch::~UT_CMusPropertyWatch()
       
    66     {
       
    67     // NOP
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // Default constructor
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 UT_CMusPropertyWatch::UT_CMusPropertyWatch()
       
    76     {
       
    77     // NOP
       
    78     }
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // Second phase construct
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void UT_CMusPropertyWatch::ConstructL()
       
    86     {
       
    87     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    88     // It generates the test case table.
       
    89     CEUnitTestSuiteClass::ConstructL();
       
    90     }
       
    91 
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void UT_CMusPropertyWatch::SetupL()
       
    98     {
       
    99     PropertyHelper::SetErrorCode( KErrNone );
       
   100     RProperty::Set( KMusUiDummyUid, KMusUiTestKey, KMusUiTestPropertyReadInteger );
       
   101     iPropertyWatch = CMusPropertyWatch::NewL( iPropertyObserver,
       
   102                                                 KMusUiDummyUid,
       
   103                                                 KMusUiTestKey );
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void UT_CMusPropertyWatch::Teardown()
       
   112     {
       
   113     delete iPropertyWatch;
       
   114     PropertyHelper::Close();
       
   115     }
       
   116 
       
   117 
       
   118 
       
   119 // TEST CASES
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void UT_CMusPropertyWatch::UT_CMusPropertyWatch_ReadIntPropertyLL()
       
   126     {
       
   127 
       
   128     // Teesting leave
       
   129     PropertyHelper::SetErrorCode( KErrNotFound );
       
   130     RProperty::Set( KMusUiDummyUid, KMusUiTestKey, KMusUiTestPropertyReadInteger );
       
   131     TInt value;
       
   132     TRAPD( err, value = CMusPropertyWatch::ReadIntPropertyL( KMusUiTestKey ) );
       
   133     EUNIT_ASSERT( err == KErrNotFound );
       
   134 
       
   135     // Testing return value
       
   136     PropertyHelper::SetErrorCode( KErrNone );
       
   137     RProperty::Set( KMusUiDummyUid, KMusUiTestKey, KMusUiTestPropertyReadInteger );
       
   138     EUNIT_ASSERT(  CMusPropertyWatch::ReadIntPropertyL( KMusUiTestKey ) ==
       
   139                    KMusUiTestPropertyReadInteger );
       
   140 
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void UT_CMusPropertyWatch::UT_CMusPropertyWatch_ReadDescPropertyLL()
       
   149     {
       
   150     // Teesting leave
       
   151     PropertyHelper::SetErrorCode( KErrNotFound );
       
   152     TRAPD( err,  CMusPropertyWatch::ReadDescPropertyL( KMusUiTestKey ) );
       
   153     EUNIT_ASSERT( err == KErrNotFound );
       
   154 
       
   155     // Testing return value
       
   156     RProperty::Set( KMusUiDummyUid, KMusUiTestKey, KMusUiTestPropertyReadDesc );
       
   157     PropertyHelper::SetErrorCode( KErrNone );
       
   158     HBufC* result = CMusPropertyWatch::ReadDescPropertyL( KMusUiTestKey );
       
   159     CleanupStack::PushL( result );
       
   160     EUNIT_ASSERT(  KMusUiTestPropertyReadDesc().Compare( result->Des() ) == 0 );
       
   161     CleanupStack::PopAndDestroy( result );
       
   162     }
       
   163 
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void UT_CMusPropertyWatch::UT_CMusPropertyWatch_DoCancelL()
       
   170     {
       
   171     PropertyHelper::SetErrorCode( KErrNone );
       
   172     iPropertyWatch->Cancel();
       
   173     EUNIT_ASSERT( PropertyHelper::GetCalledFunction() == RProperty::ECancel );
       
   174     }
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void UT_CMusPropertyWatch::UT_CMusPropertyWatch_RunLL()
       
   182     {
       
   183 
       
   184     // Leave test
       
   185     PropertyHelper::SetErrorCode( KErrNotFound );
       
   186     iPropertyWatch->Cancel();
       
   187     TRAPD( err, iPropertyWatch->RunL() );
       
   188     EUNIT_ASSERT( err == KErrNotFound );
       
   189 
       
   190 
       
   191     // SessionPropertyChanged
       
   192     PropertyHelper::SetErrorCode( KErrNone );
       
   193     iPropertyWatch->Cancel();
       
   194     iPropertyWatch->RunL();
       
   195     EUNIT_ASSERT( iPropertyObserver.iCalledFunction ==
       
   196                   TMusPropertyObserverStub::EPropertyChanged );
       
   197 
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void UT_CMusPropertyWatch::UT_CMusPropertyWatch_RunErrorL()
       
   206     {
       
   207 
       
   208     // Allways returns KErrNone
       
   209     PropertyHelper::SetErrorCode( KErrNone );
       
   210     EUNIT_ASSERT( iPropertyWatch->RunError( KErrNotFound ) == KErrNone );
       
   211 
       
   212     // is right observer called
       
   213     PropertyHelper::SetErrorCode( KErrNone );
       
   214     EUNIT_ASSERT( iPropertyObserver.iCalledFunction ==
       
   215                   TMusPropertyObserverStub::EHandlePropertyError );
       
   216     }
       
   217 
       
   218 
       
   219 
       
   220 //  TEST TABLE
       
   221 
       
   222 EUNIT_BEGIN_TEST_TABLE(
       
   223     UT_CMusPropertyWatch,
       
   224     "UT_CMusPropertyWatch",
       
   225     "UNIT" )
       
   226 
       
   227 EUNIT_TEST(
       
   228     "ReadIntPropertyLL - test ",
       
   229     "CMusPropertyWatch",
       
   230     "ReadIntPropertyLL",
       
   231     "FUNCTIONALITY",
       
   232     SetupL, UT_CMusPropertyWatch_ReadIntPropertyLL, Teardown)
       
   233 
       
   234 EUNIT_TEST(
       
   235     "ReadDescPropertyLL - test ",
       
   236     "CMusPropertyWatch",
       
   237     "ReadDescPropertyLL",
       
   238     "FUNCTIONALITY",
       
   239     SetupL, UT_CMusPropertyWatch_ReadDescPropertyLL, Teardown)
       
   240 
       
   241 EUNIT_TEST(
       
   242     "DoCancelL - test ",
       
   243     "CMusPropertyWatch",
       
   244     "DoCancelL",
       
   245     "FUNCTIONALITY",
       
   246     SetupL, UT_CMusPropertyWatch_DoCancelL, Teardown)
       
   247 
       
   248 EUNIT_TEST(
       
   249     "RunLL - test ",
       
   250     "CMusPropertyWatch",
       
   251     "RunLL",
       
   252     "FUNCTIONALITY",
       
   253     SetupL, UT_CMusPropertyWatch_RunLL, Teardown)
       
   254 
       
   255 EUNIT_TEST(
       
   256     "RunErrorL - test ",
       
   257     "CMusPropertyWatch",
       
   258     "RunErrorL",
       
   259     "FUNCTIONALITY",
       
   260     SetupL, UT_CMusPropertyWatch_RunErrorL, Teardown)
       
   261 
       
   262 
       
   263 EUNIT_END_TEST_TABLE
       
   264 
       
   265 
       
   266 //  END OF FILE
       
   267 
       
   268