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), //to get rid of assert
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));
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));
162 TEST_F(controlInterfaceTest,ackConnect)
164 am_connectionID_t connectionID;
168 am_domainID_t domainID;
169 std::vector<am_Connection_s> connectionList;
170 std::vector<am_Handle_s> handlesList;
172 pCF.createSink(sink);
173 pCF.createDomain(domain);
175 domain.busname="mock";
180 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
181 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
183 //when asyncConnect is called, we expect a call on the routingInterface
184 EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_STEREO)).WillOnce(Return(E_OK));
185 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
187 //The handle should have the correct type
188 ASSERT_EQ(handle.handleType,H_CONNECT);
189 ASSERT_EQ(handle.handle,1);
190 ASSERT_EQ(connectionID,1);
192 //The list of handles shall have the handle inside
193 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
194 ASSERT_EQ(handlesList[0].handle,handle.handle);
195 ASSERT_EQ(handlesList[0].handleType,handle.handleType);
197 //we check the list of connections - but it must be empty because the ack did not arrive yet
198 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
199 ASSERT_TRUE(connectionList.empty());
201 //finally we answer via the RoutingInterface and expect a call on the controlInterface
202 EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1);
203 pRoutingReceiver.ackConnect(handle,connectionID,E_OK);
205 //the list of handles must be empty now
206 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
207 ASSERT_TRUE(handlesList.empty());
209 //but the connection must be in the connectionlist
210 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
211 ASSERT_TRUE(!connectionList.empty());
213 //no we try the same, but do expect a no_change answer directly and no call because connection already exists
214 ASSERT_EQ(E_ALREADY_EXISTS,pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
217 TEST_F(controlInterfaceTest,ackDisconnect)
219 am_connectionID_t connectionID;
223 am_domainID_t domainID;
224 std::vector<am_Connection_s> connectionList;
225 std::vector<am_Handle_s> handlesList;
227 pCF.createSink(sink);
228 pCF.createDomain(domain);
230 domain.busname="mock";
235 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
236 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
238 //now we first need to connect, we expect a call on the routing interface
239 EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_STEREO)).WillOnce(Return(E_OK));
240 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
242 //answer with an ack to insert the connection in the database
243 EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1);
244 pRoutingReceiver.ackConnect(handle,connectionID,E_OK);
246 //now we can start to disconnect and expect a call on the routing interface
247 EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK));
248 ASSERT_EQ(E_OK,pControlReceiver.disconnect(handle,1));
250 //during the disconnection, the connection is still in the list!
251 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
252 ASSERT_TRUE(!connectionList.empty());
254 //then we fire the ack and expect a call on the controlInterface
255 EXPECT_CALL(pMockControlInterface,cbAckDisconnect(_,E_OK)).Times(1);
256 pRoutingReceiver.ackDisconnect(handle,connectionID,E_OK);
258 //make sure the handle is gone
259 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
260 ASSERT_TRUE(handlesList.empty());
262 //make sure the connection is gone
263 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
264 ASSERT_TRUE(connectionList.empty());
266 //Now let's try to disconnect what is not existing...
267 ASSERT_EQ(E_NON_EXISTENT,pControlReceiver.disconnect(handle,2));
270 TEST_F(controlInterfaceTest,setSourceState)
274 am_sourceID_t sourceID;
276 am_domainID_t domainID;
277 std::vector<am_Handle_s> handlesList;
279 am_SourceState_e state;
280 pCF.createSource(source);
281 pCF.createDomain(domain);
283 domain.busname="mock";
288 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
289 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
291 //we set the sourcestate and expect a call on the routingInterface
292 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceState(_,2,SS_PAUSED)).WillOnce(Return(E_OK));
293 ASSERT_EQ(E_OK,pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED));
295 //we want our handle in the list and let the type be the right one
296 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
297 ASSERT_EQ(handlesList[0].handle,handle.handle);
298 ASSERT_EQ(handlesList[0].handleType,H_SETSOURCESTATE);
300 //the state must be unchanged because did not get the ack
301 ASSERT_EQ(E_OK,pDatabaseHandler.getSoureState(source.sourceID,state));
302 ASSERT_EQ(state,SS_ON);
304 //now we sent out the ack and expect a call on the controlInterface
305 EXPECT_CALL(pMockControlInterface,cbAckSetSourceState(_,E_OK)).Times(1);
306 pRoutingReceiver.ackSetSourceState(handle,E_OK);
308 //finally we need the sourcestate to be changed
309 ASSERT_EQ(E_OK,pDatabaseHandler.getSoureState(source.sourceID,state));
310 ASSERT_EQ(state,SS_PAUSED);
312 //make sure the handle is gone
313 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
314 ASSERT_TRUE(handlesList.empty());
316 //we try again but expect a no change error
317 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED));
320 TEST_F(controlInterfaceTest,SetSinkVolumeChange)
325 am_domainID_t domainID;
327 std::vector<am_Handle_s> handlesList;
329 pCF.createSink(sink);
330 pCF.createDomain(domain);
332 domain.busname="mock";
337 //setup environment, we need a domain and a sink
338 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
339 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
341 //set the volume and expect a call on the routing interface
342 EXPECT_CALL(pMockRoutingInterface,asyncSetSinkVolume(_,2,11,RAMP_DIRECT,23)).WillOnce(Return(E_OK));
343 ASSERT_EQ(E_OK,pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_DIRECT,23));
345 //check the list of handles. The handle must be in there and have the right type
346 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
347 ASSERT_EQ(handlesList[0].handle,handle.handle);
348 ASSERT_EQ(handlesList[0].handleType,H_SETSINKVOLUME);
350 //now we read out the volume, but we expect no change because the ack did not arrive yet
351 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkVolume(sinkID,volume));
352 ASSERT_EQ(sink.volume,volume);
354 //lets send the answer and expect a call on the controlInterface
355 EXPECT_CALL(pMockControlInterface,cbAckSetSinkVolumeChange(_,11,E_OK)).Times(1);
356 pRoutingReceiver.ackSetSinkVolumeChange(handle,11,E_OK);
358 //finally, the new value must be in the database
359 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkVolume(sinkID,volume));
360 ASSERT_EQ(11,volume);
362 //and the handle must be destroyed
363 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
364 ASSERT_TRUE(handlesList.empty());
366 //Now we try again, but the value is unchanged
367 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_DIRECT,23));
370 TEST_F(controlInterfaceTest,ackSetSourceVolumeChange)
373 am_sourceID_t sourceID;
375 am_domainID_t domainID;
377 std::vector<am_Handle_s> handlesList;
379 pCF.createSource(source);
380 pCF.createDomain(domain);
382 domain.busname="mock";
388 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
389 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
391 //change the sinkVolume, expect a call on the routingInterface
392 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceVolume(_,2,11,RAMP_DIRECT,23)).WillOnce(Return(E_OK));
393 ASSERT_EQ(E_OK,pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_DIRECT,23));
395 //check the list of handles. The handle must be in there and have the right type
396 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
397 ASSERT_EQ(handlesList[0].handle,handle.handle);
398 ASSERT_EQ(handlesList[0].handleType,H_SETSOURCEVOLUME);
400 //now we read out the volume, but we expect no change because the ack did not arrive yet
401 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceVolume(sourceID,volume));
402 ASSERT_EQ(source.volume,volume);
404 //lets send the answer and expect a call on the controlInterface
405 EXPECT_CALL(pMockControlInterface,cbAckSetSourceVolumeChange(_,11,E_OK)).Times(1);
406 pRoutingReceiver.ackSetSourceVolumeChange(handle,11,E_OK);
408 //finally, the new value must be in the database
409 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceVolume(sourceID,volume));
410 ASSERT_EQ(11,volume);
412 //and the handle must be destroyed
413 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
414 ASSERT_TRUE(handlesList.empty());
416 //Now we try again, but the value is unchanged
417 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_DIRECT,23));
420 TEST_F(controlInterfaceTest,ackSetSinkSoundProperty)
425 am_domainID_t domainID;
426 std::vector<am_Handle_s> handlesList;
428 am_SoundProperty_s soundProperty;
430 pCF.createSink(sink);
431 pCF.createDomain(domain);
433 domain.busname="mock";
436 soundProperty.type=SP_BASS;
437 soundProperty.value=244;
439 //setup environment, we need a domain and a sink
440 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
441 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
443 //change the soundproperty, expect a call on the routinginterface
444 EXPECT_CALL(pMockRoutingInterface,asyncSetSinkSoundProperty(_,_,2)).WillOnce(Return(E_OK));
445 ASSERT_EQ(E_OK,pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty));
447 //check the list of handles. The handle must be in there and have the right type
448 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
449 ASSERT_EQ(handlesList[0].handle,handle.handle);
450 ASSERT_EQ(handlesList[0].handleType,H_SETSINKSOUNDPROPERTY);
452 //read out this property. There is no change, because the ack did not arrive yet.
453 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkSoundPropertyValue(2,SP_BASS,oldvalue));
454 ASSERT_EQ(sink.listSoundProperties[0].value,oldvalue);
456 //lets send the answer and expect a call on the controlInterface
457 EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)).Times(1);
458 pRoutingReceiver.ackSetSinkSoundProperty(handle,E_OK);
460 //finally, the new value must be in the database
461 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkSoundPropertyValue(sinkID,SP_BASS,oldvalue));
462 ASSERT_EQ(soundProperty.value,oldvalue);
464 //and the handle must be destroyed
465 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
466 ASSERT_TRUE(handlesList.empty());
468 //Now we try again, but the value is unchanged
469 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty));
472 TEST_F(controlInterfaceTest,ackSetSourceSoundProperty)
475 am_sourceID_t sourceID;
477 am_domainID_t domainID;
478 std::vector<am_Handle_s> handlesList;
480 am_SoundProperty_s soundProperty;
482 pCF.createSource(source);
483 pCF.createDomain(domain);
485 domain.busname="mock";
488 soundProperty.type=SP_BASS;
489 soundProperty.value=244;
492 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
493 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
495 //we trigger the change and wait for a call on the routinginterface
496 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceSoundProperty(_,_,2)).WillOnce(Return(E_OK));
497 ASSERT_EQ(E_OK,pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty));
499 //check the list of handles. The handle must be in there and have the right type
500 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
501 ASSERT_EQ(handlesList[0].handle,handle.handle);
502 ASSERT_EQ(handlesList[0].handleType,H_SETSOURCESOUNDPROPERTY);
504 //read out this property. There is no change, because the ack did not arrive yet.
505 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceSoundPropertyValue(2,SP_BASS,oldvalue));
506 ASSERT_EQ(source.listSoundProperties[0].value,oldvalue);
508 //lets send the answer and expect a call on the controlInterface
509 EXPECT_CALL(pMockControlInterface,cbAckSetSourceSoundProperty(_,E_OK)).Times(1);
510 pRoutingReceiver.ackSetSourceSoundProperty(handle,E_OK);
512 //finally, the new value must be in the database
513 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceSoundPropertyValue(sourceID,SP_BASS,oldvalue));
514 ASSERT_EQ(soundProperty.value,oldvalue);
516 //and the handle must be destroyed
517 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
518 ASSERT_TRUE(handlesList.empty());
520 //Now we try again, but the value is unchanged
521 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty));
524 TEST_F(controlInterfaceTest,crossFading)
526 //todo: implement crossfading test
529 int main(int argc, char **argv)
531 ::testing::InitGoogleTest(&argc, argv);
532 return RUN_ALL_TESTS();