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