diff options
Diffstat (limited to 'AudioManagerCore/test')
35 files changed, 12017 insertions, 0 deletions
diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp new file mode 100644 index 0000000..9008ce6 --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp @@ -0,0 +1,673 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmControlInterfaceTest.h" +#include <algorithm> +#include <string> +#include <vector> +#include <set> +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + +DLT_DECLARE_CONTEXT(AudioManager) +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + +ACTION(returnResyncConnection) +{ + std::vector<am_Connection_s> listConnections; + am_Connection_s conn; + conn.sinkID=1; + conn.sourceID=1; + conn.connectionFormat=CF_GENIVI_ANALOG; + listConnections.push_back(conn); + arg1=listConnections; +} + +CAmControlInterfaceTest::CAmControlInterfaceTest() : + pSocketHandler(), // + plistCommandPluginDirs(), // + plistRoutingPluginDirs(), // + pDatabaseHandler(), // + pRoutingSender(plistRoutingPluginDirs), //RoutingReceiver + pCommandSender(plistCommandPluginDirs), // + pMockControlInterface(), // + pMockRoutingInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlInterfaceBackdoor(), // + pControlSender(), // + pRouter(&pDatabaseHandler,&pControlSender), // + pDatabaseObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pDatabaseObserver); + pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); + pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockRoutingInterface, "mock"); + +} + +CAmControlInterfaceTest::~CAmControlInterfaceTest() +{ + CAmDltWrapper::instance()->unregisterContext(AudioManager); +} + +void CAmControlInterfaceTest::SetUp() +{ + +} + +void CAmControlInterfaceTest::TearDown() +{ +} + +TEST_F(CAmControlInterfaceTest,registerDomain) +{ + + am_Domain_s domain; + am_domainID_t domainID; + pCF.createDomain(domain); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterDomain(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerDomain(domain,domainID)); + ASSERT_EQ(domainID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterDomain) +{ + am_domainID_t domainID = 34; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterDomain(34)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterDomain(domainID)); +} + +TEST_F(CAmControlInterfaceTest,registerSink) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterSink(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerSink(sink,sinkID)); + ASSERT_EQ(sinkID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterSink) +{ + am_sinkID_t sinkID = 12; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSink(12)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSink(sinkID)); +} + +TEST_F(CAmControlInterfaceTest,registerSource) +{ + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterSource(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerSource(source,sourceID)); + ASSERT_EQ(sourceID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterSource) +{ + am_sourceID_t sourceID = 12; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSource(12)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSource(sourceID)); +} + +TEST_F(CAmControlInterfaceTest,registerGateway) +{ + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + pCF.createGateway(gateway); + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemRegisterGateway(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK))); + ASSERT_EQ(E_OK, pRoutingReceiver.registerGateway(gateway,gatewayID)); + ASSERT_EQ(gatewayID, 2); +} + +TEST_F(CAmControlInterfaceTest,deregisterGateway) +{ + am_gatewayID_t gatewayID = 12; + + //When we run this test, we expect the call on the control interface + EXPECT_CALL(pMockControlInterface,hookSystemDeregisterGateway(12)).WillRepeatedly(Return(E_OK)); + ASSERT_EQ(E_OK, pRoutingReceiver.deregisterGateway(gatewayID)); +} + +TEST_F(CAmControlInterfaceTest,ackConnect) +{ + am_connectionID_t connectionID; + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Connection_s> connectionList; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //when asyncConnect is called, we expect a call on the routingInterface + EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + + //The handle should have the correct type + ASSERT_EQ(handle.handleType, H_CONNECT); + ASSERT_EQ(handle.handle, 1); + ASSERT_EQ(connectionID, 1); + + //The list of handles shall have the handle inside + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, handle.handleType); + + //we check the list of connections - but it must be empty because the ack did not arrive yet + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList.empty()); + + //finally we answer via the RoutingInterface and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1); + pRoutingReceiver.ackConnect(handle, connectionID, E_OK); + + //the list of handles must be empty now + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //but the connection must be in the connectionlist + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(!connectionList.empty()); + + //no we try the same, but do expect a no_change answer directly and no call because connection already exists + //ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + //needed to be removed because logic changed here +} + +TEST_F(CAmControlInterfaceTest,ackDisconnect) +{ + am_connectionID_t connectionID; + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Connection_s> connectionList; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //now we first need to connect, we expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + + //answer with an ack to insert the connection in the database + EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1); + pRoutingReceiver.ackConnect(handle, connectionID, E_OK); + + //now we can start to disconnect and expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1)); + + //during the disconnection, the connection is still in the list! + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(!connectionList.empty()); + + //then we fire the ack and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckDisconnect(_,E_OK)).Times(1); + pRoutingReceiver.ackDisconnect(handle, connectionID, E_OK); + + //make sure the handle is gone + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //make sure the connection is gone + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList.empty()); + + //Now let's try to disconnect what is not existing... + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,2)); +} + +TEST_F(CAmControlInterfaceTest,ackDisconnectFailAndRetry) +{ + logInfo("ackDisconnectFailAndRetry test started"); + am_connectionID_t connectionID; + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Connection_s> connectionList; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //now we first need to connect, we expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + + //answer with an ack to insert the connection in the database + EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1); + pRoutingReceiver.ackConnect(handle, connectionID, E_OK); + + //now we can start to disconnect and expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1)); + + //during the disconnection, the connection is still in the list! + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(!connectionList.empty()); + + //then we fire the ack and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckDisconnect(_,E_NON_EXISTENT)).Times(1); + pRoutingReceiver.ackDisconnect(handle, connectionID+1, E_NON_EXISTENT); + + //make sure the handle is gone + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //make sure the connection is still there + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_FALSE(connectionList.empty()); + + ASSERT_TRUE(pDatabaseHandler.existConnectionID(1)); + + //Now let's try to disconnect now + EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1)); + logInfo("ackDisconnectFailAndRetry test finished"); +} + +TEST_F(CAmControlInterfaceTest,setSourceState) +{ + + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + am_SourceState_e state; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = DYNAMIC_ID_BOUNDARY; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //we set the sourcestate and expect a call on the routingInterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSourceState(_,2,SS_PAUSED)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED)); + + //we want our handle in the list and let the type be the right one + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESTATE); + + //the state must be unchanged because did not get the ack + ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state)); + ASSERT_EQ(state, SS_ON); + + //now we sent out the ack and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSourceState(_,E_OK)).Times(1); + pRoutingReceiver.ackSetSourceState(handle, E_OK); + + //finally we need the sourcestate to be changed + ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state)); + ASSERT_EQ(state, SS_PAUSED); + + //make sure the handle is gone + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //we try again but expect a no change error + //ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED)); + //needed to be removed because logic changed here +} + +TEST_F(CAmControlInterfaceTest,SetSinkVolumeChange) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_volume_t volume; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + sink.volume = 10; + + //setup environment, we need a domain and a sink + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //set the volume and expect a call on the routing interface + EXPECT_CALL(pMockRoutingInterface,asyncSetSinkVolume(_,2,11,RAMP_GENIVI_DIRECT,23)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_GENIVI_DIRECT,23)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSINKVOLUME); + + //now we read out the volume, but we expect no change because the ack did not arrive yet + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume)); + ASSERT_EQ(sink.volume, volume); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSinkVolumeChange(_,11,E_OK)).Times(1); + pRoutingReceiver.ackSetSinkVolumeChange(handle, 11, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume)); + ASSERT_EQ(11, volume); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + //ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_GENIVI_DIRECT,23)); + //needed to be removed because logic changed here +} + +TEST_F(CAmControlInterfaceTest,ackSetSourceVolumeChange) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_volume_t volume; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = DYNAMIC_ID_BOUNDARY; + source.volume = 12; + + //prepare the scene + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //change the sinkVolume, expect a call on the routingInterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSourceVolume(_,2,11,RAMP_GENIVI_DIRECT,23)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_GENIVI_DIRECT,23)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSOURCEVOLUME); + + //now we read out the volume, but we expect no change because the ack did not arrive yet + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume)); + ASSERT_EQ(source.volume, volume); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSourceVolumeChange(_,11,E_OK)).Times(1); + pRoutingReceiver.ackSetSourceVolumeChange(handle, 11, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume)); + ASSERT_EQ(11, volume); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + //ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_GENIVI_DIRECT,23)); + //needed to be removed because logic changed here +} + +TEST_F(CAmControlInterfaceTest,ackSetSinkSoundProperty) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + int16_t oldvalue; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + soundProperty.type = SP_GENIVI_BASS; + soundProperty.value = 244; + + //setup environment, we need a domain and a sink + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //change the soundproperty, expect a call on the routinginterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSinkSoundProperty(_,2,_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSINKSOUNDPROPERTY); + + //read out this property. There is no change, because the ack did not arrive yet. + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(2,SP_GENIVI_BASS,oldvalue)); + ASSERT_EQ(sink.listSoundProperties[0].value, oldvalue); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)).Times(1); + pRoutingReceiver.ackSetSinkSoundProperty(handle, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID,SP_GENIVI_BASS,oldvalue)); + ASSERT_EQ(soundProperty.value, oldvalue); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + //ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty)); + //needed to be removed because logic changed here +} + +TEST_F(CAmControlInterfaceTest,ackSetSourceSoundProperty) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + int16_t oldvalue; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = DYNAMIC_ID_BOUNDARY; + soundProperty.type = SP_GENIVI_BASS; + soundProperty.value = 244; + + //prepare the scene + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //we trigger the change and wait for a call on the routinginterface + EXPECT_CALL(pMockRoutingInterface,asyncSetSourceSoundProperty(_,2,_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty)); + + //check the list of handles. The handle must be in there and have the right type + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_EQ(handlesList[0].handle, handle.handle); + ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESOUNDPROPERTY); + + //read out this property. There is no change, because the ack did not arrive yet. + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(2,SP_GENIVI_BASS,oldvalue)); + ASSERT_EQ(source.listSoundProperties[0].value, oldvalue); + + //lets send the answer and expect a call on the controlInterface + EXPECT_CALL(pMockControlInterface,cbAckSetSourceSoundProperty(_,E_OK)).Times(1); + pRoutingReceiver.ackSetSourceSoundProperty(handle, E_OK); + + //finally, the new value must be in the database + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID,SP_GENIVI_BASS,oldvalue)); + ASSERT_EQ(soundProperty.value, oldvalue); + + //and the handle must be destroyed + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + //Now we try again, but the value is unchanged + //ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty)); + //needed to be removed because logic changed here +} + +TEST_F(CAmControlInterfaceTest,crossFading) +{ + //todo: implement crossfading test +} + +TEST_F(CAmControlInterfaceTest,resyncConnectionsTest) +{ + am_Domain_s domain; + am_domainID_t domainID; + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + + //prepare the scene + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + + std::vector<am_Connection_s> listConnections; + + EXPECT_CALL(pMockRoutingInterface,resyncConnectionState(domainID,_)).WillOnce(DoAll(returnResyncConnection(), Return(E_OK))); + ASSERT_EQ(am_Error_e::E_OK,pControlReceiver.resyncConnectionState(domainID,listConnections)); + ASSERT_EQ(listConnections[0].sinkID,1); + ASSERT_EQ(listConnections[0].sourceID,1); + ASSERT_EQ(listConnections[0].connectionFormat,CF_GENIVI_ANALOG); +} + +TEST_F(CAmControlInterfaceTest,ackConnectNotPossible) +{ + am_connectionID_t connectionID; + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Connection_s> connectionList; + std::vector<am_Handle_s> handlesList; + am_Handle_s handle; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //when asyncConnect is called, we expect a call on the routingInterface + EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_GENIVI_STEREO)).WillOnce(Return(E_COMMUNICATION)); + ASSERT_EQ(E_COMMUNICATION, pControlReceiver.connect(handle,connectionID,CF_GENIVI_STEREO,2,2)); + + //The list of handles shall be empty + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList)); + ASSERT_TRUE(handlesList.empty()); + + + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList.empty()); + +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("AudioManagerDeamon", "AudioManagerDeamon"); + CAmDltWrapper::instance()->registerContext(AudioManager, "Main", "Main Context"); + logInfo("RoutingSendInterface Test started"); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h new file mode 100644 index 0000000..b7fa27a --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h @@ -0,0 +1,76 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTINGINTERFACETEST_H_ +#define ROUTINGINTERFACETEST_H_ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +//#include "CAmDatabaseHandlerSQLite.h" +#include "CAmDatabaseHandlerMap.h" +#include "CAmControlReceiver.h" +#include "CAmRoutingReceiver.h" +#include "CAmDatabaseObserver.h" +#include "CAmControlSender.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "../IAmRoutingBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../IAmControlBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmRoutingSend.h" +#include "../MockIAmControlSend.h" +#include "CAmSocketHandler.h" + +namespace am +{ + +class CAmControlInterfaceTest: public ::testing::Test +{ +public: + CAmControlInterfaceTest(); + ~CAmControlInterfaceTest(); + CAmSocketHandler pSocketHandler; + std::vector<std::string> plistCommandPluginDirs; + std::vector<std::string> plistRoutingPluginDirs; + CAmDatabaseHandlerMap pDatabaseHandler; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + MockIAmControlSend pMockControlInterface; + MockIAmRoutingSend pMockRoutingInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + IAmControlBackdoor pControlInterfaceBackdoor; + CAmControlSender pControlSender; + CAmRouter pRouter; + CAmDatabaseObserver pDatabaseObserver; + CAmControlReceiver pControlReceiver; + CAmRoutingReceiver pRoutingReceiver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); +}; + +} + +#endif /* ROUTINGINTERFACETEST_H_ */ diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt new file mode 100644 index 0000000..4f33ac5 --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmControlInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + + + file(GLOB CONTROL_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +add_executable(AmControlInterfaceTest ${CONTROL_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmControlInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +add_test(AmControlInterfaceTest AmControlInterfaceTest) + +ADD_DEPENDENCIES(AmControlInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmControlInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests) + + + + diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt~ b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt~ new file mode 100644 index 0000000..5b71a59 --- /dev/null +++ b/AudioManagerCore/test/AmControlInterfaceTest/CMakeLists.txt~ @@ -0,0 +1,50 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmControlInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + + + file(GLOB CONTROL_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +add_executable(AmControlInterfaceTest ${CONTROL_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmControlInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmControlInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmControlInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests) + + + + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp new file mode 100644 index 0000000..337ecb7 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp @@ -0,0 +1,3276 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmMapHandlerTest.h" +#include <algorithm> +#include <string> +#include <vector> +#include <set> +#include <ios> +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + + +extern bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b); +extern bool equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_s b); +extern bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b); +extern std::string int2string(int i); + +int16_t const TEST_MAX_CONNECTION_ID = 20; +int16_t const TEST_MAX_MAINCONNECTION_ID = 20; +int16_t const TEST_MAX_SINK_ID = 40; + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + + +CAmMapBasicTest::CAmMapBasicTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(),// + pDatabaseHandler(), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlSender(), // + pRouter(&pDatabaseHandler, &pControlSender), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pCF() +{ +} + +CAmMapBasicTest::~CAmMapBasicTest() +{ +} + +void CAmMapBasicTest::createMainConnectionSetup(am_mainConnectionID_t & mainConnectionID, am_MainConnection_s & mainConnection) +{ + //fill the connection database + am_Connection_s connection; + am_Source_s source; + am_Sink_s sink; + std::vector<am_connectionID_t> connectionList; + + //we create 9 sources and sinks: + + for (uint16_t i = 1; i < 10; i++) + { + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + + pCF.createSink(sink); + sink.sinkID = i; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = i; + source.name = "source" + int2string(i); + source.domainID = 4; + + connection.sinkID = i; + connection.sourceID = i; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + connectionList.push_back(connectionID); + } + + //create a mainConnection + std::vector<am_MainConnection_s> mainConnectionList; + mainConnection.listConnectionID = connectionList; + mainConnection.mainConnectionID = 0; + mainConnection.sinkID = 1; + mainConnection.sourceID = 1; + mainConnection.connectionState = CS_CONNECTED; + mainConnection.delay = -1; + + //enter mainconnection in database + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_NE(0, mainConnectionID); + + //read out the mainconnections and check if they are equal to the data written. + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(mainConnectionList)); + std::vector<am_MainConnection_s>::iterator listIterator = mainConnectionList.begin(); + for (; listIterator < mainConnectionList.end(); ++listIterator) + { + if (listIterator->mainConnectionID == mainConnectionID) + { + ASSERT_EQ(listIterator->connectionState, mainConnection.connectionState); + ASSERT_EQ(listIterator->sinkID, mainConnection.sinkID); + ASSERT_EQ(listIterator->sourceID, mainConnection.sourceID); + ASSERT_EQ(listIterator->delay, mainConnection.delay); + ASSERT_TRUE(std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin())); + } + } +} + +void CAmMapBasicTest::SetUp() +{ + ::testing::FLAGS_gmock_verbose = "error"; +} + +void CAmMapBasicTest::TearDown() +{ + ::testing::FLAGS_gmock_verbose = "warning"; +} + + + +CAmMapHandlerTest::CAmMapHandlerTest() : + pMockInterface(), // + pObserver(&pCommandSender,&pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pDatabaseHandler.setConnectionIDRange(1, TEST_MAX_CONNECTION_ID); + pDatabaseHandler.setMainConnectionIDRange(1, TEST_MAX_MAINCONNECTION_ID); + pDatabaseHandler.setSinkIDRange(DYNAMIC_ID_BOUNDARY, DYNAMIC_ID_BOUNDARY+TEST_MAX_SINK_ID); + pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); +} + +CAmMapHandlerTest::~CAmMapHandlerTest() +{ +} + +TEST_F(CAmMapHandlerTest,getMainConnectionInfo) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection, mainConnectionT; + createMainConnectionSetup(mainConnectionID, mainConnection); + + ASSERT_EQ(E_OK, pDatabaseHandler.getMainConnectionInfoDB(mainConnectionID,mainConnectionT)); + ASSERT_TRUE(mainConnection.connectionState == mainConnectionT.connectionState); + ASSERT_TRUE(mainConnection.delay == mainConnectionT.delay); + ASSERT_TRUE(std::equal(mainConnection.listConnectionID.begin(),mainConnection.listConnectionID.end(),mainConnectionT.listConnectionID.begin())); + ASSERT_TRUE(mainConnection.sinkID == mainConnectionT.sinkID); + ASSERT_TRUE(mainConnection.sourceID == mainConnectionT.sourceID); + ASSERT_TRUE(mainConnectionID == mainConnectionT.mainConnectionID); +} + +TEST_F(CAmMapHandlerTest,getSinkInfo) +{ + //fill the connection database + am_Sink_s staticSink, firstDynamicSink, secondDynamicSink; + am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID; + std::vector<am_Sink_s> sinkList; + + pCF.createSink(staticSink); + staticSink.sinkID = 4; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) + << "ERROR: database error"; + ASSERT_EQ(staticSink.sinkID,staticSinkID) + << "ERROR: ID not the one given in staticSink"; + + pCF.createSink(firstDynamicSink); + firstDynamicSink.name = "firstdynamic"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + pCF.createSink(secondDynamicSink); + secondDynamicSink.name = "seconddynamic"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList)) + << "ERROR: database error"; + + std::vector<am_Sink_s>::iterator listIterator = sinkList.begin(); + for (; listIterator < sinkList.end(); ++listIterator) + { + if (listIterator->sinkID == staticSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, staticSink)); + } + + if (listIterator->sinkID == firstDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, firstDynamicSink)); + } + + if (listIterator->sinkID == secondDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, secondDynamicSink)); + } + } + + am_Sink_s sinkData; + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkInfoDB(secondDynamicSinkID,sinkData)); + ASSERT_EQ(secondDynamicSink.available.availability, sinkData.available.availability); + ASSERT_EQ(secondDynamicSink.available.availabilityReason, sinkData.available.availabilityReason); + ASSERT_EQ(secondDynamicSink.sinkClassID, sinkData.sinkClassID); + ASSERT_EQ(secondDynamicSink.domainID, sinkData.domainID); + ASSERT_EQ(secondDynamicSink.visible, sinkData.visible); + ASSERT_EQ(0, secondDynamicSink.name.compare(sinkData.name)); + ASSERT_EQ(secondDynamicSink.volume, sinkData.volume); + ASSERT_TRUE(std::equal(secondDynamicSink.listConnectionFormats.begin(), secondDynamicSink.listConnectionFormats.end(), sinkData.listConnectionFormats.begin())); + ASSERT_TRUE(std::equal(secondDynamicSink.listMainSoundProperties.begin(), secondDynamicSink.listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty)); + ASSERT_TRUE(std::equal(secondDynamicSink.listNotificationConfigurations.begin(), secondDynamicSink.listNotificationConfigurations.end(), sinkData.listNotificationConfigurations.begin(), equalNotificationConfiguration)); + ASSERT_TRUE(std::equal(secondDynamicSink.listMainNotificationConfigurations.begin(), secondDynamicSink.listMainNotificationConfigurations.end(), sinkData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration)); +} + +TEST_F(CAmMapHandlerTest,getSourceInfo) +{ + //fill the connection database + am_Source_s staticSource, firstDynamicSource, secondDynamicSource; + am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID; + std::vector<am_Source_s> sourceList; + + pCF.createSource(staticSource); + staticSource.sourceID = 4; + staticSource.name = "Static"; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) + << "ERROR: database error"; + ASSERT_EQ(staticSource.sourceID,staticSourceID) + << "ERROR: ID not the one given in staticSource"; + + pCF.createSource(firstDynamicSource); + firstDynamicSource.name = "firstDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + + pCF.createSource(secondDynamicSource); + secondDynamicSource.name = "secondDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList)) + << "ERROR: database error"; + + std::vector<am_Source_s>::iterator listIterator = sourceList.begin(); + for (; listIterator < sourceList.end(); ++listIterator) + { + if (listIterator->sourceID == staticSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, staticSource)); + } + + if (listIterator->sourceID == firstDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, firstDynamicSource)); + } + + if (listIterator->sourceID == secondDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, secondDynamicSource)); + } + } + + am_Source_s sourceData; + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceInfoDB(secondDynamicSourceID,sourceData)); + ASSERT_EQ(secondDynamicSource.available.availability, sourceData.available.availability); + ASSERT_EQ(secondDynamicSource.available.availabilityReason, sourceData.available.availabilityReason); + ASSERT_EQ(secondDynamicSource.sourceClassID, sourceData.sourceClassID); + ASSERT_EQ(secondDynamicSource.domainID, sourceData.domainID); + ASSERT_EQ(secondDynamicSource.interruptState, sourceData.interruptState); + ASSERT_EQ(secondDynamicSource.visible, sourceData.visible); + ASSERT_EQ(0, secondDynamicSource.name.compare(sourceData.name)); + ASSERT_EQ(secondDynamicSource.volume, sourceData.volume); + ASSERT_TRUE(std::equal(secondDynamicSource.listConnectionFormats.begin(), secondDynamicSource.listConnectionFormats.end(), sourceData.listConnectionFormats.begin())); + ASSERT_TRUE(std::equal(secondDynamicSource.listMainSoundProperties.begin(), secondDynamicSource.listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty)); + ASSERT_TRUE(std::equal(secondDynamicSource.listMainNotificationConfigurations.begin(), secondDynamicSource.listMainNotificationConfigurations.end(), sourceData.listMainNotificationConfigurations.begin(), equalNotificationConfiguration)); + ASSERT_TRUE(std::equal(secondDynamicSource.listNotificationConfigurations.begin(), secondDynamicSource.listNotificationConfigurations.end(), sourceData.listNotificationConfigurations.begin(), equalNotificationConfiguration)); +} + +TEST_F(CAmMapHandlerTest, peekSourceID) +{ + + std::string sourceName("myClassID"); + am_sourceClass_t sourceClassID, peekID; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 13; + sourceClass.name = sourceName; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID)); + + //now we enter the class into the database + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSourceClassID(sourceName,peekID)); + ASSERT_EQ(sourceClassID, peekID); +} + +TEST_F(CAmMapHandlerTest, peekSinkID) +{ + + std::string sinkName("myClassID"); + am_sinkClass_t sinkClassID, peekID; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 13; + sinkClass.name = sinkName; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID)); + + //now we enter the class into the database + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSinkClassID(sinkName,peekID)); + ASSERT_EQ(sinkClassID, peekID); +} + +TEST_F(CAmMapHandlerTest,crossfaders) +{ + am_Crossfader_s crossfader; + am_crossfaderID_t crossfaderID; + am_Sink_s sinkA, sinkB; + am_Source_s source; + am_sourceID_t sourceID; + am_sinkID_t sinkAID, sinkBID; + pCF.createSink(sinkA); + pCF.createSink(sinkB); + sinkB.name = "sinkB"; + pCF.createSource(source); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); + + crossfader.crossfaderID = 0; + crossfader.hotSink = HS_SINKA; + crossfader.sinkID_A = sinkAID; + crossfader.sinkID_B = sinkBID; + crossfader.sourceID = sourceID; + crossfader.name = "Crossfader"; + crossfader.hotSink = HS_UNKNOWN; + + std::vector<am_Crossfader_s> listCrossfaders; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListCrossfaders(listCrossfaders)); + ASSERT_EQ(crossfader.sinkID_A, listCrossfaders[0].sinkID_A); + ASSERT_EQ(crossfader.sinkID_B, listCrossfaders[0].sinkID_B); + ASSERT_EQ(crossfader.sourceID, listCrossfaders[0].sourceID); + ASSERT_EQ(crossfader.hotSink, listCrossfaders[0].hotSink); + ASSERT_EQ(DYNAMIC_ID_BOUNDARY, listCrossfaders[0].crossfaderID); + ASSERT_EQ(crossfader.name.compare(listCrossfaders[0].name), 0); +} + +TEST_F(CAmMapHandlerTest,crossfadersGetFromDomain) +{ + + + + am_Crossfader_s crossfader; + am_crossfaderID_t crossfaderID; + am_Sink_s sinkA, sinkB; + am_Source_s source; + am_sourceID_t sourceID; + am_sinkID_t sinkAID, sinkBID; + am_domainID_t domainID; + am_Domain_s domain; + pCF.createSink(sinkA); + pCF.createSink(sinkB); + pCF.createDomain(domain); + sinkB.name = "sinkB"; + pCF.createSource(source); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + source.domainID = domainID; + sinkA.domainID = domainID; + sinkB.domainID = domainID; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); + + crossfader.crossfaderID = 0; + crossfader.hotSink = HS_SINKA; + crossfader.sinkID_A = sinkAID; + crossfader.sinkID_B = sinkBID; + crossfader.sourceID = sourceID; + crossfader.name = "Crossfader"; + crossfader.hotSink = HS_UNKNOWN; + + std::vector<am_crossfaderID_t> listCrossfaders; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListCrossfadersOfDomain(source.domainID,listCrossfaders)); + ASSERT_EQ(DYNAMIC_ID_BOUNDARY, listCrossfaders[0]); + +} + +TEST_F(CAmMapHandlerTest,sourceState) +{ + am_Source_s source; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + pCF.createSource(source); + source.sourceState = SS_OFF; + + //prepare the test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //change the source state + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceState(sourceID,SS_ON)); + + //read out the changed values + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(listSources[0].sourceState, SS_ON); +} + +TEST_F(CAmMapHandlerTest,sinkVolumeChange) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + pCF.createSink(sink); + sink.volume = 23; + + //prepare the test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //change the volume and check the read out + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkVolume(sinkID,34)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(listSinks[0].volume, 34); +} + +TEST_F(CAmMapHandlerTest,sourceVolumeChange) +{ + am_Source_s source; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + pCF.createSource(source); + source.volume = 23; + + //prepare test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + //change the volume and check the read out + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceVolume(sourceID,34)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(listSources[0].volume, 34); +} + +TEST_F(CAmMapHandlerTest, peekSource) +{ + std::vector<am_SourceType_s> listSourceTypes; + std::vector<am_Source_s> listSources; + am_sourceID_t sourceID, source2ID, source3ID; + am_Source_s source; + pCF.createSource(source); + + //peek a source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); + + //make sure it is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_TRUE(listSources.empty()); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_TRUE(listSourceTypes.empty()); + ASSERT_EQ(sourceID, DYNAMIC_ID_BOUNDARY); + + //now enter the source with the same name and make sure it does not get a new ID + source.name = "newsource"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source2ID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(sourceID, source2ID); + ASSERT_FALSE(listSources.empty()); + ASSERT_TRUE(listSources.at(0).sourceID==sourceID); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_FALSE(listSourceTypes.empty()); + ASSERT_TRUE(listSourceTypes.at(0).sourceID==sourceID); + + //now we peek again. This time, the source exists + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(source.name,source3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_TRUE(listSources.size()==1); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_TRUE(listSourceTypes.size()==1); + ASSERT_TRUE(listSourceTypes.at(0).sourceID==source3ID); + ASSERT_EQ(source3ID, source2ID); +} + +TEST_F(CAmMapHandlerTest, peekSourceDouble) +{ + std::vector<am_SourceType_s> listSourceTypes; + std::vector<am_Source_s> listSources; + am_sourceID_t sourceID; + am_sourceID_t source2ID; + am_sourceID_t source3ID; + am_Source_s source; + pCF.createSource(source); + + //peek a source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); + + //peek a second source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource2"),source2ID)); + + //make sure they are is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_TRUE(listSources.empty()); + ASSERT_EQ(sourceID, DYNAMIC_ID_BOUNDARY); + source.name = "newsource"; + + //now enter the source with the same name than the first peek and make sure it does not get a new ID + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(sourceID, source3ID); + ASSERT_TRUE(listSources.size()==1); + ASSERT_TRUE(listSources[0].sourceID==sourceID); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listSourceTypes)); + ASSERT_TRUE(listSourceTypes.size()==1); + ASSERT_TRUE(listSourceTypes[0].sourceID==source3ID); +} + +TEST_F(CAmMapHandlerTest, peekSink) +{ + std::vector<am_SinkType_s> listSinkTypes; + std::vector<am_Sink_s> listSinks; + am_sinkID_t sinkID, sink2ID, sink3ID; + am_Sink_s sink; + pCF.createSink(sink); + + //peek a sink that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); + + //make sure it is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_TRUE(listSinks.empty()); + ASSERT_EQ(sinkID, DYNAMIC_ID_BOUNDARY); + sink.name = "newsink"; + + //now enter the source with the same name and make sure it does not get a new ID + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(sinkID, sink2ID); + ASSERT_TRUE(listSinks[0].sinkID==sinkID); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); + ASSERT_FALSE(listSinkTypes.empty()); + ASSERT_TRUE(listSinkTypes.at(0).sinkID==sinkID); + + //now we peek again, this time, the sink exists + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(sink.name,sink3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_TRUE(listSinks.size()==1); + ASSERT_EQ(sink3ID, sink2ID); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); + ASSERT_TRUE(listSinkTypes.size()==1); + ASSERT_TRUE(listSinkTypes.at(0).sinkID==sink3ID); +} + +TEST_F(CAmMapHandlerTest, peekSinkDouble) +{ + std::vector<am_SinkType_s> listSinkTypes; + std::vector<am_Sink_s> listSinks; + am_sinkID_t sinkID; + am_sinkID_t sink2ID; + am_sinkID_t sink3ID; + am_Sink_s sink; + pCF.createSink(sink); + + //peek a sink that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); + + //peek again + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("nextsink"),sink2ID)); + + //make sure they are is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_TRUE(listSinks.empty()); + ASSERT_EQ(sinkID, DYNAMIC_ID_BOUNDARY); + sink.name = "newsink"; + + //now enter the sink with the same name than the first peek and make sure it does not get a new ID + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(sinkID, sink3ID); + ASSERT_TRUE(listSinks[0].sinkID==sinkID); + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listSinkTypes)); + ASSERT_TRUE(listSinkTypes.size()==1); + ASSERT_TRUE(listSinkTypes[0].sinkID==sink3ID); +} + +TEST_F(CAmMapHandlerTest,changeConnectionTimingInformationCheckMainConnection) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + std::vector<am_Connection_s> connectionList; + std::vector<am_MainConnectionType_s> mainList; + + //prepare the test, it is one mainconnection, so we expect one callback + createMainConnectionSetup(mainConnectionID, mainConnection); + + //first get all visible mainconnections and make sure, the delay is set to -1 for the first entry + ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList)); + ASSERT_EQ(mainList[0].delay, -1); + + //no go through all connections and set the delay time to 24 for each connection + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + std::vector<am_Connection_s>::iterator iteratorConnectionList = connectionList.begin(); + for (; iteratorConnectionList < connectionList.end(); ++iteratorConnectionList) + { + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->connectionID,24)); + } + + //we read the result again and expect that the value is now different from -1 + ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList)); + ASSERT_EQ(mainList[0].delay, 216); +} + +TEST_F(CAmMapHandlerTest,changeConnectionTimingInformation) +{ + am_Connection_s connection; + am_connectionID_t connectionID; + std::vector<am_Connection_s> connectionList; + pCF.createConnection(connection); + + //enter a connection + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + + //change the timing and check it + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(connectionID, 24)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_TRUE(connectionList[0].delay == 24); +} + +TEST_F(CAmMapHandlerTest,getSinkClassOfSink) +{ + std::vector<am_SinkClass_s> sinkClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SinkClass_s sinkClass, returnClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + am_Sink_s sink; + am_sinkID_t sinkID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 4; + sinkClass.listClassProperties = classPropertyList; + pCF.createSink(sink); + sink.sinkClassID = 4; + + //prepare test + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //enter a new sinkclass, read out again and check + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 4); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkClassInfoDB(sinkID,returnClass)); + ASSERT_EQ(sinkClassList[0].name, returnClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, returnClass.sinkClassID); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),returnClass.listClassProperties.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,getSourceClassOfSource) +{ + std::vector<am_SourceClass_s> sourceClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SourceClass_s sourceClass, sinkSourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + am_Source_s source; + am_sourceID_t sourceID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 1; + sourceClass.listClassProperties = classPropertyList; + pCF.createSource(source); + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 1); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceClassInfoDB(sourceID,sinkSourceClass)); + ASSERT_EQ(sourceClassList[0].name, sinkSourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, sinkSourceClass.sourceClassID); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),sinkSourceClass.listClassProperties.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,removeSourceClass) +{ + std::vector<am_SourceClass_s> sourceClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 3; + sourceClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 3); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeSourceClassDB(3)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_TRUE(sourceClassList.empty()); +} + +TEST_F(CAmMapHandlerTest,updateSourceClass) +{ + std::vector<am_SourceClass_s> sourceClassList; + std::vector<am_ClassProperty_s> classPropertyList, changedPropertyList; + am_SourceClass_s sourceClass, changedClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties = classPropertyList; + changedClass = sourceClass; + changedClass.listClassProperties[1].value = 6; + changedPropertyList = changedClass.listClassProperties; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + changedClass.sourceClassID = sourceClassID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceClassInfoDB(changedClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,enterSourceClass) +{ + std::vector<am_SourceClass_s> sourceClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,enterSourceClassStatic) +{ + std::vector<am_SourceClass_s> sourceClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + am_sourceClass_t sourceClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sourceClass.name = "test"; + sourceClass.sourceClassID = 3; + sourceClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); + ASSERT_EQ(sourceClassList[0].name, sourceClass.name); + ASSERT_EQ(sourceClassList[0].sourceClassID, 3); + ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,removeSinkClass) +{ + std::vector<am_SinkClass_s> sinkClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkClassDB(sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_TRUE(sinkClassList.empty()); +} + +TEST_F(CAmMapHandlerTest,updateSinkClass) +{ + std::vector<am_SinkClass_s> sinkClassList; + std::vector<am_ClassProperty_s> classPropertyList, changedPropertyList; + am_SinkClass_s sinkClass, changedClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties = classPropertyList; + changedClass = sinkClass; + changedClass.listClassProperties[1].value = 6; + changedPropertyList = changedClass.listClassProperties; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + changedClass.sinkClassID = sinkClassID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkClassInfoDB(changedClass)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,enterSinkClass) +{ + std::vector<am_SinkClass_s> sinkClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, DYNAMIC_ID_BOUNDARY); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest,enterSinkClassStatic) +{ + std::vector<am_SinkClass_s> sinkClassList; + std::vector<am_ClassProperty_s> classPropertyList; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + am_sinkClass_t sinkClassID; + classProperty.classProperty = CP_GENIVI_SINK_TYPE; + classProperty.value = 1; + classPropertyList.push_back(classProperty); + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 4; + classPropertyList.push_back(classProperty); + sinkClass.name = "test"; + sinkClass.sinkClassID = 4; + sinkClass.listClassProperties = classPropertyList; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); + ASSERT_EQ(sinkClassList[0].name, sinkClass.name); + ASSERT_EQ(sinkClassList[0].sinkClassID, 4); + ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties)); +} + +TEST_F(CAmMapHandlerTest, changeSystemProperty) +{ + std::vector<am_SystemProperty_s> listSystemProperties, listReturn; + am_SystemProperty_s systemProperty; + + systemProperty.type = SYP_UNKNOWN; + systemProperty.value = 33; + listSystemProperties.push_back(systemProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); + systemProperty.value = 444; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn)); + ASSERT_EQ(listReturn[0].type, systemProperty.type); + ASSERT_EQ(listReturn[0].value, systemProperty.value); +} + +TEST_F(CAmMapHandlerTest, systemProperties) +{ + std::vector<am_SystemProperty_s> listSystemProperties, listReturn; + am_SystemProperty_s systemProperty; + + systemProperty.type = SYP_UNKNOWN; + systemProperty.value = 33; + listSystemProperties.push_back(systemProperty); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn)); + ASSERT_EQ(listReturn[0].type, systemProperty.type); + ASSERT_EQ(listReturn[0].value, systemProperty.value); +} + +TEST_F(CAmMapHandlerTest,enterSourcesCorrect) +{ + //fill the connection database + am_Source_s staticSource, firstDynamicSource, secondDynamicSource; + am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID; + std::vector<am_Source_s> sourceList; + + pCF.createSource(staticSource); + staticSource.sourceID = 4; + staticSource.name = "Static"; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) + << "ERROR: database error"; + ASSERT_EQ(staticSource.sourceID,staticSourceID) + << "ERROR: ID not the one given in staticSource"; + + pCF.createSource(firstDynamicSource); + firstDynamicSource.name = "firstDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + pCF.createSource(secondDynamicSource); + secondDynamicSource.name = "secondDynamicSource"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList)) + << "ERROR: database error"; + + std::vector<am_Source_s>::iterator listIterator = sourceList.begin(); + for (; listIterator < sourceList.end(); ++listIterator) + { + if (listIterator->sourceID == staticSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, staticSource)); + } + + if (listIterator->sourceID == firstDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, firstDynamicSource)); + } + + if (listIterator->sourceID == secondDynamicSourceID) + { + ASSERT_TRUE(pCF.compareSource(listIterator, secondDynamicSource)); + } + + } +} + +TEST_F(CAmMapHandlerTest, changeSinkMuteState) +{ + std::vector<am_Sink_s> listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_MuteState_e muteState = MS_MUTED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(muteState, listSinks[0].muteState); +} + +TEST_F(CAmMapHandlerTest, changeSourceMainSoundProperty) +{ + std::vector<am_Source_s> listSources; + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + am_MainSoundProperty_s property; + property.type = MSP_UNKNOWN; + property.value = 33; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB(property,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + + std::vector<am_MainSoundProperty_s>::iterator listIterator = listSources[0].listMainSoundProperties.begin(); + for (; listIterator < listSources[0].listMainSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + ASSERT_EQ(listIterator->value, property.value); + } + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB({property.type, 34},sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getMainSourceSoundPropertyValue(sourceID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, changeSinkMainSoundProperty) +{ + std::vector<am_Sink_s> listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_MainSoundProperty_s property; + property.type = MSP_UNKNOWN; + property.value = 33; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB(property,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + std::vector<am_MainSoundProperty_s>::iterator listIterator = listSinks[0].listMainSoundProperties.begin(); + for (; listIterator < listSinks[0].listMainSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + ASSERT_EQ(listIterator->value, property.value); + } + + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB({property.type, 34},sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getMainSinkSoundPropertyValue(sinkID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, changeSourceSoundProperty) +{ + std::vector<am_Source_s> listSources; + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + am_SoundProperty_s property; + property.type = SP_GENIVI_MID; + property.value = 33; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB(property,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + + std::vector<am_SoundProperty_s>::iterator listIterator = listSources[0].listSoundProperties.begin(); + for (; listIterator < listSources[0].listSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + ASSERT_EQ(listIterator->value, property.value); + } + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB({property.type, 34},sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getSourceSoundPropertyValue(sourceID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, changeSinkSoundProperty) +{ + std::vector<am_Sink_s> listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_SoundProperty_s property; + property.type = SP_GENIVI_MID; + property.value = 33; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB(property,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + std::vector<am_SoundProperty_s>::iterator listIterator = listSinks[0].listSoundProperties.begin(); + for (; listIterator < listSinks[0].listSoundProperties.end(); ++listIterator) + { + if (listIterator->type == property.type) + ASSERT_EQ(listIterator->value, property.value); + } + + int16_t value; + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, property.value); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB({property.type, 34},sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, property.type, value)); + ASSERT_EQ(value, 34); + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.getSinkSoundPropertyValue(sinkID, 1000, value)); +} + +TEST_F(CAmMapHandlerTest, peekDomain) +{ + std::vector<am_Domain_s> listDomains; + am_Domain_s domain; + am_domainID_t domainID; + am_domainID_t domain2ID; + pCF.createDomain(domain); + ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_TRUE(listDomains.empty()); + ASSERT_EQ(domainID, DYNAMIC_ID_BOUNDARY); + domain.name = "newdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domainID, domain2ID); + ASSERT_TRUE(listDomains[0].domainID==domainID); +} + +TEST_F(CAmMapHandlerTest, peekDomainFirstEntered) +{ + std::vector<am_Domain_s> listDomains; + am_Domain_s domain; + am_domainID_t domainID; + am_domainID_t domain2ID; + pCF.createDomain(domain); + domain.name = "newdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domain2ID)); + ASSERT_EQ(domainID, domain2ID); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_TRUE(listDomains.size()==1); +} + +TEST_F(CAmMapHandlerTest, changeDomainState) +{ + std::vector<am_Domain_s> listDomains; + am_Domain_s domain; + am_domainID_t domainID; + pCF.createDomain(domain); + am_DomainState_e newState = DS_INDEPENDENT_STARTUP; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changDomainStateDB(newState,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(newState, listDomains[0].state); +} + +TEST_F(CAmMapHandlerTest, changeMainConnectionState) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + std::vector<am_MainConnection_s> listMainConnections; + createMainConnectionSetup(mainConnectionID, mainConnection); + + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionStateDB(1,CS_DISCONNECTING)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections)); + ASSERT_EQ(CS_DISCONNECTING, listMainConnections[0].connectionState); +} + +TEST_F(CAmMapHandlerTest, changeSinkAvailability) +{ + std::vector<am_Sink_s> listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_Availability_s availability; + availability.availability = A_UNKNOWN; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(availability.availability, listSinks[0].available.availability); + ASSERT_EQ(availability.availabilityReason, listSinks[0].available.availabilityReason); +} + +TEST_F(CAmMapHandlerTest, changeSourceAvailability) +{ + std::vector<am_Source_s> listSources; + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + am_Availability_s availability; + availability.availability = A_UNKNOWN; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + source.visible = true; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(availability.availability, listSources[0].available.availability); + ASSERT_EQ(availability.availabilityReason, listSources[0].available.availabilityReason); +} + +TEST_F(CAmMapHandlerTest,changeMainConnectionRoute) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + std::vector<am_MainConnection_s> originalList; + std::vector<am_MainConnection_s> newList; + createMainConnectionSetup(mainConnectionID, mainConnection); + + //fill the connection database + am_Connection_s connection; + am_Source_s source; + am_Sink_s sink; + std::vector<am_connectionID_t> listConnectionID; + + uint16_t i = 1; + for (; i < 10; i++) + { + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + + connection.sinkID = i + 20; + connection.sourceID = i + 20; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + + pCF.createSink(sink); + sink.sinkID = i + 20; + sink.name = "sink" + int2string(i + 20); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = i + 20; + source.name = "source" + int2string(i + 30); + source.domainID = 4; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + listConnectionID.push_back(connectionID); + } + + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(originalList)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionRouteDB(mainConnectionID,listConnectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(newList)); + ASSERT_FALSE(std::equal(newList[0].listConnectionID.begin(),newList[0].listConnectionID.end(),originalList[0].listConnectionID.begin())); +} + +TEST_F(CAmMapHandlerTest,changeMainSinkVolume) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_mainVolume_t newVol = 20; + std::vector<am_Sink_s> listSinks; + pCF.createSink(sink); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(listSinks[0].mainVolume, newVol); +} + +TEST_F(CAmMapHandlerTest,getMainSourceSoundProperties) +{ + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + std::vector<am_MainSoundProperty_s> mainSoundProperties = source.listMainSoundProperties; + std::vector<am_MainSoundProperty_s> listMainSoundProperties; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSourceSoundProperties(sourceID,listMainSoundProperties)); + ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); +} + +TEST_F(CAmMapHandlerTest,getMainSinkSoundProperties) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + std::vector<am_MainSoundProperty_s> mainSoundProperties = sink.listMainSoundProperties; + std::vector<am_MainSoundProperty_s> listMainSoundProperties; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinkSoundProperties(sinkID,listMainSoundProperties)); + ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); +} + +TEST_F(CAmMapHandlerTest,getMainSources) +{ + am_Source_s source, source1, source2; + am_sourceID_t sourceID; + pCF.createSource(source); + pCF.createSource(source1); + pCF.createSource(source2); + source1.name = "source1"; + source2.name = "source2"; + bool equal = true; + source1.visible = false; + std::vector<am_SourceType_s> listMainSources; + std::vector<am_Source_s> listSources; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + source.sourceID = sourceID; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source1,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source2,sourceID)); + source2.sourceID = sourceID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listMainSources)); + listSources.push_back(source); + listSources.push_back(source2); + std::vector<am_SourceType_s>::iterator listIterator = listMainSources.begin(); + for (; listIterator < listMainSources.end(); ++listIterator) + { + equal = equal && pCF.compareSinkMainSource(listIterator, listSources); + } + ASSERT_TRUE(equal); +} + +TEST_F(CAmMapHandlerTest,getMainSinks) +{ + am_Sink_s sink, sink1, sink2; + am_sinkID_t sinkID; + pCF.createSink(sink); + pCF.createSink(sink1); + pCF.createSink(sink2); + sink1.name = "sink1"; + sink2.name = "sink2"; + sink1.visible = false; + std::vector<am_SinkType_s> listMainSinks; + std::vector<am_Sink_s> listSinks; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + sink.sinkID = sinkID; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink1,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink2,sinkID)); + sink2.sinkID = sinkID; + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listMainSinks)); + listSinks.push_back(sink); + listSinks.push_back(sink2); + + std::vector<am_SinkType_s>::iterator listIterator = listMainSinks.begin(); + for (; listIterator < listMainSinks.end(); ++listIterator) + { + ASSERT_TRUE(pCF.compareSinkMainSink(listIterator, listSinks)); + } +} + +TEST_F(CAmMapHandlerTest,getVisibleMainConnections) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + createMainConnectionSetup(mainConnectionID, mainConnection); + + std::vector<am_MainConnectionType_s> listVisibleMainConnections; + std::vector<am_MainConnection_s> listMainConnections; + ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(listVisibleMainConnections)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections)); + ASSERT_EQ(listMainConnections[0].mainConnectionID, listVisibleMainConnections[0].mainConnectionID); + ASSERT_EQ(listMainConnections[0].connectionState, listVisibleMainConnections[0].connectionState); + ASSERT_EQ(listMainConnections[0].delay, listVisibleMainConnections[0].delay); + ASSERT_EQ(listMainConnections[0].sinkID, listVisibleMainConnections[0].sinkID); + ASSERT_EQ(listMainConnections[0].sourceID, listVisibleMainConnections[0].sourceID); +} + +TEST_F(CAmMapHandlerTest,getListSourcesOfDomain) +{ + am_Source_s source, source2; + am_Domain_s domain; + am_domainID_t domainID; + am_sourceID_t sourceID; + std::vector<am_sourceID_t> sourceList, sourceCheckList; + pCF.createSource(source); + source.sourceID = 1; + source.name = "testSource"; + source.domainID = DYNAMIC_ID_BOUNDARY; + pCF.createSource(source2); + source2.sourceID = 0; + source2.name = "testSource2"; + source2.domainID = 5; + pCF.createDomain(domain); + sourceCheckList.push_back(1); //sink.sinkID); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source2,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSourcesOfDomain(2,sourceList)) + << "ERROR: database error";ASSERT_TRUE(sourceList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListSourcesOfDomain(DYNAMIC_ID_BOUNDARY,sourceList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(sourceList.begin(),sourceList.end(),sourceCheckList.begin()) && !sourceList.empty()); +} + +TEST_F(CAmMapHandlerTest,getListSinksOfDomain) +{ + am_Sink_s sink, sink2; + am_Domain_s domain; + am_domainID_t domainID; + am_sinkID_t sinkID; + std::vector<am_sinkID_t> sinkList, sinkCheckList; + pCF.createSink(sink); + sink.sinkID = 1; + sink.domainID = DYNAMIC_ID_BOUNDARY; + pCF.createSink(sink2); + sink2.domainID = 5; + sink2.name = "sink2"; + pCF.createDomain(domain); + sinkCheckList.push_back(1); //sink.sinkID); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink2,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSinksOfDomain(DYNAMIC_ID_BOUNDARY+1,sinkList)) + << "ERROR: database error";ASSERT_TRUE(sinkList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinksOfDomain(DYNAMIC_ID_BOUNDARY,sinkList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(sinkList.begin(),sinkList.end(),sinkCheckList.begin()) && !sinkList.empty()); +} + +TEST_F(CAmMapHandlerTest,getListGatewaysOfDomain) +{ + am_Gateway_s gateway, gateway2; + am_gatewayID_t gatewayID1, gatewayID2; + am_domainID_t domainID; + am_Domain_s domain; + std::vector<am_gatewayID_t> gatewayList, gatewayCheckList; + + pCF.createDomain(domain); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + + pCF.createGateway(gateway); + gateway.gatewayID = 1; + gateway.name = "testGateway"; + gateway.controlDomainID = domainID; + gateway.sourceID = 1; + gateway.sinkID = 1; + gateway.domainSinkID = 1; + gateway.domainSourceID = 1; + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(true, gatewayID1==1); + + pCF.createGateway(gateway2); + gateway2.gatewayID = 2; + gateway2.name = "testGateway2"; + gateway2.controlDomainID = 4; + gateway2.sourceID = 1; + gateway2.sinkID = 1; + gateway2.domainSinkID = 1; + gateway2.domainSourceID = 1; + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(true, gatewayID2==2); + gatewayCheckList.push_back(gatewayID1); + + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + sink.sinkID = sinkID; + + pCF.createSource(source); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + source.sourceID = sourceID; + + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListGatewaysOfDomain(2,gatewayList)) + << "ERROR: database error"; + ASSERT_TRUE(gatewayList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListGatewaysOfDomain(domainID,gatewayList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty()); +} + +TEST_F(CAmMapHandlerTest,getListConvertersOfDomain) +{ + am_Converter_s converter, converter2; + am_converterID_t converterID1, converterID2; + am_domainID_t domainID; + am_Domain_s domain; + std::vector<am_converterID_t> converterList, converterCheckList; + + pCF.createDomain(domain); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + + pCF.createConverter(converter); + converter.converterID = 1; + converter.name = "testGateway"; + converter.sourceID = 1; + converter.sinkID = 1; + converter.domainID = domainID; + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter,converterID1)) + << "ERROR: database error"; + ASSERT_EQ(true, converterID1==1); + + pCF.createConverter(converter2); + converter2.converterID = 2; + converter2.name = "testGateway2"; + converter2.domainID = 4; + converter2.sourceID = 1; + converter2.sinkID = 1; + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter2,converterID2)) + << "ERROR: database error"; + ASSERT_EQ(true, converterID2==2); + converterCheckList.push_back(converterID1); + + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + sink.sinkID = sinkID; + + pCF.createSource(source); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + source.sourceID = sourceID; + + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListConvertersOfDomain(4,converterList)) + << "ERROR: database error"; + ASSERT_TRUE(converterList.empty()); + ASSERT_EQ(E_OK,pDatabaseHandler.getListConvertersOfDomain(domainID,converterList)) + << "ERROR: database error"; + ASSERT_TRUE(std::equal(converterList.begin(),converterList.end(),converterCheckList.begin()) && !converterList.empty()); +} + +TEST_F(CAmMapHandlerTest,removeDomain) +{ + am_Domain_s domain; + am_domainID_t domainID; + std::vector<am_Domain_s> listDomains; + pCF.createDomain(domain); + ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListDomains(listDomains)) + << "ERROR: database error"; + ASSERT_TRUE(listDomains.empty()); +} + +TEST_F(CAmMapHandlerTest,removeGateway) +{ + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + std::vector<am_Gateway_s> listGateways; + pCF.createGateway(gateway); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListGateways(listGateways)) + << "ERROR: database error"; + ASSERT_TRUE(listGateways.empty()); +} + +TEST_F(CAmMapHandlerTest,removeConverter) +{ + am_Converter_s converter; + am_converterID_t converterID; + std::vector<am_Converter_s> listConverters; + pCF.createConverter(converter); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter,converterID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(converterID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListConverters(listConverters)) + << "ERROR: database error"; + ASSERT_TRUE(listConverters.empty()); +} + +TEST_F(CAmMapHandlerTest,removeSink) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + pCF.createSink(sink); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + ASSERT_TRUE(listSinks.empty()); +} + +TEST_F(CAmMapHandlerTest,removeSource) +{ + //fill the connection database + am_Source_s source; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + pCF.createSource(source); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources)) + << "ERROR: database error"; + ASSERT_TRUE(listSources.empty()); +} + +TEST_F(CAmMapHandlerTest, removeMainConnection) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + createMainConnectionSetup(mainConnectionID, mainConnection); + + ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentMainConnectionFail) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentSource) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentSink) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentGateway) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,removeNonexistentConverter) +{ + ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeConverterDB(12)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,registerGatewayCorrect) +{ + //initialize gateway + std::vector<am_Gateway_s> returnList; + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createGateway(gateway); + pCF.createGateway(gateway1); + gateway1.gatewayID = 20; + pCF.createGateway(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.gatewayID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); + std::vector<am_Gateway_s>::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->gatewayID == gatewayID) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway)); + } + + if (listIterator->gatewayID == gatewayID1) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway1)); + } + + if (listIterator->gatewayID == gatewayID2) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway2)); + } + } +} + +TEST_F(CAmMapHandlerTest,registerConverterCorrect) +{ + //initialize gateway + std::vector<am_Converter_s> returnList; + am_Converter_s gateway, gateway1, gateway2; + am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createConverter(gateway); + pCF.createConverter(gateway1); + gateway1.converterID = 20; + pCF.createConverter(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.converterID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); + std::vector<am_Converter_s>::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->converterID == gatewayID) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway)); + } + + if (listIterator->converterID == gatewayID1) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway1)); + } + + if (listIterator->converterID == gatewayID2) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway2)); + } + } +} + +TEST_F(CAmMapHandlerTest,getGatewayInfo) +{ + + + //initialize gateway + std::vector<am_Gateway_s> returnList; + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createGateway(gateway); + pCF.createGateway(gateway1); + gateway1.gatewayID = 20; + pCF.createGateway(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.gatewayID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList)); + std::vector<am_Gateway_s>::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->gatewayID == gatewayID) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway)); + } + + if (listIterator->gatewayID == gatewayID1) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway1)); + } + + if (listIterator->gatewayID == gatewayID2) + { + ASSERT_TRUE(pCF.compareGateway(listIterator, gateway2)); + } + } + + am_Gateway_s gatewayInfo; + ASSERT_EQ(E_OK, pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo)); + ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo)); + +} + +TEST_F(CAmMapHandlerTest,getConverterInfo) +{ + //initialize gateway + std::vector<am_Converter_s> returnList; + am_Converter_s gateway, gateway1, gateway2; + am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + + pCF.createConverter(gateway); + pCF.createConverter(gateway1); + gateway1.converterID = 20; + pCF.createConverter(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1)) + << "ERROR: database error"; + ASSERT_EQ(gateway1.converterID,gatewayID1) + << "ERROR: domainID zero"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2)) + << "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList)); + std::vector<am_Converter_s>::iterator listIterator = returnList.begin(); + + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->converterID == gatewayID) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway)); + } + + if (listIterator->converterID == gatewayID1) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway1)); + } + + if (listIterator->converterID == gatewayID2) + { + ASSERT_TRUE(pCF.compareConverter(listIterator, gateway2)); + } + } + + am_Converter_s gatewayInfo; + ASSERT_EQ(E_OK, pDatabaseHandler.getConverterInfoDB(20,gatewayInfo)); + ASSERT_TRUE(pCF.compareConverter1(gateway1,gatewayInfo)); + +} + +TEST_F(CAmMapHandlerTest,enterSinkThatAlreadyExistFail) +{ + //fill the connection database + am_Sink_s staticSink, SecondSink; + am_sinkID_t staticSinkID, SecondSinkID; + + pCF.createSink(staticSink); + staticSink.sinkID = 43; + staticSink.name = "Static"; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) + << "ERROR: database error"; + ASSERT_EQ(staticSink.sinkID,staticSinkID) + << "ERROR: ID not the one given in staticSink"; + + pCF.createSink(SecondSink); + SecondSink.sinkID = 43; + SecondSink.name = "SecondSink"; + + ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSinkDB(SecondSink,SecondSinkID)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,enterSourcesThatAlreadyExistFail) +{ + //fill the connection database + am_Source_s staticSource, SecondSource; + am_sourceID_t staticSourceID, SecondSourceID; + pCF.createSource(staticSource); + staticSource.sourceID = 4; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) + << "ERROR: database error"; + ASSERT_EQ(staticSource.sourceID,staticSourceID) + << "ERROR: ID not the one given in staticSource"; + + pCF.createSource(SecondSource); + SecondSource.sourceID = 4; + + ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSourceDB(SecondSource,SecondSourceID)) + << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerTest,registerDomainCorrect) +{ + //initialize domain + std::vector<am_Domain_s> returnList; + am_Domain_s domain; + am_domainID_t domainID = 0; + pCF.createDomain(domain); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) + << "ERROR: database error"; + ASSERT_NE(0,domainID) + << "ERROR: domainID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList)); + bool equal = true; + std::vector<am_Domain_s>::iterator listIterator = returnList.begin(); + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->domainID == domainID) + { + equal = equal && (listIterator->name.compare(domain.name) == 0) && (listIterator->busname.compare(domain.busname) == 0) && (listIterator->complete == domain.complete) && (listIterator->early == domain.early) && (listIterator->state == domain.state); + } + } + ASSERT_EQ(true, equal); +} + +TEST_F(CAmMapHandlerTest,registerDomainPredefined) +{ + //initialize domain + std::vector<am_Domain_s> returnList; + am_Domain_s domain; + am_domainID_t domainID = 10; + pCF.createDomain(domain); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) + << "ERROR: database error"; + ASSERT_NE(10,domainID) + << "ERROR: domainID not predefined one"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList)); + std::vector<am_Domain_s>::iterator listIterator = returnList.begin(); + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->domainID == domainID) + { + ASSERT_EQ(0, listIterator->name.compare(domain.name)); + ASSERT_EQ(0, listIterator->busname.compare(domain.busname)); + ASSERT_EQ(domain.complete, listIterator->complete); + ASSERT_EQ(domain.early, listIterator->early); + ASSERT_EQ(domain.state, listIterator->state); + } + } +} + +TEST_F(CAmMapHandlerTest,registerConnectionCorrect) +{ + am_Connection_s connection; + am_connectionID_t connectionID; + std::vector<am_Connection_s> returnList; + pCF.createConnection(connection); + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID)) + << "ERROR: database error";; + ASSERT_NE(0,connectionID) + << "ERROR: connectionID zero"; + + //now check if we read out the correct values + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(returnList)); + std::vector<am_Connection_s>::iterator listIterator = returnList.begin(); + for (; listIterator < returnList.end(); ++listIterator) + { + if (listIterator->connectionID == connectionID) + { + ASSERT_EQ(connection.sourceID, listIterator->sourceID); + ASSERT_EQ(connection.sinkID, listIterator->sinkID); + ASSERT_EQ(connection.delay, listIterator->delay); + ASSERT_EQ(connection.connectionFormat, listIterator->connectionFormat); + } + } +} + +TEST_F(CAmMapHandlerTest,enterMainConnectionCorrect) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + createMainConnectionSetup(mainConnectionID, mainConnection); +} + +TEST_F(CAmMapHandlerTest,enterSinksCorrect) +{ + //fill the connection database + am_Sink_s staticSink, firstDynamicSink, secondDynamicSink; + am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID; + std::vector<am_Sink_s> sinkList; + + pCF.createSink(staticSink); + staticSink.sinkID = 4; + + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) + << "ERROR: database error"; + ASSERT_EQ(staticSink.sinkID,staticSinkID) + << "ERROR: ID not the one given in staticSink"; + + pCF.createSink(firstDynamicSink); + firstDynamicSink.name = "firstdynamic"; + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID)) + << "ERROR: database error"; + ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY) + << "ERROR: ID not the one given in firstDynamicSink"; + + pCF.createSink(secondDynamicSink); + secondDynamicSink.name = "seconddynamic"; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID)) + << "ERROR: database error"; + ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10) + << "ERROR: ID not the one given in secondDynamicSink"; + + //now read back and check the returns agains the given values + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList)) + << "ERROR: database error"; + + std::vector<am_Sink_s>::iterator listIterator = sinkList.begin(); + for (; listIterator < sinkList.end(); ++listIterator) + { + if (listIterator->sinkID == staticSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, staticSink)); + } + + if (listIterator->sinkID == firstDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, firstDynamicSink)); + } + + if (listIterator->sinkID == secondDynamicSinkID) + { + ASSERT_TRUE(pCF.compareSink(listIterator, secondDynamicSink)); + } + } +} + +TEST_F(CAmMapHandlerTest,enterNotificationConfigurationCorrect) +{ + am_Sink_s testSinkData, readoutData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + testSinkData.listNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSinks.begin()->listNotificationConfigurations[2].type,notify.type); + + ASSERT_EQ(E_OK,pDatabaseHandler.getSinkInfoDB(testSinkData.sinkID,readoutData)) + << "ERROR: database error"; + + ASSERT_EQ(readoutData.listNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(readoutData.listNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(readoutData.listNotificationConfigurations[2].type,notify.type); + +} + +TEST_F(CAmMapHandlerTest,enterMainNotificationConfigurationCorrect) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); +} + +TEST_F(CAmMapHandlerTest,removeNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks)) + << "ERROR: database error"; + + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSinks.begin()->listMainNotificationConfigurations[2].type,notify.type); + + //now we remove the sink + ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)); +} + +TEST_F(CAmMapHandlerTest,removeNotificationsSource) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources)) + << "ERROR: database error"; + + ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].parameter,notify.parameter); + ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].status,notify.status); + ASSERT_EQ(listSources.begin()->listMainNotificationConfigurations[2].type,notify.type); + + //now we remove the sink + ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)); +} + +TEST_F(CAmMapHandlerTest,getMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + std::vector<am_NotificationConfiguration_s>returnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_UNKNOWN; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSinkData.listMainNotificationConfigurations.push_back(notify1); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) + << "ERROR: database error"; + + std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); + +} + +TEST_F(CAmMapHandlerTest,getMainNotificationsSources) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + std::vector<am_NotificationConfiguration_s>returnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_UNKNOWN; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSourceData.listMainNotificationConfigurations.push_back(notify1); + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + + std::equal(testSourceData.listMainNotificationConfigurations.begin(),testSourceData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); + +} + +TEST_F(CAmMapHandlerTest,changeMainNotificationsSources) +{ + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + std::vector<am_NotificationConfiguration_s>returnList,returnList1; + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + + ASSERT_EQ(true, std::equal(testSourceData.listMainNotificationConfigurations.begin(), + testSourceData.listMainNotificationConfigurations.end(), + returnList.begin(), + equalNotificationConfiguration)); + + //change notification which is not available + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=10; + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify)); + //change a setting + notify.type=NT_TEST_2; + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify)); + + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList1)) + << "ERROR: database error"; + + ASSERT_EQ(returnList1[1].parameter,notify.parameter); + ASSERT_EQ(returnList1[1].status,notify.status); + ASSERT_EQ(returnList1[1].type,notify.type); + +} + +TEST_F(CAmMapHandlerTest,changeMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + std::vector<am_NotificationConfiguration_s>returnList,returnList1; + + //enter the sink in the database + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + + //read it again + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList)) + << "ERROR: database error"; + + std::equal(testSinkData.listMainNotificationConfigurations.begin(),testSinkData.listMainNotificationConfigurations.end(),returnList.begin(),equalNotificationConfiguration); + + //change notification which is not available + am_NotificationConfiguration_s notify; + notify.type=NT_UNKNOWN; + notify.status=NS_CHANGE; + notify.parameter=27; + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify)) + << "ERROR: database error"; + //change a setting + notify.type=NT_TEST_2; + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify)) + << "ERROR: database error"; + + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID,returnList1)) + << "ERROR: database error"; + + ASSERT_EQ(returnList1[1].parameter,notify.parameter); + ASSERT_EQ(returnList1[1].status,notify.status); + ASSERT_EQ(returnList1[1].type,notify.type); +} + +TEST_F(CAmMapHandlerTest, peekDomain_2) +{ + std::vector<am_Domain_s> listDomains; + am_Domain_s domain; + am_domainID_t domainID; + am_domainID_t domain2ID; + pCF.createDomain(domain); + ASSERT_EQ(E_OK,pDatabaseHandler.peekDomain(std::string("newdomain"),domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_TRUE(listDomains.empty()); + ASSERT_EQ(domainID, DYNAMIC_ID_BOUNDARY); + + domain.name = "anotherdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domain2ID, DYNAMIC_ID_BOUNDARY+1); + + domain.name = "newdomain"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domainID, domain2ID); // FAILS, ID is 2 instead of 1 + bool containsDomainID = std::find_if(listDomains.begin(), listDomains.end(), [&](const am_Domain_s & ref) { + return ref.domainID==domainID; + })!=listDomains.end(); + ASSERT_TRUE(containsDomainID); +} + +TEST_F(CAmMapHandlerTest, connectionIDBoundary) +{ + am_Sink_s sink; + am_Source_s source; + am_Connection_s connection; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + for (uint16_t i = 1; i < TEST_MAX_SINK_ID; i++) + { + pCF.createSink(sink); + sink.sinkID = 0; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = 0; + source.name = "source" + int2string(i); + source.domainID = 4; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); + connection.sinkID = forgetSink; + connection.sourceID = forgetSource; + if( i < TEST_MAX_CONNECTION_ID ) + { + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(i, connectionID); + } + } + std::vector<am_Connection_s> connectionList; + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_EQ(TEST_MAX_CONNECTION_ID-1, static_cast<int>(connectionList.size())); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + logInfo("here"); + ASSERT_EQ(0, connectionID); + + ASSERT_EQ(E_OK, pDatabaseHandler.removeConnection(10)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeConnection(12)); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(10, connectionID); + connection.sinkID = 77; + connection.sourceID = 77; + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(12, connectionID); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(0, connectionID); +} + +TEST_F(CAmMapHandlerTest, mainConnectionIDBoundary) +{ + am_Sink_s sink; + am_Source_s source; + am_Connection_s connection; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + am_sinkID_t forgetSink; + am_sourceID_t forgetSource; + am_connectionID_t connectionID; + std::vector<am_connectionID_t> connectionIDList; + for (uint16_t i = 1; i < TEST_MAX_SINK_ID; i++) + { + pCF.createSink(sink); + sink.sinkID = 0; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + pCF.createSource(source); + source.sourceID = 0; + source.name = "source" + int2string(i); + source.domainID = 4; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); + connection.sinkID = forgetSink; + connection.sourceID = forgetSource; + if( i < TEST_MAX_CONNECTION_ID ) + { + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(i, connectionID); + connectionIDList.push_back(i); + } + } + std::vector<am_Connection_s> connectionList; + ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList)); + ASSERT_EQ(TEST_MAX_CONNECTION_ID-1, static_cast<int>(connectionList.size())); + + //create a mainConnection + + am_MainConnection_s mainConnection; + am_mainConnectionID_t mainConnectionID; + mainConnection.listConnectionID = connectionIDList; + mainConnection.mainConnectionID = 0; + mainConnection.connectionState = CS_CONNECTED; + mainConnection.delay = -1; + + for (uint16_t i = 1; i < TEST_MAX_MAINCONNECTION_ID; i++) + { + mainConnection.sinkID = DYNAMIC_ID_BOUNDARY + i; + mainConnection.sourceID = DYNAMIC_ID_BOUNDARY + i; + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(i, mainConnectionID); + } + ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(10)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(12)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(10, mainConnectionID); + mainConnection.sinkID = 77; + mainConnection.sourceID = 77; + ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(12, mainConnectionID); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); + ASSERT_EQ(0, mainConnectionID); +} + +TEST_F(CAmMapHandlerTest, increaseID) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + for (uint16_t i = 0; i < TEST_MAX_SINK_ID; i++) + { + pCF.createSink(sink); + sink.sinkID = 0; + sink.name = "sink" + int2string(i); + sink.domainID = 4; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+i, sinkID); + } + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); + + ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+10)); + ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+12)); + + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); +} + + +CAmMapHandlerObserverCallbacksTest::CAmMapHandlerObserverCallbacksTest() : + mMockObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&mMockObserver); +} + +CAmMapHandlerObserverCallbacksTest::~CAmMapHandlerObserverCallbacksTest() +{ +} + +MATCHER_P(IsDomainDataEqualTo, value, "") { + auto lh = arg; + return lh.domainID == value.domainID && + lh.name == value.name && + lh.nodename == value.nodename && + lh.early == value.early && + lh.complete == value.complete && + lh.state == value.state; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_removeDomain) +{ + std::vector<am_Domain_s> listDomains; + am_Domain_s domain; + am_domainID_t domainID; + am_domainID_t domain2ID; + pCF.createDomain(domain); + ASSERT_EQ(E_OK,pDatabaseHandler.peekDomain(std::string("newdomain"), domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_TRUE(listDomains.empty()); + ASSERT_EQ(domainID, DYNAMIC_ID_BOUNDARY); + + domain.name = "anotherdomain"; + const am_Domain_s expDomain1 = {DYNAMIC_ID_BOUNDARY+1, domain.name, domain.busname, domain.nodename, domain.early, domain.complete, domain.state}; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(IsDomainDataEqualTo(expDomain1))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domain2ID, DYNAMIC_ID_BOUNDARY+1); + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); + domain.name = "newdomain"; + const am_Domain_s expDomain2 = {DYNAMIC_ID_BOUNDARY, domain.name, domain.busname, domain.nodename, domain.early, domain.complete, domain.state}; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(IsDomainDataEqualTo(expDomain2))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); + ASSERT_EQ(domainID, domain2ID); // FAILS, ID is 2 instead of 1 + bool containsDomainID = std::find_if(listDomains.begin(), listDomains.end(), [&](const am_Domain_s & ref) { + return ref.domainID==domainID; + })!=listDomains.end(); + ASSERT_TRUE(containsDomainID); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeDomain(domainID)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID))<< "ERROR: database error"; + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSource) +{ + std::vector<am_Source_s> listSources; + am_sourceID_t sourceID; + am_sourceID_t source2ID; + am_sourceID_t source3ID; + am_Source_s source; + pCF.createSource(source); + + //peek a source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); + + //peek a second source that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource2"),source2ID)); + + //make sure they are is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_TRUE(listSources.empty()); + ASSERT_EQ(sourceID, DYNAMIC_ID_BOUNDARY); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(Field(&am_Source_s::sourceID, DYNAMIC_ID_BOUNDARY+2))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); + ASSERT_EQ(source3ID, DYNAMIC_ID_BOUNDARY+2); + + source.name = "newsource"; + //now enter the source with the same name than the first peek and make sure it does not get a new ID + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(Field(&am_Source_s::sourceID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(sourceID, source3ID); + bool containsSourceID = std::find_if(listSources.begin(), listSources.end(), [&](const am_Source_s & ref) { + return ref.sourceID==sourceID; + })!=listSources.end(); + ASSERT_TRUE(containsSourceID); + + std::vector<am_SoundProperty_s> listSoundProperties; + std::vector<am_CustomAvailabilityReason_t> listConnectionFormats; + std::vector<am_MainSoundProperty_s> listMainSoundProperties; +#ifndef WITH_DATABASE_CHANGE_CHECK + //check no change + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#else + //check no change + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(0); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of class id + source.sourceClassID++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, source.sourceClassID, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of main sound properties + am_MainSoundProperty_s mainSoundProperties; + mainSoundProperties.type = MSP_GENIVI_TREBLE; + mainSoundProperties.value = 0; + listMainSoundProperties.push_back(mainSoundProperties); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, source.sourceClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#endif + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSource(sourceID, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID))<< "ERROR: database error"; + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSink) +{ + std::vector<am_Sink_s> listSinks; + am_sinkID_t sinkID; + am_sinkID_t sink2ID; + am_sinkID_t sink3ID; + am_Sink_s sink; + pCF.createSink(sink); + + //peek a sink that does not exits + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); + + //peek again + + ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("nextsink"),sink2ID)); + + //make sure they are is not in the list + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_TRUE(listSinks.empty()); + ASSERT_EQ(sinkID, DYNAMIC_ID_BOUNDARY); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(Field(&am_Sink_s::sinkID, DYNAMIC_ID_BOUNDARY+2))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); + ASSERT_EQ(sink3ID, DYNAMIC_ID_BOUNDARY+2); + + sink.name = "newsink"; + //now enter the sink with the same name than the first peek and make sure it does not get a new ID + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(Field(&am_Sink_s::sinkID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(sinkID, sink3ID); + bool containsSourceID = std::find_if(listSinks.begin(), listSinks.end(), [&](const am_Sink_s & ref) { + return ref.sinkID==sinkID; + })!=listSinks.end(); + ASSERT_TRUE(containsSourceID); + + std::vector<am_SoundProperty_s> listSoundProperties; + std::vector<am_CustomAvailabilityReason_t> listConnectionFormats; + std::vector<am_MainSoundProperty_s> listMainSoundProperties; +#ifndef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#else + //check no change + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(0); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of class id + sink.sinkClassID++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, sink.sinkClassID, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; + //check change of main sound properties + am_MainSoundProperty_s mainSoundProperties; + mainSoundProperties.type = MSP_GENIVI_TREBLE; + mainSoundProperties.value = 0; + listMainSoundProperties.push_back(mainSoundProperties); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, sink.sinkClassID, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error"; +#endif + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSink(sinkID, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID))<< "ERROR: database error"; + EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peekSourceClassID) +{ + std::string sourceName("myClassID"); + am_sourceClass_t sourceClassID, peekID; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 13; + sourceClass.name = sourceName; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID)); + + //now we enter the class into the database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSourceClassID(sourceName,peekID)); + ASSERT_EQ(sourceClassID, peekID); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, peekSinkClassID) +{ + std::string sinkName("myClassID"); + am_sinkClass_t sinkClassID, peekID; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_GENIVI_SOURCE_TYPE; + classProperty.value = 13; + sinkClass.name = sinkName; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID)); + + //now we enter the class into the database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSinkClassID(sinkName,peekID)); + ASSERT_EQ(sinkClassID, peekID); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeGateway) +{ + //initialize gateway + std::vector<am_Gateway_s> returnList; + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + pCF.createGateway(gateway); + pCF.createGateway(gateway1); + gateway1.gatewayID = 20; + pCF.createGateway(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, 20))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))<< "ERROR: database error"; + ASSERT_EQ(gateway1.gatewayID,gatewayID1)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway(Field(&am_Gateway_s::gatewayID, DYNAMIC_ID_BOUNDARY+1))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeGateway(gatewayID2)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID2))<< "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeConverter) +{ + //initialize gateway + std::vector<am_Converter_s> returnList; + am_Converter_s gateway, gateway1, gateway2; + am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0; + pCF.createConverter(gateway); + pCF.createConverter(gateway1); + gateway1.converterID = 20; + pCF.createConverter(gateway2); + am_Sink_s sink; + am_Source_s source; + am_sinkID_t sinkID; + am_sourceID_t sourceID; + pCF.createSink(sink); + pCF.createSource(source); + sink.sinkID = 1; + source.sourceID = 2; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY,gatewayID)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, 20))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1))<< "ERROR: database error"; + ASSERT_EQ(gateway1.converterID,gatewayID1)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, DYNAMIC_ID_BOUNDARY+1))).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2))<< "ERROR: database error"; + ASSERT_EQ(DYNAMIC_ID_BOUNDARY+1,gatewayID2)<< "ERROR: domainID zero"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeConverter(gatewayID2)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(gatewayID2))<< "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeCrossfader) +{ + am_Crossfader_s crossfader; + am_crossfaderID_t crossfaderID; + am_Sink_s sinkA, sinkB; + am_Source_s source; + am_sourceID_t sourceID; + am_sinkID_t sinkAID, sinkBID; + pCF.createSink(sinkA); + pCF.createSink(sinkB); + sinkB.name = "sinkB"; + pCF.createSource(source); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); + + crossfader.crossfaderID = 0; + crossfader.hotSink = HS_SINKA; + crossfader.sinkID_A = sinkAID; + crossfader.sinkID_B = sinkBID; + crossfader.sourceID = sourceID; + crossfader.name = "Crossfader"; + crossfader.hotSink = HS_UNKNOWN; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newCrossfader(Field(&am_Crossfader_s::crossfaderID, DYNAMIC_ID_BOUNDARY))).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeCrossfader(crossfaderID)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeCrossfaderDB(crossfaderID))<< "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, enter_update_removeMainConnection) +{ + am_mainConnectionID_t mainConnectionID; + am_MainConnection_s mainConnection; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(9); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(9); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection(Field(&am_MainConnectionType_s::mainConnectionID, 1))).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, CS_CONNECTED)).Times(1); +#ifndef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(1); +#else + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(0); +#endif + createMainConnectionSetup(mainConnectionID, mainConnection); + + //change delay of first connection + am_timeSync_t delay = 20; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(mainConnectionID, 20)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(mainConnection.listConnectionID[0], delay)); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeConnectionTimingInformation(mainConnection.listConnectionID[0], delay)); +#endif + + //change delay of route + delay = 40; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(mainConnectionID, 40)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeDelayMainConnection(delay, mainConnectionID)); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeDelayMainConnection(delay, mainConnectionID)); +#endif + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedMainConnection(1)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) << "ERROR: database error"; +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkAvailability) +{ + std::vector<am_Sink_s> listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_Availability_s availability; + availability.availability = A_UNKNOWN; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkAvailabilityChanged(_, _)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(availability.availability, listSinks[0].available.availability); + ASSERT_EQ(availability.availabilityReason, listSinks[0].available.availabilityReason); + +#ifdef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkAvailabilityChanged(_, _)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); + availability.availability = A_AVAILABLE; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeSourceAvailability) +{ + std::vector<am_Source_s> listSources; + am_Source_s source; + am_sourceID_t sourceID; + pCF.createSource(source); + am_Availability_s availability; + availability.availability = A_UNKNOWN; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + source.visible = true; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceAvailabilityChanged(_, _)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); + ASSERT_EQ(availability.availability, listSources[0].available.availability); + ASSERT_EQ(availability.availabilityReason, listSources[0].available.availabilityReason); + +#ifdef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceAvailabilityChanged(_, _)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); + availability.availability = A_AVAILABLE; + availability.availabilityReason = AR_GENIVI_TEMPERATURE; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest,changeMainSinkVolume) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_mainVolume_t newVol = 20; + std::vector<am_Sink_s> listSinks; + pCF.createSink(sink); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), volumeChanged(sinkID, newVol)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(listSinks[0].mainVolume, newVol); + +#ifdef WITH_DATABASE_CHANGE_CHECK + am_mainVolume_t incVol = 21; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), volumeChanged( sinkID, incVol)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(incVol,sinkID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkMuteState) +{ + std::vector<am_Sink_s> listSinks; + am_Sink_s sink; + am_sinkID_t sinkID; + pCF.createSink(sink); + am_MuteState_e muteState = MS_MUTED; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMuteStateChanged(sinkID, muteState)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); + ASSERT_EQ(muteState, listSinks[0].muteState); + +#ifdef WITH_DATABASE_CHANGE_CHECK + am_MuteState_e newMuteState = MS_UNMUTED; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMuteStateChanged(sinkID, newMuteState)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(newMuteState,sinkID)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeSystemProperty) +{ + std::vector<am_SystemProperty_s> listSystemProperties, listReturn; + am_SystemProperty_s systemProperty; + + systemProperty.type = SYP_UNKNOWN; + systemProperty.value = 33; + listSystemProperties.push_back(systemProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); + systemProperty.value = 444; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), systemPropertyChanged(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); + ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn)); + ASSERT_EQ(listReturn[0].type, systemProperty.type); + ASSERT_EQ(listReturn[0].value, systemProperty.value); + +#ifdef WITH_DATABASE_CHANGE_CHECK + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), systemPropertyChanged(_)).Times(1); + ASSERT_EQ(E_NO_CHANGE, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); + systemProperty.value = 33; + ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); +#endif +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSink) +{ + am_Sink_s testSinkData; + pCF.createSink(testSinkData); + testSinkData.sinkID = 4; + am_sinkID_t sinkID; + std::vector<am_Sink_s> listSinks; + std::vector<am_NotificationConfiguration_s>returnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_TEST_1; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSinkData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_TEST_1; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSinkData.listMainNotificationConfigurations.push_back(notify1); + + am_NotificationConfiguration_s notify2; + notify2.type=NT_TEST_2; + notify2.status=NS_CHANGE; + notify2.parameter=27; + + testSinkData.listMainNotificationConfigurations.push_back(notify2); + + //enter the sink in the database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSinkNotificationConfigurations(sinkID, returnList)) + << "ERROR: database error"; + ASSERT_EQ(2, returnList.size()) << "ERROR: database error"; + + //change a setting + notify2.parameter++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMainNotificationConfigurationChanged(sinkID, _)).Times(1); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify1)); +#endif + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify2)); +} + +TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSources) +{ + + am_Source_s testSourceData; + pCF.createSource(testSourceData); + testSourceData.sourceID = 4; + am_sourceID_t sourceID; + std::vector<am_Source_s> listSources; + std::vector<am_NotificationConfiguration_s>returnList; + + am_NotificationConfiguration_s notify; + notify.type=NT_TEST_1; + notify.status=NS_CHANGE; + notify.parameter=25; + + testSourceData.listMainNotificationConfigurations.push_back(notify); + + am_NotificationConfiguration_s notify1; + notify1.type=NT_TEST_1; + notify1.status=NS_PERIODIC; + notify1.parameter=5; + + testSourceData.listMainNotificationConfigurations.push_back(notify1); + + am_NotificationConfiguration_s notify2; + notify2.type=NT_TEST_2; + notify2.status=NS_CHANGE; + notify2.parameter=10; + + testSourceData.listMainNotificationConfigurations.push_back(notify2); + + //enter the sink in the database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) + << "ERROR: database error"; + ASSERT_EQ(E_OK,pDatabaseHandler.getListMainSourceNotificationConfigurations(sourceID,returnList)) + << "ERROR: database error"; + ASSERT_EQ(2, returnList.size()) << "ERROR: database error"; + + //change a setting + notify2.parameter++; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceMainNotificationConfigurationChanged(sourceID, _)).Times(1); +#ifdef WITH_DATABASE_CHANGE_CHECK + ASSERT_EQ(E_NO_CHANGE,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify1)); +#endif + ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify2)); +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("databse", "databasetest"); + logInfo("Database Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h new file mode 100644 index 0000000..e3cc0ef --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h @@ -0,0 +1,92 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MAPHANDLERTEST_H_ +#define MAPHANDLERTEST_H_ + +#define UNIT_TEST 1 + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "CAmSocketHandler.h" +#include "CAmDatabaseHandlerMap.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "CAmControlSender.h" +#include "../IAmControlBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmControlSend.h" +#include "../MockIAmCommandSend.h" +#include "MockDatabaseObserver.h" + +namespace am +{ + +class CAmMapBasicTest : public ::testing::Test +{ +public: + CAmMapBasicTest(); + ~CAmMapBasicTest(); + std::vector<std::string> plistRoutingPluginDirs; + std::vector<std::string> plistCommandPluginDirs; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + CAmSocketHandler pSocketHandler; + CAmDatabaseHandlerMap pDatabaseHandler; + CAmControlSender pControlSender; + CAmRouter pRouter; + CAmControlReceiver pControlReceiver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); + void createMainConnectionSetup(am_mainConnectionID_t & mainConnectionID, am_MainConnection_s & mainConnection); +}; + +class CAmMapHandlerTest: public CAmMapBasicTest +{ +public: + CAmMapHandlerTest(); + ~CAmMapHandlerTest(); + MockIAmCommandSend pMockInterface; + CAmDatabaseObserver pObserver; +}; + +class CAmMapHandlerObserverCallbacksTest : public CAmMapBasicTest +{ +public: + CAmMapHandlerObserverCallbacksTest(); + ~CAmMapHandlerObserverCallbacksTest(); + CAmDatabaseObserver mMockObserver; +}; + + +} + +#endif /* MAPHANDLERTEST_H_ */ diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp new file mode 100644 index 0000000..a035cee --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp @@ -0,0 +1,98 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file CAmTestDatabaseObserver.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmDatabaseObserver.h" +#include "MockDatabaseObserver.h" + +namespace am { + +CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : +mCommandSender(iCommandSender), // +mRoutingSender(iRoutingSender), // +mTelnetServer(NULL), // +mSerializer(iSocketHandler) // +{} + +CAmDatabaseObserver::~CAmDatabaseObserver() {} + + +void CAmDatabaseObserver::numberOfSinkClassesChanged() +{ MockDatabaseObserver::getMockObserverObject()->numberOfSinkClassesChanged(); } +void CAmDatabaseObserver::numberOfSourceClassesChanged() +{ MockDatabaseObserver::getMockObserverObject()->numberOfSourceClassesChanged(); } +void CAmDatabaseObserver::newSink(const am_Sink_s& sink) +{ MockDatabaseObserver::getMockObserverObject()->newSink(sink); } +void CAmDatabaseObserver::newSource(const am_Source_s& source) +{ MockDatabaseObserver::getMockObserverObject()->newSource(source); } +void CAmDatabaseObserver::newDomain(const am_Domain_s& domain) +{ MockDatabaseObserver::getMockObserverObject()->newDomain(domain); } +void CAmDatabaseObserver::newGateway(const am_Gateway_s& gateway) +{ MockDatabaseObserver::getMockObserverObject()->newGateway(gateway); } +void CAmDatabaseObserver::newConverter(const am_Converter_s& coverter) +{ MockDatabaseObserver::getMockObserverObject()->newConverter(coverter); } +void CAmDatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) +{ MockDatabaseObserver::getMockObserverObject()->newCrossfader(crossfader); } +void CAmDatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) +{ MockDatabaseObserver::getMockObserverObject()->newMainConnection(mainConnection); } +void CAmDatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) +{ MockDatabaseObserver::getMockObserverObject()->removedMainConnection(mainConnection); } +void CAmDatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->removedSink(sinkID, visible); } +void CAmDatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->removedSource(sourceID, visible); } +void CAmDatabaseObserver::removeDomain(const am_domainID_t domainID) +{ MockDatabaseObserver::getMockObserverObject()->removeDomain(domainID); } +void CAmDatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) +{ MockDatabaseObserver::getMockObserverObject()->removeGateway(gatewayID); } +void CAmDatabaseObserver::removeConverter(const am_converterID_t converterID) +{ MockDatabaseObserver::getMockObserverObject()->removeConverter(converterID); } +void CAmDatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) +{ MockDatabaseObserver::getMockObserverObject()->removeCrossfader(crossfaderID); } +void CAmDatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) +{ MockDatabaseObserver::getMockObserverObject()->mainConnectionStateChanged(connectionID, connectionState); } +void CAmDatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) +{ MockDatabaseObserver::getMockObserverObject()->mainSinkSoundPropertyChanged(sinkID, SoundProperty); } +void CAmDatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) +{ MockDatabaseObserver::getMockObserverObject()->mainSourceSoundPropertyChanged(sourceID, SoundProperty); } +void CAmDatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) +{ MockDatabaseObserver::getMockObserverObject()->sinkAvailabilityChanged(sinkID, availability); } +void CAmDatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) +{ MockDatabaseObserver::getMockObserverObject()->sourceAvailabilityChanged(sourceID, availability); } +void CAmDatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) +{ MockDatabaseObserver::getMockObserverObject()->volumeChanged(sinkID, volume); } +void CAmDatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) +{ MockDatabaseObserver::getMockObserverObject()->sinkMuteStateChanged(sinkID, muteState); } +void CAmDatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) +{ MockDatabaseObserver::getMockObserverObject()->systemPropertyChanged(SystemProperty); } +void CAmDatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) +{ MockDatabaseObserver::getMockObserverObject()->timingInformationChanged(mainConnection,time); } +void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->sinkUpdated(sinkID,sinkClassID,listMainSoundProperties, visible); } +void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible) +{ MockDatabaseObserver::getMockObserverObject()->sourceUpdated(sourceID,sourceClassID,listMainSoundProperties, visible); } +void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ MockDatabaseObserver::getMockObserverObject()->sinkMainNotificationConfigurationChanged(sinkID,mainNotificationConfiguration); } +void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) +{ MockDatabaseObserver::getMockObserverObject()->sourceMainNotificationConfigurationChanged(sourceID,mainNotificationConfiguration); } +} + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt new file mode 100644 index 0000000..6588710 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmMapHandlerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS} +) + +file(GLOB DATABASE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "CAmTestDatabaseObserver.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmMapHandlerTest ${DATABASE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES( AmMapHandlerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmMapHandlerTest AudioManagerCore) + +INSTALL(TARGETS AmMapHandlerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt~ b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt~ new file mode 100644 index 0000000..05d2a05 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CMakeLists.txt~ @@ -0,0 +1,54 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmMapHandlerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_UTILITIES_INCLUDE} + ${GMOCK_INCLUDE_DIRS} +) + +if(WITH_DLT) + INCLUDE_DIRECTORIES( + ${INCLUDE_DIRECTORIES} + ${DLT_INCLUDE_DIRS}) +endif(WITH_DLT) + +file(GLOB DATABASE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "CAmTestDatabaseObserver.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmMapHandlerTest ${DATABASE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES( AmMapHandlerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmMapHandlerTest AudioManagerCore) + +INSTALL(TARGETS AmMapHandlerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h b/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h new file mode 100644 index 0000000..da1b3b4 --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h @@ -0,0 +1,120 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * \file MockDatabaseObserver.h + * For further information see http://www.genivi.org/. + * + */ + + +#ifndef MOCKDATABASEOBSERVER_H_ +#define MOCKDATABASEOBSERVER_H_ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "CAmDatabaseObserver.h" + +class CAmCommandSender; +class CAmRoutingSender; +class CAmSocketHandler; +class CAmTelnetServer; + +namespace am { +using namespace testing; + +class IAmDatabaseObserver +{ +public: + IAmDatabaseObserver() {}; + virtual ~IAmDatabaseObserver() {}; + + virtual void numberOfSinkClassesChanged() = 0; + virtual void numberOfSourceClassesChanged() = 0; + virtual void newSink(const am_Sink_s& sink) = 0; + virtual void newSource(const am_Source_s& source) = 0; + virtual void newDomain(const am_Domain_s& domain) = 0; + virtual void newGateway(const am_Gateway_s& gateway) = 0; + virtual void newConverter(const am_Converter_s& coverter) = 0; + virtual void newCrossfader(const am_Crossfader_s& crossfader) = 0; + virtual void newMainConnection(const am_MainConnectionType_s& mainConnection) = 0; + virtual void removedMainConnection(const am_mainConnectionID_t mainConnection) = 0; + virtual void removedSink(const am_sinkID_t sinkID, const bool visible) = 0; + virtual void removedSource(const am_sourceID_t sourceID, const bool visible) = 0; + virtual void removeDomain(const am_domainID_t domainID) = 0; + virtual void removeGateway(const am_gatewayID_t gatewayID) = 0; + virtual void removeConverter(const am_converterID_t converterID) = 0; + virtual void removeCrossfader(const am_crossfaderID_t crossfaderID) = 0; + virtual void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) = 0; + virtual void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) = 0; + virtual void mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) = 0; + virtual void sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) = 0; + virtual void sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) = 0; + virtual void volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) = 0; + virtual void sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) = 0; + virtual void systemPropertyChanged(const am_SystemProperty_s& SystemProperty) = 0; + virtual void timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) = 0; + virtual void sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible) = 0; + virtual void sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible) = 0; + virtual void sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; + virtual void sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0; + +}; + +class MockDatabaseObserver : public IAmDatabaseObserver{ + public: + MOCK_METHOD0(numberOfSinkClassesChanged, void()); + MOCK_METHOD0(numberOfSourceClassesChanged, void()); + MOCK_METHOD1(newSink, void(const am_Sink_s& sink)); + MOCK_METHOD1(newSource, void(const am_Source_s& source)); + MOCK_METHOD1(newDomain, void(const am_Domain_s& domain)); + MOCK_METHOD1(newGateway, void(const am_Gateway_s& gateway)); + MOCK_METHOD1(newConverter, void(const am_Converter_s& converter)); + MOCK_METHOD1(newCrossfader, void(const am_Crossfader_s& crossfader)); + MOCK_METHOD1(newMainConnection, void(const am_MainConnectionType_s & mainConnection)); + MOCK_METHOD1(removedMainConnection, void(const am_mainConnectionID_t mainConnection)); + MOCK_METHOD2(removedSink, void(const am_sinkID_t sinkID, const bool visible)); + MOCK_METHOD2(removedSource, void(const am_sourceID_t sourceID, const bool visible)); + MOCK_METHOD1(removeDomain, void(const am_domainID_t domainID)); + MOCK_METHOD1(removeGateway, void(const am_gatewayID_t gatewayID)); + MOCK_METHOD1(removeConverter, void(const am_converterID_t converterID)); + MOCK_METHOD1(removeCrossfader, void(const am_crossfaderID_t crossfaderID)); + MOCK_METHOD2(mainConnectionStateChanged, void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)); + MOCK_METHOD2(mainSinkSoundPropertyChanged, void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty)); + MOCK_METHOD2(mainSourceSoundPropertyChanged, void(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty)); + MOCK_METHOD2(sinkAvailabilityChanged, void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(sourceAvailabilityChanged, void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(volumeChanged, void(const am_sinkID_t sinkID, const am_mainVolume_t volume)); + MOCK_METHOD2(sinkMuteStateChanged, void(const am_sinkID_t sinkID, const am_MuteState_e muteState)); + MOCK_METHOD1(systemPropertyChanged, void(const am_SystemProperty_s& SystemProperty)); + MOCK_METHOD2(timingInformationChanged, void(const am_mainConnectionID_t mainConnection, const am_timeSync_t time)); + MOCK_METHOD4(sinkUpdated, void(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible)); + MOCK_METHOD4(sourceUpdated, void(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties, const bool visible)); + MOCK_METHOD2(sinkMainNotificationConfigurationChanged, void(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration)); + MOCK_METHOD2(sourceMainNotificationConfigurationChanged, void(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration)); + + static MockDatabaseObserver *getMockObserverObject() + { + static MockDatabaseObserver glMockObserverObject; + return &glMockObserverObject; + } +}; + + + +} // namespace am +#endif /* MOCKDATABASEOBSERVER_H_ */ diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp new file mode 100644 index 0000000..f95a24a --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp @@ -0,0 +1,3183 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 + * + * For further information see http://www.genivi.org/. + * + */ + +#include <ctime> +#include <chrono> +#include "CAmRouterMapTest.h" +#include <string.h> +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + + +using namespace am; +using namespace testing; + +CAmRouterMapTest::CAmRouterMapTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pControlSender(), // + pDatabaseHandler(), + pRouter(&pDatabaseHandler, &pControlSender), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pMockInterface(), // + pMockControlInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlInterfaceBackdoor(), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter), // + pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); + pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); +} + +CAmRouterMapTest::~CAmRouterMapTest() +{ + +} + +void CAmRouterMapTest::SetUp() +{ + logInfo("Routing Test started "); +} + +void CAmRouterMapTest::TearDown() +{ +} + +ACTION(returnConnectionFormat){ + arg4=arg3; +} + +void CAmRouterMapTest::enterDomainDB(const std::string & domainName, am_domainID_t & domainID) +{ + am_Domain_s domain1; + domain1.domainID = 0; + domain1.name = domainName; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID)); +} + +void CAmRouterMapTest::enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector<am_CustomConnectionFormat_t> & connectionFormats, am_sourceID_t & sourceID) +{ + am_Source_s source; + source.domainID = domainID; + source.name = sourceName; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats = connectionFormats; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); +} + +void CAmRouterMapTest::enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector<am_CustomConnectionFormat_t> & connectionFormats, am_sinkID_t & sinkID) +{ + am_Sink_s sink; + sink.domainID = domainID; + sink.name = sinkName; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats = connectionFormats; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); +} + +void CAmRouterMapTest::enterGatewayDB(const std::string & gwName, + const am_domainID_t domainSourceID, + const am_domainID_t domainSinkID, + const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats, + const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats, + const std::vector<bool> & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_gatewayID_t & gatewayID) +{ + am_Gateway_s gateway; + gateway.controlDomainID = domainSourceID; + gateway.gatewayID = 0; + gateway.sinkID = sinkID; + gateway.sourceID = sourceID; + gateway.domainSourceID = domainSourceID; + gateway.domainSinkID = domainSinkID; + gateway.listSinkFormats = sinkConnectionFormats; + gateway.listSourceFormats = sourceConnectionFormats; + gateway.convertionMatrix = matrix; + gateway.name = gwName; + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); +} + +void CAmRouterMapTest::enterConverterDB(const std::string & gwName, + const am_domainID_t domainID, + const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats, + const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats, + const std::vector<bool> & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_converterID_t & converterID) +{ + am_Converter_s converter; + converter.converterID = 0; + converter.sinkID = sinkID; + converter.sourceID = sourceID; + converter.domainID = domainID; + converter.listSinkFormats = sinkConnectionFormats; + converter.listSourceFormats = sourceConnectionFormats; + converter.convertionMatrix = matrix; + converter.name = gwName; + ASSERT_EQ(E_OK, pDatabaseHandler.enterConverterDB(converter,converterID)); +} + +void CAmRouterMapTest::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector<am_Route_s> & listRoutes) +{ + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, aSource, aSink, listRoutes)); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << "getRoute did find " << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; + std::cout << " in " << std::chrono::duration<double, std::milli>(t_end-t_start).count() << " ms\n"; + std::cout.flags (oldflags); + std::cout.precision (oldprecision); +} + +void CAmRouterMapTest::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s>& returnList) +{ + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, sourceID, sinkID, returnList)); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << "getRoute by id did find " << returnList.size() <<" routes from " << sourceID << " to " << sinkID; + std::cout << " in " << std::chrono::duration<double, std::milli>(t_end-t_start).count() << " ms\n"; + std::cout.flags (oldflags); + std::cout.precision (oldprecision); +} + +void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, + CAmRoutingNode & aSink, + std::vector<am_Route_s> & resultPath, + std::vector<std::vector<CAmRoutingNode*>> & resultNodesPath, + const bool includeCycles) +{ + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + ASSERT_EQ(E_OK, pRouter.getAllPaths(aSource, aSink, resultPath, resultNodesPath, includeCycles)); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << "getAllPaths did find " << resultPath.size() + << " routes from " << aSource.getData().data.source->sourceID + << " to " << aSink.getData().data.sink->sinkID; + std::cout << " in " << std::chrono::duration<double, std::milli>(t_end-t_start).count() << " ms\n"; + std::cout.flags (oldflags); + std::cout.precision (oldprecision); +} + +TEST_F(CAmRouterMapTest,checkInsertedDomain) +{ + std::vector<am_domainID_t> domains; + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + domains.push_back(22); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + domains.push_back(22); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 50)); + domains.push_back(30); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); + domains.push_back(30); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 60)); +} + +//test that checks just sinks and source in a domain but connectionformats do not match +TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1; + am_domainID_t domainID1; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + + am_Source_s source; + am_sourceID_t sourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + am_Sink_s sink; + am_sinkID_t sinkID; + + sink.domainID = domainID1; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sinkID = sinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); +} + +//test that checks just sinks and source in a domain +TEST_F(CAmRouterMapTest,simpleRoute2withDomain) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1; + am_domainID_t domainID1; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + + am_Source_s source; + am_sourceID_t sourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + am_Sink_s sink; + am_sinkID_t sinkID; + + sink.domainID = domainID1; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sinkID = sinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + + getRoute(true,sourceID,sinkID,listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + + +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am_Connection_s connection,connection1; + am_connectionID_t id1,id2; + connection.sourceID=sourceID; + connection.sinkID=gwSinkID; + connection.connectionFormat=CF_GENIVI_ANALOG; + connection.connectionID=0; + connection1.sourceID=gwSourceID; + connection1.sinkID=sinkID; + connection1.connectionFormat=CF_GENIVI_ANALOG; + connection1.connectionID=0; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,id1)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2)); + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); + + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks just 2 domains, with gateway for each direction (possible circular route) +TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource, gwSource2; + am_sourceID_t sourceID, gwSourceID, gwSourceID2; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID1; + gwSource2.name = "gwsource2"; + gwSource2.sourceState = SS_ON; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + + am_Sink_s sink, gwSink, gwSink2; + am_sinkID_t sinkID, gwSinkID, gwSinkID2; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID2; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + + am_Gateway_s gateway, gateway2; + am_gatewayID_t gatewayID, gatewayID2; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway2.controlDomainID = domainID1; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID1; + gateway2.domainSinkID = domainID2; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + gwSink1.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(false); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[1]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[1]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(false); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[1]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + + +//test that checks 4 domains, one sink and one source but there are 2 routes because there are 2 gateways +TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3, domain4; + am_domainID_t domainID1, domainID2, domainID3, domainID4; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + domain4.domainID = 0; + domain4.name = "domain4"; + domain4.busname = "domain4bus"; + domain4.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + + am_Source_s source, gwSource, gwSource1, gwSource2, gwSource3; + am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2, gwSourceID3; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID4; + gwSource2.name = "gwsource3"; + gwSource2.sourceState = SS_OFF; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSource3.domainID = domainID3; + gwSource3.name = "gwsource4"; + gwSource3.sourceState = SS_OFF; + gwSource3.sourceID = 0; + gwSource3.sourceClassID = 5; + gwSource3.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource3,gwSourceID3)); + + am_Sink_s sink, gwSink, gwSink1, gwSink2, gwSink3; + am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2, gwSinkID3; + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID3; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink3.domainID = domainID2; + gwSink3.name = "gwSink3"; + gwSink3.sinkID = 0; + gwSink3.sinkClassID = 5; + gwSink3.muteState = MS_MUTED; + gwSink3.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + sink.domainID = domainID4; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink3,gwSinkID3)); + + am_Gateway_s gateway, gateway1, gateway2, gateway3; + am_gatewayID_t gatewayID, gatewayID1, gatewayID2, gatewayID3; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + gateway2.controlDomainID = domainID3; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID4; + gateway2.domainSinkID = domainID3; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + gateway3.controlDomainID = domainID2; + gateway3.gatewayID = 0; + gateway3.sinkID = gwSinkID3; + gateway3.sourceID = gwSourceID3; + gateway3.domainSourceID = domainID3; + gateway3.domainSinkID = domainID2; + gateway3.listSinkFormats = gwSink3.listConnectionFormats; + gateway3.listSourceFormats = gwSource3.listConnectionFormats; + gateway3.convertionMatrix.push_back(true); + gateway3.name = "gateway3"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway3,gatewayID3)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements, listRoutingElements1; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + am_RoutingElement_s hopp4; + am_RoutingElement_s hopp2alt; + am_RoutingElement_s hopp3alt; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = gwSinkID2; + hopp3.domainID = domainID3; + hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; + + hopp4.sourceID = gwSourceID2; + hopp4.sinkID = sinkID; + hopp4.domainID = domainID4; + hopp4.connectionFormat = sink.listConnectionFormats[0]; + + hopp2alt.sourceID = gwSourceID; + hopp2alt.sinkID = gwSinkID3; + hopp2alt.domainID = domainID2; + hopp2alt.connectionFormat = gwSink3.listConnectionFormats[0]; + + hopp3alt.sourceID = gwSourceID3; + hopp3alt.sinkID = gwSinkID2; + hopp3alt.domainID = domainID3; + hopp3alt.connectionFormat = gwSink2.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + listRoutingElements.push_back(hopp4); + listRoutingElements1.push_back(hopp1); + listRoutingElements1.push_back(hopp2alt); + listRoutingElements1.push_back(hopp3alt); + listRoutingElements1.push_back(hopp4); + + am_Route_s compareRoute, compareRoute1; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + compareRoute1.route = listRoutingElements1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(2), listRoutes.size()); + + bool containsRoute1 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { + return pCF.compareRoute(compareRoute, ref); + })!=listRoutes.end(); + bool containsRoute2 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { + return pCF.compareRoute(compareRoute1, ref); + })!=listRoutes.end(); + + ASSERT_TRUE(containsRoute1); + ASSERT_TRUE(containsRoute2); +} + +//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit. +TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); +} +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterMapTest,simpleRoute2Domains) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks just 2 domains, one sink one source but the connectionformat of source +TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); + } + +//test that checks 3 domains, one sink one source. +TEST_F(CAmRouterMapTest,simpleRoute3Domains) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 4 domains, one sink and one source. +TEST_F(CAmRouterMapTest,simpleRoute4Domains) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3, domain4; + am_domainID_t domainID1, domainID2, domainID3, domainID4; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + domain4.domainID = 0; + domain4.name = "domain4"; + domain4.busname = "domain4bus"; + domain4.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + + am_Source_s source, gwSource, gwSource1, gwSource2; + am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID4; + gwSource2.name = "gwsource3"; + gwSource2.sourceState = SS_OFF; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + + am_Sink_s sink, gwSink, gwSink1, gwSink2; + am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2; + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID3; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + sink.domainID = domainID4; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID, gatewayID1, gatewayID2; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + gateway2.controlDomainID = domainID3; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID4; + gateway2.domainSinkID = domainID3; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + am_RoutingElement_s hopp4; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = gwSinkID2; + hopp3.domainID = domainID3; + hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; + + hopp4.sourceID = gwSourceID2; + hopp4.sinkID = sinkID; + hopp4.domainID = domainID4; + hopp4.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + listRoutingElements.push_back(hopp4); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am::am_Source_s sourceDb; + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + getRoute(false, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,getAllowedFormatsFromConvMatrix) +{ + std::vector<bool> convertionMatrix; + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + convertionMatrix.push_back(0); + convertionMatrix.push_back(1); + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + + std::vector<am_CustomConnectionFormat_t> listSourceFormats; + listSourceFormats.push_back(CF_GENIVI_ANALOG); + listSourceFormats.push_back(CF_GENIVI_STEREO); + + std::vector<am_CustomConnectionFormat_t> listSinkFormats; + listSinkFormats.push_back(CF_GENIVI_MONO); + listSinkFormats.push_back(CF_GENIVI_AUTO); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + std::vector<am_CustomConnectionFormat_t> sourceFormats; + std::vector<am_CustomConnectionFormat_t> sinkFormats; + + ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + ASSERT_TRUE(sourceFormats.size()==3); + ASSERT_TRUE(sinkFormats.size()==3); + ASSERT_TRUE(sourceFormats.at(0)==CF_GENIVI_ANALOG); + ASSERT_TRUE(sourceFormats.at(1)==CF_GENIVI_STEREO); + ASSERT_TRUE(sourceFormats.at(2)==CF_GENIVI_ANALOG); + ASSERT_TRUE(sinkFormats.at(0)==CF_GENIVI_MONO); + ASSERT_TRUE(sinkFormats.at(1)==CF_GENIVI_AUTO); + ASSERT_TRUE(sinkFormats.at(2)==CF_GENIVI_STEREO); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + listSinkFormats.push_back(CF_GENIVI_STEREO); + listSourceFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + listSourceFormats.push_back(CF_GENIVI_STEREO); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); +} + +TEST_F(CAmRouterMapTest,route1Domain1Source1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); + + am_sourceID_t sourceID; + std::vector<am_CustomConnectionFormat_t> cf1; + cf1.push_back(CF_GENIVI_STEREO); + cf1.push_back(CF_GENIVI_ANALOG); + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID; + std::vector<am_CustomConnectionFormat_t> cf2; + cf2.push_back(CF_GENIVI_ANALOG); + cf2.push_back(CF_GENIVI_MONO); + enterSinkDB("sink1", domainID1, cf2, sinkID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sourceID = sourceID; + hopp1.sinkID = sinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = cf2[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); + + am_sourceID_t sourceID; + std::vector<am_CustomConnectionFormat_t> cf1; + cf1.push_back(CF_GENIVI_STEREO); + cf1.push_back(CF_GENIVI_AUTO); + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID1, sinkID2; + std::vector<am_CustomConnectionFormat_t> cf2; + cf2.push_back(CF_GENIVI_MONO); + cf2.push_back(CF_GENIVI_ANALOG); + enterSinkDB("sink1", domainID1, cf2, sinkID1); + enterSinkDB("sink2", domainID1, cf2, sinkID2); + + am_sourceID_t gwSourceID; + std::vector<am_CustomConnectionFormat_t> cf3; + cf3.push_back(CF_GENIVI_MONO); + cf3.push_back(CF_GENIVI_ANALOG); + enterSourceDB("gwSource1", domainID1, cf3, gwSourceID); + + am_sinkID_t gwSinkID; + std::vector<am_CustomConnectionFormat_t> cf4; + cf4.push_back(CF_GENIVI_STEREO); + cf4.push_back(CF_GENIVI_ANALOG); + enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); + + am_converterID_t converterID; + std::vector<bool> matrix; + matrix.resize(4, false); + matrix[0]=(true); + matrix[1]=(true); + enterConverterDB("converter", domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, converterID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID1, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = CF_GENIVI_STEREO; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = sinkID1; + hopp2.domainID = domainID1; + hopp2.connectionFormat = CF_GENIVI_MONO; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID1; + compareRoute.sourceID = sourceID; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); + + std::vector<am_CustomConnectionFormat_t> cf1; + cf1.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cf2; + cf2.push_back(CF_GENIVI_MONO); + std::vector<am_CustomConnectionFormat_t> cf3; + cf3.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID1, cf3, sinkID); + + am_sourceID_t gwSourceID; + enterSourceDB("gwSource1", domainID1, cf2, gwSourceID); + am_sinkID_t gwSinkID; + enterSinkDB("gwSink1", domainID1, cf1, gwSinkID); + am_converterID_t converterID; + std::vector<bool> matrix; + matrix.push_back(true); + enterConverterDB("converter1", domainID1, cf2, cf1, matrix, gwSourceID, gwSinkID, converterID); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource2", domainID1, cf2, gwSourceID1); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink2", domainID1, cf1, gwSinkID1); + am_converterID_t converterID1; + enterConverterDB("converter2", domainID1, cf2, cf1, matrix, gwSourceID1, gwSinkID1, converterID1); + + am_sourceID_t gwSourceID2; + enterSourceDB("gwSource3", domainID1, cf3, gwSourceID2); + am_sinkID_t gwSinkID2; + enterSinkDB("gwSink3", domainID1, cf2, gwSinkID2); + am_converterID_t converterID2; + enterConverterDB("converter3", domainID1, cf3, cf2, matrix, gwSourceID2, gwSinkID2, converterID2); + + am::am_Source_s source; + am::am_Sink_s sink; + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements1; + std::vector<am_RoutingElement_s> listRoutingElements2; + am_RoutingElement_s hopp11; + am_RoutingElement_s hopp12; + am_RoutingElement_s hopp13; + am_RoutingElement_s hopp21; + am_RoutingElement_s hopp22; + + hopp11.sourceID = sourceID; + hopp11.sinkID = gwSinkID; + hopp11.domainID = domainID1; + hopp11.connectionFormat = CF_GENIVI_STEREO; + + hopp12.sourceID = gwSourceID; + hopp12.sinkID = gwSinkID2; + hopp12.domainID = domainID1; + hopp12.connectionFormat = CF_GENIVI_MONO; + + hopp21.sourceID = sourceID; + hopp21.sinkID = gwSinkID1; + hopp21.domainID = domainID1; + hopp21.connectionFormat = CF_GENIVI_STEREO; + + hopp22.sourceID = gwSourceID1; + hopp22.sinkID = gwSinkID2; + hopp22.domainID = domainID1; + hopp22.connectionFormat = CF_GENIVI_MONO; + + hopp13.sourceID = gwSourceID2; + hopp13.sinkID = sinkID; + hopp13.domainID = domainID1; + hopp13.connectionFormat = CF_GENIVI_AUTO; + + listRoutingElements1.push_back(hopp11); + listRoutingElements1.push_back(hopp12); + listRoutingElements1.push_back(hopp13); + + listRoutingElements2.push_back(hopp21); + listRoutingElements2.push_back(hopp22); + listRoutingElements2.push_back(hopp13); + + am_Route_s compareRoute1; + compareRoute1.route = listRoutingElements1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(2), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])||pCF.compareRoute(compareRoute1,listRoutes[1])); + + am_Route_s compareRoute2; + compareRoute2.route = listRoutingElements2; + compareRoute2.sinkID = sinkID; + compareRoute2.sourceID = sourceID; + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1])||pCF.compareRoute(compareRoute2,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + am_sourceID_t sourceID; + std::vector<am_CustomConnectionFormat_t> cf1; + cf1.push_back(CF_GENIVI_STEREO); + enterSourceDB("source1", domainID1, cf1, sourceID); + + am_sinkID_t sinkID; + std::vector<am_CustomConnectionFormat_t> cf2; + cf2.push_back(CF_GENIVI_ANALOG); + enterSinkDB("sink1", domainID2, cf2, sinkID); + + am_sourceID_t gwSourceID; + std::vector<am_CustomConnectionFormat_t> cf3; + cf3.push_back(CF_GENIVI_ANALOG); + enterSourceDB("gwSource1", domainID2, cf3, gwSourceID); + + am_sinkID_t gwSinkID; + std::vector<am_CustomConnectionFormat_t> cf4; + cf4.push_back(CF_GENIVI_STEREO); + enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); + + am_gatewayID_t gatewayID; + std::vector<bool> matrix; + matrix.push_back(true); + enterGatewayDB("gateway", domainID2, domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, gatewayID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + std::vector<am_Route_s> listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID, sinkID, domainID2, CF_GENIVI_ANALOG}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1, domainID2, domainID3; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + enterDomainDB("domain3", domainID3); + + std::vector<am_CustomConnectionFormat_t> cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector<am_CustomConnectionFormat_t> cfMono; + cfMono.push_back(CF_GENIVI_MONO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); + + std::vector<bool> matrix; + matrix.push_back(true); + + am_gatewayID_t gatewayID; + enterGatewayDB("gateway", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); + + am_sourceID_t gwSourceID2; + enterSourceDB("gwSource2", domainID3, cfStereo, gwSourceID2); + + am_sinkID_t gwSinkID2; + enterSinkDB("gwSink2", domainID2, cfMono, gwSinkID2); + + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID3, cfStereo, sinkID); + + am_gatewayID_t gatewayID1; + enterGatewayDB("gateway", domainID3, domainID2, cfStereo, cfMono, matrix, gwSourceID2, gwSinkID2, gatewayID1); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector<am_Route_s> listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID1, gwSinkID2, domainID2, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gwSourceID2, sinkID, domainID3, CF_GENIVI_STEREO}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector<bool> matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector<am_CustomConnectionFormat_t> cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector<am_CustomConnectionFormat_t> cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector<am_CustomConnectionFormat_t> cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfMono, gwSinkID1); + + am_sinkID_t coSinkID21; + enterSinkDB("coSink21", domainID1, cfStereo, coSinkID21); + + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID1, cfMono, coSourceID21); + + am_converterID_t converterID1; + enterConverterDB("converter1", domainID1, cfMono, cfStereo, matrix, coSourceID21, coSinkID21, converterID1); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource21", domainID2, cfAuto, gwSourceID1); + + am_gatewayID_t gatewayID; + enterGatewayDB("gateway1", domainID2, domainID1, cfAuto, cfMono, matrix, gwSourceID1, gwSinkID1, gatewayID); + + am_sinkID_t sinkID1; + enterSinkDB("sink1", domainID2, cfAuto, sinkID1); + + am_sinkID_t sinkID2; + enterSinkDB("sink2", domainID1, cfAuto, sinkID2); + + am::am_Source_s source; + am::am_Sink_s sink1; + pDatabaseHandler.getSinkInfoDB(sinkID1, sink1); + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(sinkID2, sink2); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector<am_Route_s> listRoutes; + + getRoute(false, source, sink1, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID1; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, coSinkID21, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({coSourceID21, gwSinkID1, domainID1, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gwSourceID1, sinkID1, domainID2, CF_GENIVI_AUTO}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + + listRoutes.clear(); + getRoute(false, source, sink2, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); +} + +TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector<bool> matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector<am_CustomConnectionFormat_t> cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector<am_CustomConnectionFormat_t> cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector<am_CustomConnectionFormat_t> cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID11; + enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); + am_sourceID_t gwSourceID11; + enterSourceDB("gwSource11", domainID2, cfAnalog, gwSourceID11); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID11, gwSinkID11, gatewayID1); + + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID2, cfAnalog, gwSinkID21); + am_sourceID_t gwSourceID12; + enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); + am_gatewayID_t gatewayID2; + enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfAnalog, matrix, gwSourceID12, gwSinkID21, gatewayID2); + + am_sinkID_t sink1ID; + enterSinkDB("sink1", domainID1, cfAuto, sink1ID); + am_sinkID_t sink2ID; + enterSinkDB("sink2", domainID2, cfAnalog, sink2ID); + + std::vector<am_Route_s> listRoutes; + + am::am_Source_s source; + am::am_Sink_s sink1; + pDatabaseHandler.getSinkInfoDB(sink1ID, sink1); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + getRoute(false, source, sink1, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); + + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(sink2ID, sink2); + + getRoute(false, source, sink2, listRoutes); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sink2ID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID11, sink2ID, domainID2, CF_GENIVI_ANALOG}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector<bool> matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector<am_CustomConnectionFormat_t> cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector<am_CustomConnectionFormat_t> cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector<am_CustomConnectionFormat_t> cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t gwSinkID11; + enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); + + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); + + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID21, gwSinkID11, gatewayID1); + + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); + + am_sourceID_t gwSourceID12; + enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); + + am_sinkID_t coSinkID21; + enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); + + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); + + am_converterID_t converterID2; + enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); + + am_gatewayID_t gatewayID2; + enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); + + am_sinkID_t sink1ID; + enterSinkDB("sink1", domainID1, cfAuto, sink1ID); + am_sinkID_t sink2ID; + enterSinkDB("sink2", domainID2, cfStereo, sink2ID); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sink1ID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector<am_Route_s> listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); + + am::am_Sink_s sink1; + pDatabaseHandler.getSinkInfoDB(sink2ID, sink1); + getRoute(false, source, sink1, listRoutes); + + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + am_Route_s compareRoute1; + compareRoute1.sinkID = sink2ID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); + compareRoute1.route.push_back({coSourceID21, sink2ID, domainID2, CF_GENIVI_STEREO}); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); +} + +TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + std::vector<bool> matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector<am_CustomConnectionFormat_t> cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector<am_CustomConnectionFormat_t> cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector<am_CustomConnectionFormat_t> cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + std::vector<am_CustomConnectionFormat_t> cfFuture1; + cfFuture1.push_back(5); + std::vector<am_CustomConnectionFormat_t> cfFuture2; + cfFuture2.push_back(6); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t coSinkID11; + enterSinkDB("coSink11", domainID1, cfStereo, coSinkID11); + am_sourceID_t coSourceID11; + enterSourceDB("coSource11", domainID1, cfFuture1, coSourceID11); + am_converterID_t converterID11; + enterConverterDB("converter11", domainID1, cfFuture1, cfStereo, matrix, coSourceID11, coSinkID11, converterID11); + + am_sinkID_t coSinkID12; + enterSinkDB("coSink12", domainID1, cfStereo, coSinkID12); + am_sourceID_t coSourceID12; + enterSourceDB("coSource12", domainID1, cfFuture2, coSourceID12); + am_converterID_t converterID12; + enterConverterDB("converter12", domainID1, cfFuture2, cfStereo, matrix, coSourceID12, coSinkID12, converterID12); + + am_sinkID_t coSinkID13; + enterSinkDB("coSink13", domainID1, cfFuture2, coSinkID13); + am_sourceID_t coSourceID13; + enterSourceDB("coSource13", domainID1, cfFuture1, coSourceID13); + am_converterID_t converterID13; + enterConverterDB("converter13", domainID1, cfFuture1, cfFuture2, matrix, coSourceID13, coSinkID13, converterID13); + + am_sinkID_t gwSinkID11; + enterSinkDB("gwSink11", domainID1, cfFuture1, gwSinkID11); + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfFuture1, matrix, gwSourceID21, gwSinkID11, gatewayID1); + + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); + + am_sourceID_t gwSourceID12; + enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); + + am_sinkID_t coSinkID21; + enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); + + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); + + am_converterID_t converterID2; + enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); + + + am_gatewayID_t gatewayID2; + enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); + + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID1, cfAuto, sinkID); + + am::am_Source_s source; + am::am_Sink_s sink; + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector<am_Route_s> listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); + + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(coSinkID21, sink2); + pRouter.getRoute(false, source, sink2, listRoutes); + ASSERT_EQ(static_cast<uint>(2), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = coSinkID21; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, coSinkID11, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({coSourceID11, gwSinkID11, domainID1, 5}); + compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); + + am_Route_s compareRoute2; + compareRoute2.sinkID = coSinkID21; + compareRoute2.sourceID = sourceID; + compareRoute2.route.push_back({sourceID, coSinkID12, domainID1, CF_GENIVI_STEREO}); + compareRoute2.route.push_back({coSourceID12, coSinkID13, domainID1, 6}); + compareRoute2.route.push_back({coSourceID13, gwSinkID11, domainID1, 5}); + compareRoute2.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])||pCF.compareRoute(compareRoute1,listRoutes[0])); + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])||pCF.compareRoute(compareRoute2,listRoutes[1])); +} + +TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domain1ID, domain2ID, domain3ID; + enterDomainDB("domain1", domain1ID); + enterDomainDB("domain2", domain2ID); + enterDomainDB("domain3", domain3ID); + + //just make so many cycles as possible + std::vector<am_CustomConnectionFormat_t> cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cfAnalog = cfStereo; + std::vector<am_CustomConnectionFormat_t> cfMono = cfStereo; + std::vector<am_CustomConnectionFormat_t> cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t source1ID; + enterSourceDB("source1", domain1ID, cfStereo, source1ID); + am_sinkID_t gw1SinkID; + enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); + am_sinkID_t gw2SinkID; + enterSinkDB("gw2Sink", domain1ID, cfStereo, gw2SinkID); + am_sourceID_t gw3SourceID; + enterSourceDB("gw3Source", domain1ID, cfAnalog, gw3SourceID); + am_sourceID_t gw4SourceID; + enterSourceDB("gw4Source", domain1ID, cfAnalog, gw4SourceID); + am_sinkID_t gw5SinkID; + enterSinkDB("gw5Sink", domain1ID, cfAnalog, gw5SinkID); + + am_sourceID_t gw1SourceID; + enterSourceDB("gw1Source", domain2ID, cfMono, gw1SourceID); + am_sourceID_t gw2SourceID; + enterSourceDB("gw2Source", domain2ID, cfMono, gw2SourceID); + am_sinkID_t gw3SinkID; + enterSinkDB("gw3Sink", domain2ID, cfMono, gw3SinkID); + am_sinkID_t gw4SinkID; + enterSinkDB("gw4Sink", domain2ID, cfMono, gw4SinkID); + + am_sourceID_t gw5SourceID; + enterSourceDB("gw5Source", domain3ID, cfStereo, gw5SourceID); + am_sinkID_t sink1ID; + enterSinkDB("sink1", domain3ID, cfStereo, sink1ID); + + std::vector<bool> matrixT; + matrixT.push_back(true); + std::vector<bool> matrixF; + matrixF.push_back(false); + + am_gatewayID_t gateway1ID; + enterGatewayDB("gateway1", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); + am_gatewayID_t gateway2ID; + enterGatewayDB("gateway2", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw2SourceID, gw2SinkID, gateway2ID); + am_gatewayID_t gateway3ID; + enterGatewayDB("gateway3", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw3SourceID, gw3SinkID, gateway3ID); + am_gatewayID_t gateway4ID; + enterGatewayDB("gateway4", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw4SourceID, gw4SinkID, gateway4ID); + am_gatewayID_t gateway5ID; + enterGatewayDB("gateway5", domain3ID, domain1ID, cfStereo, cfAnalog, matrixT, gw5SourceID, gw5SinkID, gateway5ID); + + pRouter.load(false); + + CAmRoutingNode* sourceNode = pRouter.sourceNodeWithID(source1ID); + CAmRoutingNode* sinkNode = pRouter.sinkNodeWithID(sink1ID); + + ASSERT_TRUE(sourceNode); + ASSERT_TRUE(sinkNode); + + std::vector<am_Route_s> listRoutes; + std::vector<std::vector<CAmRoutingNode*>> resultNodesPath; + + am_Route_s compareRoute1; + compareRoute1.sinkID = sink1ID; + compareRoute1.sourceID = source1ID; + +#define DO_ASSERT() \ + {\ + bool didMatch = false; \ + for(auto it = listRoutes.begin(); it!=listRoutes.end(); it++) \ + didMatch|=pCF.compareRoute(compareRoute1,*it); \ + ASSERT_TRUE(didMatch); \ + } + +#ifdef ROUTING_BUILD_CONNECTIONS + getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, true); + ASSERT_EQ(static_cast<uint>(9), listRoutes.size()); + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() +#else + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); +#endif + + listRoutes.clear(); + resultNodesPath.clear(); + getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, false); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + DO_ASSERT() +} + +TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_domainID_t domainID1, domainID2, domainID3; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + enterDomainDB("domain3", domainID3); + + std::vector<am_CustomConnectionFormat_t> cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector<am_CustomConnectionFormat_t> cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector<am_CustomConnectionFormat_t> cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector<am_CustomConnectionFormat_t> cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); + am_sinkID_t gwSinkID21; + enterSinkDB("gwSink21", domainID1, cfStereo, gwSinkID21); + + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); + am_sinkID_t gwSinkID22; + enterSinkDB("gwSink22", domainID2, cfMono, gwSinkID22); + + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID3, cfAuto, gwSourceID21); + + am_sourceID_t gwSourceID22; + enterSourceDB("gwSource22", domainID3, cfAuto, gwSourceID22); + am_sourceID_t gwSourceID5; + enterSourceDB("gwSource5", domainID3, cfStereo, gwSourceID5); + am_sinkID_t gwSinkID5; + enterSinkDB("gwSink5", domainID3, cfAnalog, gwSinkID5); + am_sourceID_t gwSourceID3; + enterSourceDB("gwSource3", domainID3, cfAnalog, gwSourceID3); + am_sinkID_t gwSinkID3; + enterSinkDB("gwSink3", domainID3, cfAuto, gwSinkID3); + am_sourceID_t gwSourceID4; + enterSourceDB("gwSource4", domainID3, cfStereo, gwSourceID4); + am_sinkID_t gwSinkID4; + enterSinkDB("gwSink4", domainID3, cfAnalog, gwSinkID4); + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID3, cfStereo, sinkID); + + std::vector<bool> matrix; + matrix.push_back(true); + am_gatewayID_t gatewayID; + enterGatewayDB("gateway1", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); + am_gatewayID_t gatewayID22; + enterGatewayDB("gateway22", domainID3, domainID2, cfAuto, cfMono, matrix, gwSourceID22, gwSinkID22, gatewayID22); + am_gatewayID_t gatewayID21; + enterGatewayDB("gateway21", domainID3, domainID1, cfAuto, cfStereo, matrix, gwSourceID21, gwSinkID21, gatewayID21); + am_converterID_t converterID1; + enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, gwSourceID3, gwSinkID3, converterID1); + am_converterID_t converterID2; + enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, gwSourceID4, gwSinkID4, converterID2); + am_converterID_t converterID3; + enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, gwSourceID5, gwSinkID5, converterID3); + + am::am_Source_s source; + am::am_Sink_s sink; + + pDatabaseHandler.getSinkInfoDB(sinkID, sink); + pDatabaseHandler.getSourceInfoDB(sourceID, source); + + std::vector<am_Route_s> listRoutes; + + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(static_cast<uint>(4), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute1.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); + compareRoute1.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); + + am_Route_s compareRoute2; + compareRoute2.sinkID = sinkID; + compareRoute2.sourceID = sourceID; + compareRoute2.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); + compareRoute2.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); + compareRoute2.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute2.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); + compareRoute2.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); + + am_Route_s compareRoute3; + compareRoute3.sinkID = sinkID; + compareRoute3.sourceID = sourceID; + compareRoute3.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); + compareRoute3.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute3.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); + compareRoute3.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); + + am_Route_s compareRoute4; + compareRoute4.sinkID = sinkID; + compareRoute4.sourceID = sourceID; + compareRoute4.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); + compareRoute4.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute4.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); + compareRoute4.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])|| + pCF.compareRoute(compareRoute1,listRoutes[1])|| + pCF.compareRoute(compareRoute1,listRoutes[2])|| + pCF.compareRoute(compareRoute1,listRoutes[3])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])|| + pCF.compareRoute(compareRoute2,listRoutes[1])|| + pCF.compareRoute(compareRoute2,listRoutes[2])|| + pCF.compareRoute(compareRoute2,listRoutes[3])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[0])|| + pCF.compareRoute(compareRoute3,listRoutes[1])|| + pCF.compareRoute(compareRoute3,listRoutes[2])|| + pCF.compareRoute(compareRoute3,listRoutes[3])); + + ASSERT_TRUE(pCF.compareRoute(compareRoute4,listRoutes[0])|| + pCF.compareRoute(compareRoute4,listRoutes[1])|| + pCF.compareRoute(compareRoute4,listRoutes[2])|| + pCF.compareRoute(compareRoute4,listRoutes[3])); +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterMapTest"); + logInfo("Routing Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h new file mode 100644 index 0000000..65ff97b --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h @@ -0,0 +1,108 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * +* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MAPTEST_H_ +#define MAPTEST_H_ + +#define UNIT_TEST 1 + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <algorithm> +#include <string> +#include <vector> +#include <set> +#include "CAmDatabaseHandlerMap.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "CAmSocketHandler.h" +#include "../IAmControlBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmControlSend.h" +#include "../MockIAmCommandSend.h" + + +namespace am +{ + +class CAmRouterMapTest: public ::testing::Test +{ +public: + CAmRouterMapTest(); + ~CAmRouterMapTest(); + std::vector<std::string> plistRoutingPluginDirs; + std::vector<std::string> plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmControlSender pControlSender; + CAmDatabaseHandlerMap pDatabaseHandler; + CAmRouter pRouter; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + MockIAmCommandSend pMockInterface; + MockIAmControlSend pMockControlInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + IAmControlBackdoor pControlInterfaceBackdoor; + CAmControlReceiver pControlReceiver; + CAmDatabaseObserver pObserver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); + + void createMainConnectionSetup(); + + void enterDomainDB(const std::string & domainName, am_domainID_t & domainID); + void enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector<am_CustomConnectionFormat_t> & connectionFormats, am_sourceID_t & sourceID); + void enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector<am_CustomConnectionFormat_t> & connectionFormats, am_sinkID_t & sinkID); + void enterGatewayDB(const std::string & gwName, + const am_domainID_t domainSourceID, + const am_domainID_t domainSinkID, + const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats, + const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats, + const std::vector<bool> & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_gatewayID_t & gatewayID); + void enterConverterDB(const std::string & gwName, + const am_domainID_t domainID, + const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats, + const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats, + const std::vector<bool> & matrix, + const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, + am_converterID_t & converterID); + void getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s>& returnList); + void getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector<am_Route_s> & listRoutes); + void getAllPaths(CAmRoutingNode & aSource, + CAmRoutingNode & aSink, + std::vector<am_Route_s> & resultPath, + std::vector<std::vector<CAmRoutingNode*>> & resultNodesPath, + const bool includeCycles); +}; + +} + +#endif /* MAPTEST_H_ */ diff --git a/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt new file mode 100644 index 0000000..17689d9 --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRouterMapTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB ROUTINGMAP_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterMapTest ${ROUTINGMAP_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterMapTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterMapTest AudioManagerCore) + +INSTALL(TARGETS AmRouterMapTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt~ b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt~ new file mode 100644 index 0000000..ec79082 --- /dev/null +++ b/AudioManagerCore/test/AmRouterMapTest/CMakeLists.txt~ @@ -0,0 +1,47 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRouterMapTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB ROUTINGMAP_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterMapTest ${ROUTINGMAP_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterMapTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterMapTest AudioManagerCore) + +INSTALL(TARGETS AmRouterMapTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp new file mode 100644 index 0000000..a64979e --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp @@ -0,0 +1,1967 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmRouterTest.h" +#include <string.h> +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + +CAmRouterTest::CAmRouterTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pControlSender(), // + pDatabaseHandler(), + pRouter(&pDatabaseHandler, &pControlSender), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pMockInterface(), // + pMockControlInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlInterfaceBackdoor(), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter), // + pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); + pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); +} + +CAmRouterTest::~CAmRouterTest() +{ + +} + +void CAmRouterTest::SetUp() +{ + logInfo("Routing Test started "); +} + +void CAmRouterTest::TearDown() +{ +} + +ACTION(returnConnectionFormat){ +arg4=arg3; +} + +//test that checks just sinks and source in a domain but connectionformats do not match +TEST_F(CAmRouterTest,simpleRoute2withDomainNoMatchFormats) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1; + am_domainID_t domainID1; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + + am_Source_s source; + am_sourceID_t sourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + source.sourceID=sourceID; + + am_Sink_s sink; + am_sinkID_t sinkID; + + sink.domainID = domainID1; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + sink.sinkID=sinkID; + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sinkID = sinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); + +} + +//test that checks just sinks and source in a domain +TEST_F(CAmRouterTest,simpleRoute2withDomain) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1; + am_domainID_t domainID1; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + + am_Source_s source; + am_sourceID_t sourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + + am_Sink_s sink; + am_sinkID_t sinkID; + + sink.domainID = domainID1; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + + hopp1.sinkID = sinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + +} + +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFree) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + std::vector<am_Connection_s> listConnections; + pDatabaseHandler.getListConnections(listConnections); + ASSERT_EQ(0, listConnections.size()); + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + +} + +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFreeNotFree) +{ + + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + am_Connection_s connection,connection1; + am_connectionID_t id1,id2; + connection.sourceID=sourceID; + connection.sinkID=gwSinkID; + connection.connectionFormat=CF_GENIVI_ANALOG; + connection.connectionID=0; + connection1.sourceID=gwSourceID; + connection1.sinkID=sinkID; + connection1.connectionFormat=CF_GENIVI_ANALOG; + connection1.connectionID=0; + + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,id1)); + ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2)); + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks just 2 domains, with gateway for each direction (possible circular route) +TEST_F(CAmRouterTest,simpleRoute2DomainsCircularGWOnlyFree) +{ + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource, gwSource2; + am_sourceID_t sourceID, gwSourceID, gwSourceID2; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID1; + gwSource2.name = "gwsource2"; + gwSource2.sourceState = SS_ON; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + + am_Sink_s sink, gwSink, gwSink2; + am_sinkID_t sinkID, gwSinkID, gwSinkID2; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID2; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + + am_Gateway_s gateway, gateway2; + am_gatewayID_t gatewayID, gatewayID2; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway2.controlDomainID = domainID1; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID1; + gateway2.domainSinkID = domainID2; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats_2) +{ + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + gwSink1.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(false); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(false); + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[1]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[1]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats_1) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.convertionMatrix.push_back(false); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + + +//test that checks 3 domains, one sink one source, longer lists of connectionformats. +TEST_F(CAmRouterTest,simpleRoute3DomainsListConnectionFormats) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(false); + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[1]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + + +//test that checks 4 domains, one sink and one source but there are 2 routes because there are 2 gateways +TEST_F(CAmRouterTest,simpleRoute4Domains2Routes) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3, domain4; + am_domainID_t domainID1, domainID2, domainID3, domainID4; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + domain4.domainID = 0; + domain4.name = "domain4"; + domain4.busname = "domain4bus"; + domain4.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + + am_Source_s source, gwSource, gwSource1, gwSource2, gwSource3; + am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2, gwSourceID3; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID4; + gwSource2.name = "gwsource3"; + gwSource2.sourceState = SS_OFF; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSource3.domainID = domainID3; + gwSource3.name = "gwsource4"; + gwSource3.sourceState = SS_OFF; + gwSource3.sourceID = 0; + gwSource3.sourceClassID = 5; + gwSource3.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource3,gwSourceID3)); + + am_Sink_s sink, gwSink, gwSink1, gwSink2, gwSink3; + am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2, gwSinkID3; + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID3; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink3.domainID = domainID2; + gwSink3.name = "gwSink3"; + gwSink3.sinkID = 0; + gwSink3.sinkClassID = 5; + gwSink3.muteState = MS_MUTED; + gwSink3.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + sink.domainID = domainID4; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink3,gwSinkID3)); + + am_Gateway_s gateway, gateway1, gateway2, gateway3; + am_gatewayID_t gatewayID, gatewayID1, gatewayID2, gatewayID3; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + gateway2.controlDomainID = domainID3; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID4; + gateway2.domainSinkID = domainID3; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + gateway3.controlDomainID = domainID2; + gateway3.gatewayID = 0; + gateway3.sinkID = gwSinkID3; + gateway3.sourceID = gwSourceID3; + gateway3.domainSourceID = domainID3; + gateway3.domainSinkID = domainID2; + gateway3.listSinkFormats = gwSink3.listConnectionFormats; + gateway3.listSourceFormats = gwSource3.listConnectionFormats; + gateway3.convertionMatrix.push_back(true); + gateway3.name = "gateway3"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway3,gatewayID3)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements, listRoutingElements1; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + am_RoutingElement_s hopp4; + am_RoutingElement_s hopp2alt; + am_RoutingElement_s hopp3alt; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = gwSinkID2; + hopp3.domainID = domainID3; + hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; + + hopp4.sourceID = gwSourceID2; + hopp4.sinkID = sinkID; + hopp4.domainID = domainID4; + hopp4.connectionFormat = sink.listConnectionFormats[0]; + + hopp2alt.sourceID = gwSourceID; + hopp2alt.sinkID = gwSinkID3; + hopp2alt.domainID = domainID2; + hopp2alt.connectionFormat = gwSink3.listConnectionFormats[0]; + + hopp3alt.sourceID = gwSourceID3; + hopp3alt.sinkID = gwSinkID2; + hopp3alt.domainID = domainID3; + hopp3alt.connectionFormat = gwSink2.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + listRoutingElements.push_back(hopp4); + listRoutingElements1.push_back(hopp1); + listRoutingElements1.push_back(hopp2alt); + listRoutingElements1.push_back(hopp3alt); + listRoutingElements1.push_back(hopp4); + + am_Route_s compareRoute, compareRoute1; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + compareRoute1.route = listRoutingElements1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(2), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]) || pCF.compareRoute(compareRoute,listRoutes[1]) ); + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1]) || pCF.compareRoute(compareRoute1,listRoutes[0]) ); +} + +//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit. +TEST_F(CAmRouterTest,simpleRoute3DomainsNoConnection) +{ + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); +} +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(CAmRouterTest,simpleRoute2Domains) +{ + + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + +} + +//test that checks just 2 domains, one sink one source but the connectionformat of source +TEST_F(CAmRouterTest,simpleRoute2DomainsNoMatchConnectionFormats) +{ + + + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sinkID = gwSinkID; + hopp1.sourceID = sourceID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sinkID = sinkID; + hopp2.sourceID = gwSourceID; + hopp2.domainID = domainID2; + hopp2.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(0), listRoutes.size()); +} + +//test that checks 3 domains, one sink one source. +TEST_F(CAmRouterTest,simpleRoute3Domains) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3; + am_domainID_t domainID1, domainID2, domainID3; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + + am_Source_s source, gwSource, gwSource1; + am_sourceID_t sourceID, gwSourceID, gwSourceID1; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + + am_Sink_s sink, gwSink, gwSink1; + am_sinkID_t sinkID, gwSinkID, gwSinkID1; + + sink.domainID = domainID3; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + + am_Gateway_s gateway, gateway1; + am_gatewayID_t gatewayID, gatewayID1; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = sinkID; + hopp3.domainID = domainID3; + hopp3.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(static_cast<uint>(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +//test that checks 4 domains, one sink and one source. +TEST_F(CAmRouterTest,simpleRoute4Domains) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2, domain3, domain4; + am_domainID_t domainID1, domainID2, domainID3, domainID4; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + domain3.domainID = 0; + domain3.name = "domain3"; + domain3.busname = "domain3bus"; + domain3.state = DS_CONTROLLED; + domain4.domainID = 0; + domain4.name = "domain4"; + domain4.busname = "domain4bus"; + domain4.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + + am_Source_s source, gwSource, gwSource1, gwSource2; + am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSource1.domainID = domainID3; + gwSource1.name = "gwsource2"; + gwSource1.sourceState = SS_ON; + gwSource1.sourceID = 0; + gwSource1.sourceClassID = 5; + gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSource2.domainID = domainID4; + gwSource2.name = "gwsource3"; + gwSource2.sourceState = SS_OFF; + gwSource2.sourceID = 0; + gwSource2.sourceClassID = 5; + gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + + am_Sink_s sink, gwSink, gwSink1, gwSink2; + am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2; + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO); + + gwSink1.domainID = domainID2; + gwSink1.name = "gwSink1"; + gwSink1.sinkID = 0; + gwSink1.sinkClassID = 5; + gwSink1.muteState = MS_MUTED; + gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); + + gwSink2.domainID = domainID3; + gwSink2.name = "gwSink2"; + gwSink2.sinkID = 0; + gwSink2.sinkClassID = 5; + gwSink2.muteState = MS_MUTED; + gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); + + sink.domainID = domainID4; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + + am_Gateway_s gateway, gateway1, gateway2; + am_gatewayID_t gatewayID, gatewayID1, gatewayID2; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + gateway1.controlDomainID = domainID2; + gateway1.gatewayID = 0; + gateway1.sinkID = gwSinkID1; + gateway1.sourceID = gwSourceID1; + gateway1.domainSourceID = domainID3; + gateway1.domainSinkID = domainID2; + gateway1.listSinkFormats = gwSink1.listConnectionFormats; + gateway1.listSourceFormats = gwSource1.listConnectionFormats; + gateway1.convertionMatrix.push_back(true); + gateway1.name = "gateway1"; + + gateway2.controlDomainID = domainID3; + gateway2.gatewayID = 0; + gateway2.sinkID = gwSinkID2; + gateway2.sourceID = gwSourceID2; + gateway2.domainSourceID = domainID4; + gateway2.domainSinkID = domainID3; + gateway2.listSinkFormats = gwSink2.listConnectionFormats; + gateway2.listSourceFormats = gwSource2.listConnectionFormats; + gateway2.convertionMatrix.push_back(true); + gateway2.name = "gateway2"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + + std::vector<am_Route_s> listRoutes; + std::vector<am_RoutingElement_s> listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + am_RoutingElement_s hopp3; + am_RoutingElement_s hopp4; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = source.listConnectionFormats[0]; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = gwSinkID1; + hopp2.domainID = domainID2; + hopp2.connectionFormat = gwSink1.listConnectionFormats[0]; + + hopp3.sourceID = gwSourceID1; + hopp3.sinkID = gwSinkID2; + hopp3.domainID = domainID3; + hopp3.connectionFormat = gwSink2.listConnectionFormats[0]; + + hopp4.sourceID = gwSourceID2; + hopp4.sinkID = sinkID; + hopp4.domainID = domainID4; + hopp4.connectionFormat = sink.listConnectionFormats[0]; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + listRoutingElements.push_back(hopp3); + listRoutingElements.push_back(hopp4); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + size_t size(1); + ASSERT_EQ(size, listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); +} + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterTest"); + logInfo("Routing Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h new file mode 100644 index 0000000..4a4e35b --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h @@ -0,0 +1,81 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * +* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef DATABASETEST_H_ +#define DATABASETEST_H_ + +#define UNIT_TEST 1 + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include <algorithm> +#include <string> +#include <vector> +#include <set> +#include "CAmDatabaseHandlerMap.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRoutingSender.h" +#include "CAmRouter.h" +#include "CAmSocketHandler.h" +#include "../IAmControlBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmControlSend.h" +#include "../MockIAmCommandSend.h" + + +namespace am +{ + +class CAmRouterTest: public ::testing::Test +{ +public: + CAmRouterTest(); + ~CAmRouterTest(); + std::vector<std::string> plistRoutingPluginDirs; + std::vector<std::string> plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmControlSender pControlSender; + CAmDatabaseHandlerMap pDatabaseHandler; + CAmRouter pRouter; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + MockIAmCommandSend pMockInterface; + MockIAmControlSend pMockControlInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + IAmControlBackdoor pControlInterfaceBackdoor; + CAmControlReceiver pControlReceiver; + CAmDatabaseObserver pObserver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); + + void createMainConnectionSetup(); +}; + +} + +#endif /* DATABASETEST_H_ */ diff --git a/AudioManagerCore/test/AmRouterTest/CMakeLists.txt b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt new file mode 100644 index 0000000..db05911 --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt @@ -0,0 +1,48 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmRouterTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + + +file(GLOB ROUTING_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterTest ${ROUTING_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterTest AudioManagerCore) + +INSTALL(TARGETS AmRouterTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ new file mode 100644 index 0000000..32e1206 --- /dev/null +++ b/AudioManagerCore/test/AmRouterTest/CMakeLists.txt~ @@ -0,0 +1,47 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. if a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project(AmRouterTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR}) + + +file(GLOB ROUTING_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" + ) + +ADD_EXECUTABLE( AmRouterTest ${ROUTING_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRouterTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRouterTest AudioManagerCore) + +INSTALL(TARGETS AmRouterTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp new file mode 100644 index 0000000..5978b6d --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp @@ -0,0 +1,383 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmRoutingInterfaceTest.h" +#include "CAmDltWrapper.h" +#include "CAmCommandLineSingleton.h" + +using namespace am; +using namespace testing; + +TCLAP::SwitchArg enableNoDLTDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); + +CAmRoutingInterfaceTest::CAmRoutingInterfaceTest() : + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pDatabaseHandler(), // + pRoutingSender(plistRoutingPluginDirs), // + pCommandSender(plistCommandPluginDirs), // + pControlSender(), // + pRouter(&pDatabaseHandler, &pControlSender), // + pMockInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // + pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) +{ + pDatabaseHandler.registerObserver(&pObserver); + pRoutingInterfaceBackdoor.unloadPlugins(&pRoutingSender); + pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockInterface, "mock"); + pCommandInterfaceBackdoor.unloadPlugins(&pCommandSender); +} + +CAmRoutingInterfaceTest::~CAmRoutingInterfaceTest() +{ +} + +void CAmRoutingInterfaceTest::SetUp() +{ + logInfo("RoutingSendInterface Test started "); + +} + +void CAmRoutingInterfaceTest::TearDown() +{ +} + +TEST_F(CAmRoutingInterfaceTest,abort) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_connectionID_t connectionID; + std::vector<am_Handle_s> listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + + //prepare the stage + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + //start a connect, expect a call on the routingInterface + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + + //check the correctness of the handle + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_CONNECT); + + //the handle must be inside the handlelist + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); + + //send an abort expect a call on the routing interface + EXPECT_CALL(pMockInterface,asyncAbort(_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.abortAction(handle)); + + //the reaction on the abort is specific for every function + + //now we try to abort a handle that does not exist + handle.handle = 24; + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle)); +} + +TEST_F(CAmRoutingInterfaceTest,abortNonExistent) +{ + EXPECT_CALL(pMockInterface,asyncAbort(_)).Times(0); + am_Handle_s handle; + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle)); +} + +TEST_F(CAmRoutingInterfaceTest,alreadyConnected) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + am_Handle_s handle; + am_connectionID_t connectionID; + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + //ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_CONNECT); +} + +TEST_F(CAmRoutingInterfaceTest,setSinkSoundPropertyNoChange) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + soundProperty.type = SP_GENIVI_TREBLE; + soundProperty.value = 23; + std::vector<am_Handle_s> listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + sink.listSoundProperties.push_back(soundProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).Times(1).WillOnce(Return(E_NO_CHANGE)); + ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); +} + +TEST_F(CAmRoutingInterfaceTest,setSourceState) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + handle.handle = 0; + am_SourceState_e state = SS_PAUSED; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.domainID = DYNAMIC_ID_BOUNDARY; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,sourceID,state)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSOURCESTATE); +} + +TEST_F(CAmRoutingInterfaceTest,setSourceSoundProperty) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + std::vector<am_Handle_s> listHandles; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = DYNAMIC_ID_BOUNDARY; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceSoundProperty(_,sourceID,_)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,sourceID,soundProperty)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSOURCESOUNDPROPERTY); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,setSinkSoundProperty) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_SoundProperty_s soundProperty; + soundProperty.value=5; + soundProperty.type=SP_GENIVI_MID; + std::vector<am_Handle_s> listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + sink.listSoundProperties.push_back(soundProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).WillOnce(Return(E_OK)); + soundProperty.value=10; + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSINKSOUNDPROPERTY); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + + + +TEST_F(CAmRoutingInterfaceTest,setSourceVolume) +{ + am_Source_s source; + am_sourceID_t sourceID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_volume_t volume = 34; + am_CustomRampType_t rampType = RAMP_GENIVI_DIRECT; + am_time_t rampTime = 300; + std::vector<am_Handle_s> listHandles; + pCF.createSource(source); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + source.sourceID = 2; + source.domainID = DYNAMIC_ID_BOUNDARY; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSOURCEVOLUME); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,setSinkVolume) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_volume_t volume = 34; + am_CustomRampType_t rampType = RAMP_GENIVI_DIRECT; + am_time_t rampTime = 300; + std::vector<am_Handle_s> listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_SETSINKVOLUME); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,connect) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_connectionID_t connectionID; + std::vector<am_Handle_s> listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_CONNECT); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[0].handle==handle.handle); + ASSERT_TRUE(listHandles[0].handleType==handle.handleType); +} + +TEST_F(CAmRoutingInterfaceTest,disconnect) +{ + am_Sink_s sink; + am_sinkID_t sinkID; + am_Domain_s domain; + am_domainID_t domainID; + am_Handle_s handle; + am_connectionID_t connectionID; + std::vector<am_Handle_s> listHandles; + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_GENIVI_ANALOG)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_GENIVI_ANALOG,1,2)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + EXPECT_CALL(pMockInterface,asyncDisconnect(_,connectionID)).WillOnce(Return(E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,connectionID)); + ASSERT_NE(handle.handle, 0); + ASSERT_EQ(handle.handleType, H_DISCONNECT); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles[1].handle==handle.handle); + ASSERT_TRUE(listHandles[1].handleType==handle.handleType); +} + + +TEST_F(CAmRoutingInterfaceTest,nothingTodisconnect) +{ + am_Handle_s handle; + am_connectionID_t connectionID = 4; + std::vector<am_Handle_s> listHandles; + ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,connectionID)); + ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles)); + ASSERT_TRUE(listHandles.empty()); +} + + +int main(int argc, char **argv) +{ + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); + cmd->add(enableNoDLTDebug); + } + catch (TCLAP::ArgException &e) // catch any exceptions + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + CAmCommandLineSingleton::instance()->preparse(argc,argv); + CAmDltWrapper::instance(enableNoDLTDebug.getValue())->registerApp("routing", "CAmRouterTest"); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h new file mode 100644 index 0000000..75a7511 --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h @@ -0,0 +1,71 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTINGINTERFACETEST_H_ +#define ROUTINGINTERFACETEST_H_ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include <algorithm> +#include <string> +#include <vector> +#include <set> +#include "CAmDatabaseHandlerMap.h" +#include "CAmControlReceiver.h" +#include "CAmControlSender.h" +#include "CAmDatabaseObserver.h" +#include "CAmRouter.h" +#include "../IAmRoutingBackdoor.h" +#include "../IAmCommandBackdoor.h" +#include "../CAmCommonFunctions.h" +#include "../MockIAmRoutingSend.h" +#include "CAmSocketHandler.h" + +namespace am +{ + +class CAmRoutingInterfaceTest: public ::testing::Test +{ +public: + CAmRoutingInterfaceTest(); + ~CAmRoutingInterfaceTest(); + std::vector<std::string> plistRoutingPluginDirs; + std::vector<std::string> plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmDatabaseHandlerMap pDatabaseHandler; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + CAmControlSender pControlSender; + CAmRouter pRouter; + MockIAmRoutingSend pMockInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + CAmControlReceiver pControlReceiver; + CAmDatabaseObserver pObserver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); +}; + +} + +#endif /* ROUTINGINTERFACETEST_H_ */ diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt new file mode 100644 index 0000000..dc5115d --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRoutingInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB ROUTING_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmRoutingInterfaceTest ${ROUTING_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRoutingInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRoutingInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmRoutingInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt~ b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt~ new file mode 100644 index 0000000..e8fbb29 --- /dev/null +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CMakeLists.txt~ @@ -0,0 +1,48 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +project (AmRoutingInterfaceTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager") + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR}) + +file(GLOB ROUTING_INTERFACE_SRCS_CXX + "../CAmCommonFunctions.cpp" + "*.cpp" +) + +ADD_EXECUTABLE(AmRoutingInterfaceTest ${ROUTING_INTERFACE_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmRoutingInterfaceTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmRoutingInterfaceTest AudioManagerCore) + +INSTALL(TARGETS AmRoutingInterfaceTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + diff --git a/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp new file mode 100644 index 0000000..d3f7a11 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp @@ -0,0 +1,209 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <string> + +#include "CAmTelnetServerTest.h" +#include "CAmCommandReceiver.h" +#include "CAmRoutingReceiver.h" +#include "CAmControlReceiver.h" +#include "audiomanagerconfig.h" + + +using namespace testing; +using namespace am; +using namespace std; + + +static std::string controllerPlugin = std::string(CONTROLLER_PLUGIN_DIR); +static unsigned short servPort = 6060; +static int staticSocket = -1; +static CAmSocketHandler* mpSocketHandler = NULL; + +void* startSocketHandler(void* data) +{ + CAmEnvironment* Env = static_cast<CAmEnvironment*>(data); + Env->setSocketHandler(&Env->mSocketHandler); + Env->mSocketHandler.start_listenting(); + Env->setSocketHandler(NULL); + return (NULL); +} + +CAmEnvironment::CAmEnvironment() +: mlistRoutingPluginDirs() +, mlistCommandPluginDirs() +, mSocketHandler() +, mDatabasehandler() +, mRoutingSender(mlistRoutingPluginDirs) +, mCommandSender(mlistRoutingPluginDirs) +, mRouter(&mDatabasehandler,&mControlSender) +, mpCommandReceiver(NULL) +, mpRoutingReceiver(NULL) +, mpControlReceiver(NULL) +, mpTelnetServer(NULL) +, mSocketHandlerThread(0) +{ +} + +CAmEnvironment::~CAmEnvironment() +{ + usleep(500); + if(NULL != mpTelnetServer) + delete(mpTelnetServer); + if(NULL != mpControlReceiver) + delete(mpControlReceiver); + if(NULL != mpRoutingReceiver) + delete(mpRoutingReceiver); + if(NULL != mpCommandReceiver) + delete(mpCommandReceiver); +} + +void CAmEnvironment::SetUp() +{ + pthread_create(&mSocketHandlerThread, NULL, startSocketHandler, this); + sleep(1); +} + +void CAmEnvironment::TearDown() +{ + pthread_cancel(mSocketHandlerThread); +} + +void CAmEnvironment::setSocketHandler(CAmSocketHandler* pSocketHandler) +{ + mpSocketHandler = pSocketHandler; + + if(NULL != pSocketHandler) + { + mpCommandReceiver = new CAmCommandReceiver(&mDatabasehandler,&mControlSender,mpSocketHandler); + mpRoutingReceiver = new CAmRoutingReceiver(&mDatabasehandler,&mRoutingSender,&mControlSender,mpSocketHandler); + mpControlReceiver = new CAmControlReceiver(&mDatabasehandler,&mRoutingSender,&mCommandSender,mpSocketHandler,&mRouter); + + //startup all the Plugins and Interfaces + //mControlSender.startupController(mpControlReceiver); + //mCommandSender.startupInterfaces(mpCommandReceiver); + //mRoutingSender.startupInterfaces(mpRoutingReceiver); + + //when the routingInterface is done, all plugins are loaded: + //mControlSender.setControllerReady(); + + // Starting TelnetServer + mpTelnetServer = new CAmTelnetServer(mpSocketHandler,&mCommandSender,mpCommandReceiver,&mRoutingSender,mpRoutingReceiver,&mControlSender,mpControlReceiver,&mDatabasehandler,&mRouter,servPort,3); + } +} + +void CAmEnvironment::stopSocketHandler() +{ + mpSocketHandler->stop_listening(); +} + +CAmTelnetServerTest::CAmTelnetServerTest() +{ + +} + +CAmTelnetServerTest::~CAmTelnetServerTest() +{ + +} + +void CAmTelnetServerTest::SetUp() +{ + +} + +void CAmTelnetServerTest::TearDown() +{ + +} + +void CAmTelnetServerTest::sendCmd(std::string & command ) +{ + ssize_t sizesent = send(staticSocket, command.c_str(), command.size(), 0); + ASSERT_EQ(static_cast<uint>(sizesent),command.size()); + + char buffer[1000]; + memset(buffer,0,sizeof(buffer)); + int read=recv(staticSocket,buffer,sizeof(buffer),0); + ASSERT_GT(read,1); +} + +TEST_F(CAmTelnetServerTest,connectTelnetServer) +{ + struct sockaddr_in servAddr; + + staticSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + ASSERT_GE(staticSocket,0); + + struct hostent *host = (struct hostent*) gethostbyname("localhost"); + if (host == 0) + { + std::cout << " ERROR: gethostbyname() failed\n" << std::endl; + return; + } + + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr*) (host->h_addr_list[0]))); + servAddr.sin_port = htons(servPort); + + int return_connect = connect(staticSocket, (struct sockaddr *) &servAddr, sizeof(servAddr)); + ASSERT_GE(return_connect,0); + + char buffer[1000]; + int read=recv(staticSocket,buffer,sizeof(buffer),0); + ASSERT_GT(read,1); +} + +TEST_F(CAmTelnetServerTest,sendCmdTelnetServer) +{ + std::string cmd("help"); + sendCmd(cmd); +} + +TEST_F(CAmTelnetServerTest,sendDumpCmdTelnetServer) +{ + std::string cmd1("info"); + std::string cmd3("dump"); + sendCmd(cmd1); + sendCmd(cmd3); +} + +TEST_F(CAmTelnetServerTest,closeTelnetServerConnection) +{ + std::string cmd("exit"); + mpSocketHandler->stop_listening(); + sendCmd(cmd); + close(staticSocket); + staticSocket = -1; +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + ::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new CAmEnvironment); + (void) env; + return RUN_ALL_TESTS(); +} diff --git a/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h new file mode 100644 index 0000000..02f98a3 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h @@ -0,0 +1,107 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef CAMTELNETSERVERTEST_H_ +#define CAMTELNETSERVERTEST_H_ + +#include "gtest/gtest.h" +#include "CAmTelnetServer.h" +#include "CAmRoutingSender.h" +#include "CAmCommandSender.h" +#include "CAmControlSender.h" +#include "CAmRouter.h" +#include "audiomanagerconfig.h" +#include "CAmDatabaseHandlerMap.h" + + + + + +namespace am +{ + +class CAmSocketHandler; +class CAmRoutingSender; +class CAmCommandSender; +class CAmControlSender; +class CAmRouter; +class CAmCommandReceiver; +class CAmRoutingReceiver; +class CAmControlReceiver; +class CAmTelnetServer; + + +class CAmEnvironment : public ::testing::Environment +{ + public: + CAmEnvironment(); + + ~CAmEnvironment(); + // Override this to define how to set up the environment. + void SetUp(); + // Override this to define how to tear down the environment. + void TearDown(); + + void setSocketHandler(CAmSocketHandler* pSocketHandler); + + void stopSocketHandler(); + + std::vector<std::string> mlistRoutingPluginDirs; + std::vector<std::string> mlistCommandPluginDirs; + + CAmSocketHandler mSocketHandler; + CAmDatabaseHandlerMap mDatabasehandler; + CAmRoutingSender mRoutingSender; + CAmCommandSender mCommandSender; + CAmControlSender mControlSender; + CAmRouter mRouter; + + CAmCommandReceiver* mpCommandReceiver; + CAmRoutingReceiver* mpRoutingReceiver; + CAmControlReceiver* mpControlReceiver; + + CAmTelnetServer* mpTelnetServer; + + pthread_t mSocketHandlerThread; +}; + +class CAmTelnetServerTest : public ::testing::Test +{ + public: + CAmTelnetServerTest(); + ~CAmTelnetServerTest(); + + + void SetUp() ; + + void TearDown() ; + void sendCmd(std::string & command ); + //int mSocket; +}; + +} + + + + +#endif /* CAMTELNETSERVERTEST_H_ */ diff --git a/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt new file mode 100644 index 0000000..8dcb0a3 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt @@ -0,0 +1,48 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +PROJECT(AmTelnetServerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS}) + +file(GLOB TELNET_SRCS_CXX + "*.cpp" +) + +ADD_EXECUTABLE(AmTelnetServerTest ${TELNET_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmTelnetServerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) +add_test(AmTelnetServerTest AmTelnetServerTest) + +ADD_DEPENDENCIES(AmTelnetServerTest AudioManagerCore) + +INSTALL(TARGETS AmTelnetServerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + + diff --git a/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt~ b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt~ new file mode 100644 index 0000000..51e92b8 --- /dev/null +++ b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt~ @@ -0,0 +1,46 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + +PROJECT(AmTelnetServerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) + +INCLUDE_DIRECTORIES( + ${AUDIOMANAGER_CORE_INCLUDE} + ${GMOCK_INCLUDE_DIR}) + +file(GLOB TELNET_SRCS_CXX + "*.cpp" +) + +ADD_EXECUTABLE(AmTelnetServerTest ${TELNET_SRCS_CXX}) + +TARGET_LINK_LIBRARIES(AmTelnetServerTest + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} + AudioManagerCore +) + +ADD_DEPENDENCIES(AmTelnetServerTest AudioManagerCore) + +INSTALL(TARGETS AmTelnetServerTest + DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ + COMPONENT tests +) + + diff --git a/AudioManagerCore/test/CAmCommonFunctions.cpp b/AudioManagerCore/test/CAmCommonFunctions.cpp new file mode 100644 index 0000000..22331d4 --- /dev/null +++ b/AudioManagerCore/test/CAmCommonFunctions.cpp @@ -0,0 +1,383 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmCommonFunctions.h" +#include "IAmCommandBackdoor.h" +#include "IAmRoutingBackdoor.h" +#include "IAmControlBackdoor.h" +#include <cassert> +#include <sstream> + +using namespace am; + +IAmCommandBackdoor::IAmCommandBackdoor() +{ +} +IAmCommandBackdoor::~IAmCommandBackdoor() +{ +} + +bool IAmCommandBackdoor::unloadPlugins(CAmCommandSender *CommandSender) +{ + assert(CommandSender != NULL); + CommandSender->unloadLibraries(); + CommandSender->mListInterfaces.clear(); + if (CommandSender->mListInterfaces.empty()) + return true; + return false; +} + +bool IAmCommandBackdoor::injectInterface(CAmCommandSender *CommandSender, IAmCommandSend *CommandSendInterface) +{ + assert(CommandSender != NULL); + assert(CommandSendInterface != NULL); + CommandSender->mListInterfaces.push_back(CommandSendInterface); + return true; +} + +IAmRoutingBackdoor::IAmRoutingBackdoor() +{ +} +IAmRoutingBackdoor::~IAmRoutingBackdoor() +{ +} + +bool IAmRoutingBackdoor::unloadPlugins(CAmRoutingSender *RoutingSender) +{ + assert(RoutingSender != NULL); + RoutingSender->unloadLibraries(); + RoutingSender->mListInterfaces.clear(); + if (RoutingSender->mListInterfaces.empty()) + return true; + return false; +} + +bool IAmRoutingBackdoor::injectInterface(CAmRoutingSender *RoutingSender, IAmRoutingSend *newInterface, const std::string& busname) +{ + assert(RoutingSender != NULL); + assert(newInterface != NULL); + + CAmRoutingSender::InterfaceNamePairs newInterfacePair; + newInterfacePair.routingInterface = newInterface; + newInterfacePair.busName = busname; + RoutingSender->mListInterfaces.push_back(newInterfacePair); + return true; +} + +IAmControlBackdoor::IAmControlBackdoor() +{ +} + +IAmControlBackdoor::~IAmControlBackdoor() +{ +} + +bool IAmControlBackdoor::replaceController(CAmControlSender *controlSender, IAmControlSend *newController) +{ + controlSender->mController = newController; + return controlSender->mController == newController; +} + +//int GetRandomNumber(int nLow, int nHigh) { +// return (rand() % (nHigh - nLow + 1)) + nLow; +//} + +bool equalSoundProperty(const am_SoundProperty_s a, const am_SoundProperty_s b) +{ + return (a.type == b.type && a.value == b.value); +} + +bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b) +{ + return (a.type == b.type && a.value == b.value); +} + +bool equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_s b) +{ + return (a.parameter == b.parameter && a.status == b.status && a.type == b.type); +} + +bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b) +{ + return (a.connectionFormat == b.connectionFormat && a.domainID == b.domainID && a.sinkID == b.sinkID && a.sourceID == b.sourceID); +} + +bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b) +{ + return (a.classProperty == b.classProperty && a.value == b.value); +} + +std::string int2string(int i) +{ + std::stringstream out; + out << i; + return out.str(); +} + +bool CAmCommonFunctions::compareSource(std::vector<am_Source_s>::iterator listIterator, const am_Source_s& sourceData) +{ + return (listIterator->available.availability == sourceData.available.availability) && \ + (listIterator->available.availabilityReason == sourceData.available.availabilityReason) && + (listIterator->sourceClassID == sourceData.sourceClassID) && + (listIterator->domainID == sourceData.domainID) && + (listIterator->interruptState == sourceData.interruptState) && + (listIterator->visible == sourceData.visible) && + (listIterator->name.compare(sourceData.name) == 0) && + (listIterator->volume == sourceData.volume) && + std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sourceData.listConnectionFormats.begin()) && + std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty) && + std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sourceData.listSoundProperties.begin(), equalSoundProperty); +} + +bool CAmCommonFunctions::compareSink(std::vector<am_Sink_s>::iterator listIterator, const am_Sink_s& sinkData) +{ + return (listIterator->available.availability == sinkData.available.availability) && (listIterator->available.availabilityReason == sinkData.available.availabilityReason) && (listIterator->sinkClassID == sinkData.sinkClassID) && (listIterator->domainID == sinkData.domainID) && (listIterator->mainVolume == sinkData.mainVolume) && (listIterator->muteState == sinkData.muteState) && (listIterator->visible == sinkData.visible) && (listIterator->name.compare(sinkData.name) == 0) && (listIterator->volume == sinkData.volume) && std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sinkData.listConnectionFormats.begin()) + && std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sinkData.listSoundProperties.begin(), equalSoundProperty); +} + +bool CAmCommonFunctions::compareGateway(std::vector<am_Gateway_s>::iterator listIterator, const am_Gateway_s& gatewayData) +{ + return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->controlDomainID == gatewayData.controlDomainID) && (listIterator->domainSinkID == gatewayData.domainSinkID) && (listIterator->domainSourceID == gatewayData.domainSourceID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin()); +} + +bool CAmCommonFunctions::compareConverter(std::vector<am_Converter_s>::iterator listIterator, const am_Converter_s& gatewayData) +{ + return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->domainID == gatewayData.domainID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin()); +} + +bool CAmCommonFunctions::compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData) +{ + return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.controlDomainID == gatewayData.controlDomainID) && (gateway1.domainSinkID == gatewayData.domainSinkID) && (gateway1.domainSourceID == gatewayData.domainSourceID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin()); +} + +bool CAmCommonFunctions::compareConverter1(const am_Converter_s gateway1, const am_Converter_s gatewayData) +{ + return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.domainID == gatewayData.domainID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin()); +} + +bool CAmCommonFunctions::compareSinkMainSink(std::vector<am_SinkType_s>::iterator listIterator, const std::vector<am_Sink_s>& sinkList) +{ + std::vector<am_Sink_s>::const_iterator sinkListIterator = sinkList.begin(); + for (; sinkListIterator < sinkList.end(); ++sinkListIterator) + { + if (listIterator->sinkID == sinkListIterator->sinkID) + { + return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->muteState == sinkListIterator->muteState) && (listIterator->volume == sinkListIterator->mainVolume) && (listIterator->sinkClassID == sinkListIterator->sinkClassID); + } + } + return false; +} + +bool CAmCommonFunctions::compareSinkMainSource(std::vector<am_SourceType_s>::iterator listIterator, const std::vector<am_Source_s>& sourceList) +{ + std::vector<am_Source_s>::const_iterator sinkListIterator = sourceList.begin(); + for (; sinkListIterator < sourceList.end(); ++sinkListIterator) + { + if (listIterator->sourceID == sinkListIterator->sourceID) + { + return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->sourceClassID == sinkListIterator->sourceClassID); + } + } + return false; +} + +bool CAmCommonFunctions::compareRoute(am_Route_s a, am_Route_s b) +{ + bool retVal = true; + std::vector<am_RoutingElement_s>::iterator itA = a.route.begin(), itB = b.route.begin(); + retVal &= a.sourceID == b.sourceID; + retVal &= a.sinkID == b.sinkID; + for (; itA != a.route.end(); ++itA) + { + retVal &= itA->sinkID == itB->sinkID; + retVal &= itA->sourceID == itB->sourceID; + retVal &= itA->connectionFormat == itB->connectionFormat; + retVal &= itA->domainID == itB->domainID; + itB++; + } + return retVal; +} + +std::vector<am_CustomAvailabilityReason_t> CAmCommonFunctions::getStandardConnectionFormatList() +{ + std::vector<am_CustomAvailabilityReason_t> list; + list.push_back(CF_GENIVI_ANALOG); + list.push_back(CF_GENIVI_STEREO); + return list; +} + +std::vector<am_SoundProperty_s> CAmCommonFunctions::getStandardSoundPropertyList() +{ + std::vector<am_SoundProperty_s> soundPropertyList; + am_SoundProperty_s soundProperty; + soundProperty.type = SP_GENIVI_BASS; + soundProperty.value = 23; + soundPropertyList.push_back(soundProperty); + soundProperty.type = SP_GENIVI_MID; + soundProperty.value = 2; + soundPropertyList.push_back(soundProperty); + return soundPropertyList; +} + +std::vector<am_MainSoundProperty_s> CAmCommonFunctions::getStandardMainSoundPropertyList() +{ + std::vector<am_MainSoundProperty_s> mainSoundPropertyList; + am_MainSoundProperty_s mainSoundProperty; + mainSoundProperty.type = MSP_GENIVI_BASS; + mainSoundProperty.value = 23; + mainSoundPropertyList.push_back(mainSoundProperty); + mainSoundProperty.type = MSP_UNKNOWN; + mainSoundProperty.value = 3; + mainSoundPropertyList.push_back(mainSoundProperty); + return mainSoundPropertyList; +} + +void CAmCommonFunctions::createSink(am_Sink_s& sink) const +{ + sink.name = "AnySink"; + sink.domainID = 4; + sink.available.availability = A_AVAILABLE; + sink.available.availabilityReason = AR_GENIVI_NEWMEDIA; + sink.sinkClassID = 1; + sink.listConnectionFormats = getStandardConnectionFormatList(); + sink.listSoundProperties = getStandardSoundPropertyList(); + sink.listMainSoundProperties = getStandardMainSoundPropertyList(); + sink.listNotificationConfigurations = getStandardNotificationConfigurationList(); + sink.listMainNotificationConfigurations = getStandardNotificationConfigurationList(); + sink.mainVolume = 12; + sink.muteState = MS_UNMUTED; + sink.visible = true; + sink.volume = 23; + sink.sinkID = 0; +} + +void CAmCommonFunctions::createSource(am_Source_s& source) const +{ + source.name = "AnySource"; + source.domainID = 4; + source.available.availability = A_AVAILABLE; + source.available.availabilityReason = AR_GENIVI_NEWMEDIA; + source.sourceClassID = 1; + source.listConnectionFormats = getStandardConnectionFormatList(); + source.listSoundProperties = getStandardSoundPropertyList(); + source.listMainSoundProperties = getStandardMainSoundPropertyList(); + source.listMainNotificationConfigurations=getStandardNotificationConfigurationList(); + source.listNotificationConfigurations=getStandardNotificationConfigurationList(); + source.interruptState = IS_OFF; + source.visible = true; + source.volume = 23; + source.sourceID = 0; + source.sourceState = SS_ON; +} + +void CAmCommonFunctions::createDomain(am_Domain_s & domain) const +{ + + domain.domainID = 0; + domain.name = "AnyDomain"; + domain.nodename = "AnyNode"; + domain.busname = "AnyBusname"; + domain.complete = true; + domain.early = true; + domain.state = DS_CONTROLLED; +} + +void CAmCommonFunctions::createGateway(am_Gateway_s & gateway) +{ + gateway.name = "AnyGateway"; + gateway.sinkID = 1; + gateway.sourceID = 2; + gateway.controlDomainID = 1; + gateway.domainSinkID = 3; + gateway.domainSourceID = 4; + gateway.convertionMatrix = getStandardConvertionMatrix(); + gateway.listSourceFormats = getStandardConnectionFormatList(); + gateway.listSinkFormats = getStandardConnectionFormatList(); + gateway.gatewayID = 0; + +} + +void CAmCommonFunctions::createConverter(am_Converter_s & converter) const +{ + converter.name = "AnyConverter"; + converter.sinkID = 1; + converter.sourceID = 2; + converter.domainID = 1; + converter.convertionMatrix = getStandardConvertionMatrix(); + converter.listSourceFormats = getStandardConnectionFormatList(); + converter.listSinkFormats = getStandardConnectionFormatList(); + converter.converterID = 0; + +} + +void CAmCommonFunctions::createConnection(am_Connection_s & connection) const +{ + connection.connectionID = 0; + connection.sinkID = 1; + connection.sourceID = 2; + connection.delay = -1; + connection.connectionFormat = CF_GENIVI_ANALOG; +} + +std::vector<bool> CAmCommonFunctions::getStandardConvertionMatrix() +{ + std::vector<bool> convMatrix; + convMatrix.push_back(true); + convMatrix.push_back(false); + convMatrix.push_back(true); + convMatrix.push_back(false); + convMatrix.push_back(true); + convMatrix.push_back(true); + return convMatrix; +} + +std::vector<am_NotificationConfiguration_s> am::CAmCommonFunctions::getStandardNotificationConfigurationList() +{ + std::vector<am_NotificationConfiguration_s> listNotificationConfigurations; + am_NotificationConfiguration_s tempNotificationConfiguration; + tempNotificationConfiguration.type=NT_TEST_1; + tempNotificationConfiguration.parameter=12; + tempNotificationConfiguration.status=NS_PERIODIC; + listNotificationConfigurations.push_back(tempNotificationConfiguration); + + tempNotificationConfiguration.type=NT_TEST_2; + tempNotificationConfiguration.parameter=16; + tempNotificationConfiguration.status=NS_CHANGE; + listNotificationConfigurations.push_back(tempNotificationConfiguration); + + return (listNotificationConfigurations); +} + +void CAmCommonFunctions::connectionList2RoutingList(std::vector<am_RoutingElement_s> & routingList, const std::vector<am_Connection_s>& connectionList) +{ + am_RoutingElement_s routingElement; + std::vector<am_Connection_s>::const_iterator cIterator = connectionList.begin(); + for (; cIterator < connectionList.end(); ++cIterator) + { + routingElement.sinkID = cIterator->sinkID; + routingElement.sourceID = cIterator->sourceID; + routingElement.connectionFormat = cIterator->connectionFormat; + routingElement.domainID = 4; //todo: make this test read out the real value + routingList.push_back(routingElement); + } +} + diff --git a/AudioManagerCore/test/CAmCommonFunctions.h b/AudioManagerCore/test/CAmCommonFunctions.h new file mode 100644 index 0000000..9dbdc8f --- /dev/null +++ b/AudioManagerCore/test/CAmCommonFunctions.h @@ -0,0 +1,96 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef COMMONHEADERS_H_ +#define COMMONHEADERS_H_ + +#include "audiomanagertypes.h" + +namespace am +{ + +static const am_CustomNotificationType_t NT_TEST_1 = 1; +static const am_CustomNotificationType_t NT_TEST_2 = 2; + + +class CAmCommonFunctions +{ +public: + + static std::vector<am_CustomAvailabilityReason_t> getStandardConnectionFormatList(); + static std::vector<am_SoundProperty_s> getStandardSoundPropertyList(); + static std::vector<am_MainSoundProperty_s> getStandardMainSoundPropertyList(); + static std::vector<bool> getStandardConvertionMatrix(); + static std::vector<am_NotificationConfiguration_s> getStandardNotificationConfigurationList(); + bool compareSource(std::vector<am_Source_s>::iterator listIterator, const am_Source_s& sourceData); + bool compareSink(std::vector<am_Sink_s>::iterator listIterator, const am_Sink_s& sinkData); + bool compareGateway(std::vector<am_Gateway_s>::iterator listIterator, const am_Gateway_s& gatewayData); + bool compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData); + bool compareConverter(std::vector<am_Converter_s>::iterator listIterator, const am_Converter_s& gatewayData); + bool compareConverter1(const am_Converter_s gateway1, const am_Converter_s gatewayData); + bool compareSinkMainSink(std::vector<am_SinkType_s>::iterator listIterator, const std::vector<am_Sink_s>& sinkList); + bool compareSinkMainSource(std::vector<am_SourceType_s>::iterator listIterator, const std::vector<am_Source_s>& sourceList); + bool compareRoute(am_Route_s a, am_Route_s b); + void createSink(am_Sink_s& sink) const; + void createSource(am_Source_s& source) const; + void createDomain(am_Domain_s& domain) const; + void createGateway(am_Gateway_s& gateway); + void createConnection(am_Connection_s& connection) const; + void createConverter(am_Converter_s & converter) const; + void connectionList2RoutingList(std::vector<am_RoutingElement_s>& routingList, const std::vector<am_Connection_s>& connectionList); + + struct sortBySinkID + { + bool operator()(const am_RoutingElement_s & a, const am_RoutingElement_s & b) const + { + return (a.sinkID < b.sinkID); + } + }; + + struct sortByConnectionFormat + { + bool operator()(const am_CustomAvailabilityReason_t & a, const am_CustomAvailabilityReason_t & b) const + { + return (a < b); + } + }; + + struct sortByMainSoundProperty + { + bool operator()(const am_MainSoundProperty_s & a, const am_MainSoundProperty_s & b) const + { + return (a.type > b.type); + } + }; + + struct sortBySoundProperty + { + bool operator()(const am_SoundProperty_s & a, const am_SoundProperty_s & b) const + { + return (a.type < b.type); + } + }; +}; + +} + +#endif /* COMMONHEADERS_H_ */ diff --git a/AudioManagerCore/test/CMakeLists.txt b/AudioManagerCore/test/CMakeLists.txt new file mode 100644 index 0000000..9dd9007 --- /dev/null +++ b/AudioManagerCore/test/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright (C) 2012, BMW AG +# +# This file is part of GENIVI Project AudioManager. +# +# Contributions are licensed to the GENIVI Alliance under one or more +# Contribution License Agreements. +# +# copyright +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 +# +# For further information see http://www.genivi.org/. +# + +cmake_minimum_required(VERSION 3.0) + + +set(EXECUTABLE_OUTPUT_PATH ${TEST_EXECUTABLE_OUTPUT_PATH}) + +#make aunt google stop complaining +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager -Wno-unused-local-typedefs -lz -ldl") + +add_subdirectory (AmControlInterfaceTest) +add_subdirectory (AmMapHandlerTest) +add_subdirectory (AmRouterTest) +add_subdirectory (AmRouterMapTest) +add_subdirectory (AmRoutingInterfaceTest) + +IF(WITH_TELNET) + add_subdirectory (AmTelnetServerTest) +ENDIF(WITH_TELNET) + diff --git a/AudioManagerCore/test/IAmCommandBackdoor.h b/AudioManagerCore/test/IAmCommandBackdoor.h new file mode 100644 index 0000000..b7d2b20 --- /dev/null +++ b/AudioManagerCore/test/IAmCommandBackdoor.h @@ -0,0 +1,47 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef COMMANDINTERFACEBACKDOOR_H_ +#define COMMANDINTERFACEBACKDOOR_H_ + +#include <IAmCommand.h> +#include "CAmCommandSender.h" + +namespace am +{ + +class CAmCommandSender; + +class IAmCommandBackdoor +{ +public: + IAmCommandBackdoor(); + virtual ~IAmCommandBackdoor(); + bool unloadPlugins(CAmCommandSender *CommandSender); + bool injectInterface(CAmCommandSender* CommandSender, IAmCommandSend* CommandSendInterface); +}; + +} + +//definitions are in CAmCommonFunctions.cpp! + +#endif /* COMMANDINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerCore/test/IAmControlBackdoor.h b/AudioManagerCore/test/IAmControlBackdoor.h new file mode 100644 index 0000000..b5ba3ef --- /dev/null +++ b/AudioManagerCore/test/IAmControlBackdoor.h @@ -0,0 +1,44 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef CONTROLINTERFACEBACKDOOR_H_ +#define CONTROLINTERFACEBACKDOOR_H_ + +#include "IAmControl.h" +#include "CAmControlSender.h" + +namespace am +{ + +class CAmControlSender; + +class IAmControlBackdoor +{ +public: + IAmControlBackdoor(); + virtual ~IAmControlBackdoor(); + bool replaceController(CAmControlSender *controlSender, IAmControlSend *newController); +}; + +} + +#endif /* CONTROLINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerCore/test/IAmRoutingBackdoor.h b/AudioManagerCore/test/IAmRoutingBackdoor.h new file mode 100644 index 0000000..cbdb070 --- /dev/null +++ b/AudioManagerCore/test/IAmRoutingBackdoor.h @@ -0,0 +1,46 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef ROUTINGINTERFACEBACKDOOR_H_ +#define ROUTINGINTERFACEBACKDOOR_H_ + +#include "CAmRoutingSender.h" + +namespace am +{ + +class CAmRoutingSender; + +class IAmRoutingBackdoor +{ +public: + IAmRoutingBackdoor(); + virtual ~IAmRoutingBackdoor(); + bool unloadPlugins(CAmRoutingSender *RoutingSender); + bool injectInterface(CAmRoutingSender *RoutingSender, IAmRoutingSend *newInterface, const std::string& busname); +}; + +} + +//definitions are in CAmCommonFunctions.cpp! + +#endif /* ROUTINGINTERFACEBACKDOOR_H_ */ diff --git a/AudioManagerCore/test/MockIAmCommandSend.h b/AudioManagerCore/test/MockIAmCommandSend.h new file mode 100644 index 0000000..36bc1cb --- /dev/null +++ b/AudioManagerCore/test/MockIAmCommandSend.h @@ -0,0 +1,94 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MOCKCOMMANDINTERFACE_H_ +#define MOCKCOMMANDINTERFACE_H_ + +#include "IAmCommand.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +namespace am { + +class MockIAmCommandSend : public IAmCommandSend { + public: + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + MOCK_METHOD1(startupInterface, + am_Error_e(IAmCommandReceive* commandreceiveinterface)); + MOCK_METHOD1(setCommandReady, + void(const uint16_t handle)); + MOCK_METHOD1(setCommandRundown, + void(const uint16_t handle)); + MOCK_METHOD1(cbNewMainConnection, + void(const am_MainConnectionType_s& mainConnection)); + MOCK_METHOD1(cbRemovedMainConnection, + void(const am_mainConnectionID_t mainConnection)); + MOCK_METHOD1(cbNewSink, + void(const am_SinkType_s& sink)); + MOCK_METHOD1(cbRemovedSink, + void(const am_sinkID_t sinkID)); + MOCK_METHOD1(cbNewSource, + void(const am_SourceType_s& source)); + MOCK_METHOD1(cbRemovedSource, + void(const am_sourceID_t source)); + MOCK_METHOD0(cbNumberOfSinkClassesChanged, + void()); + MOCK_METHOD0(cbNumberOfSourceClassesChanged, + void()); + MOCK_METHOD2(cbMainConnectionStateChanged, + void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)); + MOCK_METHOD2(cbMainSinkSoundPropertyChanged, + void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD2(cbMainSourceSoundPropertyChanged, + void(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD2(cbSinkAvailabilityChanged, + void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(cbSourceAvailabilityChanged, + void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(cbVolumeChanged, + void(const am_sinkID_t sinkID, const am_mainVolume_t volume)); + MOCK_METHOD2(cbSinkMuteStateChanged, + void(const am_sinkID_t sinkID, const am_MuteState_e muteState)); + MOCK_METHOD1(cbSystemPropertyChanged, + void(const am_SystemProperty_s& systemProperty)); + MOCK_METHOD2(cbTimingInformationChanged, + void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); + MOCK_METHOD3(cbSinkUpdated, + void(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)); + MOCK_METHOD3(cbSourceUpdated, + void(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)); + MOCK_METHOD2(cbSinkNotification, + void(const am_sinkID_t sinkID, const am_NotificationPayload_s& notification)); + MOCK_METHOD2(cbSourceNotification, + void(const am_sourceID_t sourceID, const am_NotificationPayload_s& notification)); + MOCK_METHOD2(cbMainSinkNotificationConfigurationChanged, + void(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& mainNotificationConfiguration)); + MOCK_METHOD2(cbMainSourceNotificationConfigurationChanged, + void(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& mainNotificationConfiguration)); + + + +}; + +} // namespace am +#endif /* MOCKCOMMANDINTERFACE_H_ */ diff --git a/AudioManagerCore/test/MockIAmControlSend.h b/AudioManagerCore/test/MockIAmControlSend.h new file mode 100644 index 0000000..e628068 --- /dev/null +++ b/AudioManagerCore/test/MockIAmControlSend.h @@ -0,0 +1,160 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MOCKCONTROLINTERFACE_H_ +#define MOCKCONTROLINTERFACE_H_ + +#include "IAmControl.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +namespace am { + +class MockIAmControlSend : public IAmControlSend { + public: + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + MOCK_METHOD1(startupController, + am_Error_e(IAmControlReceive* controlreceiveinterface)); + MOCK_METHOD0(setControllerReady, + void()); + MOCK_METHOD1(setControllerRundown, + void(const int16_t signal)); + MOCK_METHOD3(hookUserConnectionRequest, + am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t& mainConnectionID)); + MOCK_METHOD1(hookUserDisconnectionRequest, + am_Error_e(const am_mainConnectionID_t connectionID)); + MOCK_METHOD2(hookUserSetMainSinkSoundProperty, + am_Error_e(const am_sinkID_t sinkID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD2(hookUserSetMainSourceSoundProperty, + am_Error_e(const am_sourceID_t sourceID, const am_MainSoundProperty_s& soundProperty)); + MOCK_METHOD1(hookUserSetSystemProperty, + am_Error_e(const am_SystemProperty_s& property)); + MOCK_METHOD2(hookUserVolumeChange, + am_Error_e(const am_sinkID_t SinkID, const am_mainVolume_t newVolume)); + MOCK_METHOD2(hookUserVolumeStep, + am_Error_e(const am_sinkID_t SinkID, const int16_t increment)); + MOCK_METHOD2(hookUserSetSinkMuteState, + am_Error_e(const am_sinkID_t sinkID, const am_MuteState_e muteState)); + MOCK_METHOD2(hookSystemRegisterDomain, + am_Error_e(const am_Domain_s& domainData, am_domainID_t& domainID)); + MOCK_METHOD1(hookSystemDeregisterDomain, + am_Error_e(const am_domainID_t domainID)); + MOCK_METHOD1(hookSystemDomainRegistrationComplete, + void(const am_domainID_t domainID)); + MOCK_METHOD2(hookSystemRegisterSink, + am_Error_e(const am_Sink_s& sinkData, am_sinkID_t& sinkID)); + MOCK_METHOD1(hookSystemDeregisterSink, + am_Error_e(const am_sinkID_t sinkID)); + MOCK_METHOD2(hookSystemRegisterSource, + am_Error_e(const am_Source_s& sourceData, am_sourceID_t& sourceID)); + MOCK_METHOD1(hookSystemDeregisterSource, + am_Error_e(const am_sourceID_t sourceID)); + MOCK_METHOD2(hookSystemRegisterConverter, + am_Error_e(const am_Converter_s& converterData, am_converterID_t& converterID)); + MOCK_METHOD2(hookSystemRegisterGateway, + am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID)); + MOCK_METHOD1(hookSystemDeregisterConverter, + am_Error_e(const am_converterID_t converterID)); + MOCK_METHOD1(hookSystemDeregisterGateway, + am_Error_e(const am_gatewayID_t gatewayID)); + MOCK_METHOD2(hookSystemRegisterCrossfader, + am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID)); + MOCK_METHOD1(hookSystemDeregisterCrossfader, + am_Error_e(const am_crossfaderID_t crossfaderID)); + MOCK_METHOD3(hookSystemSinkVolumeTick, + void(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)); + MOCK_METHOD3(hookSystemSourceVolumeTick, + void(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)); + MOCK_METHOD2(hookSystemInterruptStateChange, + void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); + MOCK_METHOD2(hookSystemSinkAvailablityStateChange, + void(const am_sinkID_t sinkID, const am_Availability_s& availability)); + MOCK_METHOD2(hookSystemSourceAvailablityStateChange, + void(const am_sourceID_t sourceID, const am_Availability_s& availability)); + MOCK_METHOD2(hookSystemDomainStateChange, + void(const am_domainID_t domainID, const am_DomainState_e state)); + MOCK_METHOD1(hookSystemReceiveEarlyData, + void(const std::vector<am_EarlyData_s>& data)); + MOCK_METHOD1(hookSystemSpeedChange, + void(const am_speed_t speed)); + MOCK_METHOD2(hookSystemTimingInformationChanged, + void(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)); + MOCK_METHOD2(cbAckConnect, + void(const am_Handle_s handle, const am_Error_e errorID)); + MOCK_METHOD2(cbAckDisconnect, + void(const am_Handle_s handle, const am_Error_e errorID)); + MOCK_METHOD3(cbAckCrossFade, + void(const am_Handle_s handle, const am_HotSink_e hostsink, const am_Error_e error)); + MOCK_METHOD3(cbAckSetSinkVolumeChange, + void(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)); + MOCK_METHOD3(cbAckSetSourceVolumeChange, + void(const am_Handle_s handle, const am_volume_t voulme, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceState, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceSoundProperties, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceSoundProperty, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSinkSoundProperties, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSinkSoundProperty, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD5(getConnectionFormatChoice, + am_Error_e(const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_Route_s listRoute, const std::vector<am_CustomConnectionFormat_t> listPossibleConnectionFormats, std::vector<am_CustomConnectionFormat_t>& listPrioConnectionFormats)); + MOCK_METHOD1(confirmCommandReady, + void(const am_Error_e error)); + MOCK_METHOD1(confirmRoutingReady, + void(const am_Error_e error)); + MOCK_METHOD1(confirmCommandRundown, + void(const am_Error_e error)); + MOCK_METHOD1(confirmRoutingRundown, + void(const am_Error_e error)); + MOCK_METHOD5(hookSystemUpdateSink, + am_Error_e(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)); + MOCK_METHOD5(hookSystemUpdateSource, + am_Error_e(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)); + MOCK_METHOD4(hookSystemUpdateConverter, + am_Error_e(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix)); + MOCK_METHOD4(hookSystemUpdateGateway, + am_Error_e(const am_gatewayID_t gatewayID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix)); + MOCK_METHOD3(cbAckSetVolumes, + void(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSinkNotificationConfiguration, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(cbAckSetSourceNotificationConfiguration, + void(const am_Handle_s handle, const am_Error_e error)); + MOCK_METHOD2(hookSinkNotificationDataChanged, + void(const am_sinkID_t sinkID, const am_NotificationPayload_s& payload)); + MOCK_METHOD2(hookSourceNotificationDataChanged, + void(const am_sourceID_t sourceID, const am_NotificationPayload_s& payload)); + MOCK_METHOD2(hookUserSetMainSinkNotificationConfiguration, + am_Error_e(const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD2(hookUserSetMainSourceNotificationConfiguration, + am_Error_e(const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD2(hookSystemSingleTimingInformationChanged, + void(const am_connectionID_t connectionID, const am_timeSync_t time)); +}; + + +} // namespace am +#endif /* MOCKCONTROLINTERFACE_H_ */ diff --git a/AudioManagerCore/test/MockIAmRoutingSend.h b/AudioManagerCore/test/MockIAmRoutingSend.h new file mode 100644 index 0000000..748e64e --- /dev/null +++ b/AudioManagerCore/test/MockIAmRoutingSend.h @@ -0,0 +1,83 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * For further information see http://www.genivi.org/. + * + */ + +#ifndef MOCKROUTINGINTERFACE_H_ +#define MOCKROUTINGINTERFACE_H_ + +#include "IAmRouting.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +namespace am { + +class MockIAmRoutingSend : public IAmRoutingSend { + public: + MOCK_CONST_METHOD1(getInterfaceVersion, + void(std::string& version)); + MOCK_METHOD1(startupInterface, + am_Error_e(IAmRoutingReceive* routingreceiveinterface)); + MOCK_METHOD1(setRoutingReady, + void(const uint16_t handle)); + MOCK_METHOD1(setRoutingRundown, + void(const uint16_t handle)); + MOCK_METHOD1(asyncAbort, + am_Error_e(const am_Handle_s handle)); + MOCK_METHOD5(asyncConnect, + am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_CustomAvailabilityReason_t connectionFormat)); + MOCK_METHOD2(asyncDisconnect, + am_Error_e(const am_Handle_s handle, const am_connectionID_t connectionID)); + MOCK_METHOD5(asyncSetSinkVolume, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_CustomRampType_t ramp, const am_time_t time)); + MOCK_METHOD5(asyncSetSourceVolume, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_CustomRampType_t ramp, const am_time_t time)); + MOCK_METHOD3(asyncSetSourceState, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)); + MOCK_METHOD3(asyncSetSinkSoundProperties, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)); + MOCK_METHOD3(asyncSetSinkSoundProperty, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)); + MOCK_METHOD3(asyncSetSourceSoundProperties, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)); + MOCK_METHOD3(asyncSetSourceSoundProperty, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)); + MOCK_METHOD5(asyncCrossFade, + am_Error_e(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_CustomRampType_t rampType, const am_time_t time)); + MOCK_METHOD2(setDomainState, + am_Error_e(const am_domainID_t domainID, const am_DomainState_e domainState)); + MOCK_CONST_METHOD1(returnBusName, + am_Error_e(std::string& BusName)); + MOCK_METHOD2(asyncSetVolumes, + am_Error_e(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes)); + MOCK_METHOD3(asyncSetSinkNotificationConfiguration, + am_Error_e(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD3(asyncSetSourceNotificationConfiguration, + am_Error_e(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)); + MOCK_METHOD2(resyncConnectionState, + am_Error_e(const am_domainID_t domainID, std::vector<am_Connection_s>& listOfExistingConnections)); + + +}; + +} // namespace am + + +#endif /* MOCKROUTINGINTERFACE_H_ */ |