2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file testRoutingItnerfaceAsync.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 "testRoutingInterfaceAsync.h"
30 using namespace testing;
33 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
36 std::vector<std::string> testRoutingInterfaceAsync::pListRoutingPluginDirs=returnListPlugins();
37 am_domainID_t testRoutingInterfaceAsync::mDomainIDCount=0;
38 RoutingSender testRoutingInterfaceAsync::pRoutingSender=RoutingSender(pListRoutingPluginDirs);
40 testRoutingInterfaceAsync::testRoutingInterfaceAsync()
43 ptimerCallback(this, &testRoutingInterfaceAsync::timerCallback)
47 testRoutingInterfaceAsync::~testRoutingInterfaceAsync()
51 void testRoutingInterfaceAsync::SetUp()
53 DLT_REGISTER_APP("DPtest","RoutingInterfacetest");
54 DLT_REGISTER_CONTEXT(DLT_CONTEXT,"Main","Main Context");
55 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("RoutingSendInterface Test started "));
57 std::vector<int> domainIDs;
58 domainIDs.push_back(0);
59 domainIDs.push_back(1);
61 EXPECT_CALL(pReceiveInterface,getSocketHandler(_)).WillOnce(DoAll(SetArgReferee<0>(&pSocketHandler),Return(E_OK)));
62 EXPECT_CALL(pReceiveInterface,registerDomain(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleDomainRegister));
63 EXPECT_CALL(pReceiveInterface,registerSource(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSourceRegister));
64 EXPECT_CALL(pReceiveInterface,registerSink(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSinkRegister));
66 pRoutingSender.startupRoutingInterface(&pReceiveInterface);
67 pRoutingSender.routingInterfacesReady();
73 sh_timerHandle_t handle;
75 shTimerCallBack *buf=&ptimerCallback;
76 //lets use a timeout so the test will finish
77 pSocketHandler.addTimer(t,buf,handle,(void*)NULL);
80 std::vector<std::string> am::testRoutingInterfaceAsync::returnListPlugins()
82 std::vector<std::string> list;
83 list.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
87 am_Error_e am::testRoutingInterfaceAsync::handleSourceRegister(const am_Source_s & sourceData, am_sourceID_t & sourceID)
89 sourceID=sourceData.sourceID;
90 pRoutingSender.addSourceLookup(sourceData);
94 am_Error_e am::testRoutingInterfaceAsync::handleSinkRegister(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
96 sinkID=sinkData.sinkID;
97 pRoutingSender.addSinkLookup(sinkData);
101 am_Error_e am::testRoutingInterfaceAsync::handleDomainRegister(const am_Domain_s & domainData, am_domainID_t & domainID)
103 am_Domain_s domain=domainData;
104 domainID=mDomainIDCount++;
105 domain.domainID=domainID;
106 pRoutingSender.addDomainLookup(domain);
110 void am::testRoutingInterfaceAsync::timerCallback(sh_timerHandle_t handle, void *userData)
112 pSocketHandler.stop_listening();
115 void testRoutingInterfaceAsync::TearDown()
117 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
121 TEST_F(testRoutingInterfaceAsync,setDomainState)
123 am_domainID_t domainID=1;
124 am_DomainState_e state=DS_INDEPENDENT_RUNDOWN;
126 EXPECT_CALL(pReceiveInterface,hookDomainStateChange(_,DS_INDEPENDENT_RUNDOWN)).Times(1);
128 ASSERT_EQ(E_OK,pRoutingSender.setDomainState(domainID,state));
129 pSocketHandler.start_listenting();
132 TEST_F(testRoutingInterfaceAsync,setSourceSoundProperty)
137 handle.handleType=H_SETSOURCESOUNDPROPERTY;
139 am_sourceID_t sourceID=3;
140 am_SoundProperty_s property;
141 property.type=SP_MID;
144 EXPECT_CALL(pReceiveInterface,ackSetSourceSoundProperty(_,E_OK)).Times(1);
146 ASSERT_EQ(E_OK,pRoutingSender.asyncSetSourceSoundProperty(handle,sourceID,property));
147 pSocketHandler.start_listenting();
150 TEST_F(testRoutingInterfaceAsync,setSinkSoundProperty)
155 handle.handleType=H_SETSINKSOUNDPROPERTY;
157 am_sinkID_t sinkID=1;
158 am_SoundProperty_s property;
159 property.type=SP_MID;
162 EXPECT_CALL(pReceiveInterface,ackSetSinkSoundProperty(_,E_OK)).Times(1);
164 ASSERT_EQ(E_OK,pRoutingSender.asyncSetSinkSoundProperty(handle,sinkID,property));
165 pSocketHandler.start_listenting();
168 TEST_F(testRoutingInterfaceAsync,setSourceState)
173 handle.handleType=H_SETSOURCEVOLUME;
175 am_sourceID_t sourceID=1;
176 am_SourceState_e state=SS_OFF;
178 EXPECT_CALL(pReceiveInterface,ackSetSourceState(_,E_OK)).Times(1);
180 ASSERT_EQ(E_OK,pRoutingSender.asyncSetSourceState(handle,sourceID,state));
181 pSocketHandler.start_listenting();
184 TEST_F(testRoutingInterfaceAsync,setSourceVolume)
189 handle.handleType=H_SETSOURCEVOLUME;
191 am_sourceID_t sourceID=3;
192 am_volume_t volume=3;
193 am_RampType_e ramp=RAMP_DIRECT;
196 EXPECT_CALL(pReceiveInterface,ackSourceVolumeTick(_,sourceID,_)).Times(3);
197 EXPECT_CALL(pReceiveInterface,ackSetSourceVolumeChange(_,volume,E_OK)).Times(1);
199 ASSERT_EQ(E_OK,pRoutingSender.asyncSetSourceVolume(handle,sourceID,volume,ramp,myTime));
200 pSocketHandler.start_listenting();
203 TEST_F(testRoutingInterfaceAsync,setSinkVolume)
208 handle.handleType=H_SETSINKVOLUME;
210 am_sinkID_t sinkID=1;
211 am_volume_t volume=9;
212 am_RampType_e ramp=RAMP_DIRECT;
215 EXPECT_CALL(pReceiveInterface,ackSinkVolumeTick(_,sinkID,_)).Times(9);
216 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,volume,E_OK)).Times(1);
218 ASSERT_EQ(E_OK,pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
219 pSocketHandler.start_listenting();
222 TEST_F(testRoutingInterfaceAsync,setSinkVolumeAbort)
227 handle.handleType=H_SETSINKVOLUME;
229 am_sinkID_t sinkID=2;
230 am_volume_t volume=25;
231 am_RampType_e ramp=RAMP_DIRECT;
234 EXPECT_CALL(pReceiveInterface,ackSinkVolumeTick(_,sinkID,_));
235 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,AllOf(Ne(volume),Ne(0)),E_ABORTED)).Times(1);
237 ASSERT_EQ(E_OK,pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
239 ASSERT_EQ(E_OK,pRoutingSender.asyncAbort(handle));
240 pSocketHandler.start_listenting();
244 TEST_F(testRoutingInterfaceAsync,disconnectTooEarly)
249 handle.handleType=H_CONNECT;
251 am_connectionID_t connectionID=4;
252 am_sourceID_t sourceID=2;
253 am_sinkID_t sinkID=1;
254 am_ConnectionFormat_e format=CF_ANALOG;
256 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK));
257 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
258 ASSERT_EQ(E_OK,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
259 ASSERT_EQ(E_NON_EXISTENT,pRoutingSender.asyncDisconnect(handle,connectionID));
260 pSocketHandler.start_listenting();
263 TEST_F(testRoutingInterfaceAsync,disconnectAbort)
268 handle.handleType=H_CONNECT;
270 am_connectionID_t connectionID=4;
271 am_sourceID_t sourceID=2;
272 am_sinkID_t sinkID=1;
273 am_ConnectionFormat_e format=CF_ANALOG;
275 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK));
276 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_ABORTED));
277 ASSERT_EQ(E_OK,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
279 ASSERT_EQ(E_OK,pRoutingSender.asyncDisconnect(handle,connectionID));
280 ASSERT_EQ(E_OK,pRoutingSender.asyncAbort(handle));
281 pSocketHandler.start_listenting();
284 TEST_F(testRoutingInterfaceAsync,disconnectNonExisting)
289 handle.handleType=H_CONNECT;
291 am_connectionID_t connectionID=4;
292 am_sourceID_t sourceID=2;
293 am_sinkID_t sinkID=1;
294 am_ConnectionFormat_e format=CF_ANALOG;
296 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
297 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
298 ASSERT_EQ(E_NON_EXISTENT,pRoutingSender.asyncDisconnect(handle,connectionID));
299 pSocketHandler.start_listenting();
302 TEST_F(testRoutingInterfaceAsync,disconnect)
307 handle.handleType=H_CONNECT;
309 am_connectionID_t connectionID=4;
310 am_sourceID_t sourceID=2;
311 am_sinkID_t sinkID=1;
312 am_ConnectionFormat_e format=CF_ANALOG;
314 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK));
315 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK));
316 ASSERT_EQ(E_OK,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
318 ASSERT_EQ(E_OK,pRoutingSender.asyncDisconnect(handle,connectionID));
319 pSocketHandler.start_listenting();
322 TEST_F(testRoutingInterfaceAsync,connectNoMoreThreads)
327 handle.handleType=H_CONNECT;
329 am_connectionID_t connectionID=1;
330 am_sourceID_t sourceID=2;
331 am_sinkID_t sinkID=1;
332 am_ConnectionFormat_e format=CF_ANALOG;
334 EXPECT_CALL(pReceiveInterface,ackConnect(_,_,E_OK)).Times(10);
335 for(int i=0;i<10;i++)
339 ASSERT_EQ(E_OK,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
341 ASSERT_EQ(E_NOT_POSSIBLE,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
342 pSocketHandler.start_listenting();
345 TEST_F(testRoutingInterfaceAsync,connectAbortTooLate)
350 handle.handleType=H_CONNECT;
352 am_connectionID_t connectionID=4;
353 am_sourceID_t sourceID=2;
354 am_sinkID_t sinkID=1;
355 am_ConnectionFormat_e format=CF_ANALOG;
357 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(1);
358 ASSERT_EQ(E_OK,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
360 ASSERT_EQ(E_NON_EXISTENT,pRoutingSender.asyncAbort(handle));
361 pSocketHandler.start_listenting();
364 TEST_F(testRoutingInterfaceAsync,connectAbort)
369 handle.handleType=H_CONNECT;
371 am_connectionID_t connectionID=4;
372 am_sourceID_t sourceID=2;
373 am_sinkID_t sinkID=1;
374 am_ConnectionFormat_e format=CF_ANALOG;
376 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_ABORTED)).Times(1);
377 ASSERT_EQ(E_OK,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
379 ASSERT_EQ(E_OK,pRoutingSender.asyncAbort(handle));
380 pSocketHandler.start_listenting();
383 TEST_F(testRoutingInterfaceAsync,connectWrongFormat)
388 handle.handleType=H_CONNECT;
390 am_connectionID_t connectionID=4;
391 am_sourceID_t sourceID=2;
392 am_sinkID_t sinkID=1;
393 am_ConnectionFormat_e format=CF_MONO;
395 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
396 ASSERT_EQ(E_WRONG_FORMAT,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
397 pSocketHandler.start_listenting();
400 TEST_F(testRoutingInterfaceAsync,connectWrongSink)
405 handle.handleType=H_CONNECT;
407 am_connectionID_t connectionID=4;
408 am_sourceID_t sourceID=2;
409 am_sinkID_t sinkID=122;
410 am_ConnectionFormat_e format=CF_ANALOG;
412 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
413 ASSERT_EQ(E_NON_EXISTENT,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
414 pSocketHandler.start_listenting();
417 TEST_F(testRoutingInterfaceAsync,connectWrongSource)
421 handle.handleType=H_CONNECT;
423 am_connectionID_t connectionID=4;
424 am_sourceID_t sourceID=25;
425 am_sinkID_t sinkID=1;
426 am_ConnectionFormat_e format=CF_ANALOG;
428 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
429 ASSERT_EQ(E_NON_EXISTENT,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
430 pSocketHandler.start_listenting();
433 TEST_F(testRoutingInterfaceAsync,connect)
438 handle.handleType=H_CONNECT;
440 am_connectionID_t connectionID=4;
441 am_sourceID_t sourceID=2;
442 am_sinkID_t sinkID=1;
443 am_ConnectionFormat_e format=CF_ANALOG;
445 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK));
446 ASSERT_EQ(E_OK,pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
447 pSocketHandler.start_listenting();
450 int main(int argc, char **argv)
452 ::testing::InitGoogleTest(&argc, argv);
453 return RUN_ALL_TESTS();