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