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"
27 #include "DLTWrapper.h"
30 using namespace testing;
32 std::vector<std::string> testRoutingInterfaceAsync::pListRoutingPluginDirs = returnListPlugins();
33 am_domainID_t testRoutingInterfaceAsync::mDomainIDCount = 0;
34 RoutingSender testRoutingInterfaceAsync::pRoutingSender = RoutingSender(pListRoutingPluginDirs);
36 testRoutingInterfaceAsync::testRoutingInterfaceAsync() :
38 pReceiveInterface(), //
39 ptimerCallback(this, &testRoutingInterfaceAsync::timerCallback)
43 testRoutingInterfaceAsync::~testRoutingInterfaceAsync()
47 void testRoutingInterfaceAsync::SetUp()
49 logInfo("RoutingSendInterface Test started ");
51 std::vector<int> domainIDs;
52 domainIDs.push_back(0);
53 domainIDs.push_back(1);
55 EXPECT_CALL(pReceiveInterface,getSocketHandler(_)).WillOnce(DoAll(SetArgReferee<0>(&pSocketHandler), Return(E_OK)));
56 EXPECT_CALL(pReceiveInterface,registerDomain(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleDomainRegister));
57 EXPECT_CALL(pReceiveInterface,registerSource(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSourceRegister));
58 EXPECT_CALL(pReceiveInterface,registerSink(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSinkRegister));
60 pRoutingSender.startupRoutingInterface(&pReceiveInterface);
61 pRoutingSender.routingInterfacesReady();
67 sh_timerHandle_t handle;
69 shTimerCallBack *buf = &ptimerCallback;
70 //lets use a timeout so the test will finish
71 pSocketHandler.addTimer(t, buf, handle, (void*) NULL);
74 std::vector<std::string> am::testRoutingInterfaceAsync::returnListPlugins()
76 std::vector<std::string> list;
77 list.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
81 am_Error_e am::testRoutingInterfaceAsync::handleSourceRegister(const am_Source_s & sourceData, am_sourceID_t & sourceID)
83 sourceID = sourceData.sourceID;
84 pRoutingSender.addSourceLookup(sourceData);
88 am_Error_e am::testRoutingInterfaceAsync::handleSinkRegister(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
90 sinkID = sinkData.sinkID;
91 pRoutingSender.addSinkLookup(sinkData);
95 am_Error_e am::testRoutingInterfaceAsync::handleDomainRegister(const am_Domain_s & domainData, am_domainID_t & domainID)
97 am_Domain_s domain = domainData;
98 domainID = mDomainIDCount++;
99 domain.domainID = domainID;
100 pRoutingSender.addDomainLookup(domain);
104 void am::testRoutingInterfaceAsync::timerCallback(sh_timerHandle_t handle, void *userData)
108 pSocketHandler.stop_listening();
111 void testRoutingInterfaceAsync::TearDown()
115 TEST_F(testRoutingInterfaceAsync,setDomainState)
117 am_domainID_t domainID = 1;
118 am_DomainState_e state = DS_INDEPENDENT_RUNDOWN;
120 EXPECT_CALL(pReceiveInterface,hookDomainStateChange(_,DS_INDEPENDENT_RUNDOWN)).Times(1);
122 ASSERT_EQ(E_OK, pRoutingSender.setDomainState(domainID,state));
123 pSocketHandler.start_listenting();
126 TEST_F(testRoutingInterfaceAsync,setSourceSoundProperty)
131 handle.handleType = H_SETSOURCESOUNDPROPERTY;
133 am_sourceID_t sourceID = 3;
134 am_SoundProperty_s property;
135 property.type = SP_MID;
138 EXPECT_CALL(pReceiveInterface,ackSetSourceSoundProperty(_,E_OK)).Times(1);
140 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceSoundProperty(handle,sourceID,property));
141 pSocketHandler.start_listenting();
144 TEST_F(testRoutingInterfaceAsync,setSinkSoundProperty)
149 handle.handleType = H_SETSINKSOUNDPROPERTY;
151 am_sinkID_t sinkID = 1;
152 am_SoundProperty_s property;
153 property.type = SP_MID;
156 EXPECT_CALL(pReceiveInterface,ackSetSinkSoundProperty(_,E_OK)).Times(1);
158 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkSoundProperty(handle,sinkID,property));
159 pSocketHandler.start_listenting();
162 TEST_F(testRoutingInterfaceAsync,setSourceState)
167 handle.handleType = H_SETSOURCEVOLUME;
169 am_sourceID_t sourceID = 1;
170 am_SourceState_e state = SS_OFF;
172 EXPECT_CALL(pReceiveInterface,ackSetSourceState(_,E_OK)).Times(1);
174 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceState(handle,sourceID,state));
175 pSocketHandler.start_listenting();
178 TEST_F(testRoutingInterfaceAsync,setSourceVolume)
183 handle.handleType = H_SETSOURCEVOLUME;
185 am_sourceID_t sourceID = 3;
186 am_volume_t volume = 3;
187 am_RampType_e ramp = RAMP_DIRECT;
188 am_time_t myTime = 25;
190 EXPECT_CALL(pReceiveInterface,ackSourceVolumeTick(_,sourceID,_)).Times(3);
191 EXPECT_CALL(pReceiveInterface,ackSetSourceVolumeChange(_,volume,E_OK)).Times(1);
193 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceVolume(handle,sourceID,volume,ramp,myTime));
194 pSocketHandler.start_listenting();
197 TEST_F(testRoutingInterfaceAsync,setSinkVolume)
202 handle.handleType = H_SETSINKVOLUME;
204 am_sinkID_t sinkID = 1;
205 am_volume_t volume = 9;
206 am_RampType_e ramp = RAMP_DIRECT;
207 am_time_t myTime = 25;
209 EXPECT_CALL(pReceiveInterface,ackSinkVolumeTick(_,sinkID,_)).Times(9);
210 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,volume,E_OK)).Times(1);
212 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
213 pSocketHandler.start_listenting();
216 TEST_F(testRoutingInterfaceAsync,setSinkVolumeAbort)
221 handle.handleType = H_SETSINKVOLUME;
223 am_sinkID_t sinkID = 2;
224 am_volume_t volume = 25;
225 am_RampType_e ramp = RAMP_DIRECT;
226 am_time_t myTime = 25;
228 EXPECT_CALL(pReceiveInterface, ackSinkVolumeTick(_,sinkID,_));
229 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,AllOf(Ne(volume),Ne(0)),E_ABORTED)).Times(1);
231 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
233 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
234 pSocketHandler.start_listenting();
237 TEST_F(testRoutingInterfaceAsync,disconnectTooEarly)
242 handle.handleType = H_CONNECT;
244 am_connectionID_t connectionID = 4;
245 am_sourceID_t sourceID = 2;
246 am_sinkID_t sinkID = 1;
247 am_ConnectionFormat_e format = CF_ANALOG;
249 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
250 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
251 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
252 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncDisconnect(handle,connectionID));
253 pSocketHandler.start_listenting();
256 TEST_F(testRoutingInterfaceAsync,disconnectAbort)
261 handle.handleType = H_CONNECT;
263 am_connectionID_t connectionID = 4;
264 am_sourceID_t sourceID = 2;
265 am_sinkID_t sinkID = 1;
266 am_ConnectionFormat_e format = CF_ANALOG;
268 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
269 EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_ABORTED));
270 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
272 ASSERT_EQ(E_OK, pRoutingSender.asyncDisconnect(handle,connectionID));
273 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
274 pSocketHandler.start_listenting();
277 TEST_F(testRoutingInterfaceAsync,disconnectNonExisting)
282 handle.handleType = H_CONNECT;
284 am_connectionID_t connectionID = 4;
286 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
287 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
288 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncDisconnect(handle,connectionID));
289 pSocketHandler.start_listenting();
292 TEST_F(testRoutingInterfaceAsync,disconnect)
297 handle.handleType = H_CONNECT;
299 am_connectionID_t connectionID = 4;
300 am_sourceID_t sourceID = 2;
301 am_sinkID_t sinkID = 1;
302 am_ConnectionFormat_e format = CF_ANALOG;
304 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
305 EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_OK));
306 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
308 ASSERT_EQ(E_OK, pRoutingSender.asyncDisconnect(handle,connectionID));
309 pSocketHandler.start_listenting();
312 TEST_F(testRoutingInterfaceAsync,connectNoMoreThreads)
317 handle.handleType = H_CONNECT;
319 am_connectionID_t connectionID = 1;
320 am_sourceID_t sourceID = 2;
321 am_sinkID_t sinkID = 1;
322 am_ConnectionFormat_e format = CF_ANALOG;
324 EXPECT_CALL(pReceiveInterface,ackConnect(_,_,E_OK)).Times(10);
325 for (int i = 0; i < 10; i++)
329 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
330 }ASSERT_EQ(E_NOT_POSSIBLE, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
331 pSocketHandler.start_listenting();
334 TEST_F(testRoutingInterfaceAsync,connectAbortTooLate)
339 handle.handleType = H_CONNECT;
341 am_connectionID_t connectionID = 4;
342 am_sourceID_t sourceID = 2;
343 am_sinkID_t sinkID = 1;
344 am_ConnectionFormat_e format = CF_ANALOG;
346 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(1);
347 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
349 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncAbort(handle));
350 pSocketHandler.start_listenting();
353 TEST_F(testRoutingInterfaceAsync,connectAbort)
358 handle.handleType = H_CONNECT;
360 am_connectionID_t connectionID = 4;
361 am_sourceID_t sourceID = 2;
362 am_sinkID_t sinkID = 1;
363 am_ConnectionFormat_e format = CF_ANALOG;
365 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_ABORTED)).Times(1);
366 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
368 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
369 pSocketHandler.start_listenting();
372 TEST_F(testRoutingInterfaceAsync,connectWrongFormat)
377 handle.handleType = H_CONNECT;
379 am_connectionID_t connectionID = 4;
380 am_sourceID_t sourceID = 2;
381 am_sinkID_t sinkID = 1;
382 am_ConnectionFormat_e format = CF_MONO;
384 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
385 ASSERT_EQ(E_WRONG_FORMAT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
386 pSocketHandler.start_listenting();
389 TEST_F(testRoutingInterfaceAsync,connectWrongSink)
394 handle.handleType = H_CONNECT;
396 am_connectionID_t connectionID = 4;
397 am_sourceID_t sourceID = 2;
398 am_sinkID_t sinkID = 122;
399 am_ConnectionFormat_e format = CF_ANALOG;
401 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
402 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
403 pSocketHandler.start_listenting();
406 TEST_F(testRoutingInterfaceAsync,connectWrongSource)
410 handle.handleType = H_CONNECT;
412 am_connectionID_t connectionID = 4;
413 am_sourceID_t sourceID = 25;
414 am_sinkID_t sinkID = 1;
415 am_ConnectionFormat_e format = CF_ANALOG;
417 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
418 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
419 pSocketHandler.start_listenting();
422 TEST_F(testRoutingInterfaceAsync,connect)
427 handle.handleType = H_CONNECT;
429 am_connectionID_t connectionID = 4;
430 am_sourceID_t sourceID = 2;
431 am_sinkID_t sinkID = 1;
432 am_ConnectionFormat_e format = CF_ANALOG;
434 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
435 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
436 pSocketHandler.start_listenting();
439 int main(int argc, char **argv)
441 ::testing::InitGoogleTest(&argc, argv);
442 return RUN_ALL_TESTS();