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