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