summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Donchev <aleksander.donchev@partner.bmw.de>2013-09-03 16:09:49 (GMT)
committerAleksandar Donchev <aleksander.donchev@partner.bmw.de>2013-09-03 16:10:17 (GMT)
commit67b6d070bdea90463aab419d516186f498ebc6d6 (patch)
treea86ccc74725d738d8c16cb713dc19a824ed1853d
parenta2edae5cee4254b933f42399edc0e092abd4f5cf (diff)
downloadaudiomanager-67b6d070bdea90463aab419d516186f498ebc6d6.tar.gz
* AmMapHanlderTest - added tests for the callbacks in CAmDatabaseObserver.
* An object ID added to the response whenever E_ALREADY_EXISTS is returned in CAmDatabasehandlerMap Signed-off-by: Christian Linke <christian.linke@bmw.de>
-rw-r--r--.gitignore2
-rw-r--r--AudioManagerDaemon/include/CAmDatabaseHandlerMap.h2
-rw-r--r--AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp150
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp511
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h21
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp92
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt12
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h114
8 files changed, 825 insertions, 79 deletions
diff --git a/.gitignore b/.gitignore
index fbff9e6..e08a5bd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,5 @@ packages/
/patch
ProjectSpecific/
+/AudioManagerDaemon/fidls/AudioManager_dbus.conf
+/AudioManagerDaemon/fidls/AudioManager_dbus.conf.in
diff --git a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h b/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
index 28ec7e6..9e292f0 100644
--- a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
+++ b/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
@@ -353,6 +353,8 @@ public:
bool insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID);
bool insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID);
bool insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass);
+ const am_Sink_Database_s * sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const;
+ const am_Source_Database_s * sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const;
CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer
ListConnectionFormat mListConnectionFormat; //!< list of connection formats
diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
index 3e83cc5..505aa96 100644
--- a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
+++ b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
@@ -95,6 +95,27 @@ struct CAmComparatorFlag
};
/**
+ * \brief Returns an object matching predicate.
+ *
+ * Convenient method for searching in a given map.
+ *
+ * @param map Map reference.
+ * @param comparator Search predicate.
+ * @return NULL or pointer to the found object.
+ */
+template <class TReturn, typename TIdentifier> const TReturn * objectMatchingPredicate(const std::unordered_map<TIdentifier, TReturn> & map,
+ std::function<bool(const TReturn & refObject)> & comparator)
+{
+ typename std::unordered_map<TIdentifier, TReturn>::const_iterator elementIterator = map.begin();
+ for (;elementIterator != map.end(); ++elementIterator)
+ {
+ if( comparator(elementIterator->second) )
+ return &elementIterator->second;
+ }
+ return NULL;
+}
+
+/**
* \brief Returns the first object matching criteria.
*
* A common method for searching in a given map.
@@ -111,17 +132,10 @@ TMapObjectType const * findFirstObjectMatchingCriteria(const std::unordered_map<
TComparator & aComparator,
void *context = NULL)
{
- typename std::unordered_map<TMapKeyType, TMapObjectType>::const_iterator it = aMap.begin();
- TMapObjectType const * result = NULL;
- for (; it != aMap.end(); ++it)
- {
- if (aComparator(it->second, aComparisonArgument, context))
- {
- result = &it->second;
- break;
- }
- }
- return result;
+ std::function<bool(const TMapObjectType & refObject)> comparator = [&](const TMapObjectType & object)->bool{
+ return aComparator(object, aComparisonArgument, context);
+ };
+ return objectMatchingPredicate(aMap, comparator);
}
/* Domain */
@@ -425,12 +439,12 @@ am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData,
assert(!domainData.name.empty());
assert(!domainData.busname.empty());
assert(domainData.state>=DS_UNKNOWN && domainData.state<=DS_MAX);
-
//first check for a reserved domain
CAmComparator<am_Domain_s> comparator;
am_Domain_s const *reservedDomain = findFirstObjectMatchingCriteria(mMappedData.mDomainMap, domainData.name, comparator);
int16_t nextID = 0;
+
if( NULL != reservedDomain )
{
nextID = reservedDomain->domainID;
@@ -438,9 +452,7 @@ am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData,
mMappedData.mDomainMap[nextID] = domainData;
mMappedData.mDomainMap[nextID].domainID = nextID;
mMappedData.mDomainMap[nextID].reserved = 0;
-
logInfo("DatabaseHandler::enterDomainDB entered reserved domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "reserved ID:", domainID);
-
if (mpDatabaseObserver)
mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]);
return (E_OK);
@@ -452,9 +464,7 @@ am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData,
domainID = nextID;
mMappedData.mDomainMap[nextID] = domainData;
mMappedData.mDomainMap[nextID].domainID = nextID;
-
logInfo("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID);
-
if (mpDatabaseObserver)
mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]);
return (E_OK);
@@ -512,21 +522,17 @@ am_Error_e CAmDatabaseHandlerMap::enterMainConnectionDB(const am_MainConnection_
//now check the connectionTable for all connections in the route. IF connectionID exist
delay = calculateDelayForRoute(mainConnectionData.listConnectionID);
-
+ mMappedData.mMainConnectionMap[nextID].delay = delay;
logInfo("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID);
if (mpDatabaseObserver)
{
am_MainConnectionType_s mainConnection;
- mainConnection.mainConnectionID = connectionID;
- mainConnection.connectionState = mainConnectionData.connectionState;
- mainConnection.delay = delay;
- mainConnection.sinkID = mainConnectionData.sinkID;
- mainConnection.sourceID = mainConnectionData.sourceID;
+ mMappedData.mMainConnectionMap[nextID].getMainConnectionType(mainConnection);
mpDatabaseObserver->newMainConnection(mainConnection);
- mpDatabaseObserver->mainConnectionStateChanged(connectionID, mainConnectionData.connectionState);
+ mpDatabaseObserver->mainConnectionStateChanged(connectionID, mMappedData.mMainConnectionMap[nextID].connectionState);
}
- mMappedData.mMainConnectionMap[nextID].delay = delay;
+
//finally, we update the delay value for the maintable
if (delay == 0)
delay = -1;
@@ -586,7 +592,10 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkDB(const am_Sink_s & sinkData, am_sin
{
//check if the ID already exists
if (existSinkNameOrID(sinkData.sinkID, sinkData.name))
+ {
+ sinkID = sinkData.sinkID;
return (E_ALREADY_EXISTS);
+ }
}
result = insertSinkDB(sinkData, temp_SinkID);
if( false == result )
@@ -601,7 +610,7 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkDB(const am_Sink_s & sinkData, am_sin
mMappedData.mSinkMap[temp_SinkIndex].sinkID = temp_SinkID;
sinkID = temp_SinkID;
- am_Sink_s sink = mMappedData.mSinkMap[temp_SinkID];
+ am_Sink_s & sink = mMappedData.mSinkMap[temp_SinkID];
logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sink.name, "domainID:", sink.domainID, "classID:", sink.sinkClassID, "volume:", sink.volume, "assigned ID:", sink.sinkID);
if (mpDatabaseObserver != NULL)
@@ -646,7 +655,10 @@ am_Error_e CAmDatabaseHandlerMap::enterCrossfaderDB(const am_Crossfader_s & cros
{
//check if the ID already exists
if (existcrossFader(crossfaderData.crossfaderID))
+ {
+ crossfaderID = crossfaderData.crossfaderID;
return (E_ALREADY_EXISTS);
+ }
}
result = insertCrossfaderDB(crossfaderData, temp_CrossfaderID);
if( false == result )
@@ -659,14 +671,12 @@ am_Error_e CAmDatabaseHandlerMap::enterCrossfaderDB(const am_Crossfader_s & cros
mFirstStaticCrossfader = false;
}
- mMappedData.mCrossfaderMap[temp_CrossfaderIndex].crossfaderID = temp_CrossfaderID;
+ mMappedData.mCrossfaderMap[temp_CrossfaderIndex].crossfaderID = temp_CrossfaderID;
crossfaderID = temp_CrossfaderID;
logInfo("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID);
- am_Crossfader_s crossfader(crossfaderData);
- crossfader.crossfaderID = crossfaderID;
if (mpDatabaseObserver)
- mpDatabaseObserver->newCrossfader(crossfader);
+ mpDatabaseObserver->newCrossfader(mMappedData.mCrossfaderMap[temp_CrossfaderIndex]);
return (E_OK);
}
@@ -713,7 +723,10 @@ am_Error_e CAmDatabaseHandlerMap::enterGatewayDB(const am_Gateway_s & gatewayDat
{
//check if the ID already exists
if (existGateway(gatewayData.gatewayID))
+ {
+ gatewayID = gatewayData.gatewayID;
return (E_ALREADY_EXISTS);
+ }
}
result = insertGatewayDB(gatewayData, temp_GatewayID);
if( false == result )
@@ -729,10 +742,8 @@ am_Error_e CAmDatabaseHandlerMap::enterGatewayDB(const am_Gateway_s & gatewayDat
gatewayID = temp_GatewayID;
logInfo("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID);
- am_Gateway_s gateway = gatewayData;
- gateway.gatewayID = gatewayID;
if (mpDatabaseObserver)
- mpDatabaseObserver->newGateway(gateway);
+ mpDatabaseObserver->newGateway(mMappedData.mGatewayMap[temp_GatewayIndex]);
return (E_OK);
}
@@ -804,7 +815,10 @@ am_Error_e CAmDatabaseHandlerMap::enterSourceDB(const am_Source_s & sourceData,
{
//check if the ID already exists
if (existSourceNameOrID(sourceData.sourceID, sourceData.name))
+ {
+ sourceID = sourceData.sourceID;
return (E_ALREADY_EXISTS);
+ }
}
result = insertSourceDB(sourceData, temp_SourceID);
if( false == result )
@@ -822,10 +836,8 @@ am_Error_e CAmDatabaseHandlerMap::enterSourceDB(const am_Source_s & sourceData,
logInfo("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID);
- am_Source_s source = sourceData;
- source.sourceID = sourceID;
if (mpDatabaseObserver)
- mpDatabaseObserver->newSource(source);
+ mpDatabaseObserver->newSource(mMappedData.mSourceMap[temp_SourceIndex]);
return (E_OK);
}
@@ -884,7 +896,10 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkClassDB(const am_SinkClass_s & sinkCl
{
//check if the ID already exists
if (existSinkClass(sinkClass.sinkClassID))
+ {
+ sinkClassID = sinkClass.sinkClassID;
return (E_ALREADY_EXISTS);
+ }
}
result = insertSinkClassDB(sinkClass, temp_SinkClassID);
if( false == result )
@@ -937,7 +952,10 @@ am_Error_e CAmDatabaseHandlerMap::enterSourceClassDB(am_sourceClass_t & sourceCl
{
//check if the ID already exists
if (existSourceClass(sourceClass.sourceClassID))
+ {
+ sourceClassID = sourceClass.sourceClassID;
return (E_ALREADY_EXISTS);
+ }
}
result = insertSourceClassDB(temp_SourceClassID, sourceClass);
if( false == result )
@@ -1042,7 +1060,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkAvailabilityDB(const am_Availability
logInfo("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason);
- if (mpDatabaseObserver && sourceVisible(sinkID))
+ if (mpDatabaseObserver && sinkVisible(sinkID))
mpDatabaseObserver->sinkAvailabilityChanged(sinkID, availability);
return (E_OK);
}
@@ -1789,7 +1807,8 @@ am_Error_e CAmDatabaseHandlerMap::changeDelayMainConnection(const am_timeSync_t
if (!existMainConnection(connectionID))
return (E_NON_EXISTENT);
mMappedData.mMainConnectionMap[connectionID].delay = delay;
-
+ if (mpDatabaseObserver)
+ mpDatabaseObserver->timingInformationChanged(connectionID, delay);
return (E_OK);
}
@@ -1825,18 +1844,7 @@ bool CAmDatabaseHandlerMap::existSource(const am_sourceID_t sourceID) const
*/
bool CAmDatabaseHandlerMap::existSourceNameOrID(const am_sourceID_t sourceID, const std::string & name) const
{
- bool returnVal = false;
- CAmMapSource::const_iterator elementIterator = mMappedData.mSourceMap.begin();
- for (;elementIterator != mMappedData.mSourceMap.end(); ++elementIterator)
- {
- if( 0==elementIterator->second.reserved &&
- (sourceID==elementIterator->second.sourceID || name.compare(elementIterator->second.name)==0))
- {
- returnVal = true;
- break;
- }
- }
- return (returnVal);
+ return sourceWithNameOrID(sourceID, name);
}
/**
@@ -1871,6 +1879,36 @@ bool CAmDatabaseHandlerMap::existSink(const am_sinkID_t sinkID) const
}
/**
+ * returns source with given ID or the name if exists
+ * @param sourceID the ID
+ * @param name the name
+ * @return source structure if exists.
+ */
+const CAmDatabaseHandlerMap::am_Source_Database_s * CAmDatabaseHandlerMap::sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const
+{
+ std::function<bool(const CAmDatabaseHandlerMap::am_Source_Database_s & refObject)> comparator = [&](const CAmDatabaseHandlerMap::am_Source_Database_s & source)->bool{
+ return ( 0==source.reserved &&
+ (sourceID==source.sourceID || name.compare(source.name)==0));
+ };
+ return objectMatchingPredicate(mMappedData.mSourceMap, comparator);
+}
+
+/**
+ * returns sink with given ID or the name if exists
+ * @param sinkID the ID
+ * @param name the name
+ * @return sink structure if exists.
+ */
+const CAmDatabaseHandlerMap::am_Sink_Database_s * CAmDatabaseHandlerMap::sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const
+{
+ std::function<bool(const CAmDatabaseHandlerMap::am_Sink_Database_s & refObject)> comparator = [&](const CAmDatabaseHandlerMap::am_Sink_Database_s & sink)->bool{
+ return ( 0==sink.reserved &&
+ (sinkID==sink.sinkID || name.compare(sink.name)==0));
+ };
+ return objectMatchingPredicate(mMappedData.mSinkMap, comparator);
+}
+
+/**
* checks if a sink with the ID or the name exists
* @param sinkID the ID
* @param name the name
@@ -1878,19 +1916,7 @@ bool CAmDatabaseHandlerMap::existSink(const am_sinkID_t sinkID) const
*/
bool CAmDatabaseHandlerMap::existSinkNameOrID(const am_sinkID_t sinkID, const std::string & name) const
{
- bool returnVal = false;
- CAmMapSink::const_iterator elementIterator = mMappedData.mSinkMap.begin();
- for (;elementIterator != mMappedData.mSinkMap.end(); ++elementIterator)
- {
- if( 0==elementIterator->second.reserved &&
- (sinkID==elementIterator->second.sinkID || name.compare(elementIterator->second.name)==0))
- {
- returnVal = true;
- break;
- }
- }
-
- return (returnVal);
+ return sinkWithNameOrID( sinkID, name)!=NULL;
}
/**
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
index d034b54..f52dda8 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
@@ -13,6 +13,7 @@
*
*
* \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
+ * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
*
* For further information see http://www.genivi.org/.
*
@@ -136,10 +137,12 @@ void CAmMapHandlerTest::createMainConnectionSetup()
void CAmMapHandlerTest::SetUp()
{
+ ::testing::FLAGS_gmock_verbose = "error";
}
void CAmMapHandlerTest::TearDown()
{
+ ::testing::FLAGS_gmock_verbose = "warning";
}
TEST_F(CAmMapHandlerTest,getMainConnectionInfo)
@@ -413,9 +416,6 @@ TEST_F(CAmMapHandlerTest, peekSinkID)
TEST_F(CAmMapHandlerTest,crossfaders)
{
-
-
-
am_Crossfader_s crossfader;
am_crossfaderID_t crossfaderID;
am_Sink_s sinkA, sinkB;
@@ -2268,15 +2268,502 @@ TEST_F(CAmMapHandlerTest, peekDomain_2)
ASSERT_TRUE(listDomains[0].domainID==domainID);
}
-//Commented out - gives always a warning..
-//TEST_F(databaseTest,registerDomainFailonID0)
-//{
-// am_Domain_s domain;
-// am_domainID_t domainID=5;
-// pCF.createDomain(domain);
-// domain.domainID=1;
-// ASSERT_DEATH(pDatabaseHandler.enterDomainDB(domain,domainID),"Assertion `domainData.domainID==0'");
-//}
+CAmMapHandlerObserverCallbacksTest::CAmMapHandlerObserverCallbacksTest() :
+ plistRoutingPluginDirs(),
+ plistCommandPluginDirs(),
+ pSocketHandler(),
+ pRoutingSender(plistRoutingPluginDirs),
+ pCommandSender(plistCommandPluginDirs),
+ pControlSender(),
+ mMockObserver(&pCommandSender, &pRoutingSender, &pSocketHandler),
+ pDatabaseHandler(),
+ pRouter(&pDatabaseHandler, &pControlSender),
+ pCF()
+{
+ pDatabaseHandler.registerObserver(&mMockObserver);
+}
+
+void CAmMapHandlerObserverCallbacksTest::SetUp()
+{
+
+}
+
+void CAmMapHandlerObserverCallbacksTest::TearDown()
+{
+
+}
+
+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, 1);
+
+ domain.name = "anotherdomain";
+ const am_Domain_s expDomain1 = {2, 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, 2);
+ EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject()));
+ domain.name = "newdomain";
+ const am_Domain_s expDomain2 = {1, 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
+ ASSERT_TRUE(listDomains[0].domainID==domainID);
+ 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, 100);
+
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(Field(&am_Source_s::sourceID, 102))).Times(1);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID));
+ ASSERT_EQ(source3ID, 102);
+
+ 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, 100))).Times(1);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
+ ASSERT_EQ(sourceID, source3ID);
+ ASSERT_TRUE(listSources[0].sourceID==sourceID);
+ std::vector<am_SoundProperty_s> listSoundProperties;
+ std::vector<am_ConnectionFormat_e> listConnectionFormats;
+ std::vector<am_MainSoundProperty_s> listMainSoundProperties;
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceUpdated(sourceID, _, _, _)).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.changeSourceDB(sourceID, 1, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error";
+ 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, 100);
+
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(Field(&am_Sink_s::sinkID, 102))).Times(1);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID));
+ ASSERT_EQ(sink3ID, 102);
+
+ 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, 100))).Times(1);
+ 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);
+ std::vector<am_SoundProperty_s> listSoundProperties;
+ std::vector<am_ConnectionFormat_e> listConnectionFormats;
+ std::vector<am_MainSoundProperty_s> listMainSoundProperties;
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkUpdated(sinkID, _, _, _)).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.changeSinkDB(sinkID, 1, listSoundProperties, listConnectionFormats, listMainSoundProperties))<< "ERROR: database error";
+ 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, 100))).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))<< "ERROR: database error";
+ ASSERT_EQ(100,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, 101))).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))<< "ERROR: database error";
+ ASSERT_EQ(101,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_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, 100))).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_removeMainConnection)
+{
+ //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:
+ uint16_t i = 1;
+ for (; 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;
+
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink));
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1);
+ 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
+ am_MainConnection_s mainConnection;
+ am_mainConnectionID_t mainConnectionID;
+ 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
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection(Field(&am_MainConnectionType_s::mainConnectionID, 1))).Times(1);
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, CS_CONNECTED)).Times(1);
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(1);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID));
+ ASSERT_NE(0, mainConnectionID);
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedMainConnection(1)).Times(1);
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, _)).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(1)) << "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);
+}
+
+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);
+}
+
+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);
+}
+
+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);
+}
+
+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);
+}
+
+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,returnList1;
+
+ 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_MAX;
+ notify1.status=NS_PERIODIC;
+ notify1.parameter=5;
+
+ am_NotificationConfiguration_s notify2;
+ notify2.type=NT_MAX;
+ notify2.status=NS_CHANGE;
+ notify2.parameter=27;
+
+ testSinkData.listMainNotificationConfigurations.push_back(notify1);
+
+ //enter the sink in the database
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID))
+ << "ERROR: database error";
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMainNotificationConfigurationChanged(sinkID, _)).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify2))
+ << "ERROR: database error";
+}
+
+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,returnList1;
+
+ 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_MAX;
+ notify1.status=NS_PERIODIC;
+ notify1.parameter=5;
+
+ am_NotificationConfiguration_s notify2;
+ notify2.type=NT_MAX;
+ notify2.status=NS_CHANGE;
+ notify2.parameter=10;
+
+ testSourceData.listMainNotificationConfigurations.push_back(notify1);
+
+ //enter the sink in the database
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1);
+ 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";
+ //change a setting
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceMainNotificationConfigurationChanged(sourceID, _)).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSourceNotificationConfigurationDB(sourceID,notify2));
+}
int main(int argc, char **argv)
{
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h
index f4cb0cf..2f5552d 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h
@@ -13,6 +13,7 @@
*
*
* \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
+ * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
*
* For further information see http://www.genivi.org/.
*
@@ -39,6 +40,7 @@
#include "../MockIAmControlSend.h"
#include "../MockIAmCommandSend.h"
#include "shared/CAmSocketHandler.h"
+#include "MockDatabaseObserver.h"
namespace am
{
@@ -68,6 +70,25 @@ public:
void createMainConnectionSetup();
};
+class CAmMapHandlerObserverCallbacksTest: public ::testing::Test
+{
+public:
+ std::vector<std::string> plistRoutingPluginDirs;
+ std::vector<std::string> plistCommandPluginDirs;
+ CAmSocketHandler pSocketHandler;
+ CAmRoutingSender pRoutingSender;
+ CAmCommandSender pCommandSender;
+ CAmControlSender pControlSender;
+ CAmDatabaseObserver mMockObserver;
+ CAmDatabaseHandlerMap pDatabaseHandler;
+ CAmRouter pRouter;
+ CAmCommonFunctions pCF;
+ CAmMapHandlerObserverCallbacksTest();
+ ~CAmMapHandlerObserverCallbacksTest();
+ void SetUp();
+ void TearDown();
+};
+
}
#endif /* MAPHANDLERTEST_H_ */
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp b/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp
new file mode 100644
index 0000000..87942c5
--- /dev/null
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp
@@ -0,0 +1,92 @@
+/**
+ * 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::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::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/AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt b/AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt
index 493de6a..0381966 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CMakeLists.txt
@@ -45,8 +45,7 @@ INCLUDE_DIRECTORIES(
file(GLOB DATABASE_SRCS_CXX
"../../src/CAmDatabaseHandlerMap.cpp"
- "../../src/CAmDatabaseObserver.cpp"
- "../../src/CAmCommandSender.cpp"
+ "../../src/CAmCommandSender.cpp"
"../../src/CAmRoutingSender.cpp"
"../../src/CAmControlReceiver.cpp"
"../../src/CAmControlSender.cpp"
@@ -57,13 +56,16 @@ file(GLOB DATABASE_SRCS_CXX
"../../src/CAmRoutingReceiver.cpp"
"../../src/CAmDbusWrapper.cpp"
"../CAmCommonFunctions.cpp"
+ "CAmTestDatabaseObserver.cpp"
"*.cpp"
)
IF(WITH_NSM)
- SET (DATABASE_SRCS_CXX
- ${DATABASE_SRCS_CXX}
- "../../src/CAmNodeStateCommunicatorDBus.cpp")
+ IF(WITH_DBUS_WRAPPER)
+ SET (DATABASE_SRCS_CXX
+ ${DATABASE_SRCS_CXX}
+ "../../src/CAmNodeStateCommunicatorDBus.cpp")
+ ENDIF()
ENDIF(WITH_NSM)
ADD_EXECUTABLE( AmMapHandlerTest ${DATABASE_SRCS_CXX})
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h b/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h
new file mode 100644
index 0000000..52f2599
--- /dev/null
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h
@@ -0,0 +1,114 @@
+/**
+ * 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 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 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(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(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_ */