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