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"
29 using namespace testing;
31 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
33 std::vector<std::string> testRoutingInterfaceAsync::pListRoutingPluginDirs = returnListPlugins();
34 am_domainID_t testRoutingInterfaceAsync::mDomainIDCount = 0;
35 RoutingSender testRoutingInterfaceAsync::pRoutingSender = RoutingSender(pListRoutingPluginDirs);
37 testRoutingInterfaceAsync::testRoutingInterfaceAsync() :
39 pReceiveInterface(), //
40 ptimerCallback(this, &testRoutingInterfaceAsync::timerCallback)
44 testRoutingInterfaceAsync::~testRoutingInterfaceAsync()
48 void testRoutingInterfaceAsync::SetUp()
50 DLT_REGISTER_APP("DPtest", "RoutingInterfacetest");
51 DLT_REGISTER_CONTEXT(DLT_CONTEXT, "Main", "Main Context");
52 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("RoutingSendInterface Test started "));
54 std::vector<int> domainIDs;
55 domainIDs.push_back(0);
56 domainIDs.push_back(1);
58 EXPECT_CALL(pReceiveInterface,getSocketHandler(_)).WillOnce(DoAll(SetArgReferee<0>(&pSocketHandler), Return(E_OK)));
59 EXPECT_CALL(pReceiveInterface,registerDomain(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleDomainRegister));
60 EXPECT_CALL(pReceiveInterface,registerSource(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSourceRegister));
61 EXPECT_CALL(pReceiveInterface,registerSink(_,_)).WillRepeatedly(Invoke(testRoutingInterfaceAsync::handleSinkRegister));
63 pRoutingSender.startupRoutingInterface(&pReceiveInterface);
64 pRoutingSender.routingInterfacesReady();
70 sh_timerHandle_t handle;
72 shTimerCallBack *buf = &ptimerCallback;
73 //lets use a timeout so the test will finish
74 pSocketHandler.addTimer(t, buf, handle, (void*) NULL);
77 std::vector<std::string> am::testRoutingInterfaceAsync::returnListPlugins()
79 std::vector<std::string> list;
80 list.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR));
84 am_Error_e am::testRoutingInterfaceAsync::handleSourceRegister(const am_Source_s & sourceData, am_sourceID_t & sourceID)
86 sourceID = sourceData.sourceID;
87 pRoutingSender.addSourceLookup(sourceData);
91 am_Error_e am::testRoutingInterfaceAsync::handleSinkRegister(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
93 sinkID = sinkData.sinkID;
94 pRoutingSender.addSinkLookup(sinkData);
98 am_Error_e am::testRoutingInterfaceAsync::handleDomainRegister(const am_Domain_s & domainData, am_domainID_t & domainID)
100 am_Domain_s domain = domainData;
101 domainID = mDomainIDCount++;
102 domain.domainID = domainID;
103 pRoutingSender.addDomainLookup(domain);
107 void am::testRoutingInterfaceAsync::timerCallback(sh_timerHandle_t handle, void *userData)
109 pSocketHandler.stop_listening();
112 void testRoutingInterfaceAsync::TearDown()
114 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
117 TEST_F(testRoutingInterfaceAsync,setDomainState)
119 am_domainID_t domainID = 1;
120 am_DomainState_e state = DS_INDEPENDENT_RUNDOWN;
122 EXPECT_CALL(pReceiveInterface,hookDomainStateChange(_,DS_INDEPENDENT_RUNDOWN)).Times(1);
124 ASSERT_EQ(E_OK, pRoutingSender.setDomainState(domainID,state));
125 pSocketHandler.start_listenting();
128 TEST_F(testRoutingInterfaceAsync,setSourceSoundProperty)
133 handle.handleType = H_SETSOURCESOUNDPROPERTY;
135 am_sourceID_t sourceID = 3;
136 am_SoundProperty_s property;
137 property.type = SP_MID;
140 EXPECT_CALL(pReceiveInterface,ackSetSourceSoundProperty(_,E_OK)).Times(1);
142 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceSoundProperty(handle,sourceID,property));
143 pSocketHandler.start_listenting();
146 TEST_F(testRoutingInterfaceAsync,setSinkSoundProperty)
151 handle.handleType = H_SETSINKSOUNDPROPERTY;
153 am_sinkID_t sinkID = 1;
154 am_SoundProperty_s property;
155 property.type = SP_MID;
158 EXPECT_CALL(pReceiveInterface,ackSetSinkSoundProperty(_,E_OK)).Times(1);
160 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkSoundProperty(handle,sinkID,property));
161 pSocketHandler.start_listenting();
164 TEST_F(testRoutingInterfaceAsync,setSourceState)
169 handle.handleType = H_SETSOURCEVOLUME;
171 am_sourceID_t sourceID = 1;
172 am_SourceState_e state = SS_OFF;
174 EXPECT_CALL(pReceiveInterface,ackSetSourceState(_,E_OK)).Times(1);
176 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceState(handle,sourceID,state));
177 pSocketHandler.start_listenting();
180 TEST_F(testRoutingInterfaceAsync,setSourceVolume)
185 handle.handleType = H_SETSOURCEVOLUME;
187 am_sourceID_t sourceID = 3;
188 am_volume_t volume = 3;
189 am_RampType_e ramp = RAMP_DIRECT;
190 am_time_t myTime = 25;
192 EXPECT_CALL(pReceiveInterface,ackSourceVolumeTick(_,sourceID,_)).Times(3);
193 EXPECT_CALL(pReceiveInterface,ackSetSourceVolumeChange(_,volume,E_OK)).Times(1);
195 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceVolume(handle,sourceID,volume,ramp,myTime));
196 pSocketHandler.start_listenting();
199 TEST_F(testRoutingInterfaceAsync,setSinkVolume)
204 handle.handleType = H_SETSINKVOLUME;
206 am_sinkID_t sinkID = 1;
207 am_volume_t volume = 9;
208 am_RampType_e ramp = RAMP_DIRECT;
209 am_time_t myTime = 25;
211 EXPECT_CALL(pReceiveInterface,ackSinkVolumeTick(_,sinkID,_)).Times(9);
212 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,volume,E_OK)).Times(1);
214 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
215 pSocketHandler.start_listenting();
218 TEST_F(testRoutingInterfaceAsync,setSinkVolumeAbort)
223 handle.handleType = H_SETSINKVOLUME;
225 am_sinkID_t sinkID = 2;
226 am_volume_t volume = 25;
227 am_RampType_e ramp = RAMP_DIRECT;
228 am_time_t myTime = 25;
230 EXPECT_CALL(pReceiveInterface, ackSinkVolumeTick(_,sinkID,_));
231 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,AllOf(Ne(volume),Ne(0)),E_ABORTED)).Times(1);
233 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
235 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
236 pSocketHandler.start_listenting();
239 TEST_F(testRoutingInterfaceAsync,disconnectTooEarly)
244 handle.handleType = H_CONNECT;
246 am_connectionID_t connectionID = 4;
247 am_sourceID_t sourceID = 2;
248 am_sinkID_t sinkID = 1;
249 am_ConnectionFormat_e format = CF_ANALOG;
251 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
252 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
253 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
254 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncDisconnect(handle,connectionID));
255 pSocketHandler.start_listenting();
258 TEST_F(testRoutingInterfaceAsync,disconnectAbort)
263 handle.handleType = H_CONNECT;
265 am_connectionID_t connectionID = 4;
266 am_sourceID_t sourceID = 2;
267 am_sinkID_t sinkID = 1;
268 am_ConnectionFormat_e format = CF_ANALOG;
270 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
271 EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_ABORTED));
272 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
274 ASSERT_EQ(E_OK, pRoutingSender.asyncDisconnect(handle,connectionID));
275 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
276 pSocketHandler.start_listenting();
279 TEST_F(testRoutingInterfaceAsync,disconnectNonExisting)
284 handle.handleType = H_CONNECT;
286 am_connectionID_t connectionID = 4;
287 am_sourceID_t sourceID = 2;
288 am_sinkID_t sinkID = 1;
289 am_ConnectionFormat_e format = CF_ANALOG;
291 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
292 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
293 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncDisconnect(handle,connectionID));
294 pSocketHandler.start_listenting();
297 TEST_F(testRoutingInterfaceAsync,disconnect)
302 handle.handleType = H_CONNECT;
304 am_connectionID_t connectionID = 4;
305 am_sourceID_t sourceID = 2;
306 am_sinkID_t sinkID = 1;
307 am_ConnectionFormat_e format = CF_ANALOG;
309 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
310 EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_OK));
311 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
313 ASSERT_EQ(E_OK, pRoutingSender.asyncDisconnect(handle,connectionID));
314 pSocketHandler.start_listenting();
317 TEST_F(testRoutingInterfaceAsync,connectNoMoreThreads)
322 handle.handleType = H_CONNECT;
324 am_connectionID_t connectionID = 1;
325 am_sourceID_t sourceID = 2;
326 am_sinkID_t sinkID = 1;
327 am_ConnectionFormat_e format = CF_ANALOG;
329 EXPECT_CALL(pReceiveInterface,ackConnect(_,_,E_OK)).Times(10);
330 for (int i = 0; i < 10; i++)
334 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
335 }ASSERT_EQ(E_NOT_POSSIBLE, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
336 pSocketHandler.start_listenting();
339 TEST_F(testRoutingInterfaceAsync,connectAbortTooLate)
344 handle.handleType = H_CONNECT;
346 am_connectionID_t connectionID = 4;
347 am_sourceID_t sourceID = 2;
348 am_sinkID_t sinkID = 1;
349 am_ConnectionFormat_e format = CF_ANALOG;
351 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(1);
352 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
354 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncAbort(handle));
355 pSocketHandler.start_listenting();
358 TEST_F(testRoutingInterfaceAsync,connectAbort)
363 handle.handleType = H_CONNECT;
365 am_connectionID_t connectionID = 4;
366 am_sourceID_t sourceID = 2;
367 am_sinkID_t sinkID = 1;
368 am_ConnectionFormat_e format = CF_ANALOG;
370 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_ABORTED)).Times(1);
371 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
373 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
374 pSocketHandler.start_listenting();
377 TEST_F(testRoutingInterfaceAsync,connectWrongFormat)
382 handle.handleType = H_CONNECT;
384 am_connectionID_t connectionID = 4;
385 am_sourceID_t sourceID = 2;
386 am_sinkID_t sinkID = 1;
387 am_ConnectionFormat_e format = CF_MONO;
389 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
390 ASSERT_EQ(E_WRONG_FORMAT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
391 pSocketHandler.start_listenting();
394 TEST_F(testRoutingInterfaceAsync,connectWrongSink)
399 handle.handleType = H_CONNECT;
401 am_connectionID_t connectionID = 4;
402 am_sourceID_t sourceID = 2;
403 am_sinkID_t sinkID = 122;
404 am_ConnectionFormat_e format = CF_ANALOG;
406 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
407 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
408 pSocketHandler.start_listenting();
411 TEST_F(testRoutingInterfaceAsync,connectWrongSource)
415 handle.handleType = H_CONNECT;
417 am_connectionID_t connectionID = 4;
418 am_sourceID_t sourceID = 25;
419 am_sinkID_t sinkID = 1;
420 am_ConnectionFormat_e format = CF_ANALOG;
422 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
423 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
424 pSocketHandler.start_listenting();
427 TEST_F(testRoutingInterfaceAsync,connect)
432 handle.handleType = H_CONNECT;
434 am_connectionID_t connectionID = 4;
435 am_sourceID_t sourceID = 2;
436 am_sinkID_t sinkID = 1;
437 am_ConnectionFormat_e format = CF_ANALOG;
439 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
440 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
441 pSocketHandler.start_listenting();
444 int main(int argc, char **argv)
446 ::testing::InitGoogleTest(&argc, argv);
447 return RUN_ALL_TESTS();