2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file controlInterfaceTest.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.
25 #include "controlInterfaceTest.h"
32 using namespace testing;
34 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
36 controlInterfaceTest::controlInterfaceTest() :
37 pDBusWrapper((DBusWrapper*) 1), //
38 plistCommandPluginDirs(), //
39 plistRoutingPluginDirs(), //
40 pDatabaseHandler(std::string(":memory:")), //
41 pRoutingSender(plistRoutingPluginDirs), //
42 pCommandSender(plistCommandPluginDirs), //
43 pMockControlInterface(), //
44 pMockRoutingInterface(), //
45 pControlSender(std::string("")), //
46 pRoutingInterfaceBackdoor(), //
47 pCommandInterfaceBackdoor(), //
48 pControlInterfaceBackdoor(), //
49 pDatabaseObserver(&pCommandSender, &pRoutingSender), //
50 pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender), //
51 pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, pDBusWrapper)
53 pDatabaseHandler.registerObserver(&pDatabaseObserver);
54 pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface);
55 pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockRoutingInterface, "mock");
59 controlInterfaceTest::~controlInterfaceTest()
63 void controlInterfaceTest::SetUp()
65 DLT_REGISTER_APP("Rtest", "RoutingInterfacetest");
66 DLT_REGISTER_CONTEXT(DLT_CONTEXT, "Main", "Main Context");
67 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("RoutingSendInterface Test started "));
71 void controlInterfaceTest::TearDown()
73 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
76 TEST_F(controlInterfaceTest,registerDomain)
80 am_domainID_t domainID;
81 pCF.createDomain(domain);
83 //When we run this test, we expect the call on the control interface
84 EXPECT_CALL(pMockControlInterface,hookSystemRegisterDomain(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK)));
85 ASSERT_EQ(E_OK, pRoutingReceiver.registerDomain(domain,domainID));
86 ASSERT_EQ(domainID, 2);
89 TEST_F(controlInterfaceTest,deregisterDomain)
91 am_domainID_t domainID = 34;
93 //When we run this test, we expect the call on the control interface
94 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterDomain(34)).WillRepeatedly(Return(E_OK));
95 ASSERT_EQ(E_OK, pRoutingReceiver.deregisterDomain(domainID));
98 TEST_F(controlInterfaceTest,registerSink)
102 pCF.createSink(sink);
104 //When we run this test, we expect the call on the control interface
105 EXPECT_CALL(pMockControlInterface,hookSystemRegisterSink(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK)));
106 ASSERT_EQ(E_OK, pRoutingReceiver.registerSink(sink,sinkID));
107 ASSERT_EQ(sinkID, 2);
110 TEST_F(controlInterfaceTest,deregisterSink)
112 am_sinkID_t sinkID = 12;
114 //When we run this test, we expect the call on the control interface
115 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSink(12)).WillRepeatedly(Return(E_OK));
116 ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSink(sinkID));
119 TEST_F(controlInterfaceTest,registerSource)
122 am_sourceID_t sourceID;
123 pCF.createSource(source);
125 //When we run this test, we expect the call on the control interface
126 EXPECT_CALL(pMockControlInterface,hookSystemRegisterSource(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK)));
127 ASSERT_EQ(E_OK, pRoutingReceiver.registerSource(source,sourceID));
128 ASSERT_EQ(sourceID, 2);
131 TEST_F(controlInterfaceTest,deregisterSource)
133 am_sourceID_t sourceID = 12;
135 //When we run this test, we expect the call on the control interface
136 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSource(12)).WillRepeatedly(Return(E_OK));
137 ASSERT_EQ(E_OK, pRoutingReceiver.deregisterSource(sourceID));
140 TEST_F(controlInterfaceTest,registerGateway)
142 am_Gateway_s gateway;
143 am_gatewayID_t gatewayID;
144 pCF.createGateway(gateway);
146 //When we run this test, we expect the call on the control interface
147 EXPECT_CALL(pMockControlInterface,hookSystemRegisterGateway(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2), Return(E_OK)));
148 ASSERT_EQ(E_OK, pRoutingReceiver.registerGateway(gateway,gatewayID));
149 ASSERT_EQ(gatewayID, 2);
152 TEST_F(controlInterfaceTest,deregisterGateway)
154 am_gatewayID_t gatewayID = 12;
156 //When we run this test, we expect the call on the control interface
157 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterGateway(12)).WillRepeatedly(Return(E_OK));
158 ASSERT_EQ(E_OK, pRoutingReceiver.deregisterGateway(gatewayID));
161 TEST_F(controlInterfaceTest,ackConnect)
163 am_connectionID_t connectionID;
167 am_domainID_t domainID;
168 std::vector<am_Connection_s> connectionList;
169 std::vector<am_Handle_s> handlesList;
171 pCF.createSink(sink);
172 pCF.createDomain(domain);
173 domain.name = "mock";
174 domain.busname = "mock";
179 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
180 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
182 //when asyncConnect is called, we expect a call on the routingInterface
183 EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_STEREO)).WillOnce(Return(E_OK));
184 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
186 //The handle should have the correct type
187 ASSERT_EQ(handle.handleType, H_CONNECT);
188 ASSERT_EQ(handle.handle, 1);
189 ASSERT_EQ(connectionID, 1);
191 //The list of handles shall have the handle inside
192 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
193 ASSERT_EQ(handlesList[0].handle, handle.handle);
194 ASSERT_EQ(handlesList[0].handleType, handle.handleType);
196 //we check the list of connections - but it must be empty because the ack did not arrive yet
197 ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
198 ASSERT_TRUE(connectionList.empty());
200 //finally we answer via the RoutingInterface and expect a call on the controlInterface
201 EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1);
202 pRoutingReceiver.ackConnect(handle, connectionID, E_OK);
204 //the list of handles must be empty now
205 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
206 ASSERT_TRUE(handlesList.empty());
208 //but the connection must be in the connectionlist
209 ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
210 ASSERT_TRUE(!connectionList.empty());
212 //no we try the same, but do expect a no_change answer directly and no call because connection already exists
213 ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
216 TEST_F(controlInterfaceTest,ackDisconnect)
218 am_connectionID_t connectionID;
222 am_domainID_t domainID;
223 std::vector<am_Connection_s> connectionList;
224 std::vector<am_Handle_s> handlesList;
226 pCF.createSink(sink);
227 pCF.createDomain(domain);
228 domain.name = "mock";
229 domain.busname = "mock";
234 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
235 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
237 //now we first need to connect, we expect a call on the routing interface
238 EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_STEREO)).WillOnce(Return(E_OK));
239 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
241 //answer with an ack to insert the connection in the database
242 EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1);
243 pRoutingReceiver.ackConnect(handle, connectionID, E_OK);
245 //now we can start to disconnect and expect a call on the routing interface
246 EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK));
247 ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,1));
249 //during the disconnection, the connection is still in the list!
250 ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
251 ASSERT_TRUE(!connectionList.empty());
253 //then we fire the ack and expect a call on the controlInterface
254 EXPECT_CALL(pMockControlInterface,cbAckDisconnect(_,E_OK)).Times(1);
255 pRoutingReceiver.ackDisconnect(handle, connectionID, E_OK);
257 //make sure the handle is gone
258 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
259 ASSERT_TRUE(handlesList.empty());
261 //make sure the connection is gone
262 ASSERT_EQ(E_OK, pDatabaseHandler.getListConnections(connectionList));
263 ASSERT_TRUE(connectionList.empty());
265 //Now let's try to disconnect what is not existing...
266 ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,2));
269 TEST_F(controlInterfaceTest,setSourceState)
273 am_sourceID_t sourceID;
275 am_domainID_t domainID;
276 std::vector<am_Handle_s> handlesList;
278 am_SourceState_e state;
279 pCF.createSource(source);
280 pCF.createDomain(domain);
281 domain.name = "mock";
282 domain.busname = "mock";
287 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
288 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
290 //we set the sourcestate and expect a call on the routingInterface
291 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceState(_,2,SS_PAUSED)).WillOnce(Return(E_OK));
292 ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED));
294 //we want our handle in the list and let the type be the right one
295 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
296 ASSERT_EQ(handlesList[0].handle, handle.handle);
297 ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESTATE);
299 //the state must be unchanged because did not get the ack
300 ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state));
301 ASSERT_EQ(state, SS_ON);
303 //now we sent out the ack and expect a call on the controlInterface
304 EXPECT_CALL(pMockControlInterface,cbAckSetSourceState(_,E_OK)).Times(1);
305 pRoutingReceiver.ackSetSourceState(handle, E_OK);
307 //finally we need the sourcestate to be changed
308 ASSERT_EQ(E_OK, pDatabaseHandler.getSoureState(source.sourceID,state));
309 ASSERT_EQ(state, SS_PAUSED);
311 //make sure the handle is gone
312 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
313 ASSERT_TRUE(handlesList.empty());
315 //we try again but expect a no change error
316 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED));
319 TEST_F(controlInterfaceTest,SetSinkVolumeChange)
324 am_domainID_t domainID;
326 std::vector<am_Handle_s> handlesList;
328 pCF.createSink(sink);
329 pCF.createDomain(domain);
330 domain.name = "mock";
331 domain.busname = "mock";
336 //setup environment, we need a domain and a sink
337 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
338 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
340 //set the volume and expect a call on the routing interface
341 EXPECT_CALL(pMockRoutingInterface,asyncSetSinkVolume(_,2,11,RAMP_DIRECT,23)).WillOnce(Return(E_OK));
342 ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_DIRECT,23));
344 //check the list of handles. The handle must be in there and have the right type
345 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
346 ASSERT_EQ(handlesList[0].handle, handle.handle);
347 ASSERT_EQ(handlesList[0].handleType, H_SETSINKVOLUME);
349 //now we read out the volume, but we expect no change because the ack did not arrive yet
350 ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume));
351 ASSERT_EQ(sink.volume, volume);
353 //lets send the answer and expect a call on the controlInterface
354 EXPECT_CALL(pMockControlInterface,cbAckSetSinkVolumeChange(_,11,E_OK)).Times(1);
355 pRoutingReceiver.ackSetSinkVolumeChange(handle, 11, E_OK);
357 //finally, the new value must be in the database
358 ASSERT_EQ(E_OK, pDatabaseHandler.getSinkVolume(sinkID,volume));
359 ASSERT_EQ(11, volume);
361 //and the handle must be destroyed
362 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
363 ASSERT_TRUE(handlesList.empty());
365 //Now we try again, but the value is unchanged
366 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_DIRECT,23));
369 TEST_F(controlInterfaceTest,ackSetSourceVolumeChange)
372 am_sourceID_t sourceID;
374 am_domainID_t domainID;
376 std::vector<am_Handle_s> handlesList;
378 pCF.createSource(source);
379 pCF.createDomain(domain);
380 domain.name = "mock";
381 domain.busname = "mock";
387 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
388 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
390 //change the sinkVolume, expect a call on the routingInterface
391 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceVolume(_,2,11,RAMP_DIRECT,23)).WillOnce(Return(E_OK));
392 ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_DIRECT,23));
394 //check the list of handles. The handle must be in there and have the right type
395 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
396 ASSERT_EQ(handlesList[0].handle, handle.handle);
397 ASSERT_EQ(handlesList[0].handleType, H_SETSOURCEVOLUME);
399 //now we read out the volume, but we expect no change because the ack did not arrive yet
400 ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume));
401 ASSERT_EQ(source.volume, volume);
403 //lets send the answer and expect a call on the controlInterface
404 EXPECT_CALL(pMockControlInterface,cbAckSetSourceVolumeChange(_,11,E_OK)).Times(1);
405 pRoutingReceiver.ackSetSourceVolumeChange(handle, 11, E_OK);
407 //finally, the new value must be in the database
408 ASSERT_EQ(E_OK, pDatabaseHandler.getSourceVolume(sourceID,volume));
409 ASSERT_EQ(11, volume);
411 //and the handle must be destroyed
412 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
413 ASSERT_TRUE(handlesList.empty());
415 //Now we try again, but the value is unchanged
416 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_DIRECT,23));
419 TEST_F(controlInterfaceTest,ackSetSinkSoundProperty)
424 am_domainID_t domainID;
425 std::vector<am_Handle_s> handlesList;
427 am_SoundProperty_s soundProperty;
429 pCF.createSink(sink);
430 pCF.createDomain(domain);
431 domain.name = "mock";
432 domain.busname = "mock";
435 soundProperty.type = SP_BASS;
436 soundProperty.value = 244;
438 //setup environment, we need a domain and a sink
439 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
440 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
442 //change the soundproperty, expect a call on the routinginterface
443 EXPECT_CALL(pMockRoutingInterface,asyncSetSinkSoundProperty(_,_,2)).WillOnce(Return(E_OK));
444 ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty));
446 //check the list of handles. The handle must be in there and have the right type
447 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
448 ASSERT_EQ(handlesList[0].handle, handle.handle);
449 ASSERT_EQ(handlesList[0].handleType, H_SETSINKSOUNDPROPERTY);
451 //read out this property. There is no change, because the ack did not arrive yet.
452 ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(2,SP_BASS,oldvalue));
453 ASSERT_EQ(sink.listSoundProperties[0].value, oldvalue);
455 //lets send the answer and expect a call on the controlInterface
456 EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)).Times(1);
457 pRoutingReceiver.ackSetSinkSoundProperty(handle, E_OK);
459 //finally, the new value must be in the database
460 ASSERT_EQ(E_OK, pDatabaseHandler.getSinkSoundPropertyValue(sinkID,SP_BASS,oldvalue));
461 ASSERT_EQ(soundProperty.value, oldvalue);
463 //and the handle must be destroyed
464 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
465 ASSERT_TRUE(handlesList.empty());
467 //Now we try again, but the value is unchanged
468 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty));
471 TEST_F(controlInterfaceTest,ackSetSourceSoundProperty)
474 am_sourceID_t sourceID;
476 am_domainID_t domainID;
477 std::vector<am_Handle_s> handlesList;
479 am_SoundProperty_s soundProperty;
481 pCF.createSource(source);
482 pCF.createDomain(domain);
483 domain.name = "mock";
484 domain.busname = "mock";
487 soundProperty.type = SP_BASS;
488 soundProperty.value = 244;
491 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
492 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
494 //we trigger the change and wait for a call on the routinginterface
495 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceSoundProperty(_,_,2)).WillOnce(Return(E_OK));
496 ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty));
498 //check the list of handles. The handle must be in there and have the right type
499 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
500 ASSERT_EQ(handlesList[0].handle, handle.handle);
501 ASSERT_EQ(handlesList[0].handleType, H_SETSOURCESOUNDPROPERTY);
503 //read out this property. There is no change, because the ack did not arrive yet.
504 ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(2,SP_BASS,oldvalue));
505 ASSERT_EQ(source.listSoundProperties[0].value, oldvalue);
507 //lets send the answer and expect a call on the controlInterface
508 EXPECT_CALL(pMockControlInterface,cbAckSetSourceSoundProperty(_,E_OK)).Times(1);
509 pRoutingReceiver.ackSetSourceSoundProperty(handle, E_OK);
511 //finally, the new value must be in the database
512 ASSERT_EQ(E_OK, pDatabaseHandler.getSourceSoundPropertyValue(sourceID,SP_BASS,oldvalue));
513 ASSERT_EQ(soundProperty.value, oldvalue);
515 //and the handle must be destroyed
516 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(handlesList));
517 ASSERT_TRUE(handlesList.empty());
519 //Now we try again, but the value is unchanged
520 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty));
523 TEST_F(controlInterfaceTest,crossFading)
525 //todo: implement crossfading test
528 int main(int argc, char **argv)
530 ::testing::InitGoogleTest(&argc, argv);
531 return RUN_ALL_TESTS();