mmshplugins/mmshaoplugin/tsrc/ut_aoplugin/src/ut_musclirmonitor.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:  Monitor that observes the calling line identity restriction
       
    15 *                setting
       
    16 *
       
    17 */
       
    18 
       
    19 #include "musclirmonitor.h"
       
    20 #include "ut_musclirmonitor.h"
       
    21 #include "e32property.h"
       
    22 
       
    23 #include <etelmm.h>
       
    24 #include <etel.h>
       
    25 #include <mmtsy_names.h>
       
    26 #include <digia/eunit/eunitmacros.h>
       
    27 
       
    28 
       
    29 #pragma warn_illtokenpasting off
       
    30 
       
    31 // Constants
       
    32 
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // UT_CMusClirMonitor::NewLC
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 UT_CMusClirMonitor* UT_CMusClirMonitor::NewLC()
       
    39     {    
       
    40     UT_CMusClirMonitor* self = new (ELeave) UT_CMusClirMonitor();
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     return self;
       
    44     }
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // UT_CMusClirMonitor::ConstructL
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void UT_CMusClirMonitor::ConstructL()
       
    52     {
       
    53     CEUnitTestSuiteClass::ConstructL();
       
    54     }
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // UT_CMusClirMonitor::UT_CMusClirMonitor
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 UT_CMusClirMonitor::UT_CMusClirMonitor() :
       
    62     CEUnitTestSuiteClass()
       
    63     {
       
    64     }
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // UT_CMusClirMonitor::~UT_CMusClirMonitor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 UT_CMusClirMonitor::~UT_CMusClirMonitor()
       
    72     {
       
    73     }
       
    74 
       
    75    
       
    76 // -----------------------------------------------------------------------------
       
    77 // UT_CMusClirMonitor::UT_ReadClir
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void UT_CMusClirMonitor::UT_ReadClir()
       
    81     {
       
    82     // Cancel initial request
       
    83     iMonitor->Cancel();
       
    84     
       
    85     iMonitor->ReadClir();
       
    86     EUNIT_ASSERT( iMonitor->IsActive() );
       
    87     
       
    88     // Monitor is already reading, new attempts do nothing 
       
    89     iMonitor->ReadClir();
       
    90     iMonitor->ReadClir();
       
    91     
       
    92     EUNIT_ASSERT_EQUALS( iMonitor->iErrorCount, 0 );
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // UT_CMusClirMonitor::UT_RunL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void UT_CMusClirMonitor::UT_RunL()
       
   101     {
       
   102     CTelephony::TIdentityServiceStatus value1 =
       
   103         CTelephony::EIdServiceActivePermanent;
       
   104     CTelephony::TIdentityServiceStatus value2 =
       
   105             CTelephony::EIdServiceNotProvisioned;
       
   106 
       
   107     EUNIT_ASSERT( iMonitor->iAllowed );
       
   108     iMonitor->Cancel();
       
   109     iMonitor->iTIdentityServiceV1.iIdentityStatus = value1;
       
   110     iMonitor->iStatus = KErrNone;    
       
   111     iMonitor->RunL();
       
   112     EUNIT_ASSERT( !iMonitor->iAllowed );
       
   113     EUNIT_ASSERT_EQUALS( iMonitor->iErrorCount, 0 );
       
   114     
       
   115     
       
   116     iMonitor->Cancel();
       
   117     iMonitor->iTIdentityServiceV1.iIdentityStatus = value2;
       
   118     iMonitor->iStatus = KErrGeneral;
       
   119     iMonitor->RunL();
       
   120     // iAllowed value does not change because request completed with error
       
   121     EUNIT_ASSERT( !iMonitor->iAllowed );
       
   122     EUNIT_ASSERT_EQUALS( iMonitor->iErrorCount, 1 );
       
   123     
       
   124    
       
   125     iMonitor->Cancel();
       
   126     iMonitor->iTIdentityServiceV1.iIdentityStatus = value2;
       
   127     iMonitor->iStatus = KErrNone;
       
   128     iMonitor->RunL();
       
   129     EUNIT_ASSERT( iMonitor->iAllowed );
       
   130     // After successful read, error count is reset
       
   131     EUNIT_ASSERT_EQUALS( iMonitor->iErrorCount, 0 );
       
   132     }
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // UT_CMusClirMonitor::UT_RunLErrorsL
       
   137 // Test that if reading fails, it is retried few times. 
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void UT_CMusClirMonitor::UT_RunLErrorsL()
       
   141     {
       
   142     // Must have same value as in musclirmonitor.cpp
       
   143     const TInt KMaxErrorsBeforeStop = 5;
       
   144 
       
   145     EUNIT_ASSERT_EQUALS( iMonitor->iErrorCount, 0 );
       
   146     
       
   147     for ( TInt i = 1; i <= KMaxErrorsBeforeStop; ++i )
       
   148         {
       
   149         // Reading fails
       
   150         iMonitor->Cancel();
       
   151         iMonitor->iStatus = KErrNotSupported;
       
   152         iMonitor->RunL();
       
   153         EUNIT_ASSERT_EQUALS( iMonitor->iErrorCount, i );
       
   154         // Retry started
       
   155         EUNIT_ASSERT( iMonitor->IsActive() );
       
   156         }
       
   157     
       
   158     // Reading fails
       
   159     iMonitor->Cancel();
       
   160     iMonitor->iStatus = KErrNotSupported;
       
   161     iMonitor->RunL();
       
   162     EUNIT_ASSERT_EQUALS( iMonitor->iErrorCount, KMaxErrorsBeforeStop + 1 );
       
   163 
       
   164     // No more retries
       
   165     EUNIT_ASSERT( !iMonitor->IsActive() );
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // UT_CMusClirMonitor::UT_DoCancel
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void UT_CMusClirMonitor::UT_DoCancel()
       
   173     {
       
   174     EUNIT_ASSERT( iMonitor->IsActive() );
       
   175 
       
   176     // Can't call DoCancel directly, must call it via the CActive::Cancel
       
   177     iMonitor->Cancel();
       
   178     
       
   179     EUNIT_ASSERT( !iMonitor->IsActive() );
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // UT_CMusClirMonitor::UT_RunError
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void UT_CMusClirMonitor::UT_RunError()
       
   188     {
       
   189     EUNIT_ASSERT( iMonitor->RunError( KErrNone ) == KErrNone );
       
   190     EUNIT_ASSERT( iMonitor->RunError( KErrGeneral ) == KErrNone );
       
   191     EUNIT_ASSERT( iMonitor->RunError( 48 ) == KErrNone );
       
   192     EUNIT_ASSERT( iMonitor->RunError( -2092 ) == KErrNone );
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // UT_CMusClirMonitor::UT_TranslateResult
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void UT_CMusClirMonitor::UT_TranslateResult()
       
   201     {
       
   202     iMonitor->iAllowed = EFalse;
       
   203     
       
   204     iMonitor->TranslateResult( CTelephony::EIdServiceActiveDefaultAllowed );
       
   205     EUNIT_ASSERT( iMonitor->iAllowed );
       
   206     
       
   207     iMonitor->TranslateResult( CTelephony::EIdServiceActivePermanent );
       
   208     EUNIT_ASSERT( !iMonitor->iAllowed );
       
   209     
       
   210     iMonitor->TranslateResult( CTelephony::EIdServiceNotProvisioned );
       
   211     EUNIT_ASSERT( iMonitor->iAllowed );
       
   212     
       
   213     iMonitor->TranslateResult( CTelephony::EIdServiceActiveDefaultRestricted );
       
   214     EUNIT_ASSERT( !iMonitor->iAllowed );
       
   215     
       
   216     iMonitor->TranslateResult( CTelephony::EIdServiceUnknown );
       
   217     EUNIT_ASSERT( !iMonitor->iAllowed );
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // UT_CMusClirMonitor::SetupL
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void UT_CMusClirMonitor::SetupL()
       
   225     {        
       
   226     iMonitor = CMusClirMonitor::NewL();
       
   227     }
       
   228 
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // UT_CMusClirMonitor::Teardown
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void UT_CMusClirMonitor::Teardown()
       
   235     {
       
   236     delete iMonitor;
       
   237     iMonitor = NULL;
       
   238     PropertyHelper::Close();
       
   239     
       
   240     }
       
   241 
       
   242 // test table
       
   243 
       
   244 EUNIT_BEGIN_TEST_TABLE(
       
   245     UT_CMusClirMonitor,
       
   246     "UT_CMusClirMonitor",
       
   247     "UNIT" )
       
   248 
       
   249 EUNIT_TEST(
       
   250     "UT_ReadClir",
       
   251     "CMusClirMonitor",
       
   252     "ReadClir",
       
   253     "FUNCTIONALITY",
       
   254     SetupL, UT_ReadClir, Teardown)
       
   255 
       
   256 EUNIT_TEST(
       
   257     "UT_RunL",
       
   258     "CMusClirMonitor",
       
   259     "RunL",
       
   260     "FUNCTIONALITY",
       
   261     SetupL, UT_RunL, Teardown)
       
   262 
       
   263 EUNIT_TEST(
       
   264     "UT_RunLErrorsL",
       
   265     "CMusClirMonitor",
       
   266     "RunL",
       
   267     "FUNCTIONALITY",
       
   268     SetupL, UT_RunLErrorsL, Teardown)
       
   269 
       
   270 EUNIT_TEST(
       
   271     "UT_DoCancel",
       
   272     "CMusClirMonitor",
       
   273     "DoCancel",
       
   274     "FUNCTIONALITY",
       
   275     SetupL, UT_DoCancel, Teardown)
       
   276 
       
   277 EUNIT_TEST(
       
   278     "UT_RunError",
       
   279     "CMusClirMonitor",
       
   280     "RunError",
       
   281     "FUNCTIONALITY",
       
   282     SetupL, UT_RunError, Teardown)
       
   283 
       
   284 EUNIT_TEST(
       
   285     "UT_TranslateResult",
       
   286     "CMusClirMonitor",
       
   287     "TranslateResult",
       
   288     "FUNCTIONALITY",
       
   289     SetupL, UT_TranslateResult, Teardown)
       
   290 
       
   291 EUNIT_END_TEST_TABLE