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