uiservicetab/vimpstengine/tsrc/vimpstengine_ut/src/t_vimpstenginecontactmgmtextention.cpp
branchRCL_3
changeset 29 9a48e301e94b
parent 0 5e5d6b214f4f
child 30 2b4be3554d30
equal deleted inserted replaced
28:3104fc151679 29:9a48e301e94b
       
     1 /*
       
     2 * t_vimpstenginecontactmgmtextention.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_vimpstenginecontactmgmtextention.cpp
       
    15 *
       
    16 */
       
    17 #include <EUnitMacros.h>
       
    18 #include <TEUnitAssertionInfo.h>
       
    19 #include <CEUnitAllocTestCaseDecorator.h>
       
    20 #include "t_vimpstenginecontactmgmtextention.h"
       
    21 #include "cvimpstenginecontactmgmtextention.h"
       
    22 
       
    23 #include "s_ximpclient.h"
       
    24 #include "s_ximpcontext.h"
       
    25 #include "s_presencefeatures.h"
       
    26 #include "s_presentitygroups.h"
       
    27 //#include <ximpidentity.h>
       
    28 
       
    29 #include "cvimpstenginerequestmapper.h"
       
    30 #include "cvimpstenginerequest.h"
       
    31 
       
    32 #include "s_ximprequestcompleteevent.h"
       
    33 
       
    34 _LIT(KTestId, "TestId");
       
    35 _LIT(KTestIdentity, "TEST_IDENTITY");
       
    36 
       
    37 
       
    38 extern TXIMPRequestId gTXIMPRequestId;
       
    39 extern TBool gCreateXIMPIdentity;
       
    40 
       
    41 extern TInt32 gMXIMPRequestCompleteEventStubInterfaceId;
       
    42 extern TXIMPRequestId gMXIMPRequestCompleteEventStubRequestId;
       
    43 extern TBool gRequestCompleteEventResultCodeKerrNotSupported;
       
    44 
       
    45 T_VIMPSTEngineContactMgmtExtention* T_VIMPSTEngineContactMgmtExtention::NewLC()
       
    46     {
       
    47     T_VIMPSTEngineContactMgmtExtention* self = new( ELeave ) T_VIMPSTEngineContactMgmtExtention;
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     return self;
       
    51     }
       
    52 
       
    53 T_VIMPSTEngineContactMgmtExtention::~T_VIMPSTEngineContactMgmtExtention()
       
    54     {
       
    55     }
       
    56 
       
    57 void T_VIMPSTEngineContactMgmtExtention::ConstructL()
       
    58     {
       
    59     CEUnitTestSuiteClass::ConstructL();
       
    60     }
       
    61 
       
    62         
       
    63 void T_VIMPSTEngineContactMgmtExtention::SetupL()
       
    64     {   
       
    65     iClient = MXIMPClientStub::NewClientL();               
       
    66     
       
    67     //Create new sink to receive ximp context events
       
    68 	iPresenceCtx = iClient->NewPresenceContextLC();    
       
    69     // ignore code scanner warning, it gives panic
       
    70     CleanupStack::Pop();// because of LC method    
       
    71 	
       
    72 	iFeatures = MyMPresenceFeatureStub::NewStubL(iPresenceCtx);	
       
    73 	//
       
    74 	iGroups = &(iFeatures->PresentityGroups());
       
    75 	
       
    76 	iRequestMapper = CVIMPSTEngineRequestMapper::NewL() ;
       
    77 	
       
    78 	iContactManager = CVIMPSTEngineContactMgmtExtention::NewL( *iPresenceCtx,
       
    79 														*iGroups,
       
    80 														*iRequestMapper );
       
    81 	
       
    82     }    
       
    83 
       
    84 void T_VIMPSTEngineContactMgmtExtention::Teardown()
       
    85     {
       
    86     
       
    87     delete iContactManager;
       
    88     delete iRequestMapper;    
       
    89     delete iFeatures;
       
    90 	delete iPresenceCtx;
       
    91 	delete iClient;
       
    92 	
       
    93 	//gCreateXIMPIdentity = EFalse;
       
    94 	//gRequestCompleteEventResultCodeKerrNotSupported = EFalse;
       
    95     }
       
    96 
       
    97 
       
    98 void T_VIMPSTEngineContactMgmtExtention::TestConstructionL()
       
    99     {
       
   100     EUNIT_ASSERT( iContactManager );
       
   101     }
       
   102 
       
   103 void T_VIMPSTEngineContactMgmtExtention::TestCreateIdentityNormalL()
       
   104 	{
       
   105 	gCreateXIMPIdentity = ETrue;
       
   106 	MXIMPIdentity* identity = iContactManager->CreateIdentityLC(KTestId);
       
   107 	EUNIT_ASSERT( identity );
       
   108 	CleanupStack::PopAndDestroy();
       
   109 	}
       
   110 
       
   111 void T_VIMPSTEngineContactMgmtExtention::TestAddServerContactSuccessValidDataL()
       
   112 	{
       
   113 	gCreateXIMPIdentity = ETrue;
       
   114 	iContactManager->iReqResult = KErrNone;
       
   115 	iContactManager->iSupported = TVIMPSTEnums::ESupported;
       
   116 	
       
   117 	TInt error = iContactManager->AddServerContactL(KTestId(), KTestId(), KTestId());
       
   118 	
       
   119 	EUNIT_ASSERT(TVIMPSTEnums::ESupported == iContactManager->IsSupported())
       
   120 	EUNIT_ASSERT( KErrNone == error );	
       
   121 	}
       
   122 	
       
   123 void T_VIMPSTEngineContactMgmtExtention::TestAddServerContactSuccessWithDataLengthZeroL()
       
   124 	{
       
   125 	gCreateXIMPIdentity = ETrue;
       
   126 	iContactManager->iReqResult = KErrNone;
       
   127 	iContactManager->iSupported = TVIMPSTEnums::ESupported;
       
   128 	TInt error =  iContactManager->AddServerContactL(KNullDesC(), KNullDesC(), KNullDesC());
       
   129 	EUNIT_ASSERT(TVIMPSTEnums::ESupported == iContactManager->IsSupported())	
       
   130 	EUNIT_ASSERT( KErrNone == error );	
       
   131 	}
       
   132 	
       
   133 
       
   134 
       
   135 void T_VIMPSTEngineContactMgmtExtention::TestAddServerContactErrorValidDataL()
       
   136 	{
       
   137 	gCreateXIMPIdentity = ETrue;
       
   138 	iContactManager->iReqResult = KErrNotSupported;
       
   139 	iContactManager->iSupported = TVIMPSTEnums::ENotSupported;
       
   140 	TInt error = iContactManager->AddServerContactL(KTestId(), KTestId(), KTestId());
       
   141 	
       
   142 	EUNIT_ASSERT(TVIMPSTEnums::ENotSupported == iContactManager->IsSupported())
       
   143 	EUNIT_ASSERT( KErrNone == error );	
       
   144 	}		
       
   145 
       
   146 
       
   147 void T_VIMPSTEngineContactMgmtExtention::TestType()
       
   148 	{	
       
   149 	EUNIT_ASSERT(TVIMPSTEnums::EContactManagement == iContactManager->Type())	
       
   150 	}
       
   151 	
       
   152 
       
   153 void T_VIMPSTEngineContactMgmtExtention::TestIsSupported()
       
   154 	{	
       
   155 	EUNIT_ASSERT(TVIMPSTEnums::ESupportUnKnown == iContactManager->IsSupported())	
       
   156 	}
       
   157 		
       
   158 
       
   159 void T_VIMPSTEngineContactMgmtExtention::TestDeleteServerContactSuccessValidDataL()
       
   160 	{
       
   161 	gCreateXIMPIdentity = ETrue;
       
   162 	iContactManager->iReqResult = KErrNone;
       
   163 	iContactManager->iSupported = TVIMPSTEnums::ESupported;
       
   164 	
       
   165 	TInt error = iContactManager->DeleteServerContactL(KTestId(), KTestId());
       
   166 	
       
   167 	EUNIT_ASSERT(TVIMPSTEnums::ESupported == iContactManager->IsSupported())
       
   168 	EUNIT_ASSERT( KErrNone == error );	
       
   169 	}
       
   170 
       
   171 void T_VIMPSTEngineContactMgmtExtention::TestDeleteServerContactSuccessWithDataLengthZeroL()
       
   172 	{
       
   173 	gCreateXIMPIdentity = ETrue;
       
   174 	iContactManager->iReqResult = KErrNone;
       
   175 	iContactManager->iSupported = TVIMPSTEnums::ESupported;
       
   176 	
       
   177 	TInt error = iContactManager->DeleteServerContactL(KNullDesC(), KNullDesC());
       
   178 	
       
   179 	EUNIT_ASSERT(TVIMPSTEnums::ESupported == iContactManager->IsSupported())	
       
   180 	EUNIT_ASSERT( KErrNone == error );	
       
   181 	}
       
   182 
       
   183 
       
   184 	
       
   185 
       
   186 
       
   187 void T_VIMPSTEngineContactMgmtExtention::TestDeleteServerContactErrorValidDataL()
       
   188 	{
       
   189 	gCreateXIMPIdentity = ETrue;
       
   190 	iContactManager->iReqResult = KErrNotSupported;
       
   191 	iContactManager->iSupported = TVIMPSTEnums::ENotSupported;
       
   192 	TInt error = iContactManager->DeleteServerContactL(KTestId(), KTestId());
       
   193 	
       
   194 	EUNIT_ASSERT(TVIMPSTEnums::ENotSupported == iContactManager->IsSupported())
       
   195 	EUNIT_ASSERT( KErrNone == error );	
       
   196 	}
       
   197 	
       
   198 
       
   199 
       
   200 void T_VIMPSTEngineContactMgmtExtention::TestHandleSessionContextEventOperationDeleteErrNoneL()
       
   201     {
       
   202     TXIMPRequestId id;
       
   203     id.Init( 10 );
       
   204 
       
   205 	iRequestMapper->CreateRequestL(id, ETrue, EVIMPSTXimpOperationDeleteContact);// waite here
       
   206 	
       
   207     MXIMPRequestCompleteEventStub requestCompleteEvent;
       
   208     ::gMXIMPRequestCompleteEventStubInterfaceId = MXIMPRequestCompleteEvent::KInterfaceId;
       
   209 
       
   210     ::gMXIMPRequestCompleteEventStubRequestId = id;
       
   211     
       
   212     iContactManager->HandleSessionContextEventL
       
   213     				(*iPresenceCtx, requestCompleteEvent, EVIMPSTXimpOperationDeleteContact);
       
   214     
       
   215     
       
   216     CVIMPSTEngineRequest* req1 = iRequestMapper->FindRequestId(id);     
       
   217     EUNIT_ASSERT( NULL == req1 );
       
   218     
       
   219 
       
   220     EUNIT_ASSERT(KErrNone == iContactManager->iReqResult)
       
   221                                              
       
   222     }	
       
   223 
       
   224 
       
   225 void T_VIMPSTEngineContactMgmtExtention::TestHandleSessionContextEventOperationAddErrNoneL()
       
   226     {
       
   227     TXIMPRequestId id;
       
   228     id.Init( 20 );
       
   229 
       
   230     gRequestCompleteEventResultCodeKerrNotSupported = EFalse;
       
   231 	iRequestMapper->CreateRequestL(id, ETrue, EVIMPSTXimpOperationAddContact);// waite here
       
   232 	
       
   233     MXIMPRequestCompleteEventStub requestCompleteEvent;
       
   234     ::gMXIMPRequestCompleteEventStubInterfaceId = MXIMPRequestCompleteEvent::KInterfaceId;
       
   235 
       
   236     ::gMXIMPRequestCompleteEventStubRequestId = id;
       
   237     
       
   238     iContactManager->HandleSessionContextEventL
       
   239     				(*iPresenceCtx, requestCompleteEvent, EVIMPSTXimpOperationAddContact);
       
   240     
       
   241     CVIMPSTEngineRequest* req1 = iRequestMapper->FindRequestId(id);     
       
   242     EUNIT_ASSERT( NULL == req1 );
       
   243     
       
   244     TInt res = iContactManager->iReqResult;
       
   245     EUNIT_ASSERT(KErrNone == iContactManager->iReqResult)
       
   246                                              
       
   247     }	
       
   248  
       
   249  
       
   250  void T_VIMPSTEngineContactMgmtExtention::TestHandleSessionContextEventOperationDeleteNotSupportedL()
       
   251     {
       
   252     TXIMPRequestId id;
       
   253     id.Init( 10 );
       
   254 
       
   255 	gRequestCompleteEventResultCodeKerrNotSupported = ETrue;
       
   256 	
       
   257 	iRequestMapper->CreateRequestL(id, ETrue, EVIMPSTXimpOperationDeleteContact);// waite here
       
   258 	
       
   259     MXIMPRequestCompleteEventStub requestCompleteEvent;
       
   260     ::gMXIMPRequestCompleteEventStubInterfaceId = MXIMPRequestCompleteEvent::KInterfaceId;
       
   261 
       
   262     ::gMXIMPRequestCompleteEventStubRequestId = id;
       
   263     
       
   264     iContactManager->HandleSessionContextEventL
       
   265     				(*iPresenceCtx, requestCompleteEvent, EVIMPSTXimpOperationDeleteContact);
       
   266     
       
   267     
       
   268     CVIMPSTEngineRequest* req1 = iRequestMapper->FindRequestId(id);     
       
   269     EUNIT_ASSERT( NULL == req1 );
       
   270     
       
   271     EUNIT_ASSERT(KErrNotSupported == iContactManager->iReqResult)
       
   272                                              
       
   273     }	
       
   274 
       
   275 
       
   276 void T_VIMPSTEngineContactMgmtExtention::TestHandleSessionContextEventOperationAddNotSupportedL()
       
   277     {
       
   278     TXIMPRequestId id;
       
   279     id.Init( 20 );
       
   280 
       
   281 	gRequestCompleteEventResultCodeKerrNotSupported = ETrue;
       
   282 	
       
   283 	iRequestMapper->CreateRequestL(id, ETrue, EVIMPSTXimpOperationAddContact);// waite here
       
   284 	
       
   285     MXIMPRequestCompleteEventStub requestCompleteEvent;
       
   286     ::gMXIMPRequestCompleteEventStubInterfaceId = MXIMPRequestCompleteEvent::KInterfaceId;
       
   287 
       
   288     ::gMXIMPRequestCompleteEventStubRequestId = id;
       
   289     
       
   290     iContactManager->HandleSessionContextEventL
       
   291     				(*iPresenceCtx, requestCompleteEvent, EVIMPSTXimpOperationAddContact);
       
   292     
       
   293     CVIMPSTEngineRequest* req1 = iRequestMapper->FindRequestId(id);     
       
   294     EUNIT_ASSERT( NULL == req1 );
       
   295     
       
   296     EUNIT_ASSERT(KErrNotSupported == iContactManager->iReqResult)
       
   297                                              
       
   298     }	
       
   299  
       
   300 
       
   301 void T_VIMPSTEngineContactMgmtExtention::TestHandleSessionContextEventOperationNotValidOperationL()
       
   302     {
       
   303     TXIMPRequestId id;
       
   304     id.Init( 20 );
       
   305 
       
   306 	iRequestMapper->CreateRequestL(id, ETrue, EVIMPSTXimpOperationAddContact);// waite here
       
   307 	
       
   308     MXIMPRequestCompleteEventStub requestCompleteEvent;
       
   309     ::gMXIMPRequestCompleteEventStubInterfaceId = MXIMPRequestCompleteEvent::KInterfaceId;
       
   310 
       
   311     ::gMXIMPRequestCompleteEventStubRequestId = id;
       
   312     
       
   313     iContactManager->iReqResult = KErrNone;
       
   314     
       
   315     iContactManager->HandleSessionContextEventL
       
   316     				(*iPresenceCtx, requestCompleteEvent, EVIMPSTXimpOperationNoOperation);
       
   317     
       
   318     CVIMPSTEngineRequest* req1 = iRequestMapper->FindRequestId(id);     
       
   319     EUNIT_ASSERT( req1 );
       
   320     
       
   321     EUNIT_ASSERT(KErrNone == iContactManager->iReqResult)
       
   322                                              
       
   323     }
       
   324   
       
   325     
       
   326 	
       
   327 EUNIT_BEGIN_TEST_TABLE( T_VIMPSTEngineContactMgmtExtention, "T_VIMPSTEngineContactMgmtExtention", "" )
       
   328 
       
   329     EUNIT_TEST( "TestConstructionL ",
       
   330             "T_VIMPSTEngineContactMgmtExtention",
       
   331             "ConstructionL",
       
   332             "FUNCTIONALITY", SetupL, TestConstructionL, Teardown )
       
   333     EUNIT_TEST( "TestCreateIdentityNormalL ",
       
   334             "T_VIMPSTEngineContactMgmtExtention",
       
   335             "CreateIdentityLC",
       
   336             "FUNCTIONALITY", SetupL, TestCreateIdentityNormalL, Teardown )
       
   337     
       
   338     EUNIT_TEST( "TestAddServerContactSuccessValidDataL ",
       
   339             "T_VIMPSTEngineContactMgmtExtention",
       
   340             "AddServerContactL",
       
   341             "FUNCTIONALITY", SetupL, TestAddServerContactSuccessValidDataL, Teardown )
       
   342     EUNIT_TEST( "TestAddServerContactSuccessWithDataLengthZeroL ",
       
   343             "T_VIMPSTEngineContactMgmtExtention",
       
   344             "AddServerContactL",
       
   345             "FUNCTIONALITY", SetupL, TestAddServerContactSuccessWithDataLengthZeroL, Teardown )
       
   346     EUNIT_TEST( "TestAddServerContactErrorValidDataL ",
       
   347             "T_VIMPSTEngineContactMgmtExtention",
       
   348             "AddServerContactL",
       
   349             "FUNCTIONALITY", SetupL, TestAddServerContactErrorValidDataL, Teardown )	 
       
   350     EUNIT_TEST( "TestIsSupported ",
       
   351             "T_VIMPSTEngineContactMgmtExtention",
       
   352             "IsSupported",
       
   353             "FUNCTIONALITY", SetupL, TestIsSupported, Teardown )	  
       
   354     EUNIT_TEST( "TestType ",
       
   355             "T_VIMPSTEngineContactMgmtExtention",
       
   356             "Type",
       
   357             "FUNCTIONALITY", SetupL, TestType, Teardown )
       
   358     EUNIT_TEST( "TestDeleteServerContactSuccessValidDataL ",
       
   359             "T_VIMPSTEngineContactMgmtExtention",
       
   360             "DeleteServerContactL",
       
   361             "FUNCTIONALITY", SetupL, TestDeleteServerContactSuccessValidDataL, Teardown )
       
   362     EUNIT_TEST( "TestDeleteServerContactSuccessWithDataLengthZeroL ",
       
   363             "T_VIMPSTEngineContactMgmtExtention",
       
   364             "DeleteServerContactL",
       
   365             "FUNCTIONALITY", SetupL, TestDeleteServerContactSuccessWithDataLengthZeroL, Teardown )
       
   366     EUNIT_TEST( "TestDeleteServerContactErrorValidDataL ",
       
   367             "T_VIMPSTEngineContactMgmtExtention",
       
   368             "DeleteServerContactL",
       
   369             "FUNCTIONALITY", SetupL, TestDeleteServerContactErrorValidDataL, Teardown )
       
   370     
       
   371     EUNIT_TEST( "TestHandleSessionContextEventOperationDeleteErrNoneL ",
       
   372             "T_VIMPSTEngineContactMgmtExtention",
       
   373             "HandleSessionContextEventL",
       
   374             "FUNCTIONALITY", SetupL, TestHandleSessionContextEventOperationDeleteErrNoneL, Teardown )
       
   375     EUNIT_TEST( "TestHandleSessionContextEventOperationDeleteNotSupportedL ",
       
   376             "T_VIMPSTEngineContactMgmtExtention",
       
   377             "HandleSessionContextEventL",
       
   378             "FUNCTIONALITY", SetupL, TestHandleSessionContextEventOperationDeleteNotSupportedL, Teardown )
       
   379     EUNIT_TEST("TestHandleSessionContextEventOperationAddErrNoneL ",
       
   380             "T_VIMPSTEngineContactMgmtExtention",
       
   381             "HandleSessionContextEventL",
       
   382             "FUNCTIONALITY", SetupL, TestHandleSessionContextEventOperationAddErrNoneL, Teardown )
       
   383     EUNIT_TEST( "TestHandleSessionContextEventOperationAddNotSupportedL ",
       
   384             "T_VIMPSTEngineContactMgmtExtention",
       
   385             "HandleSessionContextEventL",
       
   386             "FUNCTIONALITY",SetupL, TestHandleSessionContextEventOperationAddNotSupportedL, Teardown )	  
       
   387     EUNIT_TEST( "TestHandleSessionContextEventOperationNotValidOperationL ",
       
   388             "T_VIMPSTEngineContactMgmtExtention",
       
   389             "HandleSessionContextEventL",
       
   390             "FUNCTIONALITY", SetupL, TestHandleSessionContextEventOperationNotValidOperationL, Teardown )
       
   391     
       
   392     
       
   393 EUNIT_END_TESTCASE_TABLE
       
   394 
       
   395 //  END OF FILE