From 9f4c15a8e89d798077ca3edf7f786dbc740aa176 Mon Sep 17 00:00:00 2001 From: christian mueller Date: Wed, 1 Feb 2012 10:50:15 +0100 Subject: * implemented peeksinkclassIDs and peeksourceclassIDs * changed interface of both from const to non-const * corrected include headers to c++ style, eg. * corrected sendChangedData return type to void * implemented tests for sinkclass and sourceclass peeking * fixed bug in sockethandler (FD could not be removed) thanks to Frank --- AudioManagerDaemon/test/CommonFunctions.cpp | 6 +- AudioManagerDaemon/test/database/databaseTest.cpp | 51 ++++- AudioManagerDaemon/test/routing/routingTest.cpp | 234 +++++++++++++++++++++ .../test/sockethandler/sockethandlerTest.cpp | 3 + 4 files changed, 290 insertions(+), 4 deletions(-) (limited to 'AudioManagerDaemon/test') diff --git a/AudioManagerDaemon/test/CommonFunctions.cpp b/AudioManagerDaemon/test/CommonFunctions.cpp index 2a5c8cf..30c8725 100644 --- a/AudioManagerDaemon/test/CommonFunctions.cpp +++ b/AudioManagerDaemon/test/CommonFunctions.cpp @@ -27,7 +27,7 @@ #include "CommandInterfaceBackdoor.h" #include "RoutingInterfaceBackdoor.h" #include "ControlInterfaceBackdoor.h" -#include +#include #include using namespace am; @@ -54,7 +54,7 @@ bool CommandInterfaceBackdoor::injectInterface(CommandSender *CommandSender, Com assert(CommandSender != NULL); assert(CommandSendInterface != NULL); CommandSender->mListInterfaces.push_back(CommandSendInterface); - return true; //todo: check if it worked + return true; } RoutingInterfaceBackdoor::RoutingInterfaceBackdoor() @@ -83,7 +83,7 @@ bool RoutingInterfaceBackdoor::injectInterface(RoutingSender *RoutingSender, Rou newInterfacePair.routingInterface = newInterface; newInterfacePair.busName = busname; RoutingSender->mListInterfaces.push_back(newInterfacePair); - return true; //todo: check if it worked + return true; } ControlInterfaceBackdoor::ControlInterfaceBackdoor() diff --git a/AudioManagerDaemon/test/database/databaseTest.cpp b/AudioManagerDaemon/test/database/databaseTest.cpp index 6122505..a44804b 100644 --- a/AudioManagerDaemon/test/database/databaseTest.cpp +++ b/AudioManagerDaemon/test/database/databaseTest.cpp @@ -147,13 +147,60 @@ void routingTest::createMainConnectionSetup() void routingTest::SetUp() { - logInfo("Database Test started "); } void routingTest::TearDown() { } +TEST_F(routingTest, peekSourceID) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1); + std::string sourceName("myClassID"); + am_sourceClass_t sourceClassID, peekID; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_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(routingTest, peekSinkID) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1); + std::string sinkName("myClassID"); + am_sinkClass_t sinkClassID, peekID; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_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(routingTest,crossfaders) { //todo:implement crossfader tests @@ -1592,6 +1639,8 @@ TEST_F(routingTest,enterSinksCorrect) int main(int argc, char **argv) { + DLTWrapper::instance()->registerApp("databse", "databasetest"); + logInfo("Database Test started "); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/AudioManagerDaemon/test/routing/routingTest.cpp b/AudioManagerDaemon/test/routing/routingTest.cpp index fdfbcf8..463bbfd 100644 --- a/AudioManagerDaemon/test/routing/routingTest.cpp +++ b/AudioManagerDaemon/test/routing/routingTest.cpp @@ -77,6 +77,238 @@ ACTION(returnConnectionFormat){ arg3=arg2; } +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(routingTest,simpleRoute2DomainsOnlyFree) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2); + EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2); + 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_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_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_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_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 listRoutes; + std::vector 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(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(routingTest,simpleRoute2DomainsOnlyFreeNotFree) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2); + EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2); + 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_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_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_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_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 listRoutes; + std::vector 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_ANALOG; + connection.connectionID=0; + connection1.sourceID=gwSourceID; + connection1.sinkID=sinkID; + connection1.connectionFormat=CF_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(0, listRoutes.size()); + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(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(routingTest,simpleRoute3DomainsListConnectionFormats_2) { @@ -1477,6 +1709,8 @@ TEST_F(routingTest,simpleRoute4Domains) int main(int argc, char **argv) { + DLTWrapper::instance()->registerApp("routing", "routingtest"); + logInfo("Routing Test started "); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp index 9165fa2..1f1abea 100644 --- a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp +++ b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp @@ -15,6 +15,9 @@ #include #include +//todo: expand test, implement more usecases +//todo: test removeFD + #define SOCK_PATH "/tmp/mysock" using namespace testing; -- cgit v1.2.1