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"
29 controlInterfaceTest::controlInterfaceTest()
30 :plistCommandPluginDirs(),
31 plistRoutingPluginDirs(),
32 pDatabaseHandler(std::string(":memory:")),
33 pRoutingSender(plistRoutingPluginDirs),
34 pCommandSender(plistCommandPluginDirs),
35 pMockControlInterface(),
36 pMockRoutingInterface(),
37 pControlSender(std::string("")),
38 pRoutingInterfaceBackdoor(),
39 pCommandInterfaceBackdoor(),
40 pControlInterfaceBackdoor(),
41 pDatabaseObserver(&pCommandSender,&pRoutingSender),
42 pControlReceiver(&pDatabaseHandler,&pRoutingSender,&pCommandSender),
43 pRoutingReceiver(&pDatabaseHandler,&pRoutingSender,&pControlSender)
45 pDatabaseHandler.registerObserver(&pDatabaseObserver);
46 pControlInterfaceBackdoor.replaceController(&pControlSender,&pMockControlInterface);
47 pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender,&pMockRoutingInterface,"mock");
51 controlInterfaceTest::~controlInterfaceTest()
55 void controlInterfaceTest::SetUp()
57 DLT_REGISTER_APP("Rtest","RoutingInterfacetest");
58 DLT_REGISTER_CONTEXT(AudioManager,"Main","Main Context");
59 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("RoutingSendInterface Test started "));
63 void controlInterfaceTest::TearDown()
65 DLT_UNREGISTER_CONTEXT(AudioManager);
68 TEST_F(controlInterfaceTest,registerDomain)
72 am_domainID_t domainID;
73 pCF.createDomain(domain);
75 //When we run this test, we expect the call on the control interface
76 EXPECT_CALL(pMockControlInterface,hookSystemRegisterDomain(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2),Return(E_OK)));
77 ASSERT_EQ(E_OK,pRoutingReceiver.registerDomain(domain,domainID));
78 ASSERT_EQ(domainID,2);
81 TEST_F(controlInterfaceTest,deregisterDomain)
83 am_domainID_t domainID=34;
85 //When we run this test, we expect the call on the control interface
86 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterDomain(34)).WillRepeatedly(Return(E_OK));
87 ASSERT_EQ(E_OK,pRoutingReceiver.deregisterDomain(domainID));
90 TEST_F(controlInterfaceTest,registerSink)
96 //When we run this test, we expect the call on the control interface
97 EXPECT_CALL(pMockControlInterface,hookSystemRegisterSink(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2),Return(E_OK)));
98 ASSERT_EQ(E_OK,pRoutingReceiver.registerSink(sink,sinkID));
102 TEST_F(controlInterfaceTest,deregisterSink)
104 am_sinkID_t sinkID=12;
106 //When we run this test, we expect the call on the control interface
107 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSink(12)).WillRepeatedly(Return(E_OK));
108 ASSERT_EQ(E_OK,pRoutingReceiver.deregisterSink(sinkID));
111 TEST_F(controlInterfaceTest,registerSource)
114 am_sourceID_t sourceID;
115 pCF.createSource(source);
117 //When we run this test, we expect the call on the control interface
118 EXPECT_CALL(pMockControlInterface,hookSystemRegisterSource(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2),Return(E_OK)));
119 ASSERT_EQ(E_OK,pRoutingReceiver.registerSource(source,sourceID));
120 ASSERT_EQ(sourceID,2);
123 TEST_F(controlInterfaceTest,deregisterSource)
125 am_sourceID_t sourceID=12;
127 //When we run this test, we expect the call on the control interface
128 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterSource(12)).WillRepeatedly(Return(E_OK));
129 ASSERT_EQ(E_OK,pRoutingReceiver.deregisterSource(sourceID));
132 TEST_F(controlInterfaceTest,registerGateway)
134 am_Gateway_s gateway;
135 am_gatewayID_t gatewayID;
136 pCF.createGateway(gateway);
138 //When we run this test, we expect the call on the control interface
139 EXPECT_CALL(pMockControlInterface,hookSystemRegisterGateway(_,_)).WillRepeatedly(DoAll(SetArgReferee<1>(2),Return(E_OK)));
140 ASSERT_EQ(E_OK,pRoutingReceiver.registerGateway(gateway,gatewayID));
141 ASSERT_EQ(gatewayID,2);
144 TEST_F(controlInterfaceTest,deregisterGateway)
146 am_gatewayID_t gatewayID=12;
148 //When we run this test, we expect the call on the control interface
149 EXPECT_CALL(pMockControlInterface,hookSystemDeregisterGateway(12)).WillRepeatedly(Return(E_OK));
150 ASSERT_EQ(E_OK,pRoutingReceiver.deregisterGateway(gatewayID));
154 TEST_F(controlInterfaceTest,ackConnect)
156 am_connectionID_t connectionID;
160 am_domainID_t domainID;
161 std::vector<am_Connection_s> connectionList;
162 std::vector<am_Handle_s> handlesList;
164 pCF.createSink(sink);
165 pCF.createDomain(domain);
167 domain.busname="mock";
172 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
173 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
175 //when asyncConnect is called, we expect a call on the routingInterface
176 EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_STEREO)).WillOnce(Return(E_OK));
177 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
179 //The handle should have the correct type
180 ASSERT_EQ(handle.handleType,H_CONNECT);
181 ASSERT_EQ(handle.handle,1);
182 ASSERT_EQ(connectionID,1);
184 //The list of handles shall have the handle inside
185 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
186 ASSERT_EQ(handlesList[0].handle,handle.handle);
187 ASSERT_EQ(handlesList[0].handleType,handle.handleType);
189 //we check the list of connections - but it must be empty because the ack did not arrive yet
190 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
191 ASSERT_TRUE(connectionList.empty());
193 //finally we answer via the RoutingInterface and expect a call on the controlInterface
194 EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1);
195 pRoutingReceiver.ackConnect(handle,connectionID,E_OK);
197 //the list of handles must be empty now
198 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
199 ASSERT_TRUE(handlesList.empty());
201 //but the connection must be in the connectionlist
202 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
203 ASSERT_TRUE(!connectionList.empty());
205 //no we try the same, but do expect a no_change answer directly and no call because connection already exists
206 ASSERT_EQ(E_ALREADY_EXISTS,pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
209 TEST_F(controlInterfaceTest,ackDisconnect)
211 am_connectionID_t connectionID;
215 am_domainID_t domainID;
216 std::vector<am_Connection_s> connectionList;
217 std::vector<am_Handle_s> handlesList;
219 pCF.createSink(sink);
220 pCF.createDomain(domain);
222 domain.busname="mock";
227 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
228 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
230 //now we first need to connect, we expect a call on the routing interface
231 EXPECT_CALL(pMockRoutingInterface,asyncConnect(_,1,2,2,CF_STEREO)).WillOnce(Return(E_OK));
232 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_STEREO,2,2));
234 //answer with an ack to insert the connection in the database
235 EXPECT_CALL(pMockControlInterface,cbAckConnect(_,E_OK)).Times(1);
236 pRoutingReceiver.ackConnect(handle,connectionID,E_OK);
238 //now we can start to disconnect and expect a call on the routing interface
239 EXPECT_CALL(pMockRoutingInterface,asyncDisconnect(_,1)).WillOnce(Return(E_OK));
240 ASSERT_EQ(E_OK,pControlReceiver.disconnect(handle,1));
242 //during the disconnection, the connection is still in the list!
243 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
244 ASSERT_TRUE(!connectionList.empty());
246 //then we fire the ack and expect a call on the controlInterface
247 EXPECT_CALL(pMockControlInterface,cbAckDisconnect(_,E_OK)).Times(1);
248 pRoutingReceiver.ackDisconnect(handle,connectionID,E_OK);
250 //make sure the handle is gone
251 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
252 ASSERT_TRUE(handlesList.empty());
254 //make sure the connection is gone
255 ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
256 ASSERT_TRUE(connectionList.empty());
258 //Now let's try to disconnect what is not existing...
259 ASSERT_EQ(E_NON_EXISTENT,pControlReceiver.disconnect(handle,2));
262 TEST_F(controlInterfaceTest,setSourceState)
266 am_sourceID_t sourceID;
268 am_domainID_t domainID;
269 std::vector<am_Handle_s> handlesList;
271 am_SourceState_e state;
272 pCF.createSource(source);
273 pCF.createDomain(domain);
275 domain.busname="mock";
280 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
281 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
283 //we set the sourcestate and expect a call on the routingInterface
284 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceState(_,2,SS_PAUSED)).WillOnce(Return(E_OK));
285 ASSERT_EQ(E_OK,pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED));
287 //we want our handle in the list and let the type be the right one
288 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
289 ASSERT_EQ(handlesList[0].handle,handle.handle);
290 ASSERT_EQ(handlesList[0].handleType,H_SETSOURCESTATE);
292 //the state must be unchanged because did not get the ack
293 ASSERT_EQ(E_OK,pDatabaseHandler.getSoureState(source.sourceID,state));
294 ASSERT_EQ(state,SS_ON);
296 //now we sent out the ack and expect a call on the controlInterface
297 EXPECT_CALL(pMockControlInterface,cbAckSetSourceState(_,E_OK)).Times(1);
298 pRoutingReceiver.ackSetSourceState(handle,E_OK);
300 //finally we need the sourcestate to be changed
301 ASSERT_EQ(E_OK,pDatabaseHandler.getSoureState(source.sourceID,state));
302 ASSERT_EQ(state,SS_PAUSED);
304 //make sure the handle is gone
305 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
306 ASSERT_TRUE(handlesList.empty());
308 //we try again but expect a no change error
309 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceState(handle,source.sourceID,SS_PAUSED));
312 TEST_F(controlInterfaceTest,SetSinkVolumeChange)
317 am_domainID_t domainID;
319 std::vector<am_Handle_s> handlesList;
321 pCF.createSink(sink);
322 pCF.createDomain(domain);
324 domain.busname="mock";
329 //setup environment, we need a domain and a sink
330 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
331 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
333 //set the volume and expect a call on the routing interface
334 EXPECT_CALL(pMockRoutingInterface,asyncSetSinkVolume(_,2,11,RAMP_DIRECT,23)).WillOnce(Return(E_OK));
335 ASSERT_EQ(E_OK,pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_DIRECT,23));
337 //check the list of handles. The handle must be in there and have the right type
338 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
339 ASSERT_EQ(handlesList[0].handle,handle.handle);
340 ASSERT_EQ(handlesList[0].handleType,H_SETSINKVOLUME);
342 //now we read out the volume, but we expect no change because the ack did not arrive yet
343 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkVolume(sinkID,volume));
344 ASSERT_EQ(sink.volume,volume);
346 //lets send the answer and expect a call on the controlInterface
347 EXPECT_CALL(pMockControlInterface,cbAckSetSinkVolumeChange(_,11,E_OK)).Times(1);
348 pRoutingReceiver.ackSetSinkVolumeChange(handle,11,E_OK);
350 //finally, the new value must be in the database
351 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkVolume(sinkID,volume));
352 ASSERT_EQ(11,volume);
354 //and the handle must be destroyed
355 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
356 ASSERT_TRUE(handlesList.empty());
358 //Now we try again, but the value is unchanged
359 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSinkVolume(handle,sinkID,11,RAMP_DIRECT,23));
362 TEST_F(controlInterfaceTest,ackSetSourceVolumeChange)
365 am_sourceID_t sourceID;
367 am_domainID_t domainID;
369 std::vector<am_Handle_s> handlesList;
371 pCF.createSource(source);
372 pCF.createDomain(domain);
374 domain.busname="mock";
380 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
381 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
383 //change the sinkVolume, expect a call on the routingInterface
384 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceVolume(_,2,11,RAMP_DIRECT,23)).WillOnce(Return(E_OK));
385 ASSERT_EQ(E_OK,pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_DIRECT,23));
387 //check the list of handles. The handle must be in there and have the right type
388 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
389 ASSERT_EQ(handlesList[0].handle,handle.handle);
390 ASSERT_EQ(handlesList[0].handleType,H_SETSOURCEVOLUME);
392 //now we read out the volume, but we expect no change because the ack did not arrive yet
393 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceVolume(sourceID,volume));
394 ASSERT_EQ(source.volume,volume);
396 //lets send the answer and expect a call on the controlInterface
397 EXPECT_CALL(pMockControlInterface,cbAckSetSourceVolumeChange(_,11,E_OK)).Times(1);
398 pRoutingReceiver.ackSetSourceVolumeChange(handle,11,E_OK);
400 //finally, the new value must be in the database
401 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceVolume(sourceID,volume));
402 ASSERT_EQ(11,volume);
404 //and the handle must be destroyed
405 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
406 ASSERT_TRUE(handlesList.empty());
408 //Now we try again, but the value is unchanged
409 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceVolume(handle,source.sourceID,11,RAMP_DIRECT,23));
412 TEST_F(controlInterfaceTest,ackSetSinkSoundProperty)
417 am_domainID_t domainID;
418 std::vector<am_Handle_s> handlesList;
420 am_SoundProperty_s soundProperty;
422 pCF.createSink(sink);
423 pCF.createDomain(domain);
425 domain.busname="mock";
428 soundProperty.type=SP_BASS;
429 soundProperty.value=244;
431 //setup environment, we need a domain and a sink
432 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
433 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
435 //change the soundproperty, expect a call on the routinginterface
436 EXPECT_CALL(pMockRoutingInterface,asyncSetSinkSoundProperty(_,_,2)).WillOnce(Return(E_OK));
437 ASSERT_EQ(E_OK,pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty));
439 //check the list of handles. The handle must be in there and have the right type
440 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
441 ASSERT_EQ(handlesList[0].handle,handle.handle);
442 ASSERT_EQ(handlesList[0].handleType,H_SETSINKSOUNDPROPERTY);
444 //read out this property. There is no change, because the ack did not arrive yet.
445 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkSoundPropertyValue(2,SP_BASS,oldvalue));
446 ASSERT_EQ(sink.listSoundProperties[0].value,oldvalue);
448 //lets send the answer and expect a call on the controlInterface
449 EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)).Times(1);
450 pRoutingReceiver.ackSetSinkSoundProperty(handle,E_OK);
452 //finally, the new value must be in the database
453 ASSERT_EQ(E_OK,pDatabaseHandler.getSinkSoundPropertyValue(sinkID,SP_BASS,oldvalue));
454 ASSERT_EQ(soundProperty.value,oldvalue);
456 //and the handle must be destroyed
457 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
458 ASSERT_TRUE(handlesList.empty());
460 //Now we try again, but the value is unchanged
461 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSinkSoundProperty(handle,sink.sinkID,soundProperty));
464 TEST_F(controlInterfaceTest,ackSetSourceSoundProperty)
467 am_sourceID_t sourceID;
469 am_domainID_t domainID;
471 std::vector<am_Handle_s> handlesList;
473 am_SoundProperty_s soundProperty;
475 pCF.createSource(source);
476 pCF.createDomain(domain);
478 domain.busname="mock";
481 soundProperty.type=SP_BASS;
482 soundProperty.value=244;
485 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
486 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
488 //we trigger the change and wait for a call on the routinginterface
489 EXPECT_CALL(pMockRoutingInterface,asyncSetSourceSoundProperty(_,_,2)).WillOnce(Return(E_OK));
490 ASSERT_EQ(E_OK,pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty));
492 //check the list of handles. The handle must be in there and have the right type
493 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
494 ASSERT_EQ(handlesList[0].handle,handle.handle);
495 ASSERT_EQ(handlesList[0].handleType,H_SETSOURCESOUNDPROPERTY);
497 //read out this property. There is no change, because the ack did not arrive yet.
498 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceSoundPropertyValue(2,SP_BASS,oldvalue));
499 ASSERT_EQ(source.listSoundProperties[0].value,oldvalue);
501 //lets send the answer and expect a call on the controlInterface
502 EXPECT_CALL(pMockControlInterface,cbAckSetSourceSoundProperty(_,E_OK)).Times(1);
503 pRoutingReceiver.ackSetSourceSoundProperty(handle,E_OK);
505 //finally, the new value must be in the database
506 ASSERT_EQ(E_OK,pDatabaseHandler.getSourceSoundPropertyValue(sourceID,SP_BASS,oldvalue));
507 ASSERT_EQ(soundProperty.value,oldvalue);
509 //and the handle must be destroyed
510 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(handlesList));
511 ASSERT_TRUE(handlesList.empty());
513 //Now we try again, but the value is unchanged
514 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceSoundProperty(handle,source.sourceID,soundProperty));
517 TEST_F(controlInterfaceTest,crossFading)
519 //todo: implement crossfading test
522 int main(int argc, char **argv)
524 ::testing::InitGoogleTest(&argc, argv);
525 return RUN_ALL_TESTS();