summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Donchev <aleksander.donchev@partner.bmw.de>2013-09-23 09:03:47 (GMT)
committerChristian Linke <Christian.Linke@bmw.de>2013-09-25 13:43:57 (GMT)
commit9b5173281e607bbebca8e6445dbffc38e7506c2f (patch)
treedd4ed555f7118bd213b05d9dabf5095fc2cf6bb5
parent32caf7f1db12965712a1f74016e7b55e258cab73 (diff)
downloadaudiomanager-9b5173281e607bbebca8e6445dbffc38e7506c2f.tar.gz
* Every new connection ID is initilized with the next available number.
* Additional tests for ID generation added. Signed-off-by: Christian Linke <christian.linke@bmw.de>
-rw-r--r--AudioManagerDaemon/CMakeLists.txt14
-rw-r--r--AudioManagerDaemon/include/CAmDatabaseHandlerMap.h101
-rw-r--r--AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp87
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp153
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h2
5 files changed, 286 insertions, 71 deletions
diff --git a/AudioManagerDaemon/CMakeLists.txt b/AudioManagerDaemon/CMakeLists.txt
index c122841..92eea26 100644
--- a/AudioManagerDaemon/CMakeLists.txt
+++ b/AudioManagerDaemon/CMakeLists.txt
@@ -66,11 +66,23 @@ SET(AUDIOMAN_SRCS_CXX
# Preallocation variable for the map.
IF(NOT WITH_DATABASE_STORAGE )
+
IF(NOT DEFINED AM_MAP_CAPACITY)
set (AM_MAP_CAPACITY 10)
ENDIF(NOT DEFINED AM_MAP_CAPACITY)
add_definitions( -DAM_MAP_CAPACITY=${AM_MAP_CAPACITY} )
-ENDIF(NOT WITH_DATABASE_STORAGE)
+
+ IF(NOT DEFINED AM_MAX_CONNECTIONS)
+ set (AM_MAX_CONNECTIONS 0x1000)
+ ENDIF(NOT DEFINED AM_MAX_CONNECTIONS)
+ add_definitions( -DAM_MAX_CONNECTIONS=${AM_MAX_CONNECTIONS} )
+
+ IF(NOT DEFINED AM_MAX_MAIN_CONNECTIONS)
+ set (AM_MAX_MAIN_CONNECTIONS SHRT_MAX)
+ ENDIF(NOT DEFINED AM_MAX_MAIN_CONNECTIONS)
+ add_definitions( -DAM_MAX_MAIN_CONNECTIONS=${AM_MAX_MAIN_CONNECTIONS} )
+
+ENDIF(NOT WITH_DATABASE_STORAGE)
IF(WITH_TELNET)
SET (AUDIOMAN_SRCS_CXX
diff --git a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h b/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
index 9e292f0..0d590a8 100644
--- a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
+++ b/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
@@ -22,14 +22,12 @@
#ifndef MAPHANDLER_H_
#define MAPHANDLER_H_
-#include "IAmDatabaseHandler.h"
#include <stdint.h>
#include <limits.h>
#include <sstream>
#include <iostream>
#include <unordered_map>
-
-
+#include "IAmDatabaseHandler.h"
namespace am
{
@@ -37,6 +35,16 @@ namespace am
#define AM_MAP_CAPACITY 0
#endif
+#ifndef AM_MAX_CONNECTIONS
+ #define AM_MAX_CONNECTIONS 0x1000
+#endif
+
+#ifndef AM_MAX_MAIN_CONNECTIONS
+ #define AM_MAX_MAIN_CONNECTIONS SHRT_MAX
+#endif
+
+
+
//todo: check the enum values before entering & changing in the database.
//todo: change asserts for dynamic boundary checks into failure answers.#
//todo: check autoincrement boundary and set to 16bit limits
@@ -255,16 +263,16 @@ public:
AM_TYPEDEF_SUBCLASS_END(CAmCrossfader)
private:
- typedef std::unordered_map<am_domainID_t, CAmDomain> CAmMapDomain;
+ typedef std::unordered_map<am_domainID_t, CAmDomain> CAmMapDomain;
typedef std::unordered_map<am_sourceClass_t, CAmSourceClass> CAmMapSourceClass;
typedef std::unordered_map<am_sinkClass_t, CAmSinkClass> CAmMapSinkClass;
typedef std::unordered_map<am_sinkID_t, CAmSink> CAmMapSink;
typedef std::unordered_map<am_sourceID_t, CAmSource> CAmMapSource;
- typedef std::unordered_map<am_gatewayID_t, CAmGateway> CAmMapGateway;
+ typedef std::unordered_map<am_gatewayID_t, CAmGateway> CAmMapGateway;
typedef std::unordered_map<am_crossfaderID_t, CAmCrossfader> CAmMapCrossfader;
typedef std::unordered_map<am_connectionID_t, CAmConnection> CAmMapConnection;
typedef std::unordered_map<am_mainConnectionID_t, CAmMainConnection> CAmMapMainConnection;
- typedef std::vector<am_SystemProperty_s> CAmVectorSystemProperties;
+ typedef std::vector<am_SystemProperty_s> CAmVectorSystemProperties;
/**
* The following structure groups the map objects needed for the implementation.
* Every map object is coupled with an identifier, which hold the current value.
@@ -274,17 +282,29 @@ public:
*/
typedef struct CAmMappedData
{
- int16_t mCurrentDomainID; //!< domain ID
- int16_t mCurrentSourceClassesID; //!< source classes ID
- int16_t mCurrentSinkClassesID; //!< sink classes ID
- int16_t mCurrentSinkID; //!< sink ID
- int16_t mCurrentSourceID; //!< source ID
- int16_t mCurrentGatewayID; //!< gateway ID
- int16_t mCurrentCrossfaderID; //!< crossfader ID
- int16_t mCurrentConnectionID; //!< connection ID
- int16_t mCurrentMainConnectionID; //!< mainconnection ID
-
- int16_t mDefaultIDLimit; //!< Upper limit for all IDs, default is SHRT_MAX
+ /**
+ * The structure encapsulates the id boundary and the current id value.
+ * It defines a range within the id can vary.
+ */
+ struct am_Identifier_s
+ {
+ int16_t mMin; //!< min possible value
+ int16_t mMax; //!< max possible value
+ int16_t mCurrentValue; //!< current value
+
+ am_Identifier_s():mMin(DYNAMIC_ID_BOUNDARY), mMax(SHRT_MAX), mCurrentValue(mMin){};
+ am_Identifier_s(const int16_t & min, const int16_t & max):mMin(min), mMax(max), mCurrentValue(mMin){assert(min<max);};
+ };
+
+ am_Identifier_s mCurrentDomainID; //!< domain ID
+ am_Identifier_s mCurrentSourceClassesID; //!< source classes ID
+ am_Identifier_s mCurrentSinkClassesID; //!< sink classes ID
+ am_Identifier_s mCurrentSinkID; //!< sink ID
+ am_Identifier_s mCurrentSourceID; //!< source ID
+ am_Identifier_s mCurrentGatewayID; //!< gateway ID
+ am_Identifier_s mCurrentCrossfaderID; //!< crossfader ID
+ am_Identifier_s mCurrentConnectionID; //!< connection ID
+ am_Identifier_s mCurrentMainConnectionID; //!< mainconnection ID
CAmVectorSystemProperties mSystemProperties; //!< vector with system properties
CAmMapDomain mDomainMap; //!< map for domain structures
@@ -298,10 +318,15 @@ public:
CAmMapMainConnection mMainConnectionMap; //!< map for main connection structures
CAmMappedData(): //For Domain, MainConnections, Connections we don't have static IDs.
- mCurrentDomainID(1), mCurrentSourceClassesID(DYNAMIC_ID_BOUNDARY), mCurrentSinkClassesID(DYNAMIC_ID_BOUNDARY),
- mCurrentSinkID(DYNAMIC_ID_BOUNDARY), mCurrentSourceID(DYNAMIC_ID_BOUNDARY), mCurrentGatewayID(DYNAMIC_ID_BOUNDARY),
- mCurrentCrossfaderID(DYNAMIC_ID_BOUNDARY), mCurrentConnectionID(1), mCurrentMainConnectionID(1),
- mDefaultIDLimit(SHRT_MAX),
+ mCurrentDomainID(1, SHRT_MAX),
+ mCurrentSourceClassesID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
+ mCurrentSinkClassesID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
+ mCurrentSinkID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
+ mCurrentSourceID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
+ mCurrentGatewayID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
+ mCurrentCrossfaderID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
+ mCurrentConnectionID(1, AM_MAX_CONNECTIONS),
+ mCurrentMainConnectionID(1, AM_MAX_MAIN_CONNECTIONS),
mSystemProperties(),
mDomainMap(),mSourceClassesMap(), mSinkClassesMap(), mSinkMap(AM_MAP_CAPACITY), mSourceMap(AM_MAP_CAPACITY),
@@ -319,15 +344,22 @@ public:
* @param preferedStaticIDBoundary A limit for a given dynamic ID. Default is DYNAMIC_ID_BOUNDARY.
* @return TRUE on successfully changed ID.
*/
- bool increaseID(int16_t * resultID, int16_t * sourceID,
- int16_t const desiredStaticID, int16_t const preferedStaticIDBoundary );
+ bool increaseID(int16_t & resultID, am_Identifier_s & sourceID, int16_t const desiredStaticID);
/**
* \brief Increases the main connection ID.
*
* @param resultID Pointer to an output variable.
* @return TRUE on successfully changed ID.
*/
- bool increaseMainConnectionID(int16_t * resultID);
+ bool increaseMainConnectionID(int16_t & resultID);
+
+ /**
+ * \brief Increases the connection ID.
+ *
+ * @param resultID Pointer to an output variable.
+ * @return TRUE on successfully changed ID.
+ */
+ bool increaseConnectionID(int16_t & resultID);
template <class TPrintObject> static void print (const TPrintObject & t, std::ostream & output)
{
@@ -341,6 +373,9 @@ public:
for(; iter!=t.end(); iter++)
CAmMappedData::print(iter->second, output);
}
+ private:
+ template <typename TMapKey,class TMapObject> bool getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID,
+ const std::unordered_map<TMapKey, TMapObject> & map);
} CAmMappedData;
/*
* Helper methods.
@@ -359,6 +394,24 @@ public:
CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer
ListConnectionFormat mListConnectionFormat; //!< list of connection formats
CAmMappedData mMappedData; //!< Internal structure encapsulating all the maps used in this class
+#ifdef UNIT_TEST
+ public:
+ void setConnectionIDRange(const int16_t & min, const int16_t & max)
+ {
+ mMappedData.mCurrentConnectionID.mMin = min;
+ mMappedData.mCurrentConnectionID.mMax = max;
+ }
+ void setMainConnectionIDRange(const int16_t & min, const int16_t & max)
+ {
+ mMappedData.mCurrentMainConnectionID.mMin = min;
+ mMappedData.mCurrentMainConnectionID.mMax = max;
+ }
+ void setSinkIDRange(const int16_t & min, const int16_t & max)
+ {
+ mMappedData.mCurrentSinkID.mMin = min;
+ mMappedData.mCurrentSinkID.mMax = max;
+ }
+#endif
};
}
diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
index 505aa96..ee2f35c 100644
--- a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
+++ b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
@@ -19,7 +19,6 @@
*
*/
-#include "CAmDatabaseHandlerMap.h"
#include <iostream>
#include <cassert>
#include <stdexcept>
@@ -29,11 +28,10 @@
#include <string>
#include <algorithm>
#include <limits>
+#include "CAmDatabaseHandlerMap.h"
#include "CAmDatabaseObserver.h"
#include "CAmRouter.h"
#include "shared/CAmDltWrapper.h"
-#include "CAmLog.h"
-
namespace am
{
@@ -359,46 +357,45 @@ void CAmDatabaseHandlerMap::CAmCrossfader::getDescription (std::string & outStri
outString = fmt.str();
}
-bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t * resultID,
- int16_t * sourceID,
- int16_t const desiredStaticID = 0,
- int16_t const preferedStaticIDBoundary = DYNAMIC_ID_BOUNDARY)
+bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t & resultID, am_Identifier_s & sourceID,
+ int16_t const desiredStaticID = 0)
{
- if( desiredStaticID > 0 && desiredStaticID < preferedStaticIDBoundary )
+ if( desiredStaticID > 0 && desiredStaticID < sourceID.mMin )
{
- *resultID = desiredStaticID;
+ resultID = desiredStaticID;
return true;
}
- else if( *sourceID < mDefaultIDLimit ) //The last used value is 'limit' - 1. e.g. SHRT_MAX - 1, SHRT_MAX is reserved.
+ else if( sourceID.mCurrentValue < sourceID.mMax ) //The last used value is 'limit' - 1. e.g. SHRT_MAX - 1, SHRT_MAX is reserved.
{
- *resultID = (*sourceID)++;
+ resultID = sourceID.mCurrentValue++;
return true;
}
else
{
- *resultID = -1;
+ resultID = -1;
return false;
}
}
-bool CAmDatabaseHandlerMap::CAmMappedData::increaseMainConnectionID(int16_t * resultID)
+template <typename TMapKey,class TMapObject> bool CAmDatabaseHandlerMap::CAmMappedData::getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID,
+ const std::unordered_map<TMapKey, TMapObject> & map)
{
- am_mainConnectionID_t nextID;
- am_mainConnectionID_t const lastID = mCurrentMainConnectionID;
- if( mCurrentMainConnectionID < mDefaultIDLimit )
- nextID = mCurrentMainConnectionID++;
+ TMapKey nextID;
+ int16_t const lastID = sourceID.mCurrentValue;
+ if( sourceID.mCurrentValue < sourceID.mMax )
+ nextID = sourceID.mCurrentValue++;
else
- nextID = mCurrentMainConnectionID = 1;
+ nextID = sourceID.mCurrentValue = sourceID.mMin;
bool notFreeIDs = false;
- while( existsObjectWithKeyInMap(nextID, mMainConnectionMap) )
+ while( existsObjectWithKeyInMap(nextID, map) )
{
- if( mCurrentMainConnectionID < mDefaultIDLimit )
- nextID = mCurrentMainConnectionID++;
+ if( sourceID.mCurrentValue < sourceID.mMax )
+ nextID = sourceID.mCurrentValue++;
else
- nextID = mCurrentMainConnectionID = 1;
+ nextID = sourceID.mCurrentValue = sourceID.mMin;
- if( mCurrentMainConnectionID == lastID )
+ if( sourceID.mCurrentValue == lastID )
{
notFreeIDs = true;
break;
@@ -406,13 +403,23 @@ bool CAmDatabaseHandlerMap::CAmMappedData::increaseMainConnectionID(int16_t * re
}
if(notFreeIDs)
{
- *resultID = -1;
+ resultID = -1;
return false;
}
- *resultID = nextID;
+ resultID = nextID;
return true;
}
+bool CAmDatabaseHandlerMap::CAmMappedData::increaseMainConnectionID(int16_t & resultID)
+{
+ return getNextConnectionID(resultID, mCurrentMainConnectionID, mMainConnectionMap);
+}
+
+bool CAmDatabaseHandlerMap::CAmMappedData::increaseConnectionID(int16_t & resultID)
+{
+ return getNextConnectionID(resultID, mCurrentConnectionID, mConnectionMap);
+}
+
CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): mFirstStaticSink(true), //
mFirstStaticSource(true), //
@@ -424,7 +431,7 @@ CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): mFirstStaticSink(true), //
mListConnectionFormat(), //
mMappedData()
{
- logInfo(__PRETTY_FUNCTION__,"Init");
+ logInfo(__PRETTY_FUNCTION__,"Init ");
}
CAmDatabaseHandlerMap::~CAmDatabaseHandlerMap()
@@ -459,7 +466,7 @@ am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData,
}
else
{
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentDomainID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentDomainID))
{
domainID = nextID;
mMappedData.mDomainMap[nextID] = domainData;
@@ -507,7 +514,7 @@ am_Error_e CAmDatabaseHandlerMap::enterMainConnectionDB(const am_MainConnection_
int16_t delay = 0;
int16_t nextID = 0;
- if(mMappedData.increaseMainConnectionID(&nextID))
+ if(mMappedData.increaseMainConnectionID(nextID))
{
connectionID = nextID;
mMappedData.mMainConnectionMap[nextID] = mainConnectionData;
@@ -546,7 +553,7 @@ am_Error_e CAmDatabaseHandlerMap::enterMainConnectionDB(const am_MainConnection_
bool CAmDatabaseHandlerMap::insertSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
{
int16_t nextID = 0;
- if( mMappedData.increaseID(&nextID, &mMappedData.mCurrentSinkID, sinkData.sinkID) )
+ if( mMappedData.increaseID(nextID, mMappedData.mCurrentSinkID, sinkData.sinkID) )
{
sinkID = nextID;
mMappedData.mSinkMap[nextID] = sinkData;
@@ -622,7 +629,7 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkDB(const am_Sink_s & sinkData, am_sin
bool CAmDatabaseHandlerMap::insertCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentCrossfaderID, crossfaderData.crossfaderID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentCrossfaderID, crossfaderData.crossfaderID))
{
crossfaderID = nextID;
mMappedData.mCrossfaderMap[nextID] = crossfaderData;
@@ -683,7 +690,7 @@ am_Error_e CAmDatabaseHandlerMap::enterCrossfaderDB(const am_Crossfader_s & cros
bool CAmDatabaseHandlerMap::insertGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentGatewayID, gatewayData.gatewayID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentGatewayID, gatewayData.gatewayID))
{
gatewayID = nextID;
mMappedData.mGatewayMap[nextID] = gatewayData;
@@ -769,7 +776,7 @@ void CAmDatabaseHandlerMap::dump( std::ostream & output ) const
bool CAmDatabaseHandlerMap::insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentSourceID, sourceData.sourceID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceID, sourceData.sourceID))
{
sourceID = nextID;
mMappedData.mSourceMap[nextID] = sourceData;
@@ -848,7 +855,7 @@ am_Error_e CAmDatabaseHandlerMap::enterConnectionDB(const am_Connection_s& conne
assert(connection.sourceID!=0);
//connection format is not checked, because it's project specific
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentConnectionID))
+ if(mMappedData.increaseConnectionID(nextID))
{
connectionID = nextID;
mMappedData.mConnectionMap[nextID] = connection;
@@ -868,7 +875,7 @@ am_Error_e CAmDatabaseHandlerMap::enterConnectionDB(const am_Connection_s& conne
bool CAmDatabaseHandlerMap::insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentSinkClassesID, sinkClass.sinkClassID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentSinkClassesID, sinkClass.sinkClassID))
{
sinkClassID = nextID;
mMappedData.mSinkClassesMap[nextID] = sinkClass;
@@ -924,7 +931,7 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkClassDB(const am_SinkClass_s & sinkCl
bool CAmDatabaseHandlerMap::insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentSourceClassesID, sourceClass.sourceClassID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceClassesID, sourceClass.sourceClassID))
{
sourceClassID = nextID;
mMappedData.mSourceClassesMap[nextID] = sourceClass;
@@ -1854,7 +1861,7 @@ bool CAmDatabaseHandlerMap::existSourceNameOrID(const am_sourceID_t sourceID, co
*/
bool CAmDatabaseHandlerMap::existSourceName(const std::string & name) const
{
- return existSourceNameOrID(SHRT_MAX, name);
+ return existSourceNameOrID(mMappedData.mCurrentSourceID.mMax, name);
}
/**
@@ -1926,7 +1933,7 @@ bool CAmDatabaseHandlerMap::existSinkNameOrID(const am_sinkID_t sinkID, const st
*/
bool CAmDatabaseHandlerMap::existSinkName(const std::string & name) const
{
- return existSinkNameOrID(SHRT_MAX, name);
+ return existSinkNameOrID(mMappedData.mCurrentSinkID.mMax, name);
}
/**
@@ -2265,7 +2272,7 @@ am_Error_e CAmDatabaseHandlerMap::peekDomain(const std::string & name, am_domain
else
{
int16_t nextID = 0;
- if( mMappedData.increaseID( &nextID, &mMappedData.mCurrentDomainID) )
+ if( mMappedData.increaseID( nextID, mMappedData.mCurrentDomainID) )
{
domainID = nextID;
am_Domain_Database_s domain;
@@ -2292,7 +2299,7 @@ am_Error_e CAmDatabaseHandlerMap::peekSink(const std::string & name, am_sinkID_t
else
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentSinkID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentSinkID))
{
if(mFirstStaticSink)
{
@@ -2323,7 +2330,7 @@ am_Error_e CAmDatabaseHandlerMap::peekSource(const std::string & name, am_source
else
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentSourceID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceID))
{
if(mFirstStaticSource)
{
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
index f52dda8..2dba164 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
@@ -30,14 +30,16 @@
using namespace am;
using namespace testing;
-//extern int GetRandomNumber(int nLow, int nHigh);
-//extern bool equalSoundProperty (const am_SoundProperty_s a, const am_SoundProperty_s b);
+
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 equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_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;
+
CAmMapHandlerTest::CAmMapHandlerTest() :
plistRoutingPluginDirs(), //
plistCommandPluginDirs(), //
@@ -54,6 +56,9 @@ CAmMapHandlerTest::CAmMapHandlerTest() :
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);
}
@@ -71,8 +76,6 @@ void CAmMapHandlerTest::createMainConnectionSetup()
//we create 9 sources and sinks:
-
-
for (uint16_t i = 1; i < 10; i++)
{
am_sinkID_t forgetSink;
@@ -2268,6 +2271,145 @@ TEST_F(CAmMapHandlerTest, peekDomain_2)
ASSERT_TRUE(listDomains[0].domainID==domainID);
}
+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(i, connectionID);
+ }
+ }
+ std::vector<am_Connection_s> connectionList;
+ ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
+ ASSERT_EQ(TEST_MAX_CONNECTION_ID-1, connectionList.size());
+ ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterConnectionDB(connection,connectionID));
+ 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(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, 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() :
plistRoutingPluginDirs(),
plistCommandPluginDirs(),
@@ -2773,3 +2915,4 @@ int main(int argc, char **argv)
return RUN_ALL_TESTS();
}
+
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h
index 2f5552d..f35aa0b 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.h
@@ -27,6 +27,7 @@
#include "gtest/gtest.h"
#include "gmock/gmock.h"
+#include "shared/CAmSocketHandler.h"
#include "CAmDatabaseHandlerMap.h"
#include "CAmControlReceiver.h"
#include "CAmControlSender.h"
@@ -39,7 +40,6 @@
#include "../CAmCommonFunctions.h"
#include "../MockIAmControlSend.h"
#include "../MockIAmCommandSend.h"
-#include "shared/CAmSocketHandler.h"
#include "MockDatabaseObserver.h"
namespace am