064cc055c40af62a0a02b1b1b5db9210ccd4c0d0
[profile/ivi/audiomanager.git] / AudioManagerDaemon / test / database / databaseTest.cpp
1 /**
2  * Copyright (C) 2011, BMW AG
3  *
4  * GeniviAudioMananger AudioManagerDaemon
5  *
6  * \file databasetest.cpp
7  *
8  * \date 20-Oct-2011 3:42:04 PM
9  * \author Christian Mueller (christian.ei.mueller@bmw.de)
10  *
11  * \section License
12  * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13  * Copyright (C) 2011, BMW AG Christian Mueller  Christian.ei.mueller@bmw.de
14  *
15  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17  * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18  * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19  * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20  * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21  * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
22  *
23  * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
24  */
25
26 #include "databaseTest.h"
27 #include "MockInterfaces.h"
28 #include "DatabaseHandler.h"
29 #include "ControlReceiver.h"
30 #include "ControlSender.h"
31 #include "DatabaseObserver.h"
32 #include "../ControlInterfaceBackdoor.h"
33 #include "../CommandInterfaceBackdoor.h"
34 #include "../CommonFunctions.h"
35
36 using namespace am;
37 using namespace testing;
38
39 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
40
41 //extern int GetRandomNumber(int nLow, int nHigh);
42 //extern bool equalSoundProperty (const am_SoundProperty_s a, const am_SoundProperty_s b);
43 extern bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b);
44 extern bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b);
45 extern bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b);
46 extern std::string int2string(int i);
47
48 routingTest::routingTest() :
49         plistRoutingPluginDirs(), //
50         plistCommandPluginDirs(), //
51         pDatabaseHandler(std::string(":memory:")), //
52         pRoutingSender(plistRoutingPluginDirs), //
53         pCommandSender(plistCommandPluginDirs), //
54         pMockInterface(), //
55         pRoutingInterfaceBackdoor(), //
56         pCommandInterfaceBackdoor(), //
57         pControlSender(""),//
58         pRouter(&pDatabaseHandler,&pControlSender), //
59         pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pRouter), //
60         pObserver(&pCommandSender, &pRoutingSender)
61 {
62     pDatabaseHandler.registerObserver(&pObserver);
63     pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface);
64 }
65
66 routingTest::~routingTest()
67 {
68 }
69
70 void routingTest::createMainConnectionSetup()
71 {
72     //fill the connection database
73     am_Connection_s connection;
74     am_Source_s source;
75     am_Sink_s sink;
76     std::vector<am_Connection_s> connectionList;
77
78     //we create 9 sources and sinks:
79     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(9);
80     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(9);
81
82     for (uint16_t i = 1; i < 10; i++)
83     {
84         am_sinkID_t forgetSink;
85         am_sourceID_t forgetSource;
86         am_connectionID_t forgetConnection;
87
88         pCF.createConnection(connection);
89         connection.sinkID = i;
90         connection.sourceID = i;
91         connectionList.push_back(connection);
92
93         pCF.createSink(sink);
94         sink.sinkID = i;
95         sink.name = "sink" + int2string(i);
96         sink.domainID = 4;
97         pCF.createSource(source);
98         source.sourceID = i;
99         source.name = "source" + int2string(i);
100         source.domainID = 4;
101
102         ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,forgetSink))
103             << "ERROR: database error";
104         ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,forgetSource))
105             << "ERROR: database error";
106         ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,forgetConnection))
107             << "ERROR: database error";
108         ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(forgetConnection));
109     }
110
111     //fill the route
112     std::vector<am_RoutingElement_s> routingList;
113     pCF.connectionList2RoutingList(routingList, connectionList);
114
115     //create the Route
116     am_Route_s route;
117     route.route = routingList;
118     route.sinkID = 1;
119     route.sourceID = 1;
120
121     //create a mainConnection
122     am_MainConnection_s mainConnection;
123     am_mainConnectionID_t mainConnectionID;
124     std::vector<am_MainConnection_s> mainConnectionList;
125     pCF.createMainConnection(mainConnection, route);
126
127     //enter mainconnection in database
128     EXPECT_CALL(pMockInterface,cbNumberOfMainConnectionsChanged()).Times(1);
129     EXPECT_CALL(pMockInterface,cbMainConnectionStateChanged(_,_)).Times(1);
130     ASSERT_EQ(E_OK,pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID))
131         << "ERROR: database error";
132     ASSERT_NE(0,mainConnectionID)
133         << "ERROR: connectionID zero";
134
135     //read out the mainconnections and check if they are equal to the data written.
136     ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(mainConnectionList));
137     bool equal = true;
138     std::vector<am_MainConnection_s>::iterator listIterator = mainConnectionList.begin();
139     for (; listIterator < mainConnectionList.end(); ++listIterator)
140     {
141         if (listIterator->connectionID == mainConnectionID)
142         {
143             equal = equal && (listIterator->connectionState == mainConnection.connectionState) && (listIterator->route.sinkID == mainConnection.route.sinkID) && (listIterator->route.sourceID == mainConnection.route.sourceID) && (listIterator->delay == mainConnection.delay) && (std::equal(listIterator->route.route.begin(), listIterator->route.route.end(), routingList.begin(), equalRoutingElement));
144         }
145     }
146     ASSERT_EQ(true, equal);
147 }
148
149 void routingTest::SetUp()
150 {
151     DLT_REGISTER_APP("Dtest", "AudioManagerDeamon");
152     DLT_REGISTER_CONTEXT(DLT_CONTEXT, "Main", "Main Context");
153     DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("Database Test started "));
154 }
155
156 void routingTest::TearDown()
157 {
158     DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
159 }
160
161 TEST_F(routingTest,crossfaders)
162 {
163     //todo:implement crossfader tests
164 }
165
166 TEST_F(routingTest,sourceState)
167 {
168     am_Source_s source;
169     am_sourceID_t sourceID;
170     std::vector<am_Source_s> listSources;
171     pCF.createSource(source);
172     source.sourceState = SS_OFF;
173
174     //prepare the test
175     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
176     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
177
178     //change the source state
179     ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceState(sourceID,SS_ON));
180
181     //read out the changed values
182     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
183     ASSERT_EQ(listSources[0].sourceState, SS_ON);
184 }
185
186 TEST_F(routingTest,sinkVolumeChange)
187 {
188     am_Sink_s sink;
189     am_sinkID_t sinkID;
190     std::vector<am_Sink_s> listSinks;
191     pCF.createSink(sink);
192     sink.volume = 23;
193
194     //prepare the test
195     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
196     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
197
198     //change the volume and check the read out
199     ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkVolume(sinkID,34));
200     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
201     ASSERT_EQ(listSinks[0].volume, 34);
202 }
203
204 TEST_F(routingTest,sourceVolumeChange)
205 {
206     am_Source_s source;
207     am_sourceID_t sourceID;
208     std::vector<am_Source_s> listSources;
209     pCF.createSource(source);
210     source.volume = 23;
211
212     //prepare test
213     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
214     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
215
216     //change the volume and check the read out
217     ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceVolume(sourceID,34));
218     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
219     ASSERT_EQ(listSources[0].volume, 34);
220 }
221
222 TEST_F(routingTest, peekSource)
223 {
224     std::vector<am_Source_s> listSources;
225     am_sourceID_t sourceID, source2ID, source3ID;
226     am_Source_s source;
227     pCF.createSource(source);
228
229     //peek a source that does not exits
230     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(0);
231     ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID));
232
233     //make sure it is not in the list
234     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
235     ASSERT_TRUE(listSources.empty());
236     ASSERT_EQ(sourceID, 100);
237
238     //now enter the source with the same name and make sure it does not get a new ID
239     source.name = "newsource";
240     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
241     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source2ID));
242     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
243     ASSERT_EQ(sourceID, source2ID);
244     ASSERT_TRUE(listSources[0].sourceID==sourceID);
245
246     //now we peek again. This time, the source exists
247     ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(source.name,source3ID));
248     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
249     ASSERT_TRUE(listSources.size()==1);
250     ASSERT_EQ(source3ID, source2ID);
251 }
252
253 TEST_F(routingTest, peekSourceDouble)
254 {
255     std::vector<am_Source_s> listSources;
256     am_sourceID_t sourceID;
257     am_sourceID_t source2ID;
258     am_sourceID_t source3ID;
259     am_Source_s source;
260     pCF.createSource(source);
261
262     //peek a source that does not exits
263     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(0);
264     ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID));
265
266     //peek a second source that does not exits
267     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(0);
268     ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource2"),source2ID));
269
270     //make sure they are is not in the list
271     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
272     ASSERT_TRUE(listSources.empty());
273     ASSERT_EQ(sourceID, 100);
274     source.name = "newsource";
275
276     //now enter the source with the same name than the first peek and make sure it does not get a new ID
277     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
278     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID));
279     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
280     ASSERT_EQ(sourceID, source3ID);
281     ASSERT_TRUE(listSources[0].sourceID==sourceID);
282 }
283
284 TEST_F(routingTest, peekSink)
285 {
286     std::vector<am_Sink_s> listSinks;
287     am_sinkID_t sinkID, sink2ID, sink3ID;
288     am_Sink_s sink;
289     pCF.createSink(sink);
290
291     //peek a sink that does not exits
292     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(0);
293     ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID));
294
295     //make sure it is not in the list
296     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
297     ASSERT_TRUE(listSinks.empty());
298     ASSERT_EQ(sinkID, 100);
299     sink.name = "newsink";
300
301     //now enter the source with the same name and make sure it does not get a new ID
302     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
303     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink2ID));
304     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
305     ASSERT_EQ(sinkID, sink2ID);
306     ASSERT_TRUE(listSinks[0].sinkID==sinkID);
307
308     //now we peek again, this time, the sink exists
309     ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(sink.name,sink3ID));
310     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
311     ASSERT_TRUE(listSinks.size()==1);
312     ASSERT_EQ(sink3ID, sink2ID);
313 }
314
315 TEST_F(routingTest, peekSinkDouble)
316 {
317     std::vector<am_Sink_s> listSinks;
318     am_sinkID_t sinkID;
319     am_sinkID_t sink2ID;
320     am_sinkID_t sink3ID;
321     am_Sink_s sink;
322     pCF.createSink(sink);
323
324     //peek a sink that does not exits
325     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(0);
326     ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID));
327
328     //peek again
329     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(0);
330     ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("nextsink"),sink2ID));
331
332     //make sure they are is not in the list
333     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
334     ASSERT_TRUE(listSinks.empty());
335     ASSERT_EQ(sinkID, 100);
336     sink.name = "newsink";
337
338     //now enter the sink with the same name than the first peek and make sure it does not get a new ID
339     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
340     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID));
341     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
342     ASSERT_EQ(sinkID, sink3ID);
343     ASSERT_TRUE(listSinks[0].sinkID==sinkID);
344 }
345
346 TEST_F(routingTest,changeConnectionTimingInformationCheckMainConnection)
347 {
348     am_Connection_s connection;
349     std::vector<am_Connection_s> connectionList;
350     std::vector<am_MainConnectionType_s> mainList;
351     pCF.createConnection(connection);
352
353     //prepare the test, it is one mainconnection, so we expect one callback
354     createMainConnectionSetup();
355     EXPECT_CALL(pMockInterface,cbTimingInformationChanged(1,216)).Times(1);
356
357     //first get all visible mainconnections and make sure, the delay is set to -1 for the first entry
358     ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList));
359     ASSERT_EQ(mainList[0].delay, -1);
360
361     //no go through all connections and set the delay time to 24 for each connection
362     ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
363     std::vector<am_Connection_s>::iterator iteratorConnectionList = connectionList.begin();
364     for (; iteratorConnectionList < connectionList.end(); ++iteratorConnectionList)
365     {
366         ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->sinkID,24));
367     }
368
369     //we read the result again and expect that the value is now different from -1
370     ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList));
371     ASSERT_EQ(mainList[0].delay, 216);
372 }
373
374 TEST_F(routingTest,changeConnectionTimingInformation)
375 {
376     am_Connection_s connection;
377     am_connectionID_t connectionID;
378     std::vector<am_Connection_s> connectionList;
379     pCF.createConnection(connection);
380
381     //enter a connection
382     ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID));
383     ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
384
385     //change the timing and check it
386     ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(connectionID,24));
387     ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
388     ASSERT_TRUE(connectionList[0].delay==24);
389 }
390
391 TEST_F(routingTest,getSinkClassOfSink)
392 {
393     std::vector<am_SinkClass_s> sinkClassList;
394     std::vector<am_ClassProperty_s> classPropertyList;
395     am_SinkClass_s sinkClass, returnClass;
396     am_ClassProperty_s classProperty;
397     am_sinkClass_t sinkClassID;
398     am_Sink_s sink;
399     am_sinkID_t sinkID;
400     classProperty.classProperty = CP_SINK_TYPE;
401     classProperty.value = 1;
402     classPropertyList.push_back(classProperty);
403     classProperty.classProperty = CP_SOURCE_TYPE;
404     classProperty.value = 4;
405     classPropertyList.push_back(classProperty);
406     sinkClass.name = "test";
407     sinkClass.sinkClassID = 4;
408     sinkClass.listClassProperties = classPropertyList;
409     pCF.createSink(sink);
410     sink.sinkClassID = 4;
411
412     //prepare test
413     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
414     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
415
416     //enter a new sinkclass, read out again and check
417     EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
418     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
419     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
420     ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
421     ASSERT_EQ(sinkClassList[0].sinkClassID, 4);
422     ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
423     ASSERT_EQ(E_OK, pDatabaseHandler.getSinkClassInfoDB(sinkID,returnClass));
424     ASSERT_EQ(sinkClassList[0].name, returnClass.name);
425     ASSERT_EQ(sinkClassList[0].sinkClassID, returnClass.sinkClassID);
426     ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),returnClass.listClassProperties.begin(),equalClassProperties));
427 }
428
429 TEST_F(routingTest,getSourceClassOfSource)
430 {
431     std::vector<am_SourceClass_s> sourceClassList;
432     std::vector<am_ClassProperty_s> classPropertyList;
433     am_SourceClass_s sourceClass, sinkSourceClass;
434     am_ClassProperty_s classProperty;
435     am_sourceClass_t sourceClassID;
436     am_Source_s source;
437     am_sourceID_t sourceID;
438     classProperty.classProperty = CP_SINK_TYPE;
439     classProperty.value = 1;
440     classPropertyList.push_back(classProperty);
441     classProperty.classProperty = CP_SOURCE_TYPE;
442     classProperty.value = 4;
443     classPropertyList.push_back(classProperty);
444     sourceClass.name = "test";
445     sourceClass.sourceClassID = 1;
446     sourceClass.listClassProperties = classPropertyList;
447     pCF.createSource(source);
448
449     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
450     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
451     EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
452     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
453     ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
454     ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
455     ASSERT_EQ(sourceClassList[0].sourceClassID, 1);
456     ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
457     ASSERT_EQ(E_OK, pDatabaseHandler.getSourceClassInfoDB(sourceID,sinkSourceClass));
458     ASSERT_EQ(sourceClassList[0].name, sinkSourceClass.name);
459     ASSERT_EQ(sourceClassList[0].sourceClassID, sinkSourceClass.sourceClassID);
460     ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),sinkSourceClass.listClassProperties.begin(),equalClassProperties));
461 }
462
463 TEST_F(routingTest,removeSourceClass)
464 {
465     std::vector<am_SourceClass_s> sourceClassList;
466     std::vector<am_ClassProperty_s> classPropertyList;
467     am_SourceClass_s sourceClass;
468     am_ClassProperty_s classProperty;
469     am_sourceClass_t sourceClassID;
470     classProperty.classProperty = CP_SINK_TYPE;
471     classProperty.value = 1;
472     classPropertyList.push_back(classProperty);
473     classProperty.classProperty = CP_SOURCE_TYPE;
474     classProperty.value = 4;
475     classPropertyList.push_back(classProperty);
476     sourceClass.name = "test";
477     sourceClass.sourceClassID = 3;
478     sourceClass.listClassProperties = classPropertyList;
479
480     EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(2);
481     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
482     ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
483     ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
484     ASSERT_EQ(sourceClassList[0].sourceClassID, 3);
485     ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
486     ASSERT_EQ(E_OK, pDatabaseHandler.removeSourceClassDB(3));
487     ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
488     ASSERT_TRUE(sourceClassList.empty());
489 }
490
491 TEST_F(routingTest,updateSourceClass)
492 {
493     std::vector<am_SourceClass_s> sourceClassList;
494     std::vector<am_ClassProperty_s> classPropertyList, changedPropertyList;
495     am_SourceClass_s sourceClass, changedClass;
496     am_ClassProperty_s classProperty;
497     am_sourceClass_t sourceClassID;
498     classProperty.classProperty = CP_SINK_TYPE;
499     classProperty.value = 1;
500     classPropertyList.push_back(classProperty);
501     classProperty.classProperty = CP_SOURCE_TYPE;
502     classProperty.value = 4;
503     classPropertyList.push_back(classProperty);
504     sourceClass.name = "test";
505     sourceClass.sourceClassID = 0;
506     sourceClass.listClassProperties = classPropertyList;
507     changedClass = sourceClass;
508     changedClass.listClassProperties[1].value = 6;
509     changedPropertyList = changedClass.listClassProperties;
510     EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
511     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
512     changedClass.sourceClassID = sourceClassID;
513     ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
514     ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
515     ASSERT_EQ(sourceClassList[0].sourceClassID, 100);
516     ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
517     ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceClassInfoDB(changedClass));
518     ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
519     ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
520     ASSERT_EQ(sourceClassList[0].sourceClassID, 100);
521     ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties));
522 }
523
524 TEST_F(routingTest,enterSourceClass)
525 {
526     std::vector<am_SourceClass_s> sourceClassList;
527     std::vector<am_ClassProperty_s> classPropertyList;
528     am_SourceClass_s sourceClass;
529     am_ClassProperty_s classProperty;
530     am_sourceClass_t sourceClassID;
531     classProperty.classProperty = CP_SINK_TYPE;
532     classProperty.value = 1;
533     classPropertyList.push_back(classProperty);
534     classProperty.classProperty = CP_SOURCE_TYPE;
535     classProperty.value = 4;
536     classPropertyList.push_back(classProperty);
537     sourceClass.name = "test";
538     sourceClass.sourceClassID = 0;
539     sourceClass.listClassProperties = classPropertyList;
540
541     EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
542     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
543     ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
544     ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
545     ASSERT_EQ(sourceClassList[0].sourceClassID, 100);
546     ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
547 }
548
549 TEST_F(routingTest,enterSourceClassStatic)
550 {
551     std::vector<am_SourceClass_s> sourceClassList;
552     std::vector<am_ClassProperty_s> classPropertyList;
553     am_SourceClass_s sourceClass;
554     am_ClassProperty_s classProperty;
555     am_sourceClass_t sourceClassID;
556     classProperty.classProperty = CP_SINK_TYPE;
557     classProperty.value = 1;
558     classPropertyList.push_back(classProperty);
559     classProperty.classProperty = CP_SOURCE_TYPE;
560     classProperty.value = 4;
561     classPropertyList.push_back(classProperty);
562     sourceClass.name = "test";
563     sourceClass.sourceClassID = 3;
564     sourceClass.listClassProperties = classPropertyList;
565
566     EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
567     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
568     ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
569     ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
570     ASSERT_EQ(sourceClassList[0].sourceClassID, 3);
571     ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
572 }
573
574 TEST_F(routingTest,removeSinkClass)
575 {
576     std::vector<am_SinkClass_s> sinkClassList;
577     std::vector<am_ClassProperty_s> classPropertyList;
578     am_SinkClass_s sinkClass;
579     am_ClassProperty_s classProperty;
580     am_sinkClass_t sinkClassID;
581     classProperty.classProperty = CP_SINK_TYPE;
582     classProperty.value = 1;
583     classPropertyList.push_back(classProperty);
584     classProperty.classProperty = CP_SOURCE_TYPE;
585     classProperty.value = 4;
586     classPropertyList.push_back(classProperty);
587     sinkClass.name = "test";
588     sinkClass.sinkClassID = 0;
589     sinkClass.listClassProperties = classPropertyList;
590
591     EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(2);
592     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
593     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
594     ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
595     ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
596     ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
597     ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkClassDB(sinkClassID));
598     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
599     ASSERT_TRUE(sinkClassList.empty());
600 }
601
602 TEST_F(routingTest,updateSinkClass)
603 {
604     std::vector<am_SinkClass_s> sinkClassList;
605     std::vector<am_ClassProperty_s> classPropertyList, changedPropertyList;
606     am_SinkClass_s sinkClass, changedClass;
607     am_ClassProperty_s classProperty;
608     am_sinkClass_t sinkClassID;
609     classProperty.classProperty = CP_SINK_TYPE;
610     classProperty.value = 1;
611     classPropertyList.push_back(classProperty);
612     classProperty.classProperty = CP_SOURCE_TYPE;
613     classProperty.value = 4;
614     classPropertyList.push_back(classProperty);
615     sinkClass.name = "test";
616     sinkClass.sinkClassID = 0;
617     sinkClass.listClassProperties = classPropertyList;
618     changedClass = sinkClass;
619     changedClass.listClassProperties[1].value = 6;
620     changedPropertyList = changedClass.listClassProperties;
621     EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
622     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
623     changedClass.sinkClassID = sinkClassID;
624     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
625     ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
626     ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
627     ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
628     ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkClassInfoDB(changedClass));
629     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
630     ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
631     ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
632     ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties));
633 }
634
635 TEST_F(routingTest,enterSinkClass)
636 {
637     std::vector<am_SinkClass_s> sinkClassList;
638     std::vector<am_ClassProperty_s> classPropertyList;
639     am_SinkClass_s sinkClass;
640     am_ClassProperty_s classProperty;
641     am_sinkClass_t sinkClassID;
642     classProperty.classProperty = CP_SINK_TYPE;
643     classProperty.value = 1;
644     classPropertyList.push_back(classProperty);
645     classProperty.classProperty = CP_SOURCE_TYPE;
646     classProperty.value = 4;
647     classPropertyList.push_back(classProperty);
648     sinkClass.name = "test";
649     sinkClass.sinkClassID = 0;
650     sinkClass.listClassProperties = classPropertyList;
651
652     EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
653     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
654     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
655     ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
656     ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
657     ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
658 }
659
660 TEST_F(routingTest,enterSinkClassStatic)
661 {
662     std::vector<am_SinkClass_s> sinkClassList;
663     std::vector<am_ClassProperty_s> classPropertyList;
664     am_SinkClass_s sinkClass;
665     am_ClassProperty_s classProperty;
666     am_sinkClass_t sinkClassID;
667     classProperty.classProperty = CP_SINK_TYPE;
668     classProperty.value = 1;
669     classPropertyList.push_back(classProperty);
670     classProperty.classProperty = CP_SOURCE_TYPE;
671     classProperty.value = 4;
672     classPropertyList.push_back(classProperty);
673     sinkClass.name = "test";
674     sinkClass.sinkClassID = 4;
675     sinkClass.listClassProperties = classPropertyList;
676
677     EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
678     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
679     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
680     ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
681     ASSERT_EQ(sinkClassList[0].sinkClassID, 4);
682     ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
683 }
684
685 TEST_F(routingTest, changeSystemProperty)
686 {
687     std::vector<am_SystemProperty_s> listSystemProperties, listReturn;
688     am_SystemProperty_s systemProperty;
689
690     systemProperty.type = SYP_TEST;
691     systemProperty.value = 33;
692     listSystemProperties.push_back(systemProperty);
693     EXPECT_CALL(pMockInterface,cbSystemPropertyChanged(_)).Times(1); //todo: check the exact value here
694     ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties));
695     systemProperty.value = 444;
696     ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty));
697     ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn));
698     ASSERT_EQ(listReturn[0].type, systemProperty.type);
699     ASSERT_EQ(listReturn[0].value, systemProperty.value);
700 }
701
702 TEST_F(routingTest, systemProperties)
703 {
704     std::vector<am_SystemProperty_s> listSystemProperties, listReturn;
705     am_SystemProperty_s systemProperty;
706
707     systemProperty.type = SYP_TEST;
708     systemProperty.value = 33;
709     listSystemProperties.push_back(systemProperty);
710
711     ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties));
712     ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn));
713     ASSERT_EQ(listReturn[0].type, systemProperty.type);
714     ASSERT_EQ(listReturn[0].value, systemProperty.value);
715 }
716
717 TEST_F(routingTest,enterSourcesCorrect)
718 {
719     //fill the connection database
720     am_Source_s staticSource, firstDynamicSource, secondDynamicSource;
721     am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID;
722     std::vector<am_Source_s> sourceList;
723
724     pCF.createSource(staticSource);
725     staticSource.sourceID = 4;
726     staticSource.name = "Static";
727
728     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(3);
729     ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID))
730         << "ERROR: database error";
731     ASSERT_EQ(staticSource.sourceID,staticSourceID)
732         << "ERROR: ID not the one given in staticSource";
733
734     pCF.createSource(firstDynamicSource);
735     firstDynamicSource.name = "firstDynamicSource";
736
737     ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID))
738         << "ERROR: database error";
739     ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY)
740         << "ERROR: ID not the one given in firstDynamicSink";
741
742     pCF.createSource(secondDynamicSource);
743     secondDynamicSource.name = "secondDynamicSource";
744
745     ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID))
746         << "ERROR: database error";
747     ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10)
748         << "ERROR: ID not the one given in secondDynamicSink";
749
750     //now read back and check the returns agains the given values
751     ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList))
752         << "ERROR: database error";
753     bool equal = true;
754
755     std::vector<am_Source_s>::iterator listIterator = sourceList.begin();
756     for (; listIterator < sourceList.end(); ++listIterator)
757     {
758         if (listIterator->sourceID == staticSourceID)
759         {
760             equal = equal && pCF.compareSource(listIterator, staticSource);
761         }
762
763         if (listIterator->sourceID == firstDynamicSourceID)
764         {
765             equal = equal && pCF.compareSource(listIterator, firstDynamicSource);
766         }
767
768         if (listIterator->sourceID == secondDynamicSourceID)
769         {
770             equal = equal && pCF.compareSource(listIterator, secondDynamicSource);
771         }
772
773     }
774     ASSERT_EQ(true, equal);
775 }
776
777 TEST_F(routingTest, changeSourceMainSoundProperty)
778 {
779     std::vector<am_Source_s> listSources;
780     am_Source_s source;
781     am_sourceID_t sourceID;
782     pCF.createSource(source);
783     am_MainSoundProperty_s property;
784     property.type = MSP_NAVIGATION_OFFSET;
785     property.value = 33;
786     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
787     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
788
789     EXPECT_CALL(pMockInterface,cbMainSourceSoundPropertyChanged(sourceID,_)).Times(1); //todo: check in detail
790     ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB(property,sourceID));
791     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
792     std::vector<am_MainSoundProperty_s>::iterator listIterator = listSources[0].listMainSoundProperties.begin();
793     for (; listIterator < listSources[0].listMainSoundProperties.end(); ++listIterator)
794     {
795         if (listIterator->type == property.type)
796         {
797             ASSERT_EQ(listIterator->value, property.value);
798         }
799     }
800 }
801
802 TEST_F(routingTest, changeSinkMuteState)
803 {
804     std::vector<am_Sink_s> listSinks;
805     am_Sink_s sink;
806     am_sinkID_t sinkID;
807     pCF.createSink(sink);
808     am_MuteState_e muteState = MS_MUTED;
809     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
810     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
811
812     EXPECT_CALL(pMockInterface,cbSinkMuteStateChanged(sinkID,muteState)).Times(1);
813     ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID));
814     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
815     ASSERT_EQ(muteState, listSinks[0].muteState);
816 }
817
818 TEST_F(routingTest, changeSinkMainSoundProperty)
819 {
820     std::vector<am_Sink_s> listSinks;
821     am_Sink_s sink;
822     am_sinkID_t sinkID;
823     pCF.createSink(sink);
824     am_MainSoundProperty_s property;
825     property.type = MSP_NAVIGATION_OFFSET;
826     property.value = 33;
827
828     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
829     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
830
831     EXPECT_CALL(pMockInterface,cbMainSinkSoundPropertyChanged(sinkID,_)).Times(1);
832     ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB(property,sinkID));
833     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
834     std::vector<am_MainSoundProperty_s>::iterator listIterator = listSinks[0].listMainSoundProperties.begin();
835     for (; listIterator < listSinks[0].listMainSoundProperties.end(); ++listIterator)
836     {
837         if (listIterator->type == property.type)
838         {
839             ASSERT_EQ(listIterator->value, property.value);
840         }
841     }
842 }
843
844 TEST_F(routingTest, peekDomain)
845 {
846     std::vector<am_Domain_s> listDomains;
847     am_Domain_s domain;
848     am_domainID_t domainID;
849     am_domainID_t domain2ID;
850     pCF.createDomain(domain);
851     ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domainID));
852     ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
853     ASSERT_TRUE(listDomains.empty());
854     ASSERT_EQ(domainID, 1);
855     domain.name = "newdomain";
856     ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID));
857     ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
858     ASSERT_EQ(domainID, domain2ID);
859     ASSERT_TRUE(listDomains[0].domainID==domainID);
860 }
861
862 TEST_F(routingTest, peekDomainFirstEntered)
863 {
864     std::vector<am_Domain_s> listDomains;
865     am_Domain_s domain;
866     am_domainID_t domainID;
867     am_domainID_t domain2ID;
868     pCF.createDomain(domain);
869     domain.name = "newdomain";
870     ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
871     ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domain2ID));
872     ASSERT_EQ(domainID, domain2ID);
873     ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
874     ASSERT_TRUE(listDomains.size()==1);
875 }
876
877 TEST_F(routingTest, changeDomainState)
878 {
879     std::vector<am_Domain_s> listDomains;
880     am_Domain_s domain;
881     am_domainID_t domainID;
882     pCF.createDomain(domain);
883     am_DomainState_e newState = DS_INDEPENDENT_STARTUP;
884     ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
885     ASSERT_EQ(E_OK, pDatabaseHandler.changDomainStateDB(newState,domainID));
886     ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
887     ASSERT_EQ(newState, listDomains[0].state);
888 }
889
890 TEST_F(routingTest, changeMainConnectionState)
891 {
892     std::vector<am_MainConnection_s> listMainConnections;
893     createMainConnectionSetup();
894     EXPECT_CALL(pMockInterface,cbMainConnectionStateChanged(_,_)).Times(1);
895     ASSERT_EQ(E_OK,pDatabaseHandler.changeMainConnectionStateDB(1,CS_DISCONNECTING))
896         << "ERROR: database error";ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections));
897     ASSERT_EQ(CS_DISCONNECTING, listMainConnections[0].connectionState);
898 }
899
900 TEST_F(routingTest, changeSinkAvailability)
901 {
902     std::vector<am_Sink_s> listSinks;
903     am_Sink_s sink;
904     am_sinkID_t sinkID;
905     pCF.createSink(sink);
906     am_Availability_s availability;
907     availability.availability = A_UNKNOWN;
908     availability.availabilityReason = AR_TEMPERATURE;
909
910     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
911     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
912     ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID));
913     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
914     ASSERT_EQ(availability.availability, listSinks[0].available.availability);
915     ASSERT_EQ(availability.availabilityReason, listSinks[0].available.availabilityReason);
916 }
917
918 TEST_F(routingTest, changeSourceAvailability)
919 {
920     std::vector<am_Source_s> listSources;
921     am_Source_s source;
922     am_sourceID_t sourceID;
923     pCF.createSource(source);
924     am_Availability_s availability;
925     availability.availability = A_UNKNOWN;
926     availability.availabilityReason = AR_TEMPERATURE;
927     source.visible = true;
928
929     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
930     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
931     ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID));
932     ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
933     ASSERT_EQ(availability.availability, listSources[0].available.availability);
934     ASSERT_EQ(availability.availabilityReason, listSources[0].available.availabilityReason);
935 }
936
937 TEST_F(routingTest,changeMainConnectionRoute)
938 {
939     std::vector<am_MainConnection_s> originalList;
940     std::vector<am_MainConnection_s> newList;
941     createMainConnectionSetup();
942     //fill the connection database
943     am_Connection_s connection;
944     am_Source_s source;
945     am_Sink_s sink;
946     std::vector<am_Connection_s> connectionList;
947
948     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(9);
949     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(9);
950     for (uint16_t i = 1; i < 10; i++)
951     {
952         am_sinkID_t forgetSink;
953         am_sourceID_t forgetSource;
954         am_connectionID_t forgetConnection;
955
956         pCF.createConnection(connection);
957         connection.sinkID = i + 20;
958         connection.sourceID = i + 20;
959         connection.delay = -1;
960         connectionList.push_back(connection);
961
962         pCF.createSink(sink);
963         sink.sinkID = i + 20;
964         sink.name = "sink" + int2string(i + 20);
965         sink.domainID = 4;
966         pCF.createSource(source);
967         source.sourceID = i + 20;
968         source.name = "source" + int2string(i + 30);
969         source.domainID = 4;
970
971         ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,forgetSink))
972             << "ERROR: database error";
973         ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,forgetSource))
974             << "ERROR: database error";
975         ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,forgetConnection))
976             << "ERROR: database error";
977         ASSERT_EQ(E_OK,pDatabaseHandler.getListMainConnections(originalList))
978             << "ERROR: database error";
979
980     }
981
982     //fill the route
983     std::vector<am_RoutingElement_s> routingList;
984     pCF.connectionList2RoutingList(routingList, connectionList);
985
986     //create the Route
987     am_Route_s route;
988     route.route = routingList;
989     route.sinkID = 2;
990     route.sourceID = 2;
991
992     ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionRouteDB(1,route));
993     ASSERT_EQ(E_OK,pDatabaseHandler.getListMainConnections(newList))
994         << "ERROR: database error";ASSERT_TRUE(std::equal(newList[0].route.route.begin(),newList[0].route.route.end(),routingList.begin(),equalRoutingElement));
995     ASSERT_FALSE(std::equal(newList[0].route.route.begin(),newList[0].route.route.end(),originalList[0].route.route.begin(),equalRoutingElement));
996 }
997
998 TEST_F(routingTest,changeMainSinkVolume)
999 {
1000     am_Sink_s sink;
1001     am_sinkID_t sinkID;
1002     am_mainVolume_t newVol = 20;
1003     std::vector<am_Sink_s> listSinks;
1004     pCF.createSink(sink);
1005
1006     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1007     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1008
1009     EXPECT_CALL(pMockInterface,cbVolumeChanged(sinkID,newVol)).Times(1);
1010     ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID));
1011     ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
1012     ASSERT_EQ(listSinks[0].mainVolume, newVol);
1013 }
1014
1015 TEST_F(routingTest,getMainSourceSoundProperties)
1016 {
1017     am_Source_s source;
1018     am_sourceID_t sourceID;
1019     pCF.createSource(source);
1020     std::vector<am_MainSoundProperty_s> mainSoundProperties = source.listMainSoundProperties;
1021     std::vector<am_MainSoundProperty_s> listMainSoundProperties;
1022
1023     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1024     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1025     ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSourceSoundProperties(sourceID,listMainSoundProperties));
1026     ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty));
1027 }
1028
1029 TEST_F(routingTest,getMainSinkSoundProperties)
1030 {
1031     am_Sink_s sink;
1032     am_sinkID_t sinkID;
1033     pCF.createSink(sink);
1034     std::vector<am_MainSoundProperty_s> mainSoundProperties = sink.listMainSoundProperties;
1035     std::vector<am_MainSoundProperty_s> listMainSoundProperties;
1036
1037     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1038     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1039     ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinkSoundProperties(sinkID,listMainSoundProperties));
1040     ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty));
1041 }
1042
1043 TEST_F(routingTest,getMainSources)
1044 {
1045     am_Source_s source, source1, source2;
1046     am_sourceID_t sourceID;
1047     pCF.createSource(source);
1048     pCF.createSource(source1);
1049     pCF.createSource(source2);
1050     source1.name = "source1";
1051     source2.name = "source2";
1052     bool equal = true;
1053     source1.visible = false;
1054     std::vector<am_SourceType_s> listMainSources;
1055     std::vector<am_Source_s> listSources;
1056
1057     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(3);
1058
1059     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1060     source.sourceID = sourceID;
1061     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source1,sourceID));
1062     ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source2,sourceID));
1063     source2.sourceID = sourceID;
1064     ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listMainSources));
1065     listSources.push_back(source);
1066     listSources.push_back(source2);
1067     std::vector<am_SourceType_s>::iterator listIterator = listMainSources.begin();
1068     for (; listIterator < listMainSources.end(); ++listIterator)
1069     {
1070         equal = equal && pCF.compareSinkMainSource(listIterator, listSources);
1071     }
1072     ASSERT_TRUE(equal);
1073 }
1074
1075 TEST_F(routingTest,getMainSinks)
1076 {
1077     am_Sink_s sink, sink1, sink2;
1078     am_sinkID_t sinkID;
1079     pCF.createSink(sink);
1080     pCF.createSink(sink1);
1081     pCF.createSink(sink2);
1082     sink1.name = "sink1";
1083     sink2.name = "sink2";
1084     bool equal = true;
1085     sink1.visible = false;
1086     std::vector<am_SinkType_s> listMainSinks;
1087     std::vector<am_Sink_s> listSinks;
1088
1089     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(3);
1090     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1091     sink.sinkID = sinkID;
1092     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink1,sinkID));
1093     ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink2,sinkID));
1094     sink2.sinkID = sinkID;
1095     ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listMainSinks));
1096     listSinks.push_back(sink);
1097     listSinks.push_back(sink2);
1098     std::vector<am_SinkType_s>::iterator listIterator = listMainSinks.begin();
1099     for (; listIterator < listMainSinks.end(); ++listIterator)
1100     {
1101         equal = equal && pCF.compareSinkMainSink(listIterator, listSinks);
1102     }
1103     ASSERT_TRUE(equal);
1104 }
1105
1106 TEST_F(routingTest,getVisibleMainConnections)
1107 {
1108     createMainConnectionSetup();
1109     am_MainConnection_s mainConnection;
1110     am_Route_s route;
1111     pCF.createMainConnection(mainConnection, route);
1112     std::vector<am_MainConnectionType_s> visibleMainConnection;
1113     ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(visibleMainConnection));
1114     ASSERT_TRUE(1==visibleMainConnection[0].mainConnectionID);
1115     ASSERT_TRUE(mainConnection.connectionState==visibleMainConnection[0].connectionState);
1116     ASSERT_TRUE(mainConnection.delay==visibleMainConnection[0].delay);
1117     ASSERT_TRUE(1==visibleMainConnection[0].sinkID);
1118     ASSERT_TRUE(1==visibleMainConnection[0].sourceID);
1119 }
1120
1121 TEST_F(routingTest,getListSourcesOfDomain)
1122 {
1123     am_Source_s source, source2;
1124     am_Domain_s domain;
1125     am_domainID_t domainID;
1126     am_sourceID_t sourceID;
1127     std::vector<am_sourceID_t> sourceList, sourceCheckList;
1128     pCF.createSource(source);
1129     source.sourceID = 1;
1130     source.name = "testSource";
1131     source.domainID = 1;
1132     pCF.createSource(source2);
1133     source2.sourceID = 0;
1134     source2.name = "testSource2";
1135     source2.domainID = 5;
1136     pCF.createDomain(domain);
1137     sourceCheckList.push_back(1); //sink.sinkID);
1138
1139     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2);
1140     ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
1141     ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID))
1142         << "ERROR: database error";
1143     ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source2,sourceID))
1144         << "ERROR: database error";
1145     ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSourcesOfDomain(2,sourceList))
1146         << "ERROR: database error";ASSERT_TRUE(sourceList.empty());
1147     ASSERT_EQ(E_OK,pDatabaseHandler.getListSourcesOfDomain(1,sourceList))
1148         << "ERROR: database error";
1149     ASSERT_TRUE(std::equal(sourceList.begin(),sourceList.end(),sourceCheckList.begin()) && !sourceList.empty());
1150 }
1151
1152 TEST_F(routingTest,getListSinksOfDomain)
1153 {
1154     am_Sink_s sink, sink2;
1155     am_Domain_s domain;
1156     am_domainID_t domainID;
1157     am_sinkID_t sinkID;
1158     std::vector<am_sinkID_t> sinkList, sinkCheckList;
1159     pCF.createSink(sink);
1160     sink.sinkID = 1;
1161     sink.domainID = 1;
1162     pCF.createSink(sink2);
1163     sink2.domainID = 5;
1164     sink2.name = "sink2";
1165     pCF.createDomain(domain);
1166     sinkCheckList.push_back(1); //sink.sinkID);
1167
1168     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2);
1169     ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
1170     ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID))
1171         << "ERROR: database error";
1172     ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink2,sinkID))
1173         << "ERROR: database error";
1174     ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSinksOfDomain(2,sinkList))
1175         << "ERROR: database error";ASSERT_TRUE(sinkList.empty());
1176     ASSERT_EQ(E_OK,pDatabaseHandler.getListSinksOfDomain(1,sinkList))
1177         << "ERROR: database error";
1178     ASSERT_TRUE(std::equal(sinkList.begin(),sinkList.end(),sinkCheckList.begin()) && !sinkList.empty());
1179 }
1180
1181 TEST_F(routingTest,getListGatewaysOfDomain)
1182 {
1183     am_Gateway_s gateway, gateway2;
1184     am_gatewayID_t gatewayID;
1185     am_domainID_t domainID;
1186     am_Domain_s domain;
1187     std::vector<am_gatewayID_t> gatewayList, gatewayCheckList;
1188     pCF.createGateway(gateway);
1189     gateway.gatewayID = 1;
1190     gateway.name = "testGateway";
1191     gateway.controlDomainID = 1;
1192     gateway.sourceID = 1;
1193     gateway.sinkID = 1;
1194     gateway.domainSinkID = 1;
1195     gateway.domainSourceID = 1;
1196     pCF.createGateway(gateway2);
1197     gateway2.gatewayID = 2;
1198     gateway2.name = "testGateway2";
1199     gateway2.controlDomainID = 4;
1200     gateway2.sourceID = 1;
1201     gateway2.sinkID = 1;
1202     gateway2.domainSinkID = 1;
1203     gateway2.domainSourceID = 1;
1204     pCF.createDomain(domain);
1205     gatewayCheckList.push_back(gateway.gatewayID);
1206     ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
1207     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1208         << "ERROR: database error";
1209     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID))
1210         << "ERROR: database error";
1211     ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListGatewaysOfDomain(2,gatewayList))
1212         << "ERROR: database error";ASSERT_TRUE(gatewayList.empty());
1213     ASSERT_EQ(E_OK,pDatabaseHandler.getListGatewaysOfDomain(1,gatewayList))
1214         << "ERROR: database error";
1215     ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty());
1216 }
1217
1218 TEST_F(routingTest,removeDomain)
1219 {
1220     am_Domain_s domain;
1221     am_domainID_t domainID;
1222     std::vector<am_Domain_s> listDomains;
1223     pCF.createDomain(domain);
1224     ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID))
1225         << "ERROR: database error";
1226     ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID))
1227         << "ERROR: database error";
1228     ASSERT_EQ(E_OK,pDatabaseHandler.getListDomains(listDomains))
1229         << "ERROR: database error";
1230     ASSERT_TRUE(listDomains.empty());
1231 }
1232
1233 TEST_F(routingTest,removeGateway)
1234 {
1235     am_Gateway_s gateway;
1236     am_gatewayID_t gatewayID;
1237     std::vector<am_Gateway_s> listGateways;
1238     pCF.createGateway(gateway);
1239     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1240         << "ERROR: database error";
1241     ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID))
1242         << "ERROR: database error";
1243     ASSERT_EQ(E_OK,pDatabaseHandler.getListGateways(listGateways))
1244         << "ERROR: database error";
1245     ASSERT_TRUE(listGateways.empty());
1246 }
1247
1248 TEST_F(routingTest,removeSink)
1249 {
1250     am_Sink_s sink;
1251     am_sinkID_t sinkID;
1252     std::vector<am_Sink_s> listSinks;
1253     pCF.createSink(sink);
1254     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2);
1255     ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID))
1256         << "ERROR: database error";
1257     ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID))
1258         << "ERROR: database error";
1259     ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks))
1260         << "ERROR: database error";
1261     ASSERT_TRUE(listSinks.empty());
1262 }
1263
1264 TEST_F(routingTest,removeSource)
1265 {
1266     //fill the connection database
1267     am_Source_s source;
1268     am_sourceID_t sourceID;
1269     std::vector<am_Source_s> listSources;
1270     pCF.createSource(source);
1271
1272     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2);
1273     ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID))
1274         << "ERROR: database error";
1275     ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID))
1276         << "ERROR: database error";
1277     ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources))
1278         << "ERROR: database error";
1279     ASSERT_TRUE(listSources.empty());
1280 }
1281
1282 TEST_F(routingTest, removeMainConnection)
1283 {
1284     createMainConnectionSetup();
1285     EXPECT_CALL(pMockInterface,cbNumberOfMainConnectionsChanged()).Times(1);
1286     EXPECT_CALL(pMockInterface,cbMainConnectionStateChanged(_,_)).Times(1);
1287     ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(1))
1288         << "ERROR: database error";
1289 }
1290
1291 TEST_F(routingTest,removeNonexistentMainConnectionFail)
1292 {
1293     ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34))
1294         << "ERROR: database error";
1295 }
1296
1297 TEST_F(routingTest,removeNonexistentSource)
1298 {
1299     ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3))
1300         << "ERROR: database error";
1301 }
1302
1303 TEST_F(routingTest,removeNonexistentSink)
1304 {
1305     ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2))
1306         << "ERROR: database error";
1307 }
1308
1309 TEST_F(routingTest,removeNonexistentGateway)
1310 {
1311     ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12))
1312         << "ERROR: database error";
1313 }
1314
1315 TEST_F(routingTest,registerGatewayCorrect)
1316 {
1317     //initialize gateway
1318     std::vector<am_Gateway_s> returnList;
1319     am_Gateway_s gateway, gateway1, gateway2;
1320     am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0;
1321
1322     pCF.createGateway(gateway);
1323     pCF.createGateway(gateway1);
1324     gateway1.gatewayID = 20;
1325     pCF.createGateway(gateway2);
1326
1327     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1328         << "ERROR: database error";
1329     ASSERT_EQ(100,gatewayID)
1330         << "ERROR: domainID zero";
1331
1332     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))
1333         << "ERROR: database error";
1334     ASSERT_EQ(gateway1.gatewayID,gatewayID1)
1335         << "ERROR: domainID zero";
1336
1337     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))
1338         << "ERROR: database error";
1339     ASSERT_EQ(101,gatewayID2)
1340         << "ERROR: domainID zero";
1341
1342     //now check if we read out the correct values
1343     ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList));
1344     bool equal = true;
1345     std::vector<am_Gateway_s>::iterator listIterator = returnList.begin();
1346
1347     for (; listIterator < returnList.end(); ++listIterator)
1348     {
1349         if (listIterator->gatewayID == gatewayID)
1350         {
1351             equal = equal && pCF.compareGateway(listIterator, gateway);
1352         }
1353
1354         if (listIterator->gatewayID == gatewayID1)
1355         {
1356             equal = equal && pCF.compareGateway(listIterator, gateway1);
1357         }
1358
1359         if (listIterator->gatewayID == gatewayID2)
1360         {
1361             equal = equal && pCF.compareGateway(listIterator, gateway2);
1362         }
1363     }
1364
1365     ASSERT_EQ(true, equal);
1366 }
1367
1368 TEST_F(routingTest,getGatewayInfo)
1369 {
1370     //initialize gateway
1371     std::vector<am_Gateway_s> returnList;
1372     am_Gateway_s gateway, gateway1, gateway2;
1373     am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0;
1374
1375     pCF.createGateway(gateway);
1376     pCF.createGateway(gateway1);
1377     gateway1.gatewayID = 20;
1378     pCF.createGateway(gateway2);
1379
1380     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1381         << "ERROR: database error";
1382     ASSERT_EQ(100,gatewayID)
1383         << "ERROR: domainID zero";
1384
1385     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))
1386         << "ERROR: database error";
1387     ASSERT_EQ(gateway1.gatewayID,gatewayID1)
1388         << "ERROR: domainID zero";
1389
1390     ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))
1391         << "ERROR: database error";
1392     ASSERT_EQ(101,gatewayID2)
1393         << "ERROR: domainID zero";
1394
1395     //now check if we read out the correct values
1396     ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList));
1397     bool equal = true;
1398     std::vector<am_Gateway_s>::iterator listIterator = returnList.begin();
1399
1400     for (; listIterator < returnList.end(); ++listIterator)
1401     {
1402         if (listIterator->gatewayID == gatewayID)
1403         {
1404             equal = equal && pCF.compareGateway(listIterator, gateway);
1405         }
1406
1407         if (listIterator->gatewayID == gatewayID1)
1408         {
1409             equal = equal && pCF.compareGateway(listIterator, gateway1);
1410         }
1411
1412         if (listIterator->gatewayID == gatewayID2)
1413         {
1414             equal = equal && pCF.compareGateway(listIterator, gateway2);
1415         }
1416     }
1417
1418     ASSERT_EQ(true, equal);
1419
1420     am_Gateway_s gatewayInfo;
1421     ASSERT_EQ(E_OK, pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo));
1422     ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo));
1423
1424 }
1425
1426 TEST_F(routingTest,enterSinkThatAlreadyExistFail)
1427 {
1428     //fill the connection database
1429     am_Sink_s staticSink, SecondSink;
1430     am_sinkID_t staticSinkID, SecondSinkID;
1431
1432     pCF.createSink(staticSink);
1433     staticSink.sinkID = 43;
1434     staticSink.name = "Static";
1435
1436     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1437     ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID))
1438         << "ERROR: database error";
1439     ASSERT_EQ(staticSink.sinkID,staticSinkID)
1440         << "ERROR: ID not the one given in staticSink";
1441
1442     pCF.createSink(SecondSink);
1443     SecondSink.sinkID = 43;
1444     SecondSink.name = "SecondSink";
1445
1446     ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSinkDB(SecondSink,SecondSinkID))
1447         << "ERROR: database error";
1448 }
1449
1450 TEST_F(routingTest,enterSourcesThatAlreadyExistFail)
1451 {
1452     //fill the connection database
1453     am_Source_s staticSource, SecondSource;
1454     am_sourceID_t staticSourceID, SecondSourceID;
1455     pCF.createSource(staticSource);
1456     staticSource.sourceID = 4;
1457
1458     EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1459     ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID))
1460         << "ERROR: database error";
1461     ASSERT_EQ(staticSource.sourceID,staticSourceID)
1462         << "ERROR: ID not the one given in staticSource";
1463
1464     pCF.createSource(SecondSource);
1465     SecondSource.sourceID = 4;
1466
1467     ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSourceDB(SecondSource,SecondSourceID))
1468         << "ERROR: database error";
1469 }
1470
1471 TEST_F(routingTest,registerDomainCorrect)
1472 {
1473     //initialize domain
1474     std::vector<am_Domain_s> returnList;
1475     am_Domain_s domain;
1476     am_domainID_t domainID = 0;
1477     pCF.createDomain(domain);
1478
1479     ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID))
1480         << "ERROR: database error";
1481     ASSERT_NE(0,domainID)
1482         << "ERROR: domainID zero";
1483
1484     //now check if we read out the correct values
1485     ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList));
1486     bool equal = true;
1487     std::vector<am_Domain_s>::iterator listIterator = returnList.begin();
1488     for (; listIterator < returnList.end(); ++listIterator)
1489     {
1490         if (listIterator->domainID == domainID)
1491         {
1492             equal = equal && (listIterator->name.compare(domain.name) == 0) && (listIterator->busname.compare(domain.busname) == 0) && (listIterator->complete == domain.complete) && (listIterator->early == domain.early) && (listIterator->state == domain.state);
1493         }
1494     }
1495     ASSERT_EQ(true, equal);
1496 }
1497
1498 TEST_F(routingTest,registerConnectionCorrect)
1499 {
1500     am_Connection_s connection;
1501     am_connectionID_t connectionID;
1502     std::vector<am_Connection_s> returnList;
1503     pCF.createConnection(connection);
1504
1505     ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID))
1506         << "ERROR: database error";;
1507     ASSERT_NE(0,connectionID)
1508         << "ERROR: connectionID zero";
1509
1510     //now check if we read out the correct values
1511     ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
1512     ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(returnList));
1513     bool equal = false;
1514     std::vector<am_Connection_s>::iterator listIterator = returnList.begin();
1515     for (; listIterator < returnList.end(); ++listIterator)
1516     {
1517         if (listIterator->connectionID == connectionID)
1518         {
1519             equal = (listIterator->sourceID == connection.sourceID) && (listIterator->sinkID == connection.sinkID) && (listIterator->delay == connection.delay) && (listIterator->connectionFormat = connection.connectionFormat);
1520         }
1521     }
1522     ASSERT_EQ(true, equal);
1523 }
1524
1525 TEST_F(routingTest,enterMainConnectionCorrect)
1526 {
1527     createMainConnectionSetup();
1528 }
1529
1530 TEST_F(routingTest,enterSinksCorrect)
1531 {
1532     //fill the connection database
1533     am_Sink_s staticSink, firstDynamicSink, secondDynamicSink;
1534     am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID;
1535     std::vector<am_Sink_s> sinkList;
1536
1537     pCF.createSink(staticSink);
1538     staticSink.sinkID = 4;
1539
1540     EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(3);
1541     ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID))
1542         << "ERROR: database error";
1543     ASSERT_EQ(staticSink.sinkID,staticSinkID)
1544         << "ERROR: ID not the one given in staticSink";
1545
1546     pCF.createSink(firstDynamicSink);
1547     firstDynamicSink.name = "firstdynamic";
1548     ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID))
1549         << "ERROR: database error";
1550     ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY)
1551         << "ERROR: ID not the one given in firstDynamicSink";
1552
1553     pCF.createSink(secondDynamicSink);
1554     secondDynamicSink.name = "seconddynamic";
1555
1556     ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID))
1557         << "ERROR: database error";
1558     ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10)
1559         << "ERROR: ID not the one given in secondDynamicSink";
1560
1561     //now read back and check the returns agains the given values
1562     ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList))
1563         << "ERROR: database error";
1564     bool equal = true;
1565
1566     std::vector<am_Sink_s>::iterator listIterator = sinkList.begin();
1567     for (; listIterator < sinkList.end(); ++listIterator)
1568     {
1569         if (listIterator->sinkID == staticSinkID)
1570         {
1571             equal = equal && pCF.compareSink(listIterator, staticSink);
1572         }
1573
1574         if (listIterator->sinkID == firstDynamicSinkID)
1575         {
1576             equal = equal && pCF.compareSink(listIterator, firstDynamicSink);
1577         }
1578
1579         if (listIterator->sinkID == secondDynamicSinkID)
1580         {
1581             equal = equal && pCF.compareSink(listIterator, secondDynamicSink);
1582         }
1583     }
1584     ASSERT_EQ(true, equal);
1585 }
1586
1587 //Commented out - gives always a warning..
1588 //TEST_F(databaseTest,registerDomainFailonID0)
1589 //{
1590 //      am_Domain_s domain;
1591 //      am_domainID_t domainID=5;
1592 //      pCF.createDomain(domain);
1593 //      domain.domainID=1;
1594 //      ASSERT_DEATH(pDatabaseHandler.enterDomainDB(domain,domainID),"Assertion `domainData.domainID==0'");
1595 //}
1596
1597 int main(int argc, char **argv)
1598 {
1599     ::testing::InitGoogleTest(&argc, argv);
1600     return RUN_ALL_TESTS();
1601 }
1602