* Additional tests for ID generation added.
Signed-off-by: Christian Linke <christian.linke@bmw.de>
# 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
#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
{
#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
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.
*/
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
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),
* @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)
{
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.
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
};
}
*
*/
-#include "CAmDatabaseHandlerMap.h"
#include <iostream>
#include <cassert>
#include <stdexcept>
#include <string>
#include <algorithm>
#include <limits>
+#include "CAmDatabaseHandlerMap.h"
#include "CAmDatabaseObserver.h"
#include "CAmRouter.h"
#include "shared/CAmDltWrapper.h"
-#include "CAmLog.h"
-
namespace am
{
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;
}
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), //
mListConnectionFormat(), //
mMappedData()
{
- logInfo(__PRETTY_FUNCTION__,"Init");
+ logInfo(__PRETTY_FUNCTION__,"Init ");
}
CAmDatabaseHandlerMap::~CAmDatabaseHandlerMap()
}
else
{
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentDomainID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentDomainID))
{
domainID = nextID;
mMappedData.mDomainMap[nextID] = domainData;
int16_t delay = 0;
int16_t nextID = 0;
- if(mMappedData.increaseMainConnectionID(&nextID))
+ if(mMappedData.increaseMainConnectionID(nextID))
{
connectionID = nextID;
mMappedData.mMainConnectionMap[nextID] = mainConnectionData;
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;
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;
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;
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;
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;
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;
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;
*/
bool CAmDatabaseHandlerMap::existSourceName(const std::string & name) const
{
- return existSourceNameOrID(SHRT_MAX, name);
+ return existSourceNameOrID(mMappedData.mCurrentSourceID.mMax, name);
}
/**
*/
bool CAmDatabaseHandlerMap::existSinkName(const std::string & name) const
{
- return existSinkNameOrID(SHRT_MAX, name);
+ return existSinkNameOrID(mMappedData.mCurrentSinkID.mMax, name);
}
/**
else
{
int16_t nextID = 0;
- if( mMappedData.increaseID( &nextID, &mMappedData.mCurrentDomainID) )
+ if( mMappedData.increaseID( nextID, mMappedData.mCurrentDomainID) )
{
domainID = nextID;
am_Domain_Database_s domain;
else
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentSinkID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentSinkID))
{
if(mFirstStaticSink)
{
else
{
int16_t nextID = 0;
- if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentSourceID))
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentSourceID))
{
if(mFirstStaticSource)
{
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(), //
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);
}
//we create 9 sources and sinks:
-
-
for (uint16_t i = 1; i < 10; i++)
{
am_sinkID_t forgetSink;
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(),
return RUN_ALL_TESTS();
}
+
#include "gtest/gtest.h"
#include "gmock/gmock.h"
+#include "shared/CAmSocketHandler.h"
#include "CAmDatabaseHandlerMap.h"
#include "CAmControlReceiver.h"
#include "CAmControlSender.h"
#include "../CAmCommonFunctions.h"
#include "../MockIAmControlSend.h"
#include "../MockIAmCommandSend.h"
-#include "shared/CAmSocketHandler.h"
#include "MockDatabaseObserver.h"
namespace am