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)
111 pSocketHandler.stop_listening();
114 void testRoutingInterfaceAsync::TearDown()
116 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
119 TEST_F(testRoutingInterfaceAsync,setDomainState)
121 am_domainID_t domainID = 1;
122 am_DomainState_e state = DS_INDEPENDENT_RUNDOWN;
124 EXPECT_CALL(pReceiveInterface,hookDomainStateChange(_,DS_INDEPENDENT_RUNDOWN)).Times(1);
126 ASSERT_EQ(E_OK, pRoutingSender.setDomainState(domainID,state));
127 pSocketHandler.start_listenting();
130 TEST_F(testRoutingInterfaceAsync,setSourceSoundProperty)
135 handle.handleType = H_SETSOURCESOUNDPROPERTY;
137 am_sourceID_t sourceID = 3;
138 am_SoundProperty_s property;
139 property.type = SP_MID;
142 EXPECT_CALL(pReceiveInterface,ackSetSourceSoundProperty(_,E_OK)).Times(1);
144 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceSoundProperty(handle,sourceID,property));
145 pSocketHandler.start_listenting();
148 TEST_F(testRoutingInterfaceAsync,setSinkSoundProperty)
153 handle.handleType = H_SETSINKSOUNDPROPERTY;
155 am_sinkID_t sinkID = 1;
156 am_SoundProperty_s property;
157 property.type = SP_MID;
160 EXPECT_CALL(pReceiveInterface,ackSetSinkSoundProperty(_,E_OK)).Times(1);
162 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkSoundProperty(handle,sinkID,property));
163 pSocketHandler.start_listenting();
166 TEST_F(testRoutingInterfaceAsync,setSourceState)
171 handle.handleType = H_SETSOURCEVOLUME;
173 am_sourceID_t sourceID = 1;
174 am_SourceState_e state = SS_OFF;
176 EXPECT_CALL(pReceiveInterface,ackSetSourceState(_,E_OK)).Times(1);
178 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceState(handle,sourceID,state));
179 pSocketHandler.start_listenting();
182 TEST_F(testRoutingInterfaceAsync,setSourceVolume)
187 handle.handleType = H_SETSOURCEVOLUME;
189 am_sourceID_t sourceID = 3;
190 am_volume_t volume = 3;
191 am_RampType_e ramp = RAMP_DIRECT;
192 am_time_t myTime = 25;
194 EXPECT_CALL(pReceiveInterface,ackSourceVolumeTick(_,sourceID,_)).Times(3);
195 EXPECT_CALL(pReceiveInterface,ackSetSourceVolumeChange(_,volume,E_OK)).Times(1);
197 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSourceVolume(handle,sourceID,volume,ramp,myTime));
198 pSocketHandler.start_listenting();
201 TEST_F(testRoutingInterfaceAsync,setSinkVolume)
206 handle.handleType = H_SETSINKVOLUME;
208 am_sinkID_t sinkID = 1;
209 am_volume_t volume = 9;
210 am_RampType_e ramp = RAMP_DIRECT;
211 am_time_t myTime = 25;
213 EXPECT_CALL(pReceiveInterface,ackSinkVolumeTick(_,sinkID,_)).Times(9);
214 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,volume,E_OK)).Times(1);
216 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
217 pSocketHandler.start_listenting();
220 TEST_F(testRoutingInterfaceAsync,setSinkVolumeAbort)
225 handle.handleType = H_SETSINKVOLUME;
227 am_sinkID_t sinkID = 2;
228 am_volume_t volume = 25;
229 am_RampType_e ramp = RAMP_DIRECT;
230 am_time_t myTime = 25;
232 EXPECT_CALL(pReceiveInterface, ackSinkVolumeTick(_,sinkID,_));
233 EXPECT_CALL(pReceiveInterface,ackSetSinkVolumeChange(_,AllOf(Ne(volume),Ne(0)),E_ABORTED)).Times(1);
235 ASSERT_EQ(E_OK, pRoutingSender.asyncSetSinkVolume(handle,sinkID,volume,ramp,myTime));
237 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
238 pSocketHandler.start_listenting();
241 TEST_F(testRoutingInterfaceAsync,disconnectTooEarly)
246 handle.handleType = H_CONNECT;
248 am_connectionID_t connectionID = 4;
249 am_sourceID_t sourceID = 2;
250 am_sinkID_t sinkID = 1;
251 am_ConnectionFormat_e format = CF_ANALOG;
253 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
254 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
255 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
256 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncDisconnect(handle,connectionID));
257 pSocketHandler.start_listenting();
260 TEST_F(testRoutingInterfaceAsync,disconnectAbort)
265 handle.handleType = H_CONNECT;
267 am_connectionID_t connectionID = 4;
268 am_sourceID_t sourceID = 2;
269 am_sinkID_t sinkID = 1;
270 am_ConnectionFormat_e format = CF_ANALOG;
272 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
273 EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_ABORTED));
274 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
276 ASSERT_EQ(E_OK, pRoutingSender.asyncDisconnect(handle,connectionID));
277 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
278 pSocketHandler.start_listenting();
281 TEST_F(testRoutingInterfaceAsync,disconnectNonExisting)
286 handle.handleType = H_CONNECT;
288 am_connectionID_t connectionID = 4;
290 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
291 EXPECT_CALL(pReceiveInterface,ackDisconnect(_,connectionID,E_OK)).Times(0);
292 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncDisconnect(handle,connectionID));
293 pSocketHandler.start_listenting();
296 TEST_F(testRoutingInterfaceAsync,disconnect)
301 handle.handleType = H_CONNECT;
303 am_connectionID_t connectionID = 4;
304 am_sourceID_t sourceID = 2;
305 am_sinkID_t sinkID = 1;
306 am_ConnectionFormat_e format = CF_ANALOG;
308 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
309 EXPECT_CALL(pReceiveInterface, ackDisconnect(_,connectionID,E_OK));
310 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
312 ASSERT_EQ(E_OK, pRoutingSender.asyncDisconnect(handle,connectionID));
313 pSocketHandler.start_listenting();
316 TEST_F(testRoutingInterfaceAsync,connectNoMoreThreads)
321 handle.handleType = H_CONNECT;
323 am_connectionID_t connectionID = 1;
324 am_sourceID_t sourceID = 2;
325 am_sinkID_t sinkID = 1;
326 am_ConnectionFormat_e format = CF_ANALOG;
328 EXPECT_CALL(pReceiveInterface,ackConnect(_,_,E_OK)).Times(10);
329 for (int i = 0; i < 10; i++)
333 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
334 }ASSERT_EQ(E_NOT_POSSIBLE, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
335 pSocketHandler.start_listenting();
338 TEST_F(testRoutingInterfaceAsync,connectAbortTooLate)
343 handle.handleType = H_CONNECT;
345 am_connectionID_t connectionID = 4;
346 am_sourceID_t sourceID = 2;
347 am_sinkID_t sinkID = 1;
348 am_ConnectionFormat_e format = CF_ANALOG;
350 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(1);
351 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
353 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncAbort(handle));
354 pSocketHandler.start_listenting();
357 TEST_F(testRoutingInterfaceAsync,connectAbort)
362 handle.handleType = H_CONNECT;
364 am_connectionID_t connectionID = 4;
365 am_sourceID_t sourceID = 2;
366 am_sinkID_t sinkID = 1;
367 am_ConnectionFormat_e format = CF_ANALOG;
369 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_ABORTED)).Times(1);
370 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
372 ASSERT_EQ(E_OK, pRoutingSender.asyncAbort(handle));
373 pSocketHandler.start_listenting();
376 TEST_F(testRoutingInterfaceAsync,connectWrongFormat)
381 handle.handleType = H_CONNECT;
383 am_connectionID_t connectionID = 4;
384 am_sourceID_t sourceID = 2;
385 am_sinkID_t sinkID = 1;
386 am_ConnectionFormat_e format = CF_MONO;
388 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
389 ASSERT_EQ(E_WRONG_FORMAT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
390 pSocketHandler.start_listenting();
393 TEST_F(testRoutingInterfaceAsync,connectWrongSink)
398 handle.handleType = H_CONNECT;
400 am_connectionID_t connectionID = 4;
401 am_sourceID_t sourceID = 2;
402 am_sinkID_t sinkID = 122;
403 am_ConnectionFormat_e format = CF_ANALOG;
405 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
406 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
407 pSocketHandler.start_listenting();
410 TEST_F(testRoutingInterfaceAsync,connectWrongSource)
414 handle.handleType = H_CONNECT;
416 am_connectionID_t connectionID = 4;
417 am_sourceID_t sourceID = 25;
418 am_sinkID_t sinkID = 1;
419 am_ConnectionFormat_e format = CF_ANALOG;
421 EXPECT_CALL(pReceiveInterface,ackConnect(_,connectionID,E_OK)).Times(0);
422 ASSERT_EQ(E_NON_EXISTENT, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
423 pSocketHandler.start_listenting();
426 TEST_F(testRoutingInterfaceAsync,connect)
431 handle.handleType = H_CONNECT;
433 am_connectionID_t connectionID = 4;
434 am_sourceID_t sourceID = 2;
435 am_sinkID_t sinkID = 1;
436 am_ConnectionFormat_e format = CF_ANALOG;
438 EXPECT_CALL(pReceiveInterface, ackConnect(_,connectionID,E_OK));
439 ASSERT_EQ(E_OK, pRoutingSender.asyncConnect(handle,connectionID,sourceID,sinkID,format));
440 pSocketHandler.start_listenting();
443 int main(int argc, char **argv)
445 ::testing::InitGoogleTest(&argc, argv);
446 return RUN_ALL_TESTS();