2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file databasetest.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
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
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.
23 * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
26 #include "databaseTest.h"
27 #include "DatabaseObserver.h"
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);
38 databaseTest::databaseTest()
39 :pDatabaseHandler(std::string(":memory:"))
43 databaseTest::~databaseTest()
47 void databaseTest::createMainConnectionSetup()
49 //fill the connection database
50 am_Connection_s connection;
53 std::vector<am_Connection_s> connectionList;
55 for (uint16_t i=1;i<10;i++)
57 am_sinkID_t forgetSink;
58 am_sourceID_t forgetSource;
59 am_connectionID_t forgetConnection;
61 pCF.createConnection(connection);
63 connection.sourceID=i;
64 connectionList.push_back(connection);
68 sink.name="sink" + int2string(i);
70 pCF.createSource(source);
72 source.name="source" + int2string(i);
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));
82 std::vector<am_RoutingElement_s> routingList;
83 pCF.connectionList2RoutingList(routingList,connectionList);
87 route.route=routingList;
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);
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";
101 //read out the mainconnections and check if they are equal to the data written.
102 ASSERT_EQ(E_OK,pDatabaseHandler.getListMainConnections(mainConnectionList));
104 std::vector<am_MainConnection_s>::iterator listIterator=mainConnectionList.begin();
105 for(;listIterator<mainConnectionList.end();++listIterator)
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));
115 ASSERT_EQ(true,equal);
118 void databaseTest::SetUp()
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);
127 void databaseTest::TearDown()
129 DLT_UNREGISTER_CONTEXT(AudioManager);
132 TEST_F(databaseTest,crossfaders)
134 //todo:implement crossfader tests
137 TEST_F(databaseTest,sourceState)
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);
150 TEST_F(databaseTest,sinkVolumeChange)
154 std::vector<am_Sink_s> listSinks;
155 pCF.createSink(sink);
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);
163 TEST_F(databaseTest,sourceVolumeChange)
166 am_sourceID_t sourceID;
167 std::vector<am_Source_s> listSources;
168 pCF.createSource(source);
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);
176 TEST_F(databaseTest, peekSource)
178 std::vector<am_Source_s> listSources;
179 am_sourceID_t sourceID;
180 am_sourceID_t source2ID;
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);
194 TEST_F(databaseTest, peekSourceDouble)
196 std::vector<am_Source_s> listSources;
197 am_sourceID_t sourceID;
198 am_sourceID_t source2ID;
199 am_sourceID_t source3ID;
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);
214 TEST_F(databaseTest, peekSourceExists)
216 std::vector<am_Source_s> listSources;
217 am_sourceID_t sourceID;
218 am_sourceID_t source2ID;
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);
228 TEST_F(databaseTest, peekSink)
230 std::vector<am_Sink_s> listSinks;
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);
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);
246 TEST_F(databaseTest, peekSinkDouble)
248 std::vector<am_Sink_s> listSinks;
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);
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);
266 TEST_F(databaseTest, peekSinkExists)
268 std::vector<am_Sink_s> listSinks;
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);
281 TEST_F(databaseTest,changeConnectionTimingInformationCheckMainConnection)
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)
294 ASSERT_EQ(E_OK,pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->sinkID,24));
296 ASSERT_EQ(E_OK,pDatabaseHandler.getListVisibleMainConnections(mainList));
297 ASSERT_NE(mainList[0].delay,-1);
300 TEST_F(databaseTest,changeConnectionTimingInformation)
302 am_Connection_s connection;
303 am_connectionID_t connectionID;
304 std::vector<am_Connection_s> connectionList;
305 pCF.createConnection(connection);
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);
314 TEST_F(databaseTest,getSinkClassOfSink)
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;
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);
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));
348 TEST_F(databaseTest,getSourceClassOfSource)
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;
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);
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));
381 TEST_F(databaseTest,removeSourceClass)
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;
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());
408 TEST_F(databaseTest,updateSourceClass)
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));
440 TEST_F(databaseTest,enterSourceClass)
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;
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));
464 TEST_F(databaseTest,enterSourceClassStatic)
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;
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));
489 TEST_F(databaseTest,removeSinkClass)
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;
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());
516 TEST_F(databaseTest,updateSinkClass)
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));
548 TEST_F(databaseTest,enterSinkClass)
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;
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));
572 TEST_F(databaseTest,enterSinkClassStatic)
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;
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));
597 TEST_F(databaseTest, changeSystemProperty)
599 std::vector<am_SystemProperty_s> listSystemProperties,listReturn;
600 am_SystemProperty_s systemProperty;
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);
613 TEST_F(databaseTest, systemProperties)
615 std::vector<am_SystemProperty_s> listSystemProperties,listReturn;
616 am_SystemProperty_s systemProperty;
618 systemProperty.type=SYP_TEST;
619 systemProperty.value=33;
620 listSystemProperties.push_back(systemProperty);
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);
629 TEST_F(databaseTest,enterSourcesCorrect)
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;
636 pCF.createSource(staticSource);
637 staticSource.sourceID=4;
638 staticSource.name="Static";
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";
643 pCF.createSource(firstDynamicSource);
644 firstDynamicSource.name="firstDynamicSource";
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";
649 pCF.createSource(secondDynamicSource);
650 secondDynamicSource.name="secondDynamicSource";
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";
655 //now read back and check the returns agains the given values
656 ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList))<< "ERROR: database error";
659 std::vector<am_Source_s>::iterator listIterator=sourceList.begin();
660 for(;listIterator<sourceList.end();++listIterator)
662 if(listIterator->sourceID==staticSourceID)
664 equal = equal && pCF.compareSource(listIterator,staticSource);
667 if(listIterator->sourceID==firstDynamicSourceID)
669 equal = equal && pCF.compareSource(listIterator,firstDynamicSource);
672 if(listIterator->sourceID==secondDynamicSourceID)
674 equal = equal && pCF.compareSource(listIterator,secondDynamicSource);
678 ASSERT_EQ(true,equal);
682 TEST_F(databaseTest, changeSourceMainSoundProperty)
684 std::vector<am_Source_s> listSources;
686 am_sourceID_t sourceID;
687 pCF.createSource(source);
688 am_MainSoundProperty_s property;
689 property.type=MSP_NAVIGATION_OFFSET;
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)
697 if(listIterator->type==property.type)
699 ASSERT_EQ(listIterator->value,property.value);
704 TEST_F(databaseTest, changeSinkMuteState)
706 std::vector<am_Sink_s> listSinks;
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);
717 TEST_F(databaseTest, changeSinkMainSoundProperty)
719 std::vector<am_Sink_s> listSinks;
722 pCF.createSink(sink);
723 am_MainSoundProperty_s property;
724 property.type=MSP_NAVIGATION_OFFSET;
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)
732 if(listIterator->type==property.type)
734 ASSERT_EQ(listIterator->value,property.value);
739 TEST_F(databaseTest, peekDomain)
741 std::vector<am_Domain_s> listDomains;
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);
757 TEST_F(databaseTest, peekDomainFirstEntered)
759 std::vector<am_Domain_s> listDomains;
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);
772 TEST_F(databaseTest, changeDomainState)
774 std::vector<am_Domain_s> listDomains;
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);
786 TEST_F(databaseTest, changeMainConnectionState)
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);
795 TEST_F(databaseTest, changeSinkAvailability)
797 std::vector<am_Sink_s> listSinks;
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);
811 TEST_F(databaseTest, changeSourceAvailability)
813 std::vector<am_Source_s> listSources;
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);
828 TEST_F(databaseTest,changeMainConnectionRoute)
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;
837 std::vector<am_Connection_s> connectionList;
839 for (uint16_t i=1;i<10;i++)
841 am_sinkID_t forgetSink;
842 am_sourceID_t forgetSource;
843 am_connectionID_t forgetConnection;
845 pCF.createConnection(connection);
846 connection.sinkID=i+20;
847 connection.sourceID=i+20;
849 connectionList.push_back(connection);
851 pCF.createSink(sink);
853 sink.name="sink" + int2string(i+20);
855 pCF.createSource(source);
856 source.sourceID=i+20;
857 source.name="source" + int2string(i+30);
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";
868 std::vector<am_RoutingElement_s> routingList;
869 pCF.connectionList2RoutingList(routingList,connectionList);
873 route.route=routingList;
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));
883 TEST_F(databaseTest,changeMainSinkVolume)
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);
896 TEST_F(databaseTest,getMainSourceSoundProperties)
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));
908 TEST_F(databaseTest,getMainSinkSoundProperties)
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));
920 TEST_F(databaseTest,getMainSources)
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";
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)
944 equal = equal && pCF.compareSinkMainSource(listIterator,listSources);
949 TEST_F(databaseTest,getMainSinks)
951 am_Sink_s sink, sink1,sink2;
953 pCF.createSink(sink);
954 pCF.createSink(sink1);
955 pCF.createSink(sink2);
960 std::vector<am_SinkType_s> listMainSinks;
961 std::vector<am_Sink_s> listSinks;
962 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
964 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink1,sinkID));
965 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink2,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)
973 equal = equal && pCF.compareSinkMainSink(listIterator,listSinks);
978 TEST_F(databaseTest,getVisibleMainConnections)
980 createMainConnectionSetup();
981 am_MainConnection_s mainConnection;
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);
993 TEST_F(databaseTest,getListSourcesOfDomain)
995 am_Source_s source, source2;
997 am_domainID_t domainID;
998 am_sourceID_t sourceID;
999 std::vector<am_sourceID_t> sourceList,sourceCheckList;
1000 pCF.createSource(source);
1002 source.name="testSource";
1004 pCF.createSource(source2);
1006 source2.name="testSource2";
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());
1019 TEST_F(databaseTest,getListSinksOfDomain)
1021 am_Sink_s sink, sink2;
1023 am_domainID_t domainID;
1025 std::vector<am_sinkID_t> sinkList,sinkCheckList;
1026 pCF.createSink(sink);
1029 pCF.createSink(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());
1043 TEST_F(databaseTest,getListGatewaysOfDomain)
1045 am_Gateway_s gateway, gateway2;
1046 am_gatewayID_t gatewayID;
1047 am_domainID_t domainID;
1049 std::vector<am_gatewayID_t> gatewayList,gatewayCheckList;
1050 pCF.createGateway(gateway);
1051 gateway.gatewayID=1;
1052 gateway.name="testGateway";
1053 gateway.controlDomainID=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;
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());
1077 TEST_F(databaseTest,removeDomain)
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());
1089 TEST_F(databaseTest,removeGateway)
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());
1101 TEST_F(databaseTest,removeSink)
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());
1113 TEST_F(databaseTest,removeSource)
1115 //fill the connection database
1117 am_sourceID_t sourceID;
1118 std::vector<am_Source_s> listSources;
1119 pCF.createSource(source);
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());
1127 TEST_F(databaseTest, removeMainConnection)
1129 createMainConnectionSetup();
1130 ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(1))<< "ERROR: database error";
1133 TEST_F(databaseTest,removeNonexistentMainConnectionFail)
1135 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34))<< "ERROR: database error";
1138 TEST_F(databaseTest,removeNonexistentSource)
1140 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3))<< "ERROR: database error";
1143 TEST_F(databaseTest,removeNonexistentSink)
1145 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2))<< "ERROR: database error";
1148 TEST_F(databaseTest,removeNonexistentGateway)
1150 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12))<< "ERROR: database error";
1153 TEST_F(databaseTest,registerGatewayCorrect)
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;
1160 pCF.createGateway(gateway);
1161 pCF.createGateway(gateway1);
1162 gateway1.gatewayID=20;
1163 pCF.createGateway(gateway2);
1165 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))<< "ERROR: database error";
1166 ASSERT_EQ(100,gatewayID)<< "ERROR: domainID zero";
1168 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))<< "ERROR: database error";
1169 ASSERT_EQ(gateway1.gatewayID,gatewayID1)<< "ERROR: domainID zero";
1171 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))<< "ERROR: database error";
1172 ASSERT_EQ(101,gatewayID2)<< "ERROR: domainID zero";
1174 //now check if we read out the correct values
1175 ASSERT_EQ(E_OK,pDatabaseHandler.getListGateways(returnList));
1177 std::vector<am_Gateway_s>::iterator listIterator=returnList.begin();
1179 for(;listIterator<returnList.end();++listIterator)
1181 if(listIterator->gatewayID==gatewayID)
1183 equal= equal && pCF.compareGateway(listIterator,gateway);
1186 if(listIterator->gatewayID==gatewayID1)
1188 equal= equal && pCF.compareGateway(listIterator,gateway1);
1191 if(listIterator->gatewayID==gatewayID2)
1193 equal= equal && pCF.compareGateway(listIterator,gateway2);
1197 ASSERT_EQ(true,equal);
1200 TEST_F(databaseTest,getGatewayInfo)
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;
1207 pCF.createGateway(gateway);
1208 pCF.createGateway(gateway1);
1209 gateway1.gatewayID=20;
1210 pCF.createGateway(gateway2);
1212 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))<< "ERROR: database error";
1213 ASSERT_EQ(100,gatewayID)<< "ERROR: domainID zero";
1215 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))<< "ERROR: database error";
1216 ASSERT_EQ(gateway1.gatewayID,gatewayID1)<< "ERROR: domainID zero";
1218 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))<< "ERROR: database error";
1219 ASSERT_EQ(101,gatewayID2)<< "ERROR: domainID zero";
1221 //now check if we read out the correct values
1222 ASSERT_EQ(E_OK,pDatabaseHandler.getListGateways(returnList));
1224 std::vector<am_Gateway_s>::iterator listIterator=returnList.begin();
1226 for(;listIterator<returnList.end();++listIterator)
1228 if(listIterator->gatewayID==gatewayID)
1230 equal= equal && pCF.compareGateway(listIterator,gateway);
1233 if(listIterator->gatewayID==gatewayID1)
1235 equal= equal && pCF.compareGateway(listIterator,gateway1);
1238 if(listIterator->gatewayID==gatewayID2)
1240 equal= equal && pCF.compareGateway(listIterator,gateway2);
1244 ASSERT_EQ(true,equal);
1246 am_Gateway_s gatewayInfo;
1247 ASSERT_EQ(E_OK,pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo));
1248 ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo));
1252 TEST_F(databaseTest,enterSinkThatAlreadyExistFail)
1254 //fill the connection database
1255 am_Sink_s staticSink,SecondSink;
1256 am_sinkID_t staticSinkID,SecondSinkID;
1258 pCF.createSink(staticSink);
1259 staticSink.sinkID=43;
1260 staticSink.name="Static";
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";
1265 pCF.createSink(SecondSink);
1266 SecondSink.sinkID=43;
1267 SecondSink.name="SecondSink";
1269 ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSinkDB(SecondSink,SecondSinkID))<< "ERROR: database error";
1272 TEST_F(databaseTest,enterSourcesThatAlreadyExistFail)
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;
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";
1283 pCF.createSource(SecondSource);
1284 SecondSource.sourceID=4;
1286 ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSourceDB(SecondSource,SecondSourceID))<< "ERROR: database error";
1289 TEST_F(databaseTest,registerDomainCorrect)
1292 std::vector<am_Domain_s> returnList;
1294 am_domainID_t domainID=0;
1295 pCF.createDomain(domain);
1297 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID))<< "ERROR: database error";
1298 ASSERT_NE(0,domainID)<< "ERROR: domainID zero";
1300 //now check if we read out the correct values
1301 ASSERT_EQ(E_OK,pDatabaseHandler.getListDomains(returnList));
1303 std::vector<am_Domain_s>::iterator listIterator=returnList.begin();
1304 for(;listIterator<returnList.end();++listIterator)
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);
1314 ASSERT_EQ(true,equal);
1317 TEST_F(databaseTest,registerConnectionCorrect)
1319 am_Connection_s connection;
1320 am_connectionID_t connectionID;
1321 std::vector<am_Connection_s> returnList;
1322 pCF.createConnection(connection);
1324 ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID))<< "ERROR: database error";;
1325 ASSERT_NE(0,connectionID)<< "ERROR: connectionID zero";
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));
1331 std::vector<am_Connection_s>::iterator listIterator=returnList.begin();
1332 for(;listIterator<returnList.end();++listIterator)
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);
1341 ASSERT_EQ(true,equal);
1344 TEST_F(databaseTest,enterMainConnectionCorrect)
1346 createMainConnectionSetup();
1349 TEST_F(databaseTest,enterSinksCorrect)
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;
1356 pCF.createSink(staticSink);
1357 staticSink.sinkID=4;
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";
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";
1367 pCF.createSink(secondDynamicSink);
1368 secondDynamicSink.name="seconddynamic";
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";
1373 //now read back and check the returns agains the given values
1374 ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList))<< "ERROR: database error";
1377 std::vector<am_Sink_s>::iterator listIterator=sinkList.begin();
1378 for(;listIterator<sinkList.end();++listIterator)
1380 if(listIterator->sinkID==staticSinkID)
1382 equal = equal && pCF.compareSink(listIterator,staticSink);
1385 if(listIterator->sinkID==firstDynamicSinkID)
1387 equal = equal && pCF.compareSink(listIterator,firstDynamicSink);
1390 if(listIterator->sinkID==secondDynamicSinkID)
1392 equal = equal && pCF.compareSink(listIterator,secondDynamicSink);
1395 ASSERT_EQ(true,equal);
1398 //Commented out - gives always a warning..
1399 //TEST_F(databaseTest,registerDomainFailonID0)
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'");
1409 int main(int argc, char **argv)
1411 ::testing::InitGoogleTest(&argc, argv);
1412 return RUN_ALL_TESTS();