Exemplo n.º 1
0
void ComponentEventTest::testConvertSimpleUnits()
{
  std::map<std::string, std::string> attributes;
  attributes["id"] = "1";
  attributes["name"] = "DataItemTest1";
  attributes["type"] = "ACCELERATION";
  attributes["category"] = "SAMPLE";
  
  std::string time("NOW"), value("2.0");
  attributes["nativeUnits"] = "INCH";
  DataItem data1 (attributes);
  ComponentEvent event1 (data1, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 25.4f, event1.getFValue());
  CPPUNIT_ASSERT(event1.getSValue().empty());
  
  attributes["nativeUnits"] = "FOOT";
  DataItem data2 (attributes);
  ComponentEvent event2 (data2, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 304.8f, event2.getFValue());
  CPPUNIT_ASSERT(event2.getSValue().empty());
  
  attributes["nativeUnits"] = "CENTIMETER";
  DataItem data3 (attributes);
  ComponentEvent event3 (data3, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 10.0f, event3.getFValue());
  CPPUNIT_ASSERT(event3.getSValue().empty());
  
  attributes["nativeUnits"] = "DECIMETER";
  DataItem data4 (attributes);
  ComponentEvent event4 (data4, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 100.0f, event4.getFValue());
  CPPUNIT_ASSERT(event4.getSValue().empty());
  
  attributes["nativeUnits"] = "METER";
  DataItem data5 (attributes);
  ComponentEvent event5 (data5, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 1000.0f, event5.getFValue());
  CPPUNIT_ASSERT(event5.getSValue().empty());
  
  attributes["nativeUnits"] = "FAHRENHEIT";
  DataItem data6 (attributes);
  ComponentEvent event6 (data6, 123, "NOW", "2.0");
  CPPUNIT_ASSERT_EQUAL((2.0f - 32.0f) * (5.0f / 9.0f), event6.getFValue());
  CPPUNIT_ASSERT(event6.getSValue().empty());
  
  attributes["nativeUnits"] = "POUND";
  DataItem data7 (attributes);
  ComponentEvent event7 (data7, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 0.45359237f, event7.getFValue());
  CPPUNIT_ASSERT(event7.getSValue().empty());
  
  attributes["nativeUnits"] = "GRAM";
  DataItem data8 (attributes);
  ComponentEvent event8 (data8, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f / 1000.0f, event8.getFValue());
  CPPUNIT_ASSERT(event8.getSValue().empty());
  
  attributes["nativeUnits"] = "RADIAN";
  DataItem data9 (attributes);
  ComponentEvent event9 (data9, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 57.2957795f, event9.getFValue());
  CPPUNIT_ASSERT(event9.getSValue().empty());
  
  attributes["nativeUnits"] = "MINUTE";
  DataItem data10 (attributes);
  ComponentEvent event10 (data10, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 60.0f, event10.getFValue());
  CPPUNIT_ASSERT(event10.getSValue().empty());
  
  attributes["nativeUnits"] = "HOUR";
  DataItem data11 (attributes);
  ComponentEvent event11 (data11, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f * 3600.0f, event11.getFValue());
  CPPUNIT_ASSERT(event11.getSValue().empty());
  
  attributes["nativeUnits"] = "MILLIMETER";
  DataItem data12 (attributes);
  ComponentEvent event12 (data12, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f, event12.getFValue());
  CPPUNIT_ASSERT(event12.getSValue().empty());
  
  attributes["nativeUnits"] = "PERCENT";
  DataItem data13 (attributes);
  ComponentEvent event13 (data13, 123, time, value);
  CPPUNIT_ASSERT_EQUAL(2.0f, event13.getFValue());
  CPPUNIT_ASSERT(event13.getSValue().empty());
}
void UT_CMceStateOffering::UT_CMceStateOffering_ExitLL()
    {
    CMceMsgBase* msg = NULL;
    
    iSipSession->iSubState = CMceSipSession::EOffering;
    
    TMceIds ids;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    
    TMceStateTransitionEvent event1( *iSipSession, EMceMediaUpdated );
    iState->ExitL( event1 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateEstablished );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EEstablished );
    

    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    TMceStateTransitionEvent event2( *iSipSession, EMceItcCancel, ids, *msg );
    iState->ExitL( event2 );

    //Ringing Case 1: Not Reliable
    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    
    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(), 
        KMceSipRinging, 
        SipStrConsts::EPhraseRinging );
    
    TMceStateTransitionEvent event3( *iSipSession, EMceProvisionalResponse );
    iState->ExitL( event3 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EOffering );
    
    
    
	//Ringing Case 2: Reliable Provisional Response
    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
            
    MCETestHelper::SetResponseL( 
        *iSipSession->iResponse, 
        KMceSipRinging, SipStrConsts::EPhraseRinging,
    	EFalse, ETrue, 500);
    
    TMceStateTransitionEvent event3_1( *iSipSession, EMceProvisionalResponse );
    iState->ExitL( event3_1 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EOffering );
    EUNIT_ASSERT ( iSipSession->RSeq() == 500 );
    
        

    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(), 
        KMceSipQueued, 
        SipStrConsts::EEmpty );

    TMceStateTransitionEvent event4( *iSipSession, EMceProvisionalResponse );
    iState->ExitL( event4 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EOffering );


    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    TMceStateTransitionEvent event5( *iSipSession, EMceErrorResponse );
    iState->ExitL( event5 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateTerminated );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::ETerminated );


    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    iSipSession->Dialog()->Dialog().iState = CSIPDialog::ETerminated;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(), 
        KMceSipSessionIntervalTooSmall, 
        SipStrConsts::EPhraseIntervalTooBrief );

    TMceStateTransitionEvent event6( *iSipSession, EMceErrorResponse );
    iState->ExitL( event6 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
      

    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(), 
        KMceSipBadRequest, 
        SipStrConsts::EPhraseBadRequest );
    

    TMceStateTransitionEvent event7( *iSipSession, EMceErrorResponse );
    iState->ExitL( event7 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateTerminated );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::ETerminated );

    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EUpdating;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(), 
        KMceSipBadRequest, 
        SipStrConsts::EPhraseBadRequest );
    

    TMceStateTransitionEvent event7_1( *iSipSession, EMceErrorResponse );
    iState->ExitL( event7_1 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateEstablished );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EEstablished );


    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EUpdating;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(), 
        KMceSipCallOrTransactionDoesNotExist, 
        SipStrConsts::EPhraseCallTransactionDoesNotExist );
    

    TMceStateTransitionEvent event7_2( *iSipSession, EMceErrorResponse );
    iState->ExitL( event7_2 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateTerminating );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::ETerminating );

    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EUpdating;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );

    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(), 
        KMceSipRequestTimeout, 
        SipStrConsts::EPhraseRequestTimeout );

    TMceStateTransitionEvent event7_3( *iSipSession, EMceErrorResponse );
    iState->ExitL( event7_3 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateTerminating );
    EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::ETerminating );


    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    
    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    MCETestHelper::ChangeResponseTypeL(
        *iSipSession->iResponse->ResponseElements(),
        KMceSipMovedTemporarily,
        SipStrConsts::EPhraseOk );
    
    TMceStateTransitionEvent event8( *iSipSession, EMceRedirectionResponse );
    iState->ExitL( event8 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    
    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EUpdating;
    TMceStateTransitionEvent event9( *iSipSession, EMceRedirectionResponse );
    iState->ExitL( event9 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateServerEstablishing );
    
    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EOffering;
    MCETestHelper::ChangeResponseTypeL( 
        *iSipSession->iResponse->ResponseElements(),
        KMceSipMultipleChoices,
        SipStrConsts::EPhraseOk );

    TMceStateTransitionEvent event10( *iSipSession, EMceRedirectionResponse );
    iState->ExitL( event10 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateTerminated );
    
    iSipSession->NextState( KMceStateOffering );
    iSipSession->iSubState = CMceSipSession::EAnswering;
    TMceStateTransitionEvent event11( *iSipSession, EMceRedirectionResponse );
    iState->ExitL( event11 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );   

	// Hanlding of Extension Request / Response does not change the session state    

	//EMceItcReplySend
	TMceStateTransitionEvent event12( *iSipSession, EMceItcReplySend, ids, *msg );
    iState->ExitL( event12 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );   
    
    //EMceRequest
	TMceStateTransitionEvent event13( *iSipSession, EMceRequest );
    iState->ExitL( event13 );
	EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );   
	
	//EMceProvisionalResponse
	CSIPClientTransaction* clitransaction = 
    MCETestHelper::ClientTransactionLC( SipStrConsts::EInfo, KMceSipSessionProgress, 
    									SipStrConsts::EPhraseSessionProgress, ETrue );
	iSipSession->SetPendingTransactionL( clitransaction );
    CleanupStack::Pop( clitransaction );
    iSipSession->iResponse = clitransaction;

	TMceStateTransitionEvent event14( *iSipSession, EMceProvisionalResponse );
    iState->ExitL( event14 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );   

	//EMceResponse
	CSIPClientTransaction* clitransaction1 = 
    MCETestHelper::ClientTransactionLC( SipStrConsts::EInfo, KMceSipOK, 
    									SipStrConsts::EPhraseOk, ETrue );
	iSipSession->SetPendingTransactionL( clitransaction1 );
    CleanupStack::Pop( clitransaction1 );
    iSipSession->iResponse = clitransaction1;
	
	TMceStateTransitionEvent event15( *iSipSession, EMceResponse );
    iState->ExitL( event15 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );   


	//EMceRedirectionResponse
	CSIPClientTransaction* clitransaction2 = 
    MCETestHelper::ClientTransactionLC( SipStrConsts::EInfo, KMceSipMovedTemporarily, 
    									SipStrConsts::EPhraseOk, ETrue );
	iSipSession->SetPendingTransactionL( clitransaction2 );
    CleanupStack::Pop( clitransaction2 );
    iSipSession->iResponse = clitransaction2;
	
	TMceStateTransitionEvent event16( *iSipSession, EMceRedirectionResponse );
    iState->ExitL( event16 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );   
	

	//EMceErrorResponse
	CSIPClientTransaction* clitransaction3 = 
    MCETestHelper::ClientTransactionLC( SipStrConsts::EInfo, KMceSipBadExtension, 
    									SipStrConsts::EPhraseBadExtension, ETrue );
	iSipSession->SetPendingTransactionL( clitransaction3 );
    CleanupStack::Pop( clitransaction3 );
    iSipSession->iResponse = clitransaction3;
	
	TMceStateTransitionEvent event17( *iSipSession, EMceErrorResponse );
    iState->ExitL( event17 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    
    //EMceMediaUpdated, IMS flow
    TMceStateTransitionEvent event1_1( *iSipSession, EMceMediaUpdated );
    CSIPClientTransaction* response = &iSipSession->Response();
    CSIPCSeqHeader* cSeqHeader = CSIPCSeqHeader::DecodeL( _L8("1 UPDATE") );
    CSIPMessageElements* messageElements =
        const_cast<CSIPMessageElements*>( &response->ResponseElements()->MessageElements() );
    messageElements->AddHeaderL( cSeqHeader );
    iState->ExitL( event1_1 );
    EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering );
    }