Added 'Dump' method to the database handler and to the telnet server (Info -> Dump...
authorAleksander Donchev <aleksander.donchev@partner.bmw.de>
Mon, 8 Jul 2013 09:27:30 +0000 (11:27 +0200)
committerAleksander Donchev <aleksander.donchev@partner.bmw.de>
Wed, 10 Jul 2013 12:59:18 +0000 (14:59 +0200)
Signed-off-by: Christian Linke <christian.linke@bmw.de>
20 files changed:
AudioManagerDaemon/include/CAmDatabaseHandlerInterface.h
AudioManagerDaemon/include/CAmLog.h [new file with mode: 0644]
AudioManagerDaemon/include/CAmMapHandler.h
AudioManagerDaemon/include/CAmTelnetMenuHelper.h
AudioManagerDaemon/include/CAmTelnetServer.h
AudioManagerDaemon/src/CAmDatabaseHandler.cpp
AudioManagerDaemon/src/CAmLog.cpp [new file with mode: 0644]
AudioManagerDaemon/src/CAmMapHandler.cpp
AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp
AudioManagerDaemon/src/CAmTelnetServer.cpp
AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp [new file with mode: 0644]
AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h [new file with mode: 0644]
AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt [new file with mode: 0644]
AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp
AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.h
AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.cpp
AudioManagerDaemon/test/AmTelnetServerTest/CAmTelnetServerTest.h
AudioManagerDaemon/test/AmTelnetServerTest/CMakeLists.txt
AudioManagerDaemon/test/CMakeLists.txt

index 58d97bc..de50511 100644 (file)
@@ -26,6 +26,7 @@
 #include <map>
 #include <vector>
 #include <string>
+#include <iostream>
 
 namespace am
 {
@@ -185,6 +186,8 @@ public:
     virtual void registerObserver(CAmDatabaseObserver *iObserver) = 0;
     virtual bool sourceVisible(const am_sourceID_t sourceID) const = 0;
     virtual bool sinkVisible(const am_sinkID_t sinkID) const = 0;
+
+    virtual void dump( std::ostream & output) { output << __FUNCTION__ << " not implemented!"; };
 };
 
 }
diff --git a/AudioManagerDaemon/include/CAmLog.h b/AudioManagerDaemon/include/CAmLog.h
new file mode 100644 (file)
index 0000000..2cbf68a
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * CAmLog.h
+ *
+ *  Created on: Jul 2, 2013
+ *      Author: genius
+ */
+
+/**
+ * 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 CAmLog.h
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#ifndef CAMLOG_H_
+#define CAMLOG_H_
+
+#include <iostream>
+#include <iosfwd>
+#include <stdio.h>
+#include <stdexcept>
+#include <fstream>
+#include <stdlib.h>
+#include <sstream>
+#include <assert.h>
+
+/**
+ * Implements a basic logging mechanism that can be used to print debug information into a file or to the console.
+ * It can be used either as singleton through the appropriate method getDefaultLog() or as independent instantiated object.
+ * The default initializer sets the console as output for newly created objects.
+ * Example: CAmLogger << "Text"; //to print out through the singleton object directly to the console
+ */
+
+#define DEFAULT_LOG_FOLDER             "/tmp/"
+#define DEFAULT_LOGFILE_PREFIX "am_dump_"
+#define DEFAULT_LOGFILE_EXT    ".log"
+
+#define DEL( aPointer ) delete aPointer, aPointer = NULL;
+
+/* */
+typedef enum { eCAmLogNone = 0, eCAmLogStdout = 1, eCAmLogFile = 2 } eCAmLogType;
+
+class CAmLog
+{
+private:
+       /**
+        * Private classes which usually own (wrap) a stream object. They are responsible for creating and deleting it.
+        */
+       class CAmLogger
+       {
+       protected:
+               std::ostream* mOutputStream;
+       public:
+               CAmLogger ():mOutputStream(NULL) {};
+               virtual ~CAmLogger () { };
+               virtual void log(const std::string& _s)
+           {
+               (*mOutputStream) << _s;
+               mOutputStream->flush();
+           }
+           template <class T>
+           CAmLogger & operator << (const T & t)
+           {
+               (*mOutputStream) << t;
+               return (*this);
+           }
+       };
+
+       class CAmFileLogger : public CAmLogger
+       {
+               std::string mFilename;
+       public:
+               static void generateLogFilename(std::string &result);
+               explicit CAmFileLogger(const std::string& _s) : CAmLogger()
+               {
+                       mFilename = _s;
+                       mOutputStream = new std::ofstream(mFilename.c_str());
+               }
+               ~CAmFileLogger();
+       };
+
+       class CAmStdOutLogger : public CAmLogger
+       {
+       public:
+               CAmStdOutLogger()
+               {
+                       mOutputStream = &std::cout;
+               }
+       };
+
+private:
+       eCAmLogType mLogType;
+    CAmLogger* mLogger;
+
+protected:
+    void releaseLogger();
+    void instantiateLogger( const eCAmLogType type);
+public:
+    CAmLog(const eCAmLogType type );
+    CAmLog();
+    ~CAmLog();
+
+    static CAmLog *getDefaultLog();
+
+    void setLogType( const eCAmLogType type);
+    eCAmLogType getLogType() const;
+
+    template <class T>
+    CAmLog & operator << (const T & t)
+    {
+       assert(mLogger!=NULL);
+       (*mLogger) << t;
+       return (*this);
+    }
+ };
+
+#define CAmLogger (*CAmLog::getDefaultLog())
+
+
+#endif /* CAMLOG_H_ */
index 47bd0ec..510d368 100644 (file)
@@ -14,7 +14,7 @@
  *
 * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
  *
- * \file CAmDatabaseHandler.h
+ * \file CAmMapHandler.h
  * For further information see http://www.genivi.org/.
  *
  */
 #define MAPHANDLER_H_
 
 #include "CAmDatabaseHandlerInterface.h"
-#include <unordered_map>
-#include <map>
 #include <stdint.h>
 #include <limits.h>
+#include <sstream>
+#include <iostream>
+#include <unordered_map>
+
+
 
 namespace am
 {
+
+#define AM_MAP std::unordered_map
+
 //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
@@ -158,169 +164,102 @@ public:
     bool sourceVisible(const am_sourceID_t sourceID) const;
     bool sinkVisible(const am_sinkID_t sinkID) const;
 
-    void printSources();
-    void printSinks();
-    void printSinkClasses();
-    void printSourceClasses();
-
+    void dump( std::ostream & output );
+    template <class TPrintObject> void print (const TPrintObject & t, std::ostream & output) const;
+    template <typename TPrintMapKey,class TPrintMapObject> void printMap (const AM_MAP<TPrintMapKey, TPrintMapObject> & t, std::ostream & output) const;
     /**
      * The following structures extend the base structures with the field 'reserved'.
      */
 
-    struct am_Sink_Database_s : public am_Sink_s
-    {
-        bool reserved;
-        am_Sink_Database_s():am_Sink_s(), reserved(false)
-        {};
-        void getSinkType(am_SinkType_s & sinkType) const
-        {
-            sinkType.name = name;
-            sinkType.sinkID = sinkID;
-            sinkType.availability = available;
-            sinkType.muteState = muteState;
-            sinkType.volume = mainVolume;
-            sinkType.sinkClassID = sinkClassID;
-        };
-        am_Sink_Database_s & operator=(const am_Sink_Database_s & anObject)
-        {
-            if (this != &anObject)
-            {
-                am_Sink_s::operator=(anObject);
-                reserved = anObject.reserved;
-            }
-            return *this;
-        };
-        am_Sink_Database_s & operator=(const am_Sink_s & anObject)
-        {
-            if (this != &anObject)
-                am_Sink_s::operator=(anObject);
-            return *this;
-        };
-        void print() const
-        {
-            printf("\n Sink(%s) id(%d)\n", name.c_str() ,sinkID);
-            printf("\t availability(%d) availabilityReason(%d) sinkClassID(%d) domainID(%d) visible(%d) volume(%d) mainVolume(%d) muteState(%d) reserved(%d)\n",
-                            available.availability, available.availabilityReason, sinkClassID, domainID, visible, volume, mainVolume, muteState,reserved);
-        };
-    };
-
-    struct am_Source_Database_s : public am_Source_s
-    {
-        bool reserved;
-        am_Source_Database_s():am_Source_s(), reserved(false)
-        {};
-        void getSourceType(am_SourceType_s & sourceType) const
-        {
-            sourceType.name = name;
-            sourceType.sourceClassID = sourceClassID;
-            sourceType.availability = available;
-            sourceType.sourceID = sourceID;
-        };
-        am_Source_Database_s & operator=(const am_Source_Database_s & anObject)
-        {
-            if (this != &anObject)
-            {
-                am_Source_s::operator=(anObject);
-                reserved = anObject.reserved;
-            }
-            return *this;
-        };
-        am_Source_Database_s & operator=(const am_Source_s & anObject)
-        {
-            if (this != &anObject)
-            {
-                am_Source_s::operator=(anObject);
-            }
-            return *this;
-        };
-        void print() const
-        {
-            printf("\n Source(%s) id(%d)\n", name.c_str() ,sourceID);
-            printf("\t availability(%d) availabilityReason(%d) sourceClassID(%d) domainID(%d) visible(%d) volume(%d) interruptState(%d) sourceState(%d) reserved(%d)\n",
-                            available.availability, available.availabilityReason, sourceClassID, domainID, visible, volume, interruptState, sourceState,reserved);
-        };
-    };
-
-    struct am_Connection_Database_s : public am_Connection_s
-    {
-        bool reserved;
-        am_Connection_Database_s():am_Connection_s(), reserved(true)
-        {};
-        am_Connection_Database_s & operator=(const am_Connection_Database_s & anObject)
-        {
-            if (this != &anObject)
-            {
-                am_Connection_s::operator=(anObject);
-                reserved = anObject.reserved;
-            }
-            return *this;
-        };
-        am_Connection_Database_s & operator=(const am_Connection_s & anObject)
-        {
-            if (this != &anObject)
-                am_Connection_s::operator=(anObject);
-            return *this;
-        };
-    };
-
-    struct am_Domain_Database_s : public am_Domain_s
-    {
-        bool reserved;
-        am_Domain_Database_s():am_Domain_s(), reserved(false)
-        {};
-        am_Domain_Database_s & operator=(const am_Domain_Database_s & anObject)
-        {
-            if (this != &anObject)
-            {
-                am_Domain_s::operator=(anObject);
-                reserved = anObject.reserved;
-            }
-            return *this;
-        };
-        am_Domain_Database_s & operator=(const am_Domain_s & anObject)
-        {
-            if (this != &anObject)
-                am_Domain_s::operator=(anObject);
-            return *this;
-        };
-    };
-
-    struct am_MainConnection_Database_s : public am_MainConnection_s
-    {
-        am_MainConnection_Database_s():am_MainConnection_s()
-        {};
-        void getMainConnectionType(am_MainConnectionType_s & connectionType) const
-        {
-            connectionType.mainConnectionID = mainConnectionID;
-            connectionType.sourceID = sourceID;
-            connectionType.sinkID = sinkID;
-            connectionType.connectionState = connectionState;
-            connectionType.delay = delay;
-        };
-        am_MainConnection_Database_s & operator=(const am_MainConnection_Database_s & anObject)
-        {
-            am_MainConnection_s::operator=(anObject);
-            return *this;
-        };
-        am_MainConnection_Database_s & operator=(const am_MainConnection_s & anObject)
-        {
-            am_MainConnection_s::operator=(anObject);
-            return *this;
-        };
-    };
+#define AM_TYPEDEF_SUBCLASS_BEGIN(Subclass, Class) \
+        typedef struct Subclass : public Class\
+        {\
+               Subclass & operator=(const Subclass & anObject) \
+                       {\
+                               if (this != &anObject)\
+                   {\
+                                       Class::operator=(anObject);\
+                   }\
+                   return *this;\
+               };\
+               Subclass & operator=(const Class & anObject)\
+               {\
+                   if (this != &anObject)\
+                       Class::operator=(anObject);\
+                   return *this;\
+               };\
+               void getDescription (std::string & outString) const;\
+
+#define AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(Subclass, Class) \
+           typedef struct Subclass : public Class\
+           {\
+               bool reserved;\
+               Subclass():Class(), reserved(false)\
+               {};\
+               Subclass & operator=(const Subclass & anObject)\
+               {\
+                   if (this != &anObject)\
+                   {\
+                       Class::operator=(anObject);\
+                       reserved = anObject.reserved;\
+                   }\
+                   return *this;\
+               };\
+               Subclass & operator=(const Class & anObject)\
+               {\
+                   if (this != &anObject)\
+                   Class::operator=(anObject);\
+                   return *this;\
+               };\
+               void getDescription (std::string & outString) const;\
+
+#define AM_TYPEDEF_SUBCLASS_END(Typedef) } Typedef; \
+
+    AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Domain_Database_s,am_Domain_s)
+    AM_TYPEDEF_SUBCLASS_END(CAmDomain)
+
+    AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Sink_Database_s,am_Sink_s)
+       void getSinkType(am_SinkType_s & sinkType) const;\
+    AM_TYPEDEF_SUBCLASS_END(CAmSink)
+
+    AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Source_Database_s,am_Source_s)
+       void getSourceType(am_SourceType_s & sourceType) const;\
+    AM_TYPEDEF_SUBCLASS_END(CAmSource)
+
+    AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Connection_Database_s,am_Connection_s)
+    AM_TYPEDEF_SUBCLASS_END(CAmConnection)
+
+    /**
+      * The following structures extend the base structures with print capabilities.
+    */
+    AM_TYPEDEF_SUBCLASS_BEGIN(am_MainConnection_Database_s, am_MainConnection_s)
+       void getMainConnectionType(am_MainConnectionType_s & connectionType) const;\
+    AM_TYPEDEF_SUBCLASS_END(CAmMainConnection)
+
+       AM_TYPEDEF_SUBCLASS_BEGIN(am_SourceClass_Database_s, am_SourceClass_s)
+       AM_TYPEDEF_SUBCLASS_END(CAmSourceClass)
+
+       AM_TYPEDEF_SUBCLASS_BEGIN(am_SinkClass_Database_s, am_SinkClass_s)
+       AM_TYPEDEF_SUBCLASS_END(CAmSinkClass)
+
+       AM_TYPEDEF_SUBCLASS_BEGIN(am_Gateway_Database_s, am_Gateway_s)
+       AM_TYPEDEF_SUBCLASS_END(CAmGateway)
+
+       AM_TYPEDEF_SUBCLASS_BEGIN(am_Crossfader_Database_s, am_Crossfader_s)
+       AM_TYPEDEF_SUBCLASS_END(CAmCrossfader)
 
     private:
 
-    typedef std::map<am_domainID_t, am_Domain_Database_s>                                       CAmMapDomain;
-    typedef std::map<am_sourceClass_t, am_SourceClass_s>                                        CAmMapSourceClass;
-    typedef std::map<am_sinkClass_t, am_SinkClass_s>                                    CAmMapSinkClass;
-    typedef std::map<am_sinkID_t, am_Sink_Database_s>                                           CAmMapSink;
-    typedef std::map<am_sourceID_t, am_Source_Database_s>                                       CAmMapSource;
-    typedef std::map<am_gatewayID_t, am_Gateway_s>                                                      CAmMapGateway;
-    typedef std::map<am_crossfaderID_t, am_Crossfader_s>                                        CAmMapCrossfader;
-    typedef std::map<am_connectionID_t, am_Connection_Database_s>                       CAmMapConnection;
-    typedef std::map<am_mainConnectionID_t, am_MainConnection_Database_s>       CAmMapMainConnection;
-    typedef std::vector<am_SystemProperty_s>                                                            CAmVectorSystemProperties;
+    typedef AM_MAP<am_domainID_t, CAmDomain>                                    CAmMapDomain;
+    typedef AM_MAP<am_sourceClass_t, CAmSourceClass>                            CAmMapSourceClass;
+    typedef AM_MAP<am_sinkClass_t, CAmSinkClass>                                    CAmMapSinkClass;
+    typedef AM_MAP<am_sinkID_t, CAmSink>                                                        CAmMapSink;
+    typedef AM_MAP<am_sourceID_t, CAmSource>                                            CAmMapSource;
+    typedef AM_MAP<am_gatewayID_t, CAmGateway>                                          CAmMapGateway;
+    typedef AM_MAP<am_crossfaderID_t, CAmCrossfader>                    CAmMapCrossfader;
+    typedef AM_MAP<am_connectionID_t, CAmConnection>                            CAmMapConnection;
+    typedef AM_MAP<am_mainConnectionID_t, CAmMainConnection>            CAmMapMainConnection;
+    typedef std::vector<am_SystemProperty_s>                                        CAmVectorSystemProperties;
     typedef struct CAmMappedData
     {
        int16_t mCurrentDomainID;
@@ -356,27 +295,10 @@ public:
                        mGatewayMap(), mCrossfaderMap(), mConnectionMap(), mMainConnectionMap()
        {};
 
-       bool increaseID(int16_t * resultID, int16_t * sourceID, int16_t const desiredStaticID = 0, int16_t const preferedStaticIDBoundary = DYNAMIC_ID_BOUNDARY)
-       {
-               if( desiredStaticID > 0 && desiredStaticID < preferedStaticIDBoundary )
-               {
-                               *resultID = desiredStaticID;
-                               return true;
-               }
-               else if( *sourceID < mDefaultIDLimit-1 ) //SHRT_MAX or the max limit is reserved and not used!!!
-               {
-                       *resultID = (*sourceID)++;
-                       return true;
-               }
-               else
-               {
-                       *resultID = -1;
-                       return false;
-               }
-        };
+       bool increaseID(int16_t * resultID, int16_t * sourceID,
+                                               int16_t const desiredStaticID, int16_t const preferedStaticIDBoundary );
     } CAmMappedData;
 
-
     CAmMappedData mMappedData;
 
     am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const; //!< calculates a new main connection delay
index 249d6d7..b73bf56 100644 (file)
@@ -149,6 +149,8 @@ private:
     // INFO commands
     static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
     void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
+    static void infoDumpCommand(std::queue<std::string>& CmdQueue, int& filedescriptor);
+    void infoDumpCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor);
 
 private:
 
index 755ade3..8e590ee 100644 (file)
@@ -42,7 +42,7 @@ class CAmRouter;
 class CAmTelnetMenuHelper;
 
 /**
- * Implements a telnetserver that can be used to connect to the audiomanager, retrieve some information and use it. For debugginp purposes.
+ * Implements a telnetserver that can be used to connect to the audiomanager, retrieve some information and use it. For debugging purposes.
  * For example, launch a telnet session on port 6060:
  * \code telnet localhost 6060 \endcode
  *  more details can be found at the README
index 75e3872..1e72a4c 100644 (file)
@@ -29,6 +29,7 @@
 #include "CAmDatabaseObserver.h"
 #include "CAmRouter.h"
 #include "shared/CAmDltWrapper.h"
+#include <sqlite3.h>
 
 namespace am
 {
@@ -5037,4 +5038,5 @@ void CAmDatabaseHandler::createTables()
             throw std::runtime_error("CAmDatabaseHandler Could not create tables!");
     }
 }
+
 }
diff --git a/AudioManagerDaemon/src/CAmLog.cpp b/AudioManagerDaemon/src/CAmLog.cpp
new file mode 100644 (file)
index 0000000..291408f
--- /dev/null
@@ -0,0 +1,99 @@
+/**
+ * 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 CAmLog.cpp
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#include "CAmLog.h"
+
+
+void CAmLog::CAmFileLogger::generateLogFilename(std::string &result)
+{
+       static uint32_t logFileID = 1;
+       time_t rawtime;
+       time (&rawtime);
+
+       std::ostringstream stream;
+       stream << DEFAULT_LOG_FOLDER << DEFAULT_LOGFILE_PREFIX << logFileID << "_" << rawtime << DEFAULT_LOGFILE_EXT;
+       logFileID++;
+       result =  stream.str();
+}
+
+CAmLog::CAmFileLogger::~CAmFileLogger()
+{
+       if (mOutputStream)
+       {
+               std::ofstream* of = static_cast<std::ofstream*>(mOutputStream);
+               of->close();
+               DEL(mOutputStream)
+       }
+}
+
+CAmLog::CAmLog(const eCAmLogType type ):mLogType(type)
+{
+       instantiateLogger(type);
+}
+
+CAmLog::CAmLog():mLogType(eCAmLogStdout)
+{
+       instantiateLogger((const eCAmLogType)eCAmLogStdout);
+}
+
+CAmLog::~CAmLog()
+{
+       releaseLogger();
+}
+
+void CAmLog::releaseLogger()
+{
+       if(mLogger)
+               DEL(mLogger)
+}
+
+void CAmLog::instantiateLogger( const eCAmLogType type)
+{
+       if( eCAmLogStdout == type )
+               mLogger = new CAmStdOutLogger();
+       else if( eCAmLogFile == type )
+       {
+               std::string filename("");
+               CAmLog::CAmFileLogger::generateLogFilename(filename);
+               mLogger = new CAmFileLogger(filename);
+       }
+}
+
+CAmLog *CAmLog::getDefaultLog()
+{
+       static CAmLog theInstance;
+       return &theInstance;
+}
+
+void CAmLog::setLogType( const eCAmLogType type)
+{
+       if(mLogType!=type)
+       {
+               mLogType = type;
+               releaseLogger();
+               instantiateLogger(type);
+       }
+}
+
+eCAmLogType CAmLog::getLogType() const
+{
+       return mLogType;
+}
index a70e636..66b801e 100644 (file)
  *
  * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
  *
- * \file CAmDatabaseHandler.cpp
+ * \file CAmMapHandler.cpp
  * For further information see http://www.genivi.org/.
  *
  */
 
 #include "CAmMapHandler.h"
+#include <iostream>
 #include <cassert>
 #include <stdexcept>
 #include <vector>
 #include "CAmDatabaseObserver.h"
 #include "CAmRouter.h"
 #include "shared/CAmDltWrapper.h"
+#include "CAmLog.h"
 
 
 namespace am
 {
 
-template <typename TMapKeyType, class TMapObjectType> TMapObjectType const * objectWithKeyIfExistsInMap(const TMapKeyType & key, const std::map<TMapKeyType,TMapObjectType> & map)
+/* Helper functions */
+
+template <typename TMapKeyType, class TMapObjectType> TMapObjectType const * objectWithKeyIfExistsInMap(const TMapKeyType & key, const AM_MAP<TMapKeyType,TMapObjectType> & map)
 {
-       typename std::map<TMapKeyType,TMapObjectType>::const_iterator iter = map.find(key);
+       typename AM_MAP<TMapKeyType,TMapObjectType>::const_iterator iter = map.find(key);
        if( iter!=map.end() )
                return (TMapObjectType const *)&iter->second;
        return NULL;
 }
 
-template <typename TMapKeyType, class TMapObjectType> bool existsObjectWithKeyInMap(const TMapKeyType & key, const std::map<TMapKeyType,TMapObjectType> & map)
+template <typename TMapKeyType, class TMapObjectType> bool existsObjectWithKeyInMap(const TMapKeyType & key, const AM_MAP<TMapKeyType,TMapObjectType> & map)
 {
        return objectWithKeyIfExistsInMap(key, map)!=NULL;
 }
@@ -52,12 +56,12 @@ template <typename TMapKeyType, class TMapObjectType> bool existsObjectWithKeyIn
 typedef bool (*CAmCompareObjectWithValue)(const void *, const void *, void *);
 
 template <typename TMapKeyType, class TMapObjectType, class TSearchObjectType>
-TMapObjectType const * findFirstObjectMatchingCriteria(const std::map<TMapKeyType, TMapObjectType> & aMap,
+TMapObjectType const * findFirstObjectMatchingCriteria(const AM_MAP<TMapKeyType, TMapObjectType> & aMap,
                                                                                                                          const TSearchObjectType & aComparison,
                                                                                                                          CAmCompareObjectWithValue comparator,
                                                                                                                          void *context = NULL)
 {
-       typename std::map<TMapKeyType, TMapObjectType>::const_iterator it = aMap.begin();
+       typename AM_MAP<TMapKeyType, TMapObjectType>::const_iterator it = aMap.begin();
        TMapObjectType * result = NULL;
        for (; it != aMap.end(); ++it)
        {
@@ -131,17 +135,260 @@ bool compareSourceObjectsByNameAndFlag(const void *anObject, const void *aValue,
        return false;
 }
 
-template <typename TMapKeyType, class TMapObjectType>
-void makeFirstStaticEntry(uint16_t & index, uint16_t & identifier, std::map <TMapKeyType, TMapObjectType> & storageMap)
+/* Domain */
+
+void CAmMapHandler::CAmDomain::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "Domain(" << name.c_str() << ") id(" << domainID << ")" << std::endl <<
+                       "bus name(" << busname.c_str() <<
+                       ") node name(" << nodename.c_str() <<
+                       ") early(" << early <<
+                       ") domainID(" << domainID <<
+                       ") complete(" << complete <<
+                       ") state(" << state <<
+                       ") reserved(" << reserved << ")" << std::endl;
+       outString = fmt.str();
+}
+
+/* Source */
+
+void CAmMapHandler::CAmSource::getSourceType(am_SourceType_s & sourceType) const
+{
+       sourceType.name = name;
+       sourceType.sourceClassID = sourceClassID;
+       sourceType.availability = available;
+       sourceType.sourceID = sourceID;
+}
+
+void CAmMapHandler::CAmSource::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "Source(" << name.c_str() << ") id(" << sourceID << ")" << std::endl <<
+                       "sourceClassID(" << sourceClassID <<
+                       ") domainID(" << domainID <<
+                       ") visible(" << visible <<
+                       ") volume(" << volume <<
+                       ") interruptState(" << interruptState <<
+                       ") sourceState(" << sourceState <<
+                       ") reserved(" << reserved << ")" <<
+                       ") available([availability:" << available.availability << " availabilityReason:" << available.availabilityReason << "]"
+                       ") listSoundProperties (";
+                       std::for_each(listSoundProperties.begin(), listSoundProperties.end(), [&](const am_SoundProperty_s & ref) {
+                               fmt << "[type:" << ref.type << " value:" << ref.value <<"]";
+                       });
+                       fmt << ") listConnectionFormats (";
+                       std::for_each(listConnectionFormats.begin(), listConnectionFormats.end(), [&](const am_ConnectionFormat_e & ref) {
+                               fmt << "[" << ref << "]";
+                       });
+                       fmt << ") listMainSoundProperties (";
+                       std::for_each(listMainSoundProperties.begin(), listMainSoundProperties.end(), [&](const am_MainSoundProperty_s & ref) {
+                               fmt << "[type:" << ref.type << " value:" << ref.value <<"]";
+                       });
+                       fmt << ") listMainNotificationConfigurations (";
+                       std::for_each(listMainNotificationConfigurations.begin(), listMainNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) {
+                               fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]";
+                       });
+                       fmt << ") listNotificationConfigurations (";
+                       std::for_each(listNotificationConfigurations.begin(), listNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) {
+                               fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]";
+                       });
+                       fmt <<  ")" << std::endl;
+       outString = fmt.str();
+}
+
+/* Sink */
+
+void CAmMapHandler::CAmSink::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "Sink(" << name.c_str() << ") id(" << sinkID << ")" << std::endl <<
+                       "sinkClassID(" << sinkClassID <<
+                       ") domainID(" << domainID <<
+                       ") visible(" << visible <<
+                       ") volume(" << volume <<
+                       ") muteState(" << muteState <<
+                       ") mainVolume(" << mainVolume <<
+                       ") reserved(" << reserved << ")" <<
+                       ") available([availability:" << available.availability << " availabilityReason:" << available.availabilityReason << "]"
+                       ") listSoundProperties (";
+                       std::for_each(listSoundProperties.begin(), listSoundProperties.end(), [&](const am_SoundProperty_s & ref) {
+                               fmt << "[type:" << ref.type << " value:" << ref.value <<"]";
+                       });
+                       fmt << ") listConnectionFormats (";
+                       std::for_each(listConnectionFormats.begin(), listConnectionFormats.end(), [&](const am_ConnectionFormat_e & ref) {
+                               fmt << "[" << ref << "]";
+                       });
+                       fmt << ") listMainSoundProperties (";
+                       std::for_each(listMainSoundProperties.begin(), listMainSoundProperties.end(), [&](const am_MainSoundProperty_s & ref) {
+                               fmt << "[type:" << ref.type << " value:" << ref.value <<"]";
+                       });
+                       fmt << ") listMainNotificationConfigurations (";
+                       std::for_each(listMainNotificationConfigurations.begin(), listMainNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) {
+                               fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]";
+                       });
+                       fmt << ") listNotificationConfigurations (";
+                       std::for_each(listNotificationConfigurations.begin(), listNotificationConfigurations.end(), [&](const am_NotificationConfiguration_s & ref) {
+                               fmt << "[type:" << ref.type << " status:" << ref.status << " parameter:" << ref.parameter <<"]";
+                       });
+                       fmt <<  ")" << std::endl;
+       outString = fmt.str();
+}
+
+void CAmMapHandler::CAmSink::getSinkType(am_SinkType_s & sinkType) const
+{
+       sinkType.name = name;
+       sinkType.sinkID = sinkID;
+       sinkType.availability = available;
+       sinkType.muteState = muteState;
+       sinkType.volume = mainVolume;
+       sinkType.sinkClassID = sinkClassID;
+}
+
+/* Connection */
+
+void CAmMapHandler::CAmConnection::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "Connection id(" << connectionID << ") " << std::endl <<
+                       "sourceID(" << sourceID <<
+                       ") sinkID(" << sinkID <<
+                       ") delay(" << delay <<
+                       ") connectionFormat(" << connectionFormat <<
+                       ") reserved(" << reserved << ")" << std::endl;
+       outString = fmt.str();
+}
+
+/* Main Connection */
+
+void CAmMapHandler::CAmMainConnection::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "MainConnection id(" << mainConnectionID << ") " << std::endl <<
+                       "connectionState(" << connectionState <<
+                       ") sinkID(" << sinkID <<
+                       ") sourceID(" << sourceID <<
+                       ") delay(" << delay <<
+                       ") listConnectionID (";
+                       std::for_each(listConnectionID.begin(), listConnectionID.end(), [&](const am_connectionID_t & connID) {
+                               fmt << "["<< connID << "]";
+                       });
+                       fmt << ")" << std::endl;
+       outString = fmt.str();
+}
+
+void CAmMapHandler::am_MainConnection_Database_s::getMainConnectionType(am_MainConnectionType_s & connectionType) const
+{
+       connectionType.mainConnectionID = mainConnectionID;
+       connectionType.sourceID = sourceID;
+       connectionType.sinkID = sinkID;
+       connectionType.connectionState = connectionState;
+       connectionType.delay = delay;
+}
+
+/* Source Class */
+
+void CAmMapHandler::CAmSourceClass::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "Source class(" << name.c_str() << ") id(" << sourceClassID << ")\n" <<
+                       ") listClassProperties (";
+                       std::for_each(listClassProperties.begin(), listClassProperties.end(), [&](const am_ClassProperty_s & ref) {
+                               fmt << "[classProperty:" << ref.classProperty << " value:" << ref.value << "]";
+                       });
+                       fmt << ")" << std::endl;
+       outString = fmt.str();
+}
+
+/* Sink Class */
+
+void CAmMapHandler::CAmSinkClass::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "Sink class(" << name.c_str() << ") id(" << sinkClassID << ")\n" <<
+                       ") listClassProperties (";
+                       std::for_each(listClassProperties.begin(), listClassProperties.end(), [&](const am_ClassProperty_s & ref) {
+                               fmt << "[classProperty:" << ref.classProperty << " value:" << ref.value << "]";
+                       });
+                       fmt << ")" << std::endl;
+       outString = fmt.str();
+}
+
+
+/* Gateway */
+
+void CAmMapHandler::CAmGateway::getDescription (std::string & outString) const
 {
-       identifier = DYNAMIC_ID_BOUNDARY;
-       if(index!=identifier)
+       std::ostringstream fmt;
+       fmt << "Gateway(" << name.c_str() << ") id(" << gatewayID << ")\n" <<
+                       "sinkID(" << sinkID <<
+                       ") sourceID(" << sourceID <<
+                       ") domainSinkID(" << domainSinkID <<
+                       ") domainSourceID(" << domainSourceID <<
+                       ") controlDomainID(" << controlDomainID <<
+                       ") listSourceFormats (";
+                       std::for_each(listSourceFormats.begin(), listSourceFormats.end(), [&](const am_ConnectionFormat_e & ref) {
+                               fmt << "[" << ref << "]";
+                       });
+                       fmt << ") listSinkFormats (";
+                       std::for_each(listSinkFormats.begin(), listSinkFormats.end(), [&](const am_ConnectionFormat_e & ref) {
+                               fmt << "[" << ref << "]";
+                       });
+                       fmt << ") convertionMatrix (";
+                       std::for_each(convertionMatrix.begin(), convertionMatrix.end(), [&](const bool & ref) {
+                               fmt << "[" << ref << "]";
+                       });
+                       fmt << ")" << std::endl;
+       outString = fmt.str();
+}
+
+/* Crossfader */
+
+void CAmMapHandler::CAmCrossfader::getDescription (std::string & outString) const
+{
+       std::ostringstream fmt;
+       fmt << "Crossfader(" << name.c_str() << ") id(" << crossfaderID << ")\n" <<
+                       "sinkID_A(" << sinkID_A <<
+                       ") sinkID_B(" << sinkID_B <<
+                       ") sourceID(" << sourceID <<
+                       ") hotSink(" << hotSink <<
+                       ")" << std::endl;
+       outString = fmt.str();
+}
+
+template <typename TPrintMapKey,class TPrintMapObject> void CAmMapHandler::printMap (const AM_MAP<TPrintMapKey, TPrintMapObject> & t, std::ostream & output) const
+{
+       typename AM_MAP<TPrintMapKey, TPrintMapObject>::const_iterator iter = t.begin();
+       for(; iter!=t.end(); iter++)
+               print(iter->second, output);
+}
+
+template <class TPrintObject> void CAmMapHandler::print (const TPrintObject & t, std::ostream & output) const
+{
+       std::string description("");
+       t.getDescription( description );
+       output << description;
+}
+
+bool CAmMapHandler::CAmMappedData::increaseID(int16_t * resultID, int16_t * sourceID,
+                                                                                                       int16_t const desiredStaticID = 0, int16_t const preferedStaticIDBoundary = DYNAMIC_ID_BOUNDARY)
+{
+       if( desiredStaticID > 0 && desiredStaticID < preferedStaticIDBoundary )
        {
-               storageMap[identifier] = storageMap[index];
-               storageMap.erase(index);
-               index = identifier;
+               *resultID = desiredStaticID;
+               return true;
        }
-}
+       else if( *sourceID < mDefaultIDLimit-1 ) //SHRT_MAX or the max limit is reserved and not used!!!
+       {
+               *resultID = (*sourceID)++;
+               return true;
+       }
+       else
+       {
+               *resultID = -1;
+               return false;
+       }
+ }
 
 /**
  * template to converts T to std::string
@@ -217,7 +464,7 @@ int16_t CAmMapHandler::calculateDelayForRoute(const std::vector<am_connectionID_
        for (; elementIterator < listConnectionID.end(); ++elementIterator)
        {
                am_connectionID_t key = *elementIterator;
-               std::map<am_connectionID_t, am_Connection_Database_s>::const_iterator it = mMappedData.mConnectionMap.find(key);
+               AM_MAP<am_connectionID_t, am_Connection_Database_s>::const_iterator it = mMappedData.mConnectionMap.find(key);
                if (it!=mMappedData.mConnectionMap.end())
                {
                        int16_t temp_delay = it->second.delay;
@@ -477,48 +724,23 @@ am_Error_e CAmMapHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_ga
     return (E_OK);
 }
 
-void CAmMapHandler::printSinks()
-{
-       CAmMapSink::const_iterator iter = mMappedData.mSinkMap.begin();
-       for(; iter!=mMappedData.mSinkMap.end(); iter++)
-       {
-               am_Sink_Database_s theItem = iter->second;
-               theItem.print();
-       }
-}
-
-void CAmMapHandler::printSinkClasses()
-{
-       CAmMapSinkClass::const_iterator iter = mMappedData.mSinkClassesMap.begin();
-       for(; iter!=mMappedData.mSinkClassesMap.end(); iter++)
-       {
-               am_SinkClass_s theItem = iter->second;
-               printf("\n CHECK SOURCE %d" , theItem.sinkClassID);
-               printf("\n %s ", theItem.name.c_str() );
-               printf("\n\n");
-       }
-}
-
-void CAmMapHandler::printSources()
-{
-       CAmMapSource::const_iterator iter = mMappedData.mSourceMap.begin();
-       for(; iter!=mMappedData.mSourceMap.end(); iter++)
-       {
-               am_Source_Database_s theItem = iter->second;
-               theItem.print();
-       }
-}
-
-void CAmMapHandler::printSourceClasses()
+void CAmMapHandler::dump( std::ostream & output )
 {
-       CAmMapSourceClass::const_iterator iter = mMappedData.mSourceClassesMap.begin();
-       for(; iter!=mMappedData.mSourceClassesMap.end(); iter++)
-       {
-               am_SourceClass_s theItem = iter->second;
-               printf("\n CHECK SOURCE %d" , theItem.sourceClassID);
-               printf("\n %s ", theItem.name.c_str() );
-               printf("\n\n");
-       }
+       output << std::endl << "****************** DUMP START ******************" << std::endl;
+       printMap(mMappedData.mDomainMap, output);
+       printMap(mMappedData.mSourceMap, output);
+       printMap(mMappedData.mSinkMap, output);
+       printMap(mMappedData.mSourceClassesMap, output);
+       printMap(mMappedData.mSinkClassesMap, output);
+       printMap(mMappedData.mConnectionMap, output);
+       printMap(mMappedData.mMainConnectionMap, output);
+       printMap(mMappedData.mCrossfaderMap, output);
+       printMap(mMappedData.mGatewayMap, output);
+       CAmVectorSystemProperties::const_iterator iter = mMappedData.mSystemProperties.begin();
+       output << "System properties" << "\n";
+       for(; iter!=mMappedData.mSystemProperties.end(); iter++)
+               output << "[type:" << iter->type << " value:" << iter->value << "]";
+       output << std::endl << "****************** DUMP END ******************" << std::endl;
 }
 
 bool CAmMapHandler::insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
@@ -580,7 +802,6 @@ am_Error_e CAmMapHandler::enterSourceDB(const am_Source_s & sourceData, am_sourc
     if ( isFirstStatic )
     {
       //if the first static sink is entered, we need to set it onto the boundary if needed
-//     makeFirstStaticEntry(temp_SourceIndex, temp_SourceID, mMappedData.mSinkMap); //Not necessary anymore
         mFirstStaticSource = false;
     }
     mMappedData.mSourceMap[temp_SourceIndex].sourceID = temp_SourceID;
@@ -660,7 +881,6 @@ am_Error_e CAmMapHandler::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_
        //if the ID is not created, we add it to the query
        if (sinkClass.sinkClassID == 0 && mFirstStaticSinkClass)
        {
-//             makeFirstStaticEntry(temp_SinkClassIndex, temp_SinkClassID, mMappedData.mSinkClassesMap);
                mFirstStaticSinkClass = false;
        }
        mMappedData.mSinkClassesMap[temp_SinkClassIndex].sinkClassID = temp_SinkClassID;
@@ -714,7 +934,6 @@ am_Error_e CAmMapHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID, c
        //if the ID is not created, we add it to the query
        if (sourceClass.sourceClassID == 0 && mFirstStaticSourceClass)
        {
-//             makeFirstStaticEntry(temp_SourceClassIndex, temp_SourceClassID, mMappedData.mSourceClassesMap);
                mFirstStaticSinkClass = false;
        }
        mMappedData.mSourceClassesMap[temp_SourceClassIndex].sourceClassID = temp_SourceClassID;
@@ -1246,7 +1465,7 @@ am_Error_e CAmMapHandler::getListSinksOfDomain(const am_domainID_t domainID, std
         return (E_NON_EXISTENT);
     }
 
-    std::map<am_sinkID_t, am_Sink_Database_s>::const_iterator elementIterator = mMappedData.mSinkMap.begin();
+    AM_MAP<am_sinkID_t, am_Sink_Database_s>::const_iterator elementIterator = mMappedData.mSinkMap.begin();
        for (;elementIterator != mMappedData.mSinkMap.end(); ++elementIterator)
        {
                if (0==elementIterator->second.reserved && domainID==elementIterator->second.domainID)
@@ -2256,7 +2475,7 @@ am_Error_e CAmMapHandler::changeSourceDB(const am_sourceID_t sourceID, const am_
     std::vector<am_MainSoundProperty_s> listMainSoundPropertiesOut(listMainSoundProperties);
     //check if sinkClass needs to be changed
 
-       std::map<am_sourceID_t, am_Source_Database_s>::iterator iter = mMappedData.mSourceMap.begin();
+       AM_MAP<am_sourceID_t, am_Source_Database_s>::iterator iter = mMappedData.mSourceMap.begin();
        for(; iter!=mMappedData.mSourceMap.end(); ++iter)
        {
                if( iter->second.sourceID == sourceID )
@@ -2314,7 +2533,7 @@ am_Error_e CAmMapHandler::changeSinkDB(const am_sinkID_t sinkID, const am_sinkCl
         return (E_NON_EXISTENT);
     }
 
-       std::map<am_sinkID_t, am_Sink_Database_s>::iterator iter = mMappedData.mSinkMap.begin();
+       AM_MAP<am_sinkID_t, am_Sink_Database_s>::iterator iter = mMappedData.mSinkMap.begin();
        for(; iter!=mMappedData.mSinkMap.end(); ++iter)
        {
                if( iter->second.sinkID == sinkID )
index d8efd6a..3898e50 100644 (file)
@@ -105,6 +105,7 @@ void CAmTelnetMenuHelper::createCommandMaps()
     // Info comands
     mInfoCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
     mInfoCommands.insert(std::make_pair("sysprop", sCommandPrototypeInfo("show all systemproperties", &CAmTelnetMenuHelper::infoSystempropertiesCommand)));
+    mInfoCommands.insert(std::make_pair("dump", sCommandPrototypeInfo("create a database dump of currently used data", &CAmTelnetMenuHelper::infoDumpCommand)));
     mInfoCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
     mInfoCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
 }
@@ -741,6 +742,14 @@ void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string>& C
 }
 
 /****************************************************************************/
+void CAmTelnetMenuHelper::infoDumpCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
+/****************************************************************************/
+{
+    instance->infoDumpCommandExec(CmdQueue, filedescriptor);
+}
+
+
+/****************************************************************************/
 void CAmTelnetMenuHelper::setVolumeStep(std::queue<std::string>& CmdQueue, int& filedescriptor)
 /****************************************************************************/
 {
@@ -933,6 +942,21 @@ void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string
 }
 
 /****************************************************************************/
+void CAmTelnetMenuHelper::infoDumpCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor)
+/****************************************************************************/
+{
+    (void) (CmdQueue);
+
+    std::stringstream *pOutput = new std::stringstream();
+
+    mpDatabasehandler->dump(*pOutput);
+
+    sendTelnetLine(filedescriptor, *pOutput);
+
+    delete pOutput;
+}
+
+/****************************************************************************/
 void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string>& CmdQueue, int& filedescriptor)
 /****************************************************************************/
 {
index 8ad0ecc..644b0a6 100755 (executable)
@@ -143,7 +143,7 @@ void CAmTelnetServer::connectSocket(const pollfd pfd, const sh_pollHandle_t hand
     short event = 0;
     event |= POLLIN;
 
-    //aded the filedescriptor to the sockethandler and register the callbacks for receiving the data
+    //add the filedescriptor to the sockethandler and register the callbacks for receiving the data
     mpSocketHandler->addFDPoll(connection.filedescriptor, event, NULL, &telnetReceiveFiredCB, &telnetCheckCB, &telnetDispatchCB, NULL, connection.handle);
     mListConnections.push_back(connection);
 }
index c1f0cce..d034b54 100644 (file)
@@ -129,6 +129,8 @@ void CAmMapHandlerTest::createMainConnectionSetup()
             equal = equal && (listIterator->connectionState == mainConnection.connectionState) && (listIterator->sinkID == mainConnection.sinkID) && (listIterator->sourceID == mainConnection.sourceID) && (listIterator->delay == mainConnection.delay) && (std::equal(listIterator->listConnectionID.begin(), listIterator->listConnectionID.end(), connectionList.begin()));
         }
     }
+//    pDatabaseHandler.dump();
+
     ASSERT_EQ(true, equal);
 }
 
diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp
new file mode 100644 (file)
index 0000000..4c55c34
--- /dev/null
@@ -0,0 +1,1955 @@
+/**
+ * Copyright (C) 2012, BMW AG
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *
+ * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
+ *
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#include "CAmRouterMapTest.h"
+#include <string.h>
+#include "shared/CAmDltWrapper.h"
+
+using namespace am;
+using namespace testing;
+
+CAmRouterMapTest::CAmRouterMapTest() :
+        plistRoutingPluginDirs(), //
+        plistCommandPluginDirs(), //
+        pSocketHandler(), //
+        pControlSender(), //
+               pDatabaseHandler(),
+        pRouter(&pDatabaseHandler, &pControlSender), //
+        pRoutingSender(plistRoutingPluginDirs), //
+        pCommandSender(plistCommandPluginDirs), //
+        pMockInterface(), //
+        pMockControlInterface(), //
+        pRoutingInterfaceBackdoor(), //
+        pCommandInterfaceBackdoor(), //
+        pControlInterfaceBackdoor(), //
+        pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter), //
+        pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler)
+{
+    pDatabaseHandler.registerObserver(&pObserver);
+    pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface);
+    pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface);
+}
+
+CAmRouterMapTest::~CAmRouterMapTest()
+{
+
+}
+
+void CAmRouterMapTest::SetUp()
+{
+    logInfo("Routing Test started ");
+}
+
+void CAmRouterMapTest::TearDown()
+{
+}
+
+ACTION(returnConnectionFormat){
+arg4=arg3;
+}
+
+//test that checks just sinks and source in a domain but connectionformats do not match
+TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats)
+{
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1;
+    am_domainID_t domainID1;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+
+    am_Source_s source;
+    am_sourceID_t sourceID;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+
+    am_Sink_s sink;
+    am_sinkID_t sinkID;
+
+    sink.domainID = domainID1;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+
+    hopp1.sinkID = sinkID;
+    hopp1.sourceID = sourceID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
+
+}
+
+//test that checks just sinks and source in a domain
+TEST_F(CAmRouterMapTest,simpleRoute2withDomain)
+{
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1;
+    am_domainID_t domainID1;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+
+    am_Source_s source;
+    am_sourceID_t sourceID;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+
+    am_Sink_s sink;
+    am_sinkID_t sinkID;
+
+    sink.domainID = domainID1;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+
+    hopp1.sinkID = sinkID;
+    hopp1.sourceID = sourceID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+
+}
+
+//test that checks just 2 domains, one sink one source with only one connection format each
+TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree)
+{
+
+
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2;
+    am_domainID_t domainID1, domainID2;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+
+    am_Source_s source, gwSource;
+    am_sourceID_t sourceID, gwSourceID;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+
+    am_Sink_s sink, gwSink;
+    am_sinkID_t sinkID, gwSinkID;
+
+    sink.domainID = domainID2;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+
+    am_Gateway_s gateway;
+    am_gatewayID_t gatewayID;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+
+    hopp1.sinkID = gwSinkID;
+    hopp1.sourceID = sourceID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sinkID = sinkID;
+    hopp2.sourceID = gwSourceID;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+
+}
+
+//test that checks just 2 domains, one sink one source with only one connection format each
+TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree)
+{
+
+
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2;
+    am_domainID_t domainID1, domainID2;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+
+    am_Source_s source, gwSource;
+    am_sourceID_t sourceID, gwSourceID;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+
+    am_Sink_s sink, gwSink;
+    am_sinkID_t sinkID, gwSinkID;
+
+    sink.domainID = domainID2;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+
+    am_Gateway_s gateway;
+    am_gatewayID_t gatewayID;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+
+    hopp1.sinkID = gwSinkID;
+    hopp1.sourceID = sourceID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sinkID = sinkID;
+    hopp2.sourceID = gwSourceID;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    am_Connection_s connection,connection1;
+    am_connectionID_t id1,id2;
+    connection.sourceID=sourceID;
+    connection.sinkID=gwSinkID;
+    connection.connectionFormat=CF_GENIVI_ANALOG;
+    connection.connectionID=0;
+    connection1.sourceID=gwSourceID;
+    connection1.sinkID=sinkID;
+    connection1.connectionFormat=CF_GENIVI_ANALOG;
+    connection1.connectionID=0;
+
+    ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,id1));
+    ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2));
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+//test that checks just 2 domains, with gateway for each direction (possible circular route)
+TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree)
+{
+
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2;
+    am_domainID_t domainID1, domainID2;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+
+    am_Source_s source, gwSource, gwSource2;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID2;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource2.domainID = domainID1;
+    gwSource2.name = "gwsource2";
+    gwSource2.sourceState = SS_ON;
+    gwSource2.sourceID = 0;
+    gwSource2.sourceClassID = 5;
+    gwSource2.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2));
+
+    am_Sink_s sink, gwSink, gwSink2;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID2;
+
+    sink.domainID = domainID2;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSink2.domainID = domainID2;
+    gwSink2.name = "gwSink2";
+    gwSink2.sinkID = 0;
+    gwSink2.sinkClassID = 5;
+    gwSink2.muteState = MS_MUTED;
+    gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2));
+
+    am_Gateway_s gateway, gateway2;
+    am_gatewayID_t gatewayID, gatewayID2;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    gateway2.controlDomainID = domainID1;
+    gateway2.gatewayID = 0;
+    gateway2.sinkID = gwSinkID2;
+    gateway2.sourceID = gwSourceID2;
+    gateway2.domainSourceID = domainID1;
+    gateway2.domainSinkID = domainID2;
+    gateway2.listSinkFormats = gwSink2.listConnectionFormats;
+    gateway2.listSourceFormats = gwSource2.listConnectionFormats;
+    gateway2.convertionMatrix.push_back(true);
+    gateway2.name = "gateway2";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+
+    hopp1.sinkID = gwSinkID;
+    hopp1.sourceID = sourceID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sinkID = sinkID;
+    hopp2.sourceID = gwSourceID;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+//test that checks 3 domains, one sink one source, longer lists of connectionformats.
+TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2)
+{
+
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2, domain3;
+    am_domainID_t domainID1, domainID2, domainID3;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+    domain3.domainID = 0;
+    domain3.name = "domain3";
+    domain3.busname = "domain3bus";
+    domain3.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3));
+
+    am_Source_s source, gwSource, gwSource1;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID1;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO);
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource1.domainID = domainID3;
+    gwSource1.name = "gwsource2";
+    gwSource1.sourceState = SS_ON;
+    gwSource1.sourceID = 0;
+    gwSource1.sourceClassID = 5;
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1));
+
+    am_Sink_s sink, gwSink, gwSink1;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID1;
+
+    sink.domainID = domainID3;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink1.domainID = domainID2;
+    gwSink1.name = "gwSink1";
+    gwSink1.sinkID = 0;
+    gwSink1.sinkClassID = 5;
+    gwSink1.muteState = MS_MUTED;
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1));
+
+    am_Gateway_s gateway, gateway1;
+    am_gatewayID_t gatewayID, gatewayID1;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(true);
+    gateway.convertionMatrix.push_back(true);
+    gateway.convertionMatrix.push_back(false);
+    gateway.name = "gateway";
+
+    gateway1.controlDomainID = domainID2;
+    gateway1.gatewayID = 0;
+    gateway1.sinkID = gwSinkID1;
+    gateway1.sourceID = gwSourceID1;
+    gateway1.domainSourceID = domainID3;
+    gateway1.domainSinkID = domainID2;
+    gateway1.listSinkFormats = gwSink1.listConnectionFormats;
+    gateway1.listSourceFormats = gwSource1.listConnectionFormats;
+    gateway1.convertionMatrix.push_back(false);
+    gateway1.convertionMatrix.push_back(false);
+    gateway1.convertionMatrix.push_back(false);
+    gateway1.convertionMatrix.push_back(true);
+    gateway1.name = "gateway1";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+    am_RoutingElement_s hopp3;
+
+    hopp1.sourceID = sourceID;
+    hopp1.sinkID = gwSinkID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[1];
+
+    hopp2.sourceID = gwSourceID;
+    hopp2.sinkID = gwSinkID1;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = gwSink1.listConnectionFormats[1];
+
+    hopp3.sourceID = gwSourceID1;
+    hopp3.sinkID = sinkID;
+    hopp3.domainID = domainID3;
+    hopp3.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+    listRoutingElements.push_back(hopp3);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+//test that checks 3 domains, one sink one source, longer lists of connectionformats.
+TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1)
+{
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2, domain3;
+    am_domainID_t domainID1, domainID2, domainID3;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+    domain3.domainID = 0;
+    domain3.name = "domain3";
+    domain3.busname = "domain3bus";
+    domain3.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3));
+
+    am_Source_s source, gwSource, gwSource1;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID1;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO);
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource1.domainID = domainID3;
+    gwSource1.name = "gwsource2";
+    gwSource1.sourceState = SS_ON;
+    gwSource1.sourceID = 0;
+    gwSource1.sourceClassID = 5;
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1));
+
+    am_Sink_s sink, gwSink, gwSink1;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID1;
+
+    sink.domainID = domainID3;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink1.domainID = domainID2;
+    gwSink1.name = "gwSink1";
+    gwSink1.sinkID = 0;
+    gwSink1.sinkClassID = 5;
+    gwSink1.muteState = MS_MUTED;
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1));
+
+    am_Gateway_s gateway, gateway1;
+    am_gatewayID_t gatewayID, gatewayID1;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(true);
+    gateway.convertionMatrix.push_back(false);
+    gateway.name = "gateway";
+
+    gateway1.controlDomainID = domainID2;
+    gateway1.gatewayID = 0;
+    gateway1.sinkID = gwSinkID1;
+    gateway1.sourceID = gwSourceID1;
+    gateway1.domainSourceID = domainID3;
+    gateway1.domainSinkID = domainID2;
+    gateway1.listSinkFormats = gwSink1.listConnectionFormats;
+    gateway1.listSourceFormats = gwSource1.listConnectionFormats;
+    gateway1.convertionMatrix.push_back(true);
+    gateway1.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+    am_RoutingElement_s hopp3;
+
+    hopp1.sourceID = sourceID;
+    hopp1.sinkID = gwSinkID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sourceID = gwSourceID;
+    hopp2.sinkID = gwSinkID1;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = gwSink1.listConnectionFormats[0];
+
+    hopp3.sourceID = gwSourceID1;
+    hopp3.sinkID = sinkID;
+    hopp3.domainID = domainID3;
+    hopp3.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+    listRoutingElements.push_back(hopp3);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+
+//test that checks 3 domains, one sink one source, longer lists of connectionformats.
+TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats)
+{
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2, domain3;
+    am_domainID_t domainID1, domainID2, domainID3;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+    domain3.domainID = 0;
+    domain3.name = "domain3";
+    domain3.busname = "domain3bus";
+    domain3.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3));
+
+    am_Source_s source, gwSource, gwSource1;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID1;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource1.domainID = domainID3;
+    gwSource1.name = "gwsource2";
+    gwSource1.sourceState = SS_ON;
+    gwSource1.sourceID = 0;
+    gwSource1.sourceClassID = 5;
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1));
+
+    am_Sink_s sink, gwSink, gwSink1;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID1;
+
+    sink.domainID = domainID3;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink1.domainID = domainID2;
+    gwSink1.name = "gwSink1";
+    gwSink1.sinkID = 0;
+    gwSink1.sinkClassID = 5;
+    gwSink1.muteState = MS_MUTED;
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1));
+
+    am_Gateway_s gateway, gateway1;
+    am_gatewayID_t gatewayID, gatewayID1;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(false);
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    gateway1.controlDomainID = domainID2;
+    gateway1.gatewayID = 0;
+    gateway1.sinkID = gwSinkID1;
+    gateway1.sourceID = gwSourceID1;
+    gateway1.domainSourceID = domainID3;
+    gateway1.domainSinkID = domainID2;
+    gateway1.listSinkFormats = gwSink1.listConnectionFormats;
+    gateway1.listSourceFormats = gwSource1.listConnectionFormats;
+    gateway1.convertionMatrix.push_back(true);
+    gateway1.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+    am_RoutingElement_s hopp3;
+
+    hopp1.sourceID = sourceID;
+    hopp1.sinkID = gwSinkID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[1];
+
+    hopp2.sourceID = gwSourceID;
+    hopp2.sinkID = gwSinkID1;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = gwSink1.listConnectionFormats[0];
+
+    hopp3.sourceID = gwSourceID1;
+    hopp3.sinkID = sinkID;
+    hopp3.domainID = domainID3;
+    hopp3.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+    listRoutingElements.push_back(hopp3);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+
+//test that checks 4 domains, one sink and one source but there are 2 routes because there are 2 gateways
+TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes)
+{
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2, domain3, domain4;
+    am_domainID_t domainID1, domainID2, domainID3, domainID4;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+    domain3.domainID = 0;
+    domain3.name = "domain3";
+    domain3.busname = "domain3bus";
+    domain3.state = DS_CONTROLLED;
+    domain4.domainID = 0;
+    domain4.name = "domain4";
+    domain4.busname = "domain4bus";
+    domain4.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4));
+
+    am_Source_s source, gwSource, gwSource1, gwSource2, gwSource3;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2, gwSourceID3;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource1.domainID = domainID3;
+    gwSource1.name = "gwsource2";
+    gwSource1.sourceState = SS_ON;
+    gwSource1.sourceID = 0;
+    gwSource1.sourceClassID = 5;
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource2.domainID = domainID4;
+    gwSource2.name = "gwsource3";
+    gwSource2.sourceState = SS_OFF;
+    gwSource2.sourceID = 0;
+    gwSource2.sourceClassID = 5;
+    gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+
+    gwSource3.domainID = domainID3;
+    gwSource3.name = "gwsource4";
+    gwSource3.sourceState = SS_OFF;
+    gwSource3.sourceID = 0;
+    gwSource3.sourceClassID = 5;
+    gwSource3.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource3,gwSourceID3));
+
+    am_Sink_s sink, gwSink, gwSink1, gwSink2, gwSink3;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2, gwSinkID3;
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink1.domainID = domainID2;
+    gwSink1.name = "gwSink1";
+    gwSink1.sinkID = 0;
+    gwSink1.sinkClassID = 5;
+    gwSink1.muteState = MS_MUTED;
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSink2.domainID = domainID3;
+    gwSink2.name = "gwSink2";
+    gwSink2.sinkID = 0;
+    gwSink2.sinkClassID = 5;
+    gwSink2.muteState = MS_MUTED;
+    gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink3.domainID = domainID2;
+    gwSink3.name = "gwSink3";
+    gwSink3.sinkID = 0;
+    gwSink3.sinkClassID = 5;
+    gwSink3.muteState = MS_MUTED;
+    gwSink3.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    sink.domainID = domainID4;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink3,gwSinkID3));
+
+    am_Gateway_s gateway, gateway1, gateway2, gateway3;
+    am_gatewayID_t gatewayID, gatewayID1, gatewayID2, gatewayID3;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    gateway1.controlDomainID = domainID2;
+    gateway1.gatewayID = 0;
+    gateway1.sinkID = gwSinkID1;
+    gateway1.sourceID = gwSourceID1;
+    gateway1.domainSourceID = domainID3;
+    gateway1.domainSinkID = domainID2;
+    gateway1.listSinkFormats = gwSink1.listConnectionFormats;
+    gateway1.listSourceFormats = gwSource1.listConnectionFormats;
+    gateway1.convertionMatrix.push_back(true);
+    gateway1.name = "gateway1";
+
+    gateway2.controlDomainID = domainID3;
+    gateway2.gatewayID = 0;
+    gateway2.sinkID = gwSinkID2;
+    gateway2.sourceID = gwSourceID2;
+    gateway2.domainSourceID = domainID4;
+    gateway2.domainSinkID = domainID3;
+    gateway2.listSinkFormats = gwSink2.listConnectionFormats;
+    gateway2.listSourceFormats = gwSource2.listConnectionFormats;
+    gateway2.convertionMatrix.push_back(true);
+    gateway2.name = "gateway2";
+
+    gateway3.controlDomainID = domainID2;
+    gateway3.gatewayID = 0;
+    gateway3.sinkID = gwSinkID3;
+    gateway3.sourceID = gwSourceID3;
+    gateway3.domainSourceID = domainID3;
+    gateway3.domainSinkID = domainID2;
+    gateway3.listSinkFormats = gwSink3.listConnectionFormats;
+    gateway3.listSourceFormats = gwSource3.listConnectionFormats;
+    gateway3.convertionMatrix.push_back(true);
+    gateway3.name = "gateway3";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway3,gatewayID3));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements, listRoutingElements1;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+    am_RoutingElement_s hopp3;
+    am_RoutingElement_s hopp4;
+    am_RoutingElement_s hopp2alt;
+    am_RoutingElement_s hopp3alt;
+
+    hopp1.sourceID = sourceID;
+    hopp1.sinkID = gwSinkID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sourceID = gwSourceID;
+    hopp2.sinkID = gwSinkID1;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = gwSink1.listConnectionFormats[0];
+
+    hopp3.sourceID = gwSourceID1;
+    hopp3.sinkID = gwSinkID2;
+    hopp3.domainID = domainID3;
+    hopp3.connectionFormat = gwSink2.listConnectionFormats[0];
+
+    hopp4.sourceID = gwSourceID2;
+    hopp4.sinkID = sinkID;
+    hopp4.domainID = domainID4;
+    hopp4.connectionFormat = sink.listConnectionFormats[0];
+
+    hopp2alt.sourceID = gwSourceID;
+    hopp2alt.sinkID = gwSinkID3;
+    hopp2alt.domainID = domainID2;
+    hopp2alt.connectionFormat = gwSink3.listConnectionFormats[0];
+
+    hopp3alt.sourceID = gwSourceID3;
+    hopp3alt.sinkID = gwSinkID2;
+    hopp3alt.domainID = domainID3;
+    hopp3alt.connectionFormat = gwSink2.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+    listRoutingElements.push_back(hopp3);
+    listRoutingElements.push_back(hopp4);
+    listRoutingElements1.push_back(hopp1);
+    listRoutingElements1.push_back(hopp2alt);
+    listRoutingElements1.push_back(hopp3alt);
+    listRoutingElements1.push_back(hopp4);
+
+    am_Route_s compareRoute, compareRoute1;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    compareRoute1.route = listRoutingElements1;
+    compareRoute1.sinkID = sinkID;
+    compareRoute1.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(2), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+    ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1]));
+}
+
+//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit.
+TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection)
+{
+
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2, domain3;
+    am_domainID_t domainID1, domainID2, domainID3;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+    domain3.domainID = 0;
+    domain3.name = "domain3";
+    domain3.busname = "domain3bus";
+    domain3.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3));
+
+    am_Source_s source, gwSource, gwSource1;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID1;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource1.domainID = domainID3;
+    gwSource1.name = "gwsource2";
+    gwSource1.sourceState = SS_ON;
+    gwSource1.sourceID = 0;
+    gwSource1.sourceClassID = 5;
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1));
+
+    am_Sink_s sink, gwSink, gwSink1;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID1;
+
+    sink.domainID = domainID3;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink1.domainID = domainID2;
+    gwSink1.name = "gwSink1";
+    gwSink1.sinkID = 0;
+    gwSink1.sinkClassID = 5;
+    gwSink1.muteState = MS_MUTED;
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1));
+
+    am_Gateway_s gateway, gateway1;
+    am_gatewayID_t gatewayID, gatewayID1;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    gateway1.controlDomainID = domainID2;
+    gateway1.gatewayID = 0;
+    gateway1.sinkID = gwSinkID1;
+    gateway1.sourceID = gwSourceID1;
+    gateway1.domainSourceID = domainID3;
+    gateway1.domainSinkID = domainID2;
+    gateway1.listSinkFormats = gwSink1.listConnectionFormats;
+    gateway1.listSourceFormats = gwSource1.listConnectionFormats;
+    gateway1.convertionMatrix.push_back(true);
+    gateway1.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+    am_RoutingElement_s hopp3;
+
+    hopp1.sourceID = sourceID;
+    hopp1.sinkID = gwSinkID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sourceID = gwSourceID;
+    hopp2.sinkID = gwSinkID1;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = gwSink1.listConnectionFormats[0];
+
+    hopp3.sourceID = gwSourceID1;
+    hopp3.sinkID = sinkID;
+    hopp3.domainID = domainID3;
+    hopp3.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+    listRoutingElements.push_back(hopp3);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
+}
+//test that checks just 2 domains, one sink one source with only one connection format each
+TEST_F(CAmRouterMapTest,simpleRoute2Domains)
+{
+
+
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2;
+    am_domainID_t domainID1, domainID2;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+
+    am_Source_s source, gwSource;
+    am_sourceID_t sourceID, gwSourceID;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+
+    am_Sink_s sink, gwSink;
+    am_sinkID_t sinkID, gwSinkID;
+
+    sink.domainID = domainID2;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+
+    am_Gateway_s gateway;
+    am_gatewayID_t gatewayID;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+
+    hopp1.sinkID = gwSinkID;
+    hopp1.sourceID = sourceID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sinkID = sinkID;
+    hopp2.sourceID = gwSourceID;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+
+}
+
+//test that checks just 2 domains, one sink one source but the connectionformat of source
+TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats)
+{
+
+
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2;
+    am_domainID_t domainID1, domainID2;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+
+    am_Source_s source, gwSource;
+    am_sourceID_t sourceID, gwSourceID;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+
+    am_Sink_s sink, gwSink;
+    am_sinkID_t sinkID, gwSinkID;
+
+    sink.domainID = domainID2;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+
+    am_Gateway_s gateway;
+    am_gatewayID_t gatewayID;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+
+    hopp1.sinkID = gwSinkID;
+    hopp1.sourceID = sourceID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sinkID = sinkID;
+    hopp2.sourceID = gwSourceID;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(0),  listRoutes.size());
+}
+
+//test that checks 3 domains, one sink one source.
+TEST_F(CAmRouterMapTest,simpleRoute3Domains)
+{
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2, domain3;
+    am_domainID_t domainID1, domainID2, domainID3;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+    domain3.domainID = 0;
+    domain3.name = "domain3";
+    domain3.busname = "domain3bus";
+    domain3.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3));
+
+    am_Source_s source, gwSource, gwSource1;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID1;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource1.domainID = domainID3;
+    gwSource1.name = "gwsource2";
+    gwSource1.sourceState = SS_ON;
+    gwSource1.sourceID = 0;
+    gwSource1.sourceClassID = 5;
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1));
+
+    am_Sink_s sink, gwSink, gwSink1;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID1;
+
+    sink.domainID = domainID3;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink1.domainID = domainID2;
+    gwSink1.name = "gwSink1";
+    gwSink1.sinkID = 0;
+    gwSink1.sinkClassID = 5;
+    gwSink1.muteState = MS_MUTED;
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1));
+
+    am_Gateway_s gateway, gateway1;
+    am_gatewayID_t gatewayID, gatewayID1;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    gateway1.controlDomainID = domainID2;
+    gateway1.gatewayID = 0;
+    gateway1.sinkID = gwSinkID1;
+    gateway1.sourceID = gwSourceID1;
+    gateway1.domainSourceID = domainID3;
+    gateway1.domainSinkID = domainID2;
+    gateway1.listSinkFormats = gwSink1.listConnectionFormats;
+    gateway1.listSourceFormats = gwSource1.listConnectionFormats;
+    gateway1.convertionMatrix.push_back(true);
+    gateway1.name = "gateway";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+    am_RoutingElement_s hopp3;
+
+    hopp1.sourceID = sourceID;
+    hopp1.sinkID = gwSinkID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sourceID = gwSourceID;
+    hopp2.sinkID = gwSinkID1;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = gwSink1.listConnectionFormats[0];
+
+    hopp3.sourceID = gwSourceID1;
+    hopp3.sinkID = sinkID;
+    hopp3.domainID = domainID3;
+    hopp3.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+    listRoutingElements.push_back(hopp3);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+//test that checks 4 domains, one sink and one source.
+TEST_F(CAmRouterMapTest,simpleRoute4Domains)
+{
+    EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+    //initialize 2 domains
+    am_Domain_s domain1, domain2, domain3, domain4;
+    am_domainID_t domainID1, domainID2, domainID3, domainID4;
+
+    domain1.domainID = 0;
+    domain1.name = "domain1";
+    domain1.busname = "domain1bus";
+    domain1.state = DS_CONTROLLED;
+    domain2.domainID = 0;
+    domain2.name = "domain2";
+    domain2.busname = "domain2bus";
+    domain2.state = DS_CONTROLLED;
+    domain3.domainID = 0;
+    domain3.name = "domain3";
+    domain3.busname = "domain3bus";
+    domain3.state = DS_CONTROLLED;
+    domain4.domainID = 0;
+    domain4.name = "domain4";
+    domain4.busname = "domain4bus";
+    domain4.state = DS_CONTROLLED;
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4));
+
+    am_Source_s source, gwSource, gwSource1, gwSource2;
+    am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2;
+
+    source.domainID = domainID1;
+    source.name = "source1";
+    source.sourceState = SS_ON;
+    source.sourceID = 0;
+    source.sourceClassID = 5;
+    source.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource.domainID = domainID2;
+    gwSource.name = "gwsource1";
+    gwSource.sourceState = SS_ON;
+    gwSource.sourceID = 0;
+    gwSource.sourceClassID = 5;
+    gwSource.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSource1.domainID = domainID3;
+    gwSource1.name = "gwsource2";
+    gwSource1.sourceState = SS_ON;
+    gwSource1.sourceID = 0;
+    gwSource1.sourceClassID = 5;
+    gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSource2.domainID = domainID4;
+    gwSource2.name = "gwsource3";
+    gwSource2.sourceState = SS_OFF;
+    gwSource2.sourceID = 0;
+    gwSource2.sourceClassID = 5;
+    gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2));
+
+    am_Sink_s sink, gwSink, gwSink1, gwSink2;
+    am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2;
+
+    gwSink.domainID = domainID1;
+    gwSink.name = "gwSink";
+    gwSink.sinkID = 0;
+    gwSink.sinkClassID = 5;
+    gwSink.muteState = MS_MUTED;
+    gwSink.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    gwSink1.domainID = domainID2;
+    gwSink1.name = "gwSink1";
+    gwSink1.sinkID = 0;
+    gwSink1.sinkClassID = 5;
+    gwSink1.muteState = MS_MUTED;
+    gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
+
+    gwSink2.domainID = domainID3;
+    gwSink2.name = "gwSink2";
+    gwSink2.sinkID = 0;
+    gwSink2.sinkClassID = 5;
+    gwSink2.muteState = MS_MUTED;
+    gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO);
+
+    sink.domainID = domainID4;
+    sink.name = "sink1";
+    sink.sinkID = 0;
+    sink.sinkClassID = 5;
+    sink.muteState = MS_MUTED;
+    sink.listConnectionFormats.push_back(CF_GENIVI_STEREO);
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2));
+
+    am_Gateway_s gateway, gateway1, gateway2;
+    am_gatewayID_t gatewayID, gatewayID1, gatewayID2;
+
+    gateway.controlDomainID = domainID1;
+    gateway.gatewayID = 0;
+    gateway.sinkID = gwSinkID;
+    gateway.sourceID = gwSourceID;
+    gateway.domainSourceID = domainID2;
+    gateway.domainSinkID = domainID1;
+    gateway.listSinkFormats = gwSink.listConnectionFormats;
+    gateway.listSourceFormats = gwSource.listConnectionFormats;
+    gateway.convertionMatrix.push_back(true);
+    gateway.name = "gateway";
+
+    gateway1.controlDomainID = domainID2;
+    gateway1.gatewayID = 0;
+    gateway1.sinkID = gwSinkID1;
+    gateway1.sourceID = gwSourceID1;
+    gateway1.domainSourceID = domainID3;
+    gateway1.domainSinkID = domainID2;
+    gateway1.listSinkFormats = gwSink1.listConnectionFormats;
+    gateway1.listSourceFormats = gwSource1.listConnectionFormats;
+    gateway1.convertionMatrix.push_back(true);
+    gateway1.name = "gateway1";
+
+    gateway2.controlDomainID = domainID3;
+    gateway2.gatewayID = 0;
+    gateway2.sinkID = gwSinkID2;
+    gateway2.sourceID = gwSourceID2;
+    gateway2.domainSourceID = domainID4;
+    gateway2.domainSinkID = domainID3;
+    gateway2.listSinkFormats = gwSink2.listConnectionFormats;
+    gateway2.listSourceFormats = gwSource2.listConnectionFormats;
+    gateway2.convertionMatrix.push_back(true);
+    gateway2.name = "gateway2";
+
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1));
+    ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2));
+
+    std::vector<am_Route_s> listRoutes;
+    std::vector<am_RoutingElement_s> listRoutingElements;
+    am_RoutingElement_s hopp1;
+    am_RoutingElement_s hopp2;
+    am_RoutingElement_s hopp3;
+    am_RoutingElement_s hopp4;
+
+    hopp1.sourceID = sourceID;
+    hopp1.sinkID = gwSinkID;
+    hopp1.domainID = domainID1;
+    hopp1.connectionFormat = source.listConnectionFormats[0];
+
+    hopp2.sourceID = gwSourceID;
+    hopp2.sinkID = gwSinkID1;
+    hopp2.domainID = domainID2;
+    hopp2.connectionFormat = gwSink1.listConnectionFormats[0];
+
+    hopp3.sourceID = gwSourceID1;
+    hopp3.sinkID = gwSinkID2;
+    hopp3.domainID = domainID3;
+    hopp3.connectionFormat = gwSink2.listConnectionFormats[0];
+
+    hopp4.sourceID = gwSourceID2;
+    hopp4.sinkID = sinkID;
+    hopp4.domainID = domainID4;
+    hopp4.connectionFormat = sink.listConnectionFormats[0];
+
+    listRoutingElements.push_back(hopp1);
+    listRoutingElements.push_back(hopp2);
+    listRoutingElements.push_back(hopp3);
+    listRoutingElements.push_back(hopp4);
+
+    am_Route_s compareRoute;
+    compareRoute.route = listRoutingElements;
+    compareRoute.sinkID = sinkID;
+    compareRoute.sourceID = sourceID;
+
+    ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
+    size_t size(1);
+    ASSERT_EQ(size, listRoutes.size());
+    ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+int main(int argc, char **argv)
+{
+#ifdef WITH_DLT
+    CAmDltWrapper::instance()->registerApp("routing", "CAmRouterMapTest");
+#else
+    CAmDltWrapper::instance(true)->registerApp("routing", "CAmRouterMapTest");
+#endif
+    logInfo("Routing Test started ");
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}
+
diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h
new file mode 100644 (file)
index 0000000..352b02e
--- /dev/null
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2012, BMW AG
+ *
+ * This file is part of GENIVI Project AudioManager.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ *
+* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
+ *
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#ifndef MAPTEST_H_
+#define MAPTEST_H_
+
+#define UNIT_TEST 1
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <set>
+#include "CAmMapHandler.h"
+#include "CAmControlReceiver.h"
+#include "CAmControlSender.h"
+#include "CAmDatabaseObserver.h"
+#include "CAmRoutingSender.h"
+#include "CAmRouter.h"
+#include "shared/CAmSocketHandler.h"
+#include "../IAmControlBackdoor.h"
+#include "../IAmCommandBackdoor.h"
+#include "../CAmCommonFunctions.h"
+#include "../MockIAmControlSend.h"
+#include "../MockIAmCommandSend.h"
+
+
+namespace am
+{
+
+class CAmRouterMapTest: public ::testing::Test
+{
+public:
+       CAmRouterMapTest();
+    ~CAmRouterMapTest();
+    std::vector<std::string> plistRoutingPluginDirs;
+    std::vector<std::string> plistCommandPluginDirs;
+    CAmSocketHandler pSocketHandler;
+    CAmControlSender pControlSender;
+    CAmMapHandler pDatabaseHandler;
+    CAmRouter pRouter;
+    CAmRoutingSender pRoutingSender;
+    CAmCommandSender pCommandSender;
+    MockIAmCommandSend pMockInterface;
+    MockIAmControlSend pMockControlInterface;
+    IAmRoutingBackdoor pRoutingInterfaceBackdoor;
+    IAmCommandBackdoor pCommandInterfaceBackdoor;
+    IAmControlBackdoor pControlInterfaceBackdoor;
+    CAmControlReceiver pControlReceiver;
+    CAmDatabaseObserver pObserver;
+    CAmCommonFunctions pCF;
+    void SetUp();
+    void TearDown();
+
+    void createMainConnectionSetup();
+};
+
+}
+
+#endif /* MAPTEST_H_ */
diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3667dd0
--- /dev/null
@@ -0,0 +1,89 @@
+# Copyright (C) 2012, BMW AG
+#
+# This file is part of GENIVI Project AudioManager.
+# 
+# Contributions are licensed to the GENIVI Alliance under one or more
+# Contribution License Agreements.
+# 
+# copyright
+# This Source Code Form is subject to the terms of the
+# Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
+# this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+# 
+# author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
+#
+# For further information see http://www.genivi.org/.
+#
+
+cmake_minimum_required(VERSION 2.6)
+
+PROJECT(AmRouterMapTest)
+
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager")
+
+
+FIND_PACKAGE(PkgConfig)
+
+IF(WITH_DLT)    
+    pkg_check_modules(DLT REQUIRED automotive-dlt>=2.2.0)   
+ENDIF(WITH_DLT)
+
+INCLUDE_DIRECTORIES(   
+    ${CMAKE_CURRENT_BINARY_DIR}
+    ${AUDIO_INCLUDE_FOLDER}
+    ${DBUS_ARCH_INCLUDE_DIR}
+    ${DBUS_INCLUDE_FOLDER} 
+    ${CMAKE_SOURCE_DIR} 
+    ${STD_INCLUDE_DIRS}
+    ${DLT_INCLUDE_DIRS}
+    ${DBUS_INCLUDE_DIR}
+    ${INCLUDE_FOLDER}
+    ${GOOGLE_TEST_INCLUDE_DIR}
+    ${GMOCK_INCLUDE_DIR}
+)
+
+file(GLOB ROUTINGMAP_SRCS_CXX 
+    "../../src/CAmMapHandler.cpp"
+    "../../src/CAmDatabaseObserver.cpp"
+    "../../src/CAmCommandSender.cpp"
+    "../../src/CAmRoutingSender.cpp"
+    "../../src/CAmControlReceiver.cpp"
+    "../../src/CAmControlSender.cpp"
+    "../../src/CAmRouter.cpp"
+    "../../src/CAmDltWrapper.cpp"
+    "../../src/CAmSocketHandler.cpp"
+    "../../src/CAmCommandReceiver.cpp"
+    "../../src/CAmRoutingReceiver.cpp"
+    "../../src/CAmDbusWrapper.cpp"
+    "../CAmCommonFunctions.cpp" 
+    "*.cpp"
+    )
+    
+IF(WITH_NSM)
+    SET (ROUTINGMAP_SRCS_CXX
+        ${ROUTINGMAP_SRCS_CXX}
+    "../../src/CAmNodeStateCommunicator.cpp")
+ENDIF(WITH_NSM)
+
+ADD_EXECUTABLE( AmRouterMapTest ${ROUTINGMAP_SRCS_CXX})
+
+TARGET_LINK_LIBRARIES( AmRouterMapTest 
+       ${DLT_LIBRARIES}
+       ${DBUS_LIBRARY}
+       ${CMAKE_THREAD_LIBS_INIT}
+       ${CMAKE_DL_LIBS}
+    gtest
+    gmock
+)
+
+ADD_DEPENDENCIES(AmRouterMapTest gtest gmock)
+
+INSTALL(TARGETS AmRouterMapTest 
+        DESTINATION "~/AudioManagerTest/"
+        PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ
+        COMPONENT tests
+)
+
+SET(ADD_DEPEND "audiomanager-bin" "dlt" "libdbus-1-3(>=1.2.16)"  "libpthread-stubs0")
+set_property(GLOBAL APPEND PROPERTY tests_prop "${ADD_DEPEND}")
+
index dd06384..46f9577 100644 (file)
@@ -30,11 +30,7 @@ CAmRouterTest::CAmRouterTest() :
         plistCommandPluginDirs(), //
         pSocketHandler(), //
         pControlSender(), //
-#ifdef WITH_DATABASE_STORAGE
                pDatabaseHandler(std::string(":memory:")),
-#else
-               pDatabaseHandler(),
-#endif
         pRouter(&pDatabaseHandler, &pControlSender), //
         pRoutingSender(plistRoutingPluginDirs), //
         pCommandSender(plistCommandPluginDirs), //
@@ -59,11 +55,6 @@ CAmRouterTest::~CAmRouterTest()
 void CAmRouterTest::SetUp()
 {
     logInfo("Routing Test started ");
-#ifdef WITH_DATABASE_STORAGE
-    printf("\n  WITH_DATABASE_STORAGE = 1 \n");
-#else
-    printf("\n  WITH_DATABASE_STORAGE = 0 \n");
-#endif
 }
 
 void CAmRouterTest::TearDown()
index 951eed5..93b80db 100644 (file)
 #include <string>
 #include <vector>
 #include <set>
-#ifdef WITH_DATABASE_STORAGE
-   #include "CAmDatabaseHandler.h"
-#else
-    #include "CAmMapHandler.h"
-#endif
+#include "CAmDatabaseHandler.h"
 #include "CAmControlReceiver.h"
 #include "CAmControlSender.h"
 #include "CAmDatabaseObserver.h"
@@ -60,11 +56,7 @@ public:
     std::vector<std::string> plistCommandPluginDirs;
     CAmSocketHandler pSocketHandler;
     CAmControlSender pControlSender;
-#ifdef WITH_DATABASE_STORAGE
     CAmDatabaseHandler pDatabaseHandler;
-#else
-    CAmMapHandler pDatabaseHandler;
-#endif
     CAmRouter pRouter;
     CAmRoutingSender pRoutingSender;
     CAmCommandSender pCommandSender;
index 686ac92..429ceda 100644 (file)
@@ -54,7 +54,11 @@ CAmEnvironment::CAmEnvironment()
 : mlistRoutingPluginDirs()
 , mlistCommandPluginDirs()
 , mSocketHandler()
+#ifdef WITH_DATABASE_STORAGE
 , mDatabasehandler(std::string(":memory:"))
+#else
+, mDatabasehandler()
+#endif
 , mRoutingSender(mlistRoutingPluginDirs)
 , mCommandSender(mlistRoutingPluginDirs)
 , mControlSender(controllerPlugin,&mSocketHandler)
@@ -139,6 +143,17 @@ void CAmTelnetServerTest::TearDown()
 
 }
 
+void CAmTelnetServerTest::sendCmd(std::string & command )
+{
+    ssize_t sizesent = send(staticSocket, command.c_str(), command.size(), 0);
+    ASSERT_EQ(static_cast<uint>(sizesent),command.size());
+
+    char buffer[1000];
+    memset(buffer,0,sizeof(buffer));
+    int read=recv(staticSocket,buffer,sizeof(buffer),0);
+    ASSERT_GT(read,1);
+}
+
 TEST_F(CAmTelnetServerTest,connectTelnetServer)
 {
     struct sockaddr_in servAddr;
@@ -168,31 +183,23 @@ TEST_F(CAmTelnetServerTest,connectTelnetServer)
 
 TEST_F(CAmTelnetServerTest,sendCmdTelnetServer)
 {
-    std::string string("help");
-
-    ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0);
-    ASSERT_EQ(static_cast<uint>(sizesent),string.size());
+    std::string cmd("help");
+    sendCmd(cmd);
+}
 
-    char buffer[1000];
-    memset(buffer,0,sizeof(buffer));
-    int read=recv(staticSocket,buffer,sizeof(buffer),0);
-    ASSERT_GT(read,1);
+TEST_F(CAmTelnetServerTest,sendDumpCmdTelnetServer)
+{
+    std::string cmd1("info");
+    std::string cmd3("dump");
+    sendCmd(cmd1);
+    sendCmd(cmd3);
 }
 
 TEST_F(CAmTelnetServerTest,closeTelnetServerConnection)
 {
-    std::string string ("exit");
-
+    std::string cmd("exit");
     mpSocketHandler->stop_listening();
-
-    ssize_t sizesent = send(staticSocket, string.c_str(), string.size(), 0);
-    ASSERT_EQ(static_cast<uint>(sizesent),string.size());
-
-    char buffer[1000];
-    memset(buffer,0,sizeof(buffer));
-    int read=recv(staticSocket,buffer,sizeof(buffer),0);
-    ASSERT_GT(read,1);
-
+    sendCmd(cmd);
     close(staticSocket);
     staticSocket = -1;
 }
index a584b97..5a03ba7 100644 (file)
@@ -25,6 +25,7 @@
 #include "gtest/gtest.h"
 #include "CAmTelnetServer.h"
 #include "CAmDatabaseHandler.h"
+#include "CAmMapHandler.h"
 #include "CAmRoutingSender.h"
 #include "CAmCommandSender.h"
 #include "CAmControlSender.h"
@@ -35,6 +36,7 @@ namespace am
 
 class CAmSocketHandler;
 class CAmDatabaseHandler;
+class CAmMapHandler;
 class CAmRoutingSender;
 class CAmCommandSender;
 class CAmControlSender;
@@ -64,7 +66,11 @@ class CAmEnvironment : public ::testing::Environment
   std::vector<std::string> mlistCommandPluginDirs;
 
   CAmSocketHandler     mSocketHandler;
+#ifdef WITH_DATABASE_STORAGE
   CAmDatabaseHandler   mDatabasehandler;
+#else
+  CAmMapHandler                   mDatabasehandler;
+#endif
   CAmRoutingSender     mRoutingSender;
   CAmCommandSender     mCommandSender;
   CAmControlSender     mControlSender;
@@ -89,7 +95,7 @@ class CAmTelnetServerTest : public ::testing::Test
    void SetUp() ;
 
    void TearDown() ;
-
+   void sendCmd(std::string & command );
    //int              mSocket;
 };
 
index 999ba1d..b2981eb 100644 (file)
@@ -54,6 +54,7 @@ file(GLOB TELNET_SRCS_CXX
     "../../src/CAmCommandSender.cpp"
     "../../src/CAmControlReceiver.cpp"
     "../../src/CAmControlSender.cpp"
+    "../../src/CAmMapHandler.cpp"
     "../../src/CAmDatabaseHandler.cpp"
     "../../src/CAmDatabaseObserver.cpp"
     "../../src/CAmRoutingReceiver.cpp"
index 7cd134b..5eda5cb 100644 (file)
@@ -24,6 +24,7 @@ add_subdirectory (AmControlInterfaceTest)
 add_subdirectory (AmDatabaseHandlerTest)
 add_subdirectory (AmMapHandlerTest)
 add_subdirectory (AmRouterTest)
+add_subdirectory (AmRouterMapTest)
 add_subdirectory (AmRoutingInterfaceTest)
 add_subdirectory (AmSocketHandlerTest)
 IF(WITH_NSM)