uiservicetab/vimpstengine/tsrc/vimpstengine_ut/src/t_vimpstenginecchhandler.cpp
changeset 15 81eeb8c83ce5
parent 0 5e5d6b214f4f
equal deleted inserted replaced
0:5e5d6b214f4f 15:81eeb8c83ce5
     1 /*
       
     2 * t_vimpstenginecchhandler.cpp :  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: t_vimpstenginecchhandler.cpp
       
    15 *
       
    16 */
       
    17 #include <EUnitMacros.h>
       
    18 #include <TEUnitAssertionInfo.h>
       
    19 #include <CEUnitAllocTestCaseDecorator.h>
       
    20 #include <cch.h>
       
    21 #include "t_vimpstenginecchhandler.h"
       
    22 #include "cvimpstenginecchhandler.h"
       
    23 
       
    24 
       
    25 #include "s_cch.h"
       
    26 #include "s_mcchuiobserver.h"
       
    27 
       
    28 extern MyCchService* myService;
       
    29 extern TBool createService ;
       
    30 extern TBool tryAllSubserviceAvailable ;
       
    31 extern TBool tryVoipSubServiceAvailable ;
       
    32 extern TBool tryPresenceSubServiceAvailable ;
       
    33 extern TBool tryIMSubServiceAvailable ;
       
    34 extern TBool tryConnParamLeaveWithNotSupported ;
       
    35 extern TBool tryConnParamWithSuccess ;
       
    36 extern TBool sendObserverEvent;
       
    37 extern TBool tryConnParamWithFailure ;
       
    38 
       
    39 
       
    40 T_VimpstEngineCchHandler* T_VimpstEngineCchHandler::NewLC()
       
    41     {
       
    42     T_VimpstEngineCchHandler* self = new( ELeave ) T_VimpstEngineCchHandler;
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     return self;
       
    46     }
       
    47 
       
    48 T_VimpstEngineCchHandler::~T_VimpstEngineCchHandler()
       
    49     {
       
    50     }
       
    51 
       
    52 void T_VimpstEngineCchHandler::ConstructL()
       
    53     {
       
    54     CEUnitTestSuiteClass::ConstructL();
       
    55     }
       
    56 
       
    57 void T_VimpstEngineCchHandler::SetupL()
       
    58     {
       
    59     iCChHandler = CVIMPSTEngineCchHandler::NewL( 3,*iCchUiEventObserver );
       
    60     }
       
    61     
       
    62 void T_VimpstEngineCchHandler::SetupL1()
       
    63     {
       
    64     createService = ETrue;
       
    65     iCChHandler = CVIMPSTEngineCchHandler::NewL( 3 ,*iCchUiEventObserver);
       
    66     }    
       
    67 
       
    68 void T_VimpstEngineCchHandler::Teardown()
       
    69     {
       
    70     delete myService;
       
    71     myService = NULL;    
       
    72     createService = EFalse;
       
    73     
       
    74     tryAllSubserviceAvailable = EFalse;
       
    75 	tryVoipSubServiceAvailable = EFalse;
       
    76 	tryPresenceSubServiceAvailable = EFalse;
       
    77 	tryIMSubServiceAvailable = EFalse;
       
    78 	
       
    79 	tryConnParamLeaveWithNotSupported = EFalse;
       
    80 	tryConnParamWithSuccess = EFalse;
       
    81     
       
    82     delete iCChHandler;
       
    83     iCChHandler = NULL;    
       
    84     }
       
    85 
       
    86 
       
    87 void T_VimpstEngineCchHandler::TestConstructionL()
       
    88     {
       
    89     
       
    90     EUNIT_ASSERT( iCChHandler );
       
    91     
       
    92     }
       
    93     
       
    94 void T_VimpstEngineCchHandler::TestGetServiceStateServiceNotFoundL()
       
    95     {
       
    96     
       
    97     TCCHSubserviceState state;
       
    98     EUNIT_ASSERT_EQUALS( KErrNotFound, iCChHandler->GetServiceState( 99, ECCHVoIPSub, state ) ); 
       
    99     
       
   100     
       
   101     }
       
   102   
       
   103     
       
   104 void T_VimpstEngineCchHandler::TestGetServiceStateServiceFoundL()
       
   105     {
       
   106     
       
   107     TCCHSubserviceState state;
       
   108     
       
   109     createService = ETrue;
       
   110     tryVoipSubServiceAvailable = ETrue;
       
   111     
       
   112     EUNIT_ASSERT_EQUALS( KErrNone, iCChHandler->GetServiceState( 5, ECCHVoIPSub, state ) );    
       
   113     
       
   114     }
       
   115 
       
   116 
       
   117 void T_VimpstEngineCchHandler::TestEnableServiceServiceFoundL() 
       
   118 	{
       
   119 	
       
   120     createService = ETrue;
       
   121     EUNIT_ASSERT_EQUALS( KErrNone, iCChHandler->EnableService() ); 
       
   122     	
       
   123 	}
       
   124 	
       
   125 	
       
   126 void T_VimpstEngineCchHandler::TestEnableServiceServiceNotFoundL() 
       
   127 	{
       
   128 	
       
   129     EUNIT_ASSERT_EQUALS( KErrNotFound, iCChHandler->EnableService() ); 
       
   130     
       
   131 	}
       
   132 	
       
   133 void T_VimpstEngineCchHandler::TestDisableServiceServiceFoundL() 
       
   134 	{
       
   135 	
       
   136     createService = ETrue;
       
   137     EUNIT_ASSERT_EQUALS( KErrNone, iCChHandler->DisableService() ); 
       
   138     	
       
   139 	}
       
   140 	
       
   141 	
       
   142 void T_VimpstEngineCchHandler::TestDisableServiceServiceNotFoundL() 
       
   143 	{
       
   144 	
       
   145     EUNIT_ASSERT_EQUALS( KErrNotFound, iCChHandler->DisableService() ); 
       
   146     
       
   147 	}	
       
   148 /*	
       
   149 void T_VimpstEngineCchHandler::ValidateServiceServiceNotFoundL()
       
   150 	{
       
   151 	EUNIT_ASSERT_EQUALS( EFalse, iCChHandler->ValidateService(99) ); 		
       
   152 	}*/
       
   153 /*	
       
   154 void T_VimpstEngineCchHandler::ValidateServiceAllSubserviceAvailableL()
       
   155 	{
       
   156 	createService = ETrue;
       
   157 	tryAllSubserviceAvailable = ETrue;
       
   158 	
       
   159 	EUNIT_ASSERT_EQUALS( ETrue, iCChHandler->ValidateService(99) ); 		
       
   160 	}
       
   161 */
       
   162 /*
       
   163 void T_VimpstEngineCchHandler::ValidateServiceAnyOneSubserviceAvailableL()
       
   164 	{
       
   165 	createService = ETrue;
       
   166 	tryPresenceSubServiceAvailable = ETrue;
       
   167 	
       
   168 	EUNIT_ASSERT_EQUALS( ETrue, iCChHandler->ValidateService(99) ); 		
       
   169 	}		
       
   170 */
       
   171 
       
   172 void T_VimpstEngineCchHandler::GetConParametersServiceNotFoundL()
       
   173 	{
       
   174 	HBufC* temp = NULL;
       
   175 	
       
   176 	createService = ETrue;  
       
   177 	tryConnParamWithFailure = ETrue;
       
   178 	
       
   179 	TRAPD(err, temp = iCChHandler->GetConParametersL(ECchUsername));
       
   180 	
       
   181 	EUNIT_ASSERT_EQUALS( KErrNotFound, err ); 
       
   182 	
       
   183 	if (temp)
       
   184 		{
       
   185 		User::Leave( KErrArgument ); // For alloc failure testing	  	
       
   186 		}	
       
   187 			
       
   188 	}
       
   189 	
       
   190 void T_VimpstEngineCchHandler::GetConParametersServiceFoundL()
       
   191 	{
       
   192 	HBufC* temp = NULL;
       
   193 	
       
   194 	createService = ETrue;	
       
   195 	tryConnParamWithSuccess = ETrue;
       
   196 	tryConnParamWithFailure = EFalse;
       
   197 	
       
   198 	TRAPD(err, temp = iCChHandler->GetConParametersL(ECchUsername));	
       
   199 	
       
   200 	EUNIT_ASSERT_EQUALS( KErrNone, err ); 	
       
   201 	
       
   202 	CleanupStack::PushL(temp);
       
   203 	
       
   204 	if (temp->Des().Compare(KTestUserName()))
       
   205 		{
       
   206 		User::Leave( KErrArgument ); // For alloc failure testing	    		
       
   207 		}
       
   208 	
       
   209 	CleanupStack::PopAndDestroy(temp);
       
   210 	}
       
   211 	
       
   212 
       
   213 void T_VimpstEngineCchHandler::GetConParametersLeavesServiceFoundL()
       
   214 	{
       
   215 	HBufC* temp = NULL;
       
   216 	
       
   217 	createService = ETrue;
       
   218 	tryConnParamLeaveWithNotSupported = ETrue;	
       
   219 	
       
   220 	TRAPD(err, temp = iCChHandler->GetConParametersL(ECchUsername));
       
   221 	
       
   222 	EUNIT_ASSERT_EQUALS( KErrNotSupported, err ); 	
       
   223 	
       
   224 	if (temp)
       
   225 		{
       
   226 		User::Leave( KErrArgument ); // For alloc failure testing	  	
       
   227 		}	
       
   228 	}		
       
   229 		
       
   230 		
       
   231 		
       
   232 
       
   233 void T_VimpstEngineCchHandler::SetConParametersServiceNotFoundL()
       
   234 	{
       
   235     
       
   236 	TInt err = iCChHandler->SetConnectionParameter(ECchUsername, KTestUserName);
       
   237 	
       
   238 	EUNIT_ASSERT_EQUALS( KErrNotFound, err ); 	
       
   239 			
       
   240 	}
       
   241 	
       
   242 void T_VimpstEngineCchHandler::SetConParametersServiceFoundL()
       
   243 	{
       
   244 	createService = ETrue;	
       
   245 	tryConnParamWithSuccess = ETrue;
       
   246 	
       
   247 	TInt err = iCChHandler->SetConnectionParameter(ECchUsername, KTestUserName);	
       
   248 	
       
   249 	EUNIT_ASSERT_EQUALS( KErrNone, err ); 	
       
   250 	
       
   251 	}
       
   252 	
       
   253 
       
   254 void T_VimpstEngineCchHandler::SetConParametersLeavesServiceFoundL()
       
   255 	{
       
   256 	createService = ETrue;
       
   257 	tryConnParamLeaveWithNotSupported = ETrue;	
       
   258 	
       
   259 	TInt err = iCChHandler->SetConnectionParameter(ECchUsername, KTestUserName);
       
   260 	
       
   261 	EUNIT_ASSERT_EQUALS( KErrNotSupported, err ); 			
       
   262 	}				
       
   263 		    		
       
   264 
       
   265 void T_VimpstEngineCchHandler::ShutdownCch()
       
   266 	{
       
   267 	iCChHandler->ShutdownCch();
       
   268 	}			    		
       
   269 
       
   270 void T_VimpstEngineCchHandler::CheckObservingForPresenceSubServiceL()
       
   271 	{
       
   272 	sendObserverEvent = ETrue;
       
   273 	tryPresenceSubServiceAvailable = ETrue;
       
   274 	
       
   275 	iCallingEnable = ETrue;
       
   276 	iGotObserverEvent = EFalse;
       
   277 	
       
   278 	iCChHandler->RegisterCchObserverL(this, ECCHPresenceSub);
       
   279 	iCChHandler->EnableService();
       
   280 	iCChHandler->UnRegisterCchObserver(ECCHPresenceSub);	
       
   281 	
       
   282 	EUNIT_ASSERT_EQUALS( ETrue, iGotObserverEvent ); 	
       
   283 	}
       
   284 	
       
   285 void T_VimpstEngineCchHandler::CheckNoObservingForPrsenceSubServiceL()
       
   286 	{
       
   287 	sendObserverEvent = ETrue;
       
   288 	tryPresenceSubServiceAvailable = ETrue;
       
   289 	
       
   290 	iCallingEnable = ETrue;
       
   291 	iGotObserverEvent = EFalse;
       
   292 	
       
   293 	iCChHandler->RegisterCchObserverL(this, ECCHIMSub);
       
   294 	iCChHandler->EnableService();
       
   295 	iCChHandler->UnRegisterCchObserver(ECCHIMSub);
       
   296 	
       
   297 	
       
   298 	EUNIT_ASSERT_EQUALS( EFalse, iGotObserverEvent ); 	
       
   299 	}	
       
   300 
       
   301 void T_VimpstEngineCchHandler::RegisterObserverWithNull()
       
   302 	{
       
   303 	sendObserverEvent = ETrue;
       
   304 	tryPresenceSubServiceAvailable = ETrue;
       
   305 	
       
   306 	iCallingEnable = ETrue;
       
   307 	iGotObserverEvent = EFalse;
       
   308 	
       
   309 	iCChHandler->RegisterCchObserverL(NULL, ECCHUnknown);
       
   310 	iCChHandler->EnableService();
       
   311 	iCChHandler->UnRegisterCchObserver(ECCHUnknown);
       
   312 	
       
   313 	
       
   314 	EUNIT_ASSERT_EQUALS( EFalse, iGotObserverEvent ); 	
       
   315 	}
       
   316 
       
   317 
       
   318 void T_VimpstEngineCchHandler::CchEventOccuredL( 
       
   319             TUint /*aServiceId*/, 
       
   320             TCCHSubserviceState aState, 
       
   321             TInt /*aServiceError*/ )
       
   322 	{
       
   323 	
       
   324 	if (iCallingEnable)
       
   325 		{
       
   326 		if (ECCHEnabled == aState)
       
   327 			{
       
   328 			iGotObserverEvent = ETrue;				
       
   329 			}
       
   330 		}
       
   331 	}
       
   332 	
       
   333 void T_VimpstEngineCchHandler::CheckObservingWithoutRegisteringL()
       
   334 	{
       
   335 	sendObserverEvent = ETrue;
       
   336 	
       
   337 	iCallingEnable = ETrue;
       
   338 	iGotObserverEvent = EFalse;
       
   339 	
       
   340 	iCChHandler->EnableService();	
       
   341 	
       
   342 	EUNIT_ASSERT_EQUALS( EFalse, iGotObserverEvent ); 	
       
   343 	}
       
   344 	
       
   345             		    		
       
   346 
       
   347 EUNIT_BEGIN_TEST_TABLE( T_VimpstEngineCchHandler, "T_VimpstEngineCchHandler", "" )
       
   348 
       
   349     EUNIT_TEST("TestConstructionL ",
       
   350             "T_VimpstEngineCchHandler",
       
   351             "ConstructL",
       
   352             "FUNCTIONALITY",
       
   353             SetupL, TestConstructionL, Teardown )
       
   354     EUNIT_TEST("TestGetServiceStateServiceNotFoundL ",
       
   355             "T_VimpstEngineCchHandler",
       
   356             "GetServiceState",
       
   357             "FUNCTIONALITY", 
       
   358               SetupL, TestGetServiceStateServiceNotFoundL, Teardown )
       
   359     EUNIT_TEST( "TestGetServiceStateServiceFoundL ",
       
   360             "T_VimpstEngineCchHandler",
       
   361             "GetServiceState",
       
   362             "FUNCTIONALITY",
       
   363             SetupL, TestGetServiceStateServiceFoundL, Teardown )
       
   364     EUNIT_TEST( "TestEnableServiceServiceFoundL ",
       
   365             "T_VimpstEngineCchHandler",
       
   366             "EnableService",
       
   367             "FUNCTIONALITY",
       
   368             SetupL, TestEnableServiceServiceFoundL, Teardown )
       
   369     EUNIT_TEST( "TestEnableServiceServiceNotFoundL ",
       
   370             "T_VimpstEngineCchHandler",
       
   371             "EnableService",
       
   372             "FUNCTIONALITY",
       
   373             SetupL, TestEnableServiceServiceNotFoundL, Teardown )
       
   374    /* EUNIT_TEST( "ValidateServiceServiceNotFoundL ",
       
   375             "T_VimpstEngineCchHandler",
       
   376             "ValidateService",
       
   377             "FUNCTIONALITY",
       
   378             SetupL, ValidateServiceServiceNotFoundL, Teardown )
       
   379     EUNIT_TEST("ValidateServiceAllSubserviceAvailableL ",
       
   380             "T_VimpstEngineCchHandler",
       
   381             "ValidateService",
       
   382             "FUNCTIONALITY",
       
   383             SetupL, ValidateServiceAllSubserviceAvailableL, Teardown )
       
   384     EUNIT_TEST("ValidateServiceAnyOneSubserviceAvailableL ",
       
   385             "T_VimpstEngineCchHandler",
       
   386             "ValidateService",
       
   387             "FUNCTIONALITY",
       
   388             SetupL, ValidateServiceAnyOneSubserviceAvailableL, Teardown )  
       
   389             */  
       
   390     EUNIT_TEST( "GetConParametersServiceNotFoundL ",
       
   391             "T_VimpstEngineCchHandler",
       
   392             "GetConParametersL",
       
   393             "FUNCTIONALITY",
       
   394             SetupL, GetConParametersServiceNotFoundL, Teardown )
       
   395     EUNIT_TEST( "GetConParametersServiceFoundL ",
       
   396             "T_VimpstEngineCchHandler",
       
   397             "GetConParametersL",
       
   398             "FUNCTIONALITY",
       
   399             SetupL, GetConParametersServiceFoundL, Teardown )
       
   400     EUNIT_TEST("GetConParametersLeavesServiceFoundL ",
       
   401             "T_VimpstEngineCchHandler",
       
   402             "GetConParametersL",
       
   403             "FUNCTIONALITY",
       
   404             SetupL, GetConParametersLeavesServiceFoundL, Teardown )
       
   405     EUNIT_TEST( "SetConParametersServiceNotFoundL ",
       
   406             "T_VimpstEngineCchHandler",
       
   407             "SetConParametersL",
       
   408             "FUNCTIONALITY",
       
   409             SetupL, SetConParametersServiceNotFoundL, Teardown )
       
   410     EUNIT_TEST( "SetConParametersServiceFoundL ",
       
   411             "T_VimpstEngineCchHandler",
       
   412             "SetConParametersL",
       
   413             "FUNCTIONALITY",
       
   414             SetupL, SetConParametersServiceFoundL, Teardown )
       
   415     EUNIT_TEST("SetConParametersLeavesServiceFoundL ",
       
   416             "T_VimpstEngineCchHandler",
       
   417             "SetConParametersL",
       
   418             "FUNCTIONALITY",
       
   419             SetupL, SetConParametersLeavesServiceFoundL, Teardown )
       
   420     EUNIT_TEST( "TestDisableServiceServiceFoundL ",
       
   421             "T_VimpstEngineCchHandler",
       
   422             "DisableService",
       
   423             "FUNCTIONALITY",
       
   424             SetupL, TestDisableServiceServiceFoundL, Teardown )
       
   425     EUNIT_TEST( "TestDisableServiceServiceNotFoundL ",
       
   426             "T_VimpstEngineCchHandler",
       
   427             "DisableService",
       
   428             "FUNCTIONALITY",
       
   429             SetupL, TestDisableServiceServiceNotFoundL, Teardown )
       
   430     EUNIT_TEST( "ShutdownCch ",
       
   431             "T_VimpstEngineCchHandler",
       
   432             "ShutdownCch",
       
   433             "FUNCTIONALITY",
       
   434             SetupL, ShutdownCch, Teardown )
       
   435     EUNIT_TEST( "CheckObservingForPresenceSubServiceL ",
       
   436             "T_VimpstEngineCchHandler",
       
   437             "CheckObservingForPresenceSubServiceL",
       
   438             "FUNCTIONALITY",
       
   439             SetupL1, CheckObservingForPresenceSubServiceL, Teardown )
       
   440     EUNIT_TEST( "CheckObservingWithoutRegisteringL ",
       
   441             "T_VimpstEngineCchHandler",
       
   442             "CheckObservingWithoutRegisteringL",
       
   443             "FUNCTIONALITY",
       
   444             SetupL1, CheckObservingWithoutRegisteringL, Teardown )
       
   445     EUNIT_TEST( "RegisterObserverWithNull ",
       
   446             "T_VimpstEngineCchHandler",
       
   447             "RegisterObserverWithNull",
       
   448             "FUNCTIONALITY",
       
   449             SetupL1, RegisterObserverWithNull, Teardown )  
       
   450     EUNIT_TEST( "CheckNoObservingForPrsenceSubServiceL ",
       
   451             "T_VimpstEngineCchHandler",
       
   452             "CheckNoObservingForPrsenceSubServiceL",
       
   453             "FUNCTIONALITY",
       
   454             SetupL1, CheckNoObservingForPrsenceSubServiceL, Teardown )  
       
   455      
       
   456 EUNIT_END_TESTCASE_TABLE
       
   457 
       
   458 //  END OF FILE