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 "MockInterfaces.h"
28 #include "DatabaseHandler.h"
29 #include "ControlReceiver.h"
30 #include "ControlSender.h"
31 #include "DatabaseObserver.h"
32 #include "../ControlInterfaceBackdoor.h"
33 #include "../CommandInterfaceBackdoor.h"
34 #include "../CommonFunctions.h"
35 #include "DLTWrapper.h"
38 using namespace testing;
40 //extern int GetRandomNumber(int nLow, int nHigh);
41 //extern bool equalSoundProperty (const am_SoundProperty_s a, const am_SoundProperty_s b);
42 extern bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b);
43 extern bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b);
44 extern bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b);
45 extern std::string int2string(int i);
47 routingTest::routingTest() :
48 plistRoutingPluginDirs(), //
49 plistCommandPluginDirs(), //
50 pDatabaseHandler(std::string(":memory:")), //
51 pRoutingSender(plistRoutingPluginDirs), //
52 pCommandSender(plistCommandPluginDirs), //
54 pRoutingInterfaceBackdoor(), //
55 pCommandInterfaceBackdoor(), //
56 pControlSender(""), //
57 pRouter(&pDatabaseHandler, &pControlSender), //
58 pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pRouter), //
59 pObserver(&pCommandSender, &pRoutingSender)
61 pDatabaseHandler.registerObserver(&pObserver);
62 pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface);
65 routingTest::~routingTest()
69 void routingTest::createMainConnectionSetup()
71 //fill the connection database
72 am_Connection_s connection;
75 std::vector<am_Connection_s> connectionList;
77 //we create 9 sources and sinks:
78 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(9);
79 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(9);
81 for (uint16_t i = 1; i < 10; i++)
83 am_sinkID_t forgetSink;
84 am_sourceID_t forgetSource;
85 am_connectionID_t forgetConnection;
87 pCF.createConnection(connection);
88 connection.sinkID = i;
89 connection.sourceID = i;
90 connectionList.push_back(connection);
94 sink.name = "sink" + int2string(i);
96 pCF.createSource(source);
98 source.name = "source" + int2string(i);
101 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,forgetSink))
102 << "ERROR: database error";
103 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,forgetSource))
104 << "ERROR: database error";
105 ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,forgetConnection))
106 << "ERROR: database error";
107 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(forgetConnection));
111 std::vector<am_RoutingElement_s> routingList;
112 pCF.connectionList2RoutingList(routingList, connectionList);
116 route.route = routingList;
120 //create a mainConnection
121 am_MainConnection_s mainConnection;
122 am_mainConnectionID_t mainConnectionID;
123 std::vector<am_MainConnection_s> mainConnectionList;
124 pCF.createMainConnection(mainConnection, route);
126 //enter mainconnection in database
127 EXPECT_CALL(pMockInterface,cbNumberOfMainConnectionsChanged()).Times(1);
128 EXPECT_CALL(pMockInterface,cbMainConnectionStateChanged(_,_)).Times(1);
129 ASSERT_EQ(E_OK,pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID))
130 << "ERROR: database error";
131 ASSERT_NE(0,mainConnectionID)
132 << "ERROR: connectionID zero";
134 //read out the mainconnections and check if they are equal to the data written.
135 ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(mainConnectionList));
137 std::vector<am_MainConnection_s>::iterator listIterator = mainConnectionList.begin();
138 for (; listIterator < mainConnectionList.end(); ++listIterator)
140 if (listIterator->connectionID == mainConnectionID)
142 equal = equal && (listIterator->connectionState == mainConnection.connectionState) && (listIterator->route.sinkID == mainConnection.route.sinkID) && (listIterator->route.sourceID == mainConnection.route.sourceID) && (listIterator->delay == mainConnection.delay) && (std::equal(listIterator->route.route.begin(), listIterator->route.route.end(), routingList.begin(), equalRoutingElement));
145 ASSERT_EQ(true, equal);
148 void routingTest::SetUp()
152 void routingTest::TearDown()
156 TEST_F(routingTest, peekSourceID)
158 EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
159 std::string sourceName("myClassID");
160 am_sourceClass_t sourceClassID, peekID;
161 am_SourceClass_s sourceClass;
162 am_ClassProperty_s classProperty;
163 classProperty.classProperty = CP_SOURCE_TYPE;
164 classProperty.value = 13;
165 sourceClass.name = sourceName;
166 sourceClass.sourceClassID = 0;
167 sourceClass.listClassProperties.push_back(classProperty);
169 //first we peek without an existing class
170 ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID));
172 //now we enter the class into the database
173 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
175 //first we peek without an existing class
176 ASSERT_EQ(E_OK, pDatabaseHandler.peekSourceClassID(sourceName,peekID));
177 ASSERT_EQ(sourceClassID, peekID);
180 TEST_F(routingTest, peekSinkID)
182 EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
183 std::string sinkName("myClassID");
184 am_sinkClass_t sinkClassID, peekID;
185 am_SinkClass_s sinkClass;
186 am_ClassProperty_s classProperty;
187 classProperty.classProperty = CP_SOURCE_TYPE;
188 classProperty.value = 13;
189 sinkClass.name = sinkName;
190 sinkClass.sinkClassID = 0;
191 sinkClass.listClassProperties.push_back(classProperty);
193 //first we peek without an existing class
194 ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID));
196 //now we enter the class into the database
197 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
199 //first we peek without an existing class
200 ASSERT_EQ(E_OK, pDatabaseHandler.peekSinkClassID(sinkName,peekID));
201 ASSERT_EQ(sinkClassID, peekID);
204 TEST_F(routingTest,crossfaders)
207 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2);
208 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
209 am_Crossfader_s crossfader;
210 am_crossfaderID_t crossfaderID;
211 am_Sink_s sinkA, sinkB;
213 am_sourceID_t sourceID;
214 am_sinkID_t sinkAID, sinkBID;
215 pCF.createSink(sinkA);
216 pCF.createSink(sinkB);
217 sinkB.name = "sinkB";
218 pCF.createSource(source);
220 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
221 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID));
222 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID));
224 crossfader.crossfaderID = 0;
225 crossfader.hotSink = HS_SINKA;
226 crossfader.sinkID_A = sinkAID;
227 crossfader.sinkID_B = sinkBID;
228 crossfader.sourceID = sourceID;
229 crossfader.name = "Crossfader";
230 crossfader.hotSink = HS_MIN;
232 std::vector<am_Crossfader_s> listCrossfaders;
234 ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID));
235 ASSERT_EQ(E_OK, pDatabaseHandler.getListCrossfaders(listCrossfaders));
236 ASSERT_EQ(crossfader.sinkID_A, listCrossfaders[0].sinkID_A);
237 ASSERT_EQ(crossfader.sinkID_B, listCrossfaders[0].sinkID_B);
238 ASSERT_EQ(crossfader.sourceID, listCrossfaders[0].sourceID);
239 ASSERT_EQ(crossfader.hotSink, listCrossfaders[0].hotSink);
240 ASSERT_EQ(100, listCrossfaders[0].crossfaderID);
241 ASSERT_EQ(crossfader.name.compare(listCrossfaders[0].name), 0);
244 TEST_F(routingTest,crossfadersGetFromDomain)
247 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2);
248 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
249 am_Crossfader_s crossfader;
250 am_crossfaderID_t crossfaderID;
251 am_Sink_s sinkA, sinkB;
253 am_sourceID_t sourceID;
254 am_sinkID_t sinkAID, sinkBID;
255 am_domainID_t domainID;
257 pCF.createSink(sinkA);
258 pCF.createSink(sinkB);
259 pCF.createDomain(domain);
260 sinkB.name = "sinkB";
261 pCF.createSource(source);
262 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
263 source.domainID=domainID;
264 sinkA.domainID=domainID;
265 sinkB.domainID=domainID;
267 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
268 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID));
269 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID));
271 crossfader.crossfaderID = 0;
272 crossfader.hotSink = HS_SINKA;
273 crossfader.sinkID_A = sinkAID;
274 crossfader.sinkID_B = sinkBID;
275 crossfader.sourceID = sourceID;
276 crossfader.name = "Crossfader";
277 crossfader.hotSink = HS_MIN;
279 std::vector<am_crossfaderID_t> listCrossfaders;
281 ASSERT_EQ(E_OK, pDatabaseHandler.enterCrossfaderDB(crossfader,crossfaderID));
282 ASSERT_EQ(E_OK,pDatabaseHandler.getListCrossfadersOfDomain(source.domainID,listCrossfaders));
283 ASSERT_EQ(100, listCrossfaders[0]);
287 TEST_F(routingTest,sourceState)
290 am_sourceID_t sourceID;
291 std::vector<am_Source_s> listSources;
292 pCF.createSource(source);
293 source.sourceState = SS_OFF;
296 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
297 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
299 //change the source state
300 ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceState(sourceID,SS_ON));
302 //read out the changed values
303 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
304 ASSERT_EQ(listSources[0].sourceState, SS_ON);
307 TEST_F(routingTest,sinkVolumeChange)
311 std::vector<am_Sink_s> listSinks;
312 pCF.createSink(sink);
316 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
317 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
319 //change the volume and check the read out
320 ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkVolume(sinkID,34));
321 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
322 ASSERT_EQ(listSinks[0].volume, 34);
325 TEST_F(routingTest,sourceVolumeChange)
328 am_sourceID_t sourceID;
329 std::vector<am_Source_s> listSources;
330 pCF.createSource(source);
334 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
335 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
337 //change the volume and check the read out
338 ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceVolume(sourceID,34));
339 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
340 ASSERT_EQ(listSources[0].volume, 34);
343 TEST_F(routingTest, peekSource)
345 std::vector<am_Source_s> listSources;
346 am_sourceID_t sourceID, source2ID, source3ID;
348 pCF.createSource(source);
350 //peek a source that does not exits
351 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(0);
352 ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID));
354 //make sure it is not in the list
355 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
356 ASSERT_TRUE(listSources.empty());
357 ASSERT_EQ(sourceID, 100);
359 //now enter the source with the same name and make sure it does not get a new ID
360 source.name = "newsource";
361 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
362 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source2ID));
363 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
364 ASSERT_EQ(sourceID, source2ID);
365 ASSERT_TRUE(listSources[0].sourceID==sourceID);
367 //now we peek again. This time, the source exists
368 ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(source.name,source3ID));
369 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
370 ASSERT_TRUE(listSources.size()==1);
371 ASSERT_EQ(source3ID, source2ID);
374 TEST_F(routingTest, peekSourceDouble)
376 std::vector<am_Source_s> listSources;
377 am_sourceID_t sourceID;
378 am_sourceID_t source2ID;
379 am_sourceID_t source3ID;
381 pCF.createSource(source);
383 //peek a source that does not exits
384 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(0);
385 ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID));
387 //peek a second source that does not exits
388 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(0);
389 ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource2"),source2ID));
391 //make sure they are is not in the list
392 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
393 ASSERT_TRUE(listSources.empty());
394 ASSERT_EQ(sourceID, 100);
395 source.name = "newsource";
397 //now enter the source with the same name than the first peek and make sure it does not get a new ID
398 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
399 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,source3ID));
400 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
401 ASSERT_EQ(sourceID, source3ID);
402 ASSERT_TRUE(listSources[0].sourceID==sourceID);
405 TEST_F(routingTest, peekSink)
407 std::vector<am_Sink_s> listSinks;
408 am_sinkID_t sinkID, sink2ID, sink3ID;
410 pCF.createSink(sink);
412 //peek a sink that does not exits
413 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(0);
414 ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID));
416 //make sure it is not in the list
417 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
418 ASSERT_TRUE(listSinks.empty());
419 ASSERT_EQ(sinkID, 100);
420 sink.name = "newsink";
422 //now enter the source with the same name and make sure it does not get a new ID
423 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
424 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink2ID));
425 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
426 ASSERT_EQ(sinkID, sink2ID);
427 ASSERT_TRUE(listSinks[0].sinkID==sinkID);
429 //now we peek again, this time, the sink exists
430 ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(sink.name,sink3ID));
431 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
432 ASSERT_TRUE(listSinks.size()==1);
433 ASSERT_EQ(sink3ID, sink2ID);
436 TEST_F(routingTest, peekSinkDouble)
438 std::vector<am_Sink_s> listSinks;
443 pCF.createSink(sink);
445 //peek a sink that does not exits
446 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(0);
447 ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID));
450 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(0);
451 ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("nextsink"),sink2ID));
453 //make sure they are is not in the list
454 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
455 ASSERT_TRUE(listSinks.empty());
456 ASSERT_EQ(sinkID, 100);
457 sink.name = "newsink";
459 //now enter the sink with the same name than the first peek and make sure it does not get a new ID
460 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
461 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sink3ID));
462 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
463 ASSERT_EQ(sinkID, sink3ID);
464 ASSERT_TRUE(listSinks[0].sinkID==sinkID);
467 TEST_F(routingTest,changeConnectionTimingInformationCheckMainConnection)
469 am_Connection_s connection;
470 std::vector<am_Connection_s> connectionList;
471 std::vector<am_MainConnectionType_s> mainList;
472 pCF.createConnection(connection);
474 //prepare the test, it is one mainconnection, so we expect one callback
475 createMainConnectionSetup();
476 EXPECT_CALL(pMockInterface,cbTimingInformationChanged(1,216)).Times(1);
478 //first get all visible mainconnections and make sure, the delay is set to -1 for the first entry
479 ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList));
480 ASSERT_EQ(mainList[0].delay, -1);
482 //no go through all connections and set the delay time to 24 for each connection
483 ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
484 std::vector<am_Connection_s>::iterator iteratorConnectionList = connectionList.begin();
485 for (; iteratorConnectionList < connectionList.end(); ++iteratorConnectionList)
487 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->sinkID,24));
490 //we read the result again and expect that the value is now different from -1
491 ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(mainList));
492 ASSERT_EQ(mainList[0].delay, 216);
495 TEST_F(routingTest,changeConnectionTimingInformation)
497 am_Connection_s connection;
498 am_connectionID_t connectionID;
499 std::vector<am_Connection_s> connectionList;
500 pCF.createConnection(connection);
503 ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID));
504 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
506 //change the timing and check it
507 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(connectionID,24));
508 ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
509 ASSERT_TRUE(connectionList[0].delay==24);
512 TEST_F(routingTest,getSinkClassOfSink)
514 std::vector<am_SinkClass_s> sinkClassList;
515 std::vector<am_ClassProperty_s> classPropertyList;
516 am_SinkClass_s sinkClass, returnClass;
517 am_ClassProperty_s classProperty;
518 am_sinkClass_t sinkClassID;
521 classProperty.classProperty = CP_SINK_TYPE;
522 classProperty.value = 1;
523 classPropertyList.push_back(classProperty);
524 classProperty.classProperty = CP_SOURCE_TYPE;
525 classProperty.value = 4;
526 classPropertyList.push_back(classProperty);
527 sinkClass.name = "test";
528 sinkClass.sinkClassID = 4;
529 sinkClass.listClassProperties = classPropertyList;
530 pCF.createSink(sink);
531 sink.sinkClassID = 4;
534 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
535 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
537 //enter a new sinkclass, read out again and check
538 EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
539 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
540 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
541 ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
542 ASSERT_EQ(sinkClassList[0].sinkClassID, 4);
543 ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
544 ASSERT_EQ(E_OK, pDatabaseHandler.getSinkClassInfoDB(sinkID,returnClass));
545 ASSERT_EQ(sinkClassList[0].name, returnClass.name);
546 ASSERT_EQ(sinkClassList[0].sinkClassID, returnClass.sinkClassID);
547 ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),returnClass.listClassProperties.begin(),equalClassProperties));
550 TEST_F(routingTest,getSourceClassOfSource)
552 std::vector<am_SourceClass_s> sourceClassList;
553 std::vector<am_ClassProperty_s> classPropertyList;
554 am_SourceClass_s sourceClass, sinkSourceClass;
555 am_ClassProperty_s classProperty;
556 am_sourceClass_t sourceClassID;
558 am_sourceID_t sourceID;
559 classProperty.classProperty = CP_SINK_TYPE;
560 classProperty.value = 1;
561 classPropertyList.push_back(classProperty);
562 classProperty.classProperty = CP_SOURCE_TYPE;
563 classProperty.value = 4;
564 classPropertyList.push_back(classProperty);
565 sourceClass.name = "test";
566 sourceClass.sourceClassID = 1;
567 sourceClass.listClassProperties = classPropertyList;
568 pCF.createSource(source);
570 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
571 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
572 EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
573 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
574 ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
575 ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
576 ASSERT_EQ(sourceClassList[0].sourceClassID, 1);
577 ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
578 ASSERT_EQ(E_OK, pDatabaseHandler.getSourceClassInfoDB(sourceID,sinkSourceClass));
579 ASSERT_EQ(sourceClassList[0].name, sinkSourceClass.name);
580 ASSERT_EQ(sourceClassList[0].sourceClassID, sinkSourceClass.sourceClassID);
581 ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),sinkSourceClass.listClassProperties.begin(),equalClassProperties));
584 TEST_F(routingTest,removeSourceClass)
586 std::vector<am_SourceClass_s> sourceClassList;
587 std::vector<am_ClassProperty_s> classPropertyList;
588 am_SourceClass_s sourceClass;
589 am_ClassProperty_s classProperty;
590 am_sourceClass_t sourceClassID;
591 classProperty.classProperty = CP_SINK_TYPE;
592 classProperty.value = 1;
593 classPropertyList.push_back(classProperty);
594 classProperty.classProperty = CP_SOURCE_TYPE;
595 classProperty.value = 4;
596 classPropertyList.push_back(classProperty);
597 sourceClass.name = "test";
598 sourceClass.sourceClassID = 3;
599 sourceClass.listClassProperties = classPropertyList;
601 EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(2);
602 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
603 ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
604 ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
605 ASSERT_EQ(sourceClassList[0].sourceClassID, 3);
606 ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
607 ASSERT_EQ(E_OK, pDatabaseHandler.removeSourceClassDB(3));
608 ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
609 ASSERT_TRUE(sourceClassList.empty());
612 TEST_F(routingTest,updateSourceClass)
614 std::vector<am_SourceClass_s> sourceClassList;
615 std::vector<am_ClassProperty_s> classPropertyList, changedPropertyList;
616 am_SourceClass_s sourceClass, changedClass;
617 am_ClassProperty_s classProperty;
618 am_sourceClass_t sourceClassID;
619 classProperty.classProperty = CP_SINK_TYPE;
620 classProperty.value = 1;
621 classPropertyList.push_back(classProperty);
622 classProperty.classProperty = CP_SOURCE_TYPE;
623 classProperty.value = 4;
624 classPropertyList.push_back(classProperty);
625 sourceClass.name = "test";
626 sourceClass.sourceClassID = 0;
627 sourceClass.listClassProperties = classPropertyList;
628 changedClass = sourceClass;
629 changedClass.listClassProperties[1].value = 6;
630 changedPropertyList = changedClass.listClassProperties;
631 EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
632 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
633 changedClass.sourceClassID = sourceClassID;
634 ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
635 ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
636 ASSERT_EQ(sourceClassList[0].sourceClassID, 100);
637 ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
638 ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceClassInfoDB(changedClass));
639 ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
640 ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
641 ASSERT_EQ(sourceClassList[0].sourceClassID, 100);
642 ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties));
645 TEST_F(routingTest,enterSourceClass)
647 std::vector<am_SourceClass_s> sourceClassList;
648 std::vector<am_ClassProperty_s> classPropertyList;
649 am_SourceClass_s sourceClass;
650 am_ClassProperty_s classProperty;
651 am_sourceClass_t sourceClassID;
652 classProperty.classProperty = CP_SINK_TYPE;
653 classProperty.value = 1;
654 classPropertyList.push_back(classProperty);
655 classProperty.classProperty = CP_SOURCE_TYPE;
656 classProperty.value = 4;
657 classPropertyList.push_back(classProperty);
658 sourceClass.name = "test";
659 sourceClass.sourceClassID = 0;
660 sourceClass.listClassProperties = classPropertyList;
662 EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
663 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
664 ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
665 ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
666 ASSERT_EQ(sourceClassList[0].sourceClassID, 100);
667 ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
670 TEST_F(routingTest,enterSourceClassStatic)
672 std::vector<am_SourceClass_s> sourceClassList;
673 std::vector<am_ClassProperty_s> classPropertyList;
674 am_SourceClass_s sourceClass;
675 am_ClassProperty_s classProperty;
676 am_sourceClass_t sourceClassID;
677 classProperty.classProperty = CP_SINK_TYPE;
678 classProperty.value = 1;
679 classPropertyList.push_back(classProperty);
680 classProperty.classProperty = CP_SOURCE_TYPE;
681 classProperty.value = 4;
682 classPropertyList.push_back(classProperty);
683 sourceClass.name = "test";
684 sourceClass.sourceClassID = 3;
685 sourceClass.listClassProperties = classPropertyList;
687 EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1);
688 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass));
689 ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList));
690 ASSERT_EQ(sourceClassList[0].name, sourceClass.name);
691 ASSERT_EQ(sourceClassList[0].sourceClassID, 3);
692 ASSERT_TRUE(std::equal(sourceClassList[0].listClassProperties.begin(),sourceClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
695 TEST_F(routingTest,removeSinkClass)
697 std::vector<am_SinkClass_s> sinkClassList;
698 std::vector<am_ClassProperty_s> classPropertyList;
699 am_SinkClass_s sinkClass;
700 am_ClassProperty_s classProperty;
701 am_sinkClass_t sinkClassID;
702 classProperty.classProperty = CP_SINK_TYPE;
703 classProperty.value = 1;
704 classPropertyList.push_back(classProperty);
705 classProperty.classProperty = CP_SOURCE_TYPE;
706 classProperty.value = 4;
707 classPropertyList.push_back(classProperty);
708 sinkClass.name = "test";
709 sinkClass.sinkClassID = 0;
710 sinkClass.listClassProperties = classPropertyList;
712 EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(2);
713 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
714 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
715 ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
716 ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
717 ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
718 ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkClassDB(sinkClassID));
719 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
720 ASSERT_TRUE(sinkClassList.empty());
723 TEST_F(routingTest,updateSinkClass)
725 std::vector<am_SinkClass_s> sinkClassList;
726 std::vector<am_ClassProperty_s> classPropertyList, changedPropertyList;
727 am_SinkClass_s sinkClass, changedClass;
728 am_ClassProperty_s classProperty;
729 am_sinkClass_t sinkClassID;
730 classProperty.classProperty = CP_SINK_TYPE;
731 classProperty.value = 1;
732 classPropertyList.push_back(classProperty);
733 classProperty.classProperty = CP_SOURCE_TYPE;
734 classProperty.value = 4;
735 classPropertyList.push_back(classProperty);
736 sinkClass.name = "test";
737 sinkClass.sinkClassID = 0;
738 sinkClass.listClassProperties = classPropertyList;
739 changedClass = sinkClass;
740 changedClass.listClassProperties[1].value = 6;
741 changedPropertyList = changedClass.listClassProperties;
742 EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
743 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
744 changedClass.sinkClassID = sinkClassID;
745 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
746 ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
747 ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
748 ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
749 ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkClassInfoDB(changedClass));
750 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
751 ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
752 ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
753 ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),changedPropertyList.begin(),equalClassProperties));
756 TEST_F(routingTest,enterSinkClass)
758 std::vector<am_SinkClass_s> sinkClassList;
759 std::vector<am_ClassProperty_s> classPropertyList;
760 am_SinkClass_s sinkClass;
761 am_ClassProperty_s classProperty;
762 am_sinkClass_t sinkClassID;
763 classProperty.classProperty = CP_SINK_TYPE;
764 classProperty.value = 1;
765 classPropertyList.push_back(classProperty);
766 classProperty.classProperty = CP_SOURCE_TYPE;
767 classProperty.value = 4;
768 classPropertyList.push_back(classProperty);
769 sinkClass.name = "test";
770 sinkClass.sinkClassID = 0;
771 sinkClass.listClassProperties = classPropertyList;
773 EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
774 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
775 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
776 ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
777 ASSERT_EQ(sinkClassList[0].sinkClassID, 100);
778 ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
781 TEST_F(routingTest,enterSinkClassStatic)
783 std::vector<am_SinkClass_s> sinkClassList;
784 std::vector<am_ClassProperty_s> classPropertyList;
785 am_SinkClass_s sinkClass;
786 am_ClassProperty_s classProperty;
787 am_sinkClass_t sinkClassID;
788 classProperty.classProperty = CP_SINK_TYPE;
789 classProperty.value = 1;
790 classPropertyList.push_back(classProperty);
791 classProperty.classProperty = CP_SOURCE_TYPE;
792 classProperty.value = 4;
793 classPropertyList.push_back(classProperty);
794 sinkClass.name = "test";
795 sinkClass.sinkClassID = 4;
796 sinkClass.listClassProperties = classPropertyList;
798 EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1);
799 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID));
800 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList));
801 ASSERT_EQ(sinkClassList[0].name, sinkClass.name);
802 ASSERT_EQ(sinkClassList[0].sinkClassID, 4);
803 ASSERT_TRUE(std::equal(sinkClassList[0].listClassProperties.begin(),sinkClassList[0].listClassProperties.end(),classPropertyList.begin(),equalClassProperties));
806 TEST_F(routingTest, changeSystemProperty)
808 std::vector<am_SystemProperty_s> listSystemProperties, listReturn;
809 am_SystemProperty_s systemProperty;
811 systemProperty.type = SYP_TEST;
812 systemProperty.value = 33;
813 listSystemProperties.push_back(systemProperty);
814 EXPECT_CALL(pMockInterface,cbSystemPropertyChanged(_)).Times(1); //todo: check the exact value here
815 ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties));
816 systemProperty.value = 444;
817 ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty));
818 ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn));
819 ASSERT_EQ(listReturn[0].type, systemProperty.type);
820 ASSERT_EQ(listReturn[0].value, systemProperty.value);
823 TEST_F(routingTest, systemProperties)
825 std::vector<am_SystemProperty_s> listSystemProperties, listReturn;
826 am_SystemProperty_s systemProperty;
828 systemProperty.type = SYP_TEST;
829 systemProperty.value = 33;
830 listSystemProperties.push_back(systemProperty);
832 ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties));
833 ASSERT_EQ(E_OK, pDatabaseHandler.getListSystemProperties(listReturn));
834 ASSERT_EQ(listReturn[0].type, systemProperty.type);
835 ASSERT_EQ(listReturn[0].value, systemProperty.value);
838 TEST_F(routingTest,enterSourcesCorrect)
840 //fill the connection database
841 am_Source_s staticSource, firstDynamicSource, secondDynamicSource;
842 am_sourceID_t staticSourceID, firstDynamicSourceID, secondDynamicSourceID;
843 std::vector<am_Source_s> sourceList;
845 pCF.createSource(staticSource);
846 staticSource.sourceID = 4;
847 staticSource.name = "Static";
849 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(3);
850 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID))
851 << "ERROR: database error";
852 ASSERT_EQ(staticSource.sourceID,staticSourceID)
853 << "ERROR: ID not the one given in staticSource";
855 pCF.createSource(firstDynamicSource);
856 firstDynamicSource.name = "firstDynamicSource";
858 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(firstDynamicSource,firstDynamicSourceID))
859 << "ERROR: database error";
860 ASSERT_EQ(firstDynamicSourceID,DYNAMIC_ID_BOUNDARY)
861 << "ERROR: ID not the one given in firstDynamicSink";
863 pCF.createSource(secondDynamicSource);
864 secondDynamicSource.name = "secondDynamicSource";
866 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(secondDynamicSource,secondDynamicSourceID))
867 << "ERROR: database error";
868 ASSERT_NEAR(secondDynamicSourceID,DYNAMIC_ID_BOUNDARY,10)
869 << "ERROR: ID not the one given in secondDynamicSink";
871 //now read back and check the returns agains the given values
872 ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(sourceList))
873 << "ERROR: database error";
876 std::vector<am_Source_s>::iterator listIterator = sourceList.begin();
877 for (; listIterator < sourceList.end(); ++listIterator)
879 if (listIterator->sourceID == staticSourceID)
881 equal = equal && pCF.compareSource(listIterator, staticSource);
884 if (listIterator->sourceID == firstDynamicSourceID)
886 equal = equal && pCF.compareSource(listIterator, firstDynamicSource);
889 if (listIterator->sourceID == secondDynamicSourceID)
891 equal = equal && pCF.compareSource(listIterator, secondDynamicSource);
895 ASSERT_EQ(true, equal);
898 TEST_F(routingTest, changeSourceMainSoundProperty)
900 std::vector<am_Source_s> listSources;
902 am_sourceID_t sourceID;
903 pCF.createSource(source);
904 am_MainSoundProperty_s property;
905 property.type = MSP_NAVIGATION_OFFSET;
907 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
908 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
910 EXPECT_CALL(pMockInterface,cbMainSourceSoundPropertyChanged(sourceID,_)).Times(1); //todo: check in detail
911 ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSourceSoundPropertyDB(property,sourceID));
912 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
913 std::vector<am_MainSoundProperty_s>::iterator listIterator = listSources[0].listMainSoundProperties.begin();
914 for (; listIterator < listSources[0].listMainSoundProperties.end(); ++listIterator)
916 if (listIterator->type == property.type)
918 ASSERT_EQ(listIterator->value, property.value);
923 TEST_F(routingTest, changeSinkMuteState)
925 std::vector<am_Sink_s> listSinks;
928 pCF.createSink(sink);
929 am_MuteState_e muteState = MS_MUTED;
930 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
931 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
933 EXPECT_CALL(pMockInterface,cbSinkMuteStateChanged(sinkID,muteState)).Times(1);
934 ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMuteStateDB(muteState,sinkID));
935 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
936 ASSERT_EQ(muteState, listSinks[0].muteState);
939 TEST_F(routingTest, changeSinkMainSoundProperty)
941 std::vector<am_Sink_s> listSinks;
944 pCF.createSink(sink);
945 am_MainSoundProperty_s property;
946 property.type = MSP_NAVIGATION_OFFSET;
949 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
950 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
952 EXPECT_CALL(pMockInterface,cbMainSinkSoundPropertyChanged(sinkID,_)).Times(1);
953 ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB(property,sinkID));
954 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
955 std::vector<am_MainSoundProperty_s>::iterator listIterator = listSinks[0].listMainSoundProperties.begin();
956 for (; listIterator < listSinks[0].listMainSoundProperties.end(); ++listIterator)
958 if (listIterator->type == property.type)
960 ASSERT_EQ(listIterator->value, property.value);
965 TEST_F(routingTest, peekDomain)
967 std::vector<am_Domain_s> listDomains;
969 am_domainID_t domainID;
970 am_domainID_t domain2ID;
971 pCF.createDomain(domain);
972 ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domainID));
973 ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
974 ASSERT_TRUE(listDomains.empty());
975 ASSERT_EQ(domainID, 1);
976 domain.name = "newdomain";
977 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domain2ID));
978 ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
979 ASSERT_EQ(domainID, domain2ID);
980 ASSERT_TRUE(listDomains[0].domainID==domainID);
983 TEST_F(routingTest, peekDomainFirstEntered)
985 std::vector<am_Domain_s> listDomains;
987 am_domainID_t domainID;
988 am_domainID_t domain2ID;
989 pCF.createDomain(domain);
990 domain.name = "newdomain";
991 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
992 ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domain2ID));
993 ASSERT_EQ(domainID, domain2ID);
994 ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
995 ASSERT_TRUE(listDomains.size()==1);
998 TEST_F(routingTest, changeDomainState)
1000 std::vector<am_Domain_s> listDomains;
1002 am_domainID_t domainID;
1003 pCF.createDomain(domain);
1004 am_DomainState_e newState = DS_INDEPENDENT_STARTUP;
1005 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
1006 ASSERT_EQ(E_OK, pDatabaseHandler.changDomainStateDB(newState,domainID));
1007 ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains));
1008 ASSERT_EQ(newState, listDomains[0].state);
1011 TEST_F(routingTest, changeMainConnectionState)
1013 std::vector<am_MainConnection_s> listMainConnections;
1014 createMainConnectionSetup();
1015 EXPECT_CALL(pMockInterface,cbMainConnectionStateChanged(_,_)).Times(1);
1016 ASSERT_EQ(E_OK,pDatabaseHandler.changeMainConnectionStateDB(1,CS_DISCONNECTING))
1017 << "ERROR: database error";ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections));
1018 ASSERT_EQ(CS_DISCONNECTING, listMainConnections[0].connectionState);
1021 TEST_F(routingTest, changeSinkAvailability)
1023 std::vector<am_Sink_s> listSinks;
1026 pCF.createSink(sink);
1027 am_Availability_s availability;
1028 availability.availability = A_UNKNOWN;
1029 availability.availabilityReason = AR_TEMPERATURE;
1031 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1032 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1033 ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID));
1034 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
1035 ASSERT_EQ(availability.availability, listSinks[0].available.availability);
1036 ASSERT_EQ(availability.availabilityReason, listSinks[0].available.availabilityReason);
1039 TEST_F(routingTest, changeSourceAvailability)
1041 std::vector<am_Source_s> listSources;
1043 am_sourceID_t sourceID;
1044 pCF.createSource(source);
1045 am_Availability_s availability;
1046 availability.availability = A_UNKNOWN;
1047 availability.availabilityReason = AR_TEMPERATURE;
1048 source.visible = true;
1050 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1051 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1052 ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID));
1053 ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources));
1054 ASSERT_EQ(availability.availability, listSources[0].available.availability);
1055 ASSERT_EQ(availability.availabilityReason, listSources[0].available.availabilityReason);
1058 TEST_F(routingTest,changeMainConnectionRoute)
1060 std::vector<am_MainConnection_s> originalList;
1061 std::vector<am_MainConnection_s> newList;
1062 createMainConnectionSetup();
1063 //fill the connection database
1064 am_Connection_s connection;
1067 std::vector<am_Connection_s> connectionList;
1069 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(9);
1070 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(9);
1071 for (uint16_t i = 1; i < 10; i++)
1073 am_sinkID_t forgetSink;
1074 am_sourceID_t forgetSource;
1075 am_connectionID_t forgetConnection;
1077 pCF.createConnection(connection);
1078 connection.sinkID = i + 20;
1079 connection.sourceID = i + 20;
1080 connection.delay = -1;
1081 connectionList.push_back(connection);
1083 pCF.createSink(sink);
1084 sink.sinkID = i + 20;
1085 sink.name = "sink" + int2string(i + 20);
1087 pCF.createSource(source);
1088 source.sourceID = i + 20;
1089 source.name = "source" + int2string(i + 30);
1090 source.domainID = 4;
1092 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,forgetSink))
1093 << "ERROR: database error";
1094 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,forgetSource))
1095 << "ERROR: database error";
1096 ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,forgetConnection))
1097 << "ERROR: database error";
1098 ASSERT_EQ(E_OK,pDatabaseHandler.getListMainConnections(originalList))
1099 << "ERROR: database error";
1104 std::vector<am_RoutingElement_s> routingList;
1105 pCF.connectionList2RoutingList(routingList, connectionList);
1109 route.route = routingList;
1113 ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionRouteDB(1,route));
1114 ASSERT_EQ(E_OK,pDatabaseHandler.getListMainConnections(newList))
1115 << "ERROR: database error";ASSERT_TRUE(std::equal(newList[0].route.route.begin(),newList[0].route.route.end(),routingList.begin(),equalRoutingElement));
1116 ASSERT_FALSE(std::equal(newList[0].route.route.begin(),newList[0].route.route.end(),originalList[0].route.route.begin(),equalRoutingElement));
1119 TEST_F(routingTest,changeMainSinkVolume)
1123 am_mainVolume_t newVol = 20;
1124 std::vector<am_Sink_s> listSinks;
1125 pCF.createSink(sink);
1127 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1128 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1130 EXPECT_CALL(pMockInterface,cbVolumeChanged(sinkID,newVol)).Times(1);
1131 ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID));
1132 ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks));
1133 ASSERT_EQ(listSinks[0].mainVolume, newVol);
1136 TEST_F(routingTest,getMainSourceSoundProperties)
1139 am_sourceID_t sourceID;
1140 pCF.createSource(source);
1141 std::vector<am_MainSoundProperty_s> mainSoundProperties = source.listMainSoundProperties;
1142 std::vector<am_MainSoundProperty_s> listMainSoundProperties;
1144 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1145 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1146 ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSourceSoundProperties(sourceID,listMainSoundProperties));
1147 ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty));
1150 TEST_F(routingTest,getMainSinkSoundProperties)
1154 pCF.createSink(sink);
1155 std::vector<am_MainSoundProperty_s> mainSoundProperties = sink.listMainSoundProperties;
1156 std::vector<am_MainSoundProperty_s> listMainSoundProperties;
1158 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1159 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1160 ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinkSoundProperties(sinkID,listMainSoundProperties));
1161 ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty));
1164 TEST_F(routingTest,getMainSources)
1166 am_Source_s source, source1, source2;
1167 am_sourceID_t sourceID;
1168 pCF.createSource(source);
1169 pCF.createSource(source1);
1170 pCF.createSource(source2);
1171 source1.name = "source1";
1172 source2.name = "source2";
1174 source1.visible = false;
1175 std::vector<am_SourceType_s> listMainSources;
1176 std::vector<am_Source_s> listSources;
1178 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(3);
1180 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1181 source.sourceID = sourceID;
1182 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source1,sourceID));
1183 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source2,sourceID));
1184 source2.sourceID = sourceID;
1185 ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSources(listMainSources));
1186 listSources.push_back(source);
1187 listSources.push_back(source2);
1188 std::vector<am_SourceType_s>::iterator listIterator = listMainSources.begin();
1189 for (; listIterator < listMainSources.end(); ++listIterator)
1191 equal = equal && pCF.compareSinkMainSource(listIterator, listSources);
1196 TEST_F(routingTest,getMainSinks)
1198 am_Sink_s sink, sink1, sink2;
1200 pCF.createSink(sink);
1201 pCF.createSink(sink1);
1202 pCF.createSink(sink2);
1203 sink1.name = "sink1";
1204 sink2.name = "sink2";
1206 sink1.visible = false;
1207 std::vector<am_SinkType_s> listMainSinks;
1208 std::vector<am_Sink_s> listSinks;
1210 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(3);
1211 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1212 sink.sinkID = sinkID;
1213 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink1,sinkID));
1214 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink2,sinkID));
1215 sink2.sinkID = sinkID;
1216 ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinks(listMainSinks));
1217 listSinks.push_back(sink);
1218 listSinks.push_back(sink2);
1219 std::vector<am_SinkType_s>::iterator listIterator = listMainSinks.begin();
1220 for (; listIterator < listMainSinks.end(); ++listIterator)
1222 equal = equal && pCF.compareSinkMainSink(listIterator, listSinks);
1227 TEST_F(routingTest,getVisibleMainConnections)
1229 createMainConnectionSetup();
1230 am_MainConnection_s mainConnection;
1232 pCF.createMainConnection(mainConnection, route);
1233 std::vector<am_MainConnectionType_s> visibleMainConnection;
1234 ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(visibleMainConnection));
1235 ASSERT_TRUE(1==visibleMainConnection[0].mainConnectionID);
1236 ASSERT_TRUE(mainConnection.connectionState==visibleMainConnection[0].connectionState);
1237 ASSERT_TRUE(mainConnection.delay==visibleMainConnection[0].delay);
1238 ASSERT_TRUE(1==visibleMainConnection[0].sinkID);
1239 ASSERT_TRUE(1==visibleMainConnection[0].sourceID);
1242 TEST_F(routingTest,getListSourcesOfDomain)
1244 am_Source_s source, source2;
1246 am_domainID_t domainID;
1247 am_sourceID_t sourceID;
1248 std::vector<am_sourceID_t> sourceList, sourceCheckList;
1249 pCF.createSource(source);
1250 source.sourceID = 1;
1251 source.name = "testSource";
1252 source.domainID = 1;
1253 pCF.createSource(source2);
1254 source2.sourceID = 0;
1255 source2.name = "testSource2";
1256 source2.domainID = 5;
1257 pCF.createDomain(domain);
1258 sourceCheckList.push_back(1); //sink.sinkID);
1260 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2);
1261 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
1262 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID))
1263 << "ERROR: database error";
1264 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source2,sourceID))
1265 << "ERROR: database error";
1266 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSourcesOfDomain(2,sourceList))
1267 << "ERROR: database error";ASSERT_TRUE(sourceList.empty());
1268 ASSERT_EQ(E_OK,pDatabaseHandler.getListSourcesOfDomain(1,sourceList))
1269 << "ERROR: database error";
1270 ASSERT_TRUE(std::equal(sourceList.begin(),sourceList.end(),sourceCheckList.begin()) && !sourceList.empty());
1273 TEST_F(routingTest,getListSinksOfDomain)
1275 am_Sink_s sink, sink2;
1277 am_domainID_t domainID;
1279 std::vector<am_sinkID_t> sinkList, sinkCheckList;
1280 pCF.createSink(sink);
1283 pCF.createSink(sink2);
1285 sink2.name = "sink2";
1286 pCF.createDomain(domain);
1287 sinkCheckList.push_back(1); //sink.sinkID);
1289 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2);
1290 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
1291 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID))
1292 << "ERROR: database error";
1293 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink2,sinkID))
1294 << "ERROR: database error";
1295 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListSinksOfDomain(2,sinkList))
1296 << "ERROR: database error";ASSERT_TRUE(sinkList.empty());
1297 ASSERT_EQ(E_OK,pDatabaseHandler.getListSinksOfDomain(1,sinkList))
1298 << "ERROR: database error";
1299 ASSERT_TRUE(std::equal(sinkList.begin(),sinkList.end(),sinkCheckList.begin()) && !sinkList.empty());
1302 TEST_F(routingTest,getListGatewaysOfDomain)
1304 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1305 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1306 am_Gateway_s gateway, gateway2;
1307 am_gatewayID_t gatewayID;
1308 am_domainID_t domainID;
1310 std::vector<am_gatewayID_t> gatewayList, gatewayCheckList;
1311 pCF.createGateway(gateway);
1312 gateway.gatewayID = 1;
1313 gateway.name = "testGateway";
1314 gateway.controlDomainID = 1;
1315 gateway.sourceID = 1;
1317 gateway.domainSinkID = 1;
1318 gateway.domainSourceID = 1;
1319 pCF.createGateway(gateway2);
1320 gateway2.gatewayID = 2;
1321 gateway2.name = "testGateway2";
1322 gateway2.controlDomainID = 4;
1323 gateway2.sourceID = 1;
1324 gateway2.sinkID = 1;
1325 gateway2.domainSinkID = 1;
1326 gateway2.domainSourceID = 1;
1327 pCF.createDomain(domain);
1328 gatewayCheckList.push_back(gateway.gatewayID);
1332 am_sourceID_t sourceID;
1333 pCF.createSink(sink);
1334 pCF.createSource(source);
1336 source.sourceID = 1;
1337 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1338 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1339 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
1340 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1341 << "ERROR: database error";
1342 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID))
1343 << "ERROR: database error";
1344 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListGatewaysOfDomain(2,gatewayList))
1345 << "ERROR: database error";ASSERT_TRUE(gatewayList.empty());
1346 ASSERT_EQ(E_OK,pDatabaseHandler.getListGatewaysOfDomain(1,gatewayList))
1347 << "ERROR: database error";
1348 ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty());
1351 TEST_F(routingTest,removeDomain)
1354 am_domainID_t domainID;
1355 std::vector<am_Domain_s> listDomains;
1356 pCF.createDomain(domain);
1357 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID))
1358 << "ERROR: database error";
1359 ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID))
1360 << "ERROR: database error";
1361 ASSERT_EQ(E_OK,pDatabaseHandler.getListDomains(listDomains))
1362 << "ERROR: database error";
1363 ASSERT_TRUE(listDomains.empty());
1366 TEST_F(routingTest,removeGateway)
1368 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1369 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1370 am_Gateway_s gateway;
1371 am_gatewayID_t gatewayID;
1372 std::vector<am_Gateway_s> listGateways;
1373 pCF.createGateway(gateway);
1377 am_sourceID_t sourceID;
1378 pCF.createSink(sink);
1379 pCF.createSource(source);
1381 source.sourceID = 2;
1382 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1383 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1384 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1385 << "ERROR: database error";
1386 ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID))
1387 << "ERROR: database error";
1388 ASSERT_EQ(E_OK,pDatabaseHandler.getListGateways(listGateways))
1389 << "ERROR: database error";
1390 ASSERT_TRUE(listGateways.empty());
1393 TEST_F(routingTest,removeSink)
1397 std::vector<am_Sink_s> listSinks;
1398 pCF.createSink(sink);
1399 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2);
1400 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID))
1401 << "ERROR: database error";
1402 ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID))
1403 << "ERROR: database error";
1404 ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(listSinks))
1405 << "ERROR: database error";
1406 ASSERT_TRUE(listSinks.empty());
1409 TEST_F(routingTest,removeSource)
1411 //fill the connection database
1413 am_sourceID_t sourceID;
1414 std::vector<am_Source_s> listSources;
1415 pCF.createSource(source);
1417 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2);
1418 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID))
1419 << "ERROR: database error";
1420 ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID))
1421 << "ERROR: database error";
1422 ASSERT_EQ(E_OK,pDatabaseHandler.getListSources(listSources))
1423 << "ERROR: database error";
1424 ASSERT_TRUE(listSources.empty());
1427 TEST_F(routingTest, removeMainConnection)
1429 createMainConnectionSetup();
1430 EXPECT_CALL(pMockInterface,cbNumberOfMainConnectionsChanged()).Times(1);
1431 EXPECT_CALL(pMockInterface,cbMainConnectionStateChanged(_,_)).Times(1);
1432 ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(1))
1433 << "ERROR: database error";
1436 TEST_F(routingTest,removeNonexistentMainConnectionFail)
1438 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeMainConnectionDB(34))
1439 << "ERROR: database error";
1442 TEST_F(routingTest,removeNonexistentSource)
1444 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSourceDB(3))
1445 << "ERROR: database error";
1448 TEST_F(routingTest,removeNonexistentSink)
1450 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeSinkDB(2))
1451 << "ERROR: database error";
1454 TEST_F(routingTest,removeNonexistentGateway)
1456 ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeGatewayDB(12))
1457 << "ERROR: database error";
1460 TEST_F(routingTest,registerGatewayCorrect)
1462 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1463 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1464 //initialize gateway
1465 std::vector<am_Gateway_s> returnList;
1466 am_Gateway_s gateway, gateway1, gateway2;
1467 am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0;
1469 pCF.createGateway(gateway);
1470 pCF.createGateway(gateway1);
1471 gateway1.gatewayID = 20;
1472 pCF.createGateway(gateway2);
1476 am_sourceID_t sourceID;
1477 pCF.createSink(sink);
1478 pCF.createSource(source);
1480 source.sourceID = 2;
1481 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1482 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1483 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1484 << "ERROR: database error";
1485 ASSERT_EQ(100,gatewayID)
1486 << "ERROR: domainID zero";
1488 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))
1489 << "ERROR: database error";
1490 ASSERT_EQ(gateway1.gatewayID,gatewayID1)
1491 << "ERROR: domainID zero";
1493 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))
1494 << "ERROR: database error";
1495 ASSERT_EQ(101,gatewayID2)
1496 << "ERROR: domainID zero";
1498 //now check if we read out the correct values
1499 ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList));
1501 std::vector<am_Gateway_s>::iterator listIterator = returnList.begin();
1503 for (; listIterator < returnList.end(); ++listIterator)
1505 if (listIterator->gatewayID == gatewayID)
1507 equal = equal && pCF.compareGateway(listIterator, gateway);
1510 if (listIterator->gatewayID == gatewayID1)
1512 equal = equal && pCF.compareGateway(listIterator, gateway1);
1515 if (listIterator->gatewayID == gatewayID2)
1517 equal = equal && pCF.compareGateway(listIterator, gateway2);
1521 ASSERT_EQ(true, equal);
1524 TEST_F(routingTest,getGatewayInfo)
1526 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1527 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1528 //initialize gateway
1529 std::vector<am_Gateway_s> returnList;
1530 am_Gateway_s gateway, gateway1, gateway2;
1531 am_gatewayID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0;
1533 pCF.createGateway(gateway);
1534 pCF.createGateway(gateway1);
1535 gateway1.gatewayID = 20;
1536 pCF.createGateway(gateway2);
1540 am_sourceID_t sourceID;
1541 pCF.createSink(sink);
1542 pCF.createSource(source);
1544 source.sourceID = 2;
1545 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
1546 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
1547 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID))
1548 << "ERROR: database error";
1549 ASSERT_EQ(100,gatewayID)
1550 << "ERROR: domainID zero";
1552 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1))
1553 << "ERROR: database error";
1554 ASSERT_EQ(gateway1.gatewayID,gatewayID1)
1555 << "ERROR: domainID zero";
1557 ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2))
1558 << "ERROR: database error";
1559 ASSERT_EQ(101,gatewayID2)
1560 << "ERROR: domainID zero";
1562 //now check if we read out the correct values
1563 ASSERT_EQ(E_OK, pDatabaseHandler.getListGateways(returnList));
1565 std::vector<am_Gateway_s>::iterator listIterator = returnList.begin();
1567 for (; listIterator < returnList.end(); ++listIterator)
1569 if (listIterator->gatewayID == gatewayID)
1571 equal = equal && pCF.compareGateway(listIterator, gateway);
1574 if (listIterator->gatewayID == gatewayID1)
1576 equal = equal && pCF.compareGateway(listIterator, gateway1);
1579 if (listIterator->gatewayID == gatewayID2)
1581 equal = equal && pCF.compareGateway(listIterator, gateway2);
1585 ASSERT_EQ(true, equal);
1587 am_Gateway_s gatewayInfo;
1588 ASSERT_EQ(E_OK, pDatabaseHandler.getGatewayInfoDB(20,gatewayInfo));
1589 ASSERT_TRUE(pCF.compareGateway1(gateway1,gatewayInfo));
1593 TEST_F(routingTest,enterSinkThatAlreadyExistFail)
1595 //fill the connection database
1596 am_Sink_s staticSink, SecondSink;
1597 am_sinkID_t staticSinkID, SecondSinkID;
1599 pCF.createSink(staticSink);
1600 staticSink.sinkID = 43;
1601 staticSink.name = "Static";
1603 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(1);
1604 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID))
1605 << "ERROR: database error";
1606 ASSERT_EQ(staticSink.sinkID,staticSinkID)
1607 << "ERROR: ID not the one given in staticSink";
1609 pCF.createSink(SecondSink);
1610 SecondSink.sinkID = 43;
1611 SecondSink.name = "SecondSink";
1613 ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSinkDB(SecondSink,SecondSinkID))
1614 << "ERROR: database error";
1617 TEST_F(routingTest,enterSourcesThatAlreadyExistFail)
1619 //fill the connection database
1620 am_Source_s staticSource, SecondSource;
1621 am_sourceID_t staticSourceID, SecondSourceID;
1622 pCF.createSource(staticSource);
1623 staticSource.sourceID = 4;
1625 EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(1);
1626 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID))
1627 << "ERROR: database error";
1628 ASSERT_EQ(staticSource.sourceID,staticSourceID)
1629 << "ERROR: ID not the one given in staticSource";
1631 pCF.createSource(SecondSource);
1632 SecondSource.sourceID = 4;
1634 ASSERT_EQ(E_ALREADY_EXISTS,pDatabaseHandler.enterSourceDB(SecondSource,SecondSourceID))
1635 << "ERROR: database error";
1638 TEST_F(routingTest,registerDomainCorrect)
1641 std::vector<am_Domain_s> returnList;
1643 am_domainID_t domainID = 0;
1644 pCF.createDomain(domain);
1646 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID))
1647 << "ERROR: database error";
1648 ASSERT_NE(0,domainID)
1649 << "ERROR: domainID zero";
1651 //now check if we read out the correct values
1652 ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(returnList));
1654 std::vector<am_Domain_s>::iterator listIterator = returnList.begin();
1655 for (; listIterator < returnList.end(); ++listIterator)
1657 if (listIterator->domainID == domainID)
1659 equal = equal && (listIterator->name.compare(domain.name) == 0) && (listIterator->busname.compare(domain.busname) == 0) && (listIterator->complete == domain.complete) && (listIterator->early == domain.early) && (listIterator->state == domain.state);
1662 ASSERT_EQ(true, equal);
1665 TEST_F(routingTest,registerConnectionCorrect)
1667 am_Connection_s connection;
1668 am_connectionID_t connectionID;
1669 std::vector<am_Connection_s> returnList;
1670 pCF.createConnection(connection);
1672 ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID))
1673 << "ERROR: database error";;
1674 ASSERT_NE(0,connectionID)
1675 << "ERROR: connectionID zero";
1677 //now check if we read out the correct values
1678 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
1679 ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(returnList));
1681 std::vector<am_Connection_s>::iterator listIterator = returnList.begin();
1682 for (; listIterator < returnList.end(); ++listIterator)
1684 if (listIterator->connectionID == connectionID)
1686 equal = (listIterator->sourceID == connection.sourceID) && (listIterator->sinkID == connection.sinkID) && (listIterator->delay == connection.delay) && (listIterator->connectionFormat = connection.connectionFormat);
1689 ASSERT_EQ(true, equal);
1692 TEST_F(routingTest,enterMainConnectionCorrect)
1694 createMainConnectionSetup();
1697 TEST_F(routingTest,enterSinksCorrect)
1699 //fill the connection database
1700 am_Sink_s staticSink, firstDynamicSink, secondDynamicSink;
1701 am_sinkID_t staticSinkID, firstDynamicSinkID, secondDynamicSinkID;
1702 std::vector<am_Sink_s> sinkList;
1704 pCF.createSink(staticSink);
1705 staticSink.sinkID = 4;
1707 EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(3);
1708 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID))
1709 << "ERROR: database error";
1710 ASSERT_EQ(staticSink.sinkID,staticSinkID)
1711 << "ERROR: ID not the one given in staticSink";
1713 pCF.createSink(firstDynamicSink);
1714 firstDynamicSink.name = "firstdynamic";
1715 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(firstDynamicSink,firstDynamicSinkID))
1716 << "ERROR: database error";
1717 ASSERT_EQ(firstDynamicSinkID,DYNAMIC_ID_BOUNDARY)
1718 << "ERROR: ID not the one given in firstDynamicSink";
1720 pCF.createSink(secondDynamicSink);
1721 secondDynamicSink.name = "seconddynamic";
1723 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(secondDynamicSink,secondDynamicSinkID))
1724 << "ERROR: database error";
1725 ASSERT_NEAR(secondDynamicSinkID,DYNAMIC_ID_BOUNDARY,10)
1726 << "ERROR: ID not the one given in secondDynamicSink";
1728 //now read back and check the returns agains the given values
1729 ASSERT_EQ(E_OK,pDatabaseHandler.getListSinks(sinkList))
1730 << "ERROR: database error";
1733 std::vector<am_Sink_s>::iterator listIterator = sinkList.begin();
1734 for (; listIterator < sinkList.end(); ++listIterator)
1736 if (listIterator->sinkID == staticSinkID)
1738 equal = equal && pCF.compareSink(listIterator, staticSink);
1741 if (listIterator->sinkID == firstDynamicSinkID)
1743 equal = equal && pCF.compareSink(listIterator, firstDynamicSink);
1746 if (listIterator->sinkID == secondDynamicSinkID)
1748 equal = equal && pCF.compareSink(listIterator, secondDynamicSink);
1751 ASSERT_EQ(true, equal);
1754 //Commented out - gives always a warning..
1755 //TEST_F(databaseTest,registerDomainFailonID0)
1757 // am_Domain_s domain;
1758 // am_domainID_t domainID=5;
1759 // pCF.createDomain(domain);
1760 // domain.domainID=1;
1761 // ASSERT_DEATH(pDatabaseHandler.enterDomainDB(domain,domainID),"Assertion `domainData.domainID==0'");
1764 int main(int argc, char **argv)
1766 DLTWrapper::instance()->registerApp("databse", "databasetest");
1767 logInfo("Database Test started ");
1768 ::testing::InitGoogleTest(&argc, argv);
1769 return RUN_ALL_TESTS();