2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file routingInterfaces.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.
23 * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
26 #include "routingInterfaceTest.h"
27 #include "DLTWrapper.h"
30 using namespace testing;
32 routingInterfaceTest::routingInterfaceTest() :
33 plistRoutingPluginDirs(), //
34 plistCommandPluginDirs(), //
35 pDatabaseHandler(std::string(":memory:")), //
36 pRoutingSender(plistRoutingPluginDirs), //
37 pCommandSender(plistCommandPluginDirs), //
38 pControlSender(""), //
39 pRouter(&pDatabaseHandler, &pControlSender), //
41 pRoutingInterfaceBackdoor(), //
42 pCommandInterfaceBackdoor(), //
43 pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pRouter), //
44 pObserver(&pCommandSender, &pRoutingSender)
46 pDatabaseHandler.registerObserver(&pObserver);
47 pRoutingInterfaceBackdoor.unloadPlugins(&pRoutingSender);
48 pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockInterface, "mock");
49 pCommandInterfaceBackdoor.unloadPlugins(&pCommandSender);
52 routingInterfaceTest::~routingInterfaceTest()
56 void routingInterfaceTest::SetUp()
58 logInfo("RoutingSendInterface Test started ");
62 void routingInterfaceTest::TearDown()
66 TEST_F(routingInterfaceTest,abort)
71 am_domainID_t domainID;
73 am_connectionID_t connectionID;
74 std::vector<am_Handle_s> listHandles;
76 pCF.createDomain(domain);
78 domain.busname = "mock";
83 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
84 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
86 //start a connect, expect a call on the routingInterface
87 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
88 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
90 //check the correctness of the handle
91 ASSERT_NE(handle.handle, 0);
92 ASSERT_EQ(handle.handleType, H_CONNECT);
94 //the handle must be inside the handlelist
95 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
96 ASSERT_TRUE(listHandles[0].handle==handle.handle);
97 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
99 //send an abort expect a call on the routing interface
100 EXPECT_CALL(pMockInterface,asyncAbort(_)).WillOnce(Return(E_OK));
101 ASSERT_EQ(E_OK, pControlReceiver.abortAction(handle));
103 //the reaction on the abort is specific for every function
105 //now we try to abort a handle that does not exist
107 ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle));
110 TEST_F(routingInterfaceTest,abortNonExistent)
112 EXPECT_CALL(pMockInterface,asyncAbort(_)).Times(0);
114 ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle));
117 TEST_F(routingInterfaceTest,alreadyConnected)
122 am_domainID_t domainID;
123 pCF.createSink(sink);
124 pCF.createDomain(domain);
125 domain.name = "mock";
126 domain.busname = "mock";
129 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
130 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
131 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
133 am_connectionID_t connectionID;
134 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
135 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
136 ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
137 ASSERT_NE(handle.handle, 0);
138 ASSERT_EQ(handle.handleType, H_CONNECT);
141 TEST_F(routingInterfaceTest,setSinkSoundPropertyNoChange)
146 am_domainID_t domainID;
148 am_SoundProperty_s soundProperty;
149 soundProperty.type = SP_TREBLE;
150 soundProperty.value = 23;
151 std::vector<am_Handle_s> listHandles;
152 pCF.createSink(sink);
153 pCF.createDomain(domain);
154 domain.name = "mock";
155 domain.busname = "mock";
158 sink.listSoundProperties.push_back(soundProperty);
159 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
160 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
161 EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).Times(0);
162 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty));
165 TEST_F(routingInterfaceTest,setSourceState)
168 am_sourceID_t sourceID;
170 am_domainID_t domainID;
173 am_SourceState_e state = SS_PAUSED;
174 pCF.createSource(source);
175 pCF.createDomain(domain);
176 domain.name = "mock";
177 domain.busname = "mock";
179 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
180 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
181 EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).WillOnce(Return(E_OK));
182 ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,sourceID,state));
183 ASSERT_NE(handle.handle, 0);
184 ASSERT_EQ(handle.handleType, H_SETSOURCESTATE);
187 TEST_F(routingInterfaceTest,setSourceSoundProperty)
190 am_sourceID_t sourceID;
192 am_domainID_t domainID;
194 am_SoundProperty_s soundProperty;
195 std::vector<am_Handle_s> listHandles;
196 pCF.createSource(source);
197 pCF.createDomain(domain);
198 domain.name = "mock";
199 domain.busname = "mock";
202 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
203 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
204 EXPECT_CALL(pMockInterface,asyncSetSourceSoundProperty(_,sourceID,_)).WillOnce(Return(E_OK));
205 ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,sourceID,soundProperty));
206 ASSERT_NE(handle.handle, 0);
207 ASSERT_EQ(handle.handleType, H_SETSOURCESOUNDPROPERTY);
208 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
209 ASSERT_TRUE(listHandles[0].handle==handle.handle);
210 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
213 TEST_F(routingInterfaceTest,setSinkSoundProperty)
218 am_domainID_t domainID;
220 am_SoundProperty_s soundProperty;
221 std::vector<am_Handle_s> listHandles;
222 pCF.createSink(sink);
223 pCF.createDomain(domain);
224 domain.name = "mock";
225 domain.busname = "mock";
228 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
229 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
230 EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).WillOnce(Return(E_OK));
231 ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty));
232 ASSERT_NE(handle.handle, 0);
233 ASSERT_EQ(handle.handleType, H_SETSINKSOUNDPROPERTY);
234 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
235 ASSERT_TRUE(listHandles[0].handle==handle.handle);
236 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
239 TEST_F(routingInterfaceTest,setSourceVolumeNoChange)
242 am_sourceID_t sourceID;
244 am_domainID_t domainID;
246 am_volume_t volume = 34;
247 am_RampType_e rampType = RAMP_DIRECT;
248 am_time_t rampTime = 300;
249 std::vector<am_Handle_s> listHandles;
250 pCF.createSource(source);
251 pCF.createDomain(domain);
252 domain.name = "mock";
253 domain.busname = "mock";
256 source.volume = volume;
257 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
258 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
259 EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).Times(0);
260 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime));
261 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
262 ASSERT_TRUE(listHandles.empty());
265 TEST_F(routingInterfaceTest,setSourceVolume)
268 am_sourceID_t sourceID;
270 am_domainID_t domainID;
272 am_volume_t volume = 34;
273 am_RampType_e rampType = RAMP_DIRECT;
274 am_time_t rampTime = 300;
275 std::vector<am_Handle_s> listHandles;
276 pCF.createSource(source);
277 pCF.createDomain(domain);
278 domain.name = "mock";
279 domain.busname = "mock";
282 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
283 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
284 EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK));
285 ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime));
286 ASSERT_NE(handle.handle, 0);
287 ASSERT_EQ(handle.handleType, H_SETSOURCEVOLUME);
288 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
289 ASSERT_TRUE(listHandles[0].handle==handle.handle);
290 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
293 TEST_F(routingInterfaceTest,setSinkVolumeNoChange)
298 am_domainID_t domainID;
300 am_volume_t volume = 34;
301 am_RampType_e rampType = RAMP_DIRECT;
302 am_time_t rampTime = 300;
303 std::vector<am_Handle_s> listHandles;
304 pCF.createSink(sink);
305 pCF.createDomain(domain);
306 domain.name = "mock";
307 domain.busname = "mock";
310 sink.volume = volume;
311 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
312 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
313 EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).Times(0);
314 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime));
315 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
316 ASSERT_TRUE(listHandles.empty());
319 TEST_F(routingInterfaceTest,setSinkVolume)
324 am_domainID_t domainID;
326 am_volume_t volume = 34;
327 am_RampType_e rampType = RAMP_DIRECT;
328 am_time_t rampTime = 300;
329 std::vector<am_Handle_s> listHandles;
330 pCF.createSink(sink);
331 pCF.createDomain(domain);
332 domain.name = "mock";
333 domain.busname = "mock";
336 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
337 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
338 EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK));
339 ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime));
340 ASSERT_NE(handle.handle, 0);
341 ASSERT_EQ(handle.handleType, H_SETSINKVOLUME);
342 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
343 ASSERT_TRUE(listHandles[0].handle==handle.handle);
344 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
347 TEST_F(routingInterfaceTest,connect)
352 am_domainID_t domainID;
354 am_connectionID_t connectionID;
355 std::vector<am_Handle_s> listHandles;
356 pCF.createSink(sink);
357 pCF.createDomain(domain);
358 domain.name = "mock";
359 domain.busname = "mock";
362 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
363 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
364 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
365 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
366 ASSERT_NE(handle.handle, 0);
367 ASSERT_EQ(handle.handleType, H_CONNECT);
368 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
369 ASSERT_TRUE(listHandles[0].handle==handle.handle);
370 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
373 TEST_F(routingInterfaceTest,disconnect)
378 am_domainID_t domainID;
380 am_connectionID_t connectionID;
381 std::vector<am_Handle_s> listHandles;
382 pCF.createSink(sink);
383 pCF.createDomain(domain);
384 domain.name = "mock";
385 domain.busname = "mock";
388 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
389 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
390 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
391 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
392 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
393 EXPECT_CALL(pMockInterface,asyncDisconnect(_,connectionID)).WillOnce(Return(E_OK));
394 ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,connectionID));
395 ASSERT_NE(handle.handle, 0);
396 ASSERT_EQ(handle.handleType, H_DISCONNECT);
397 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
398 ASSERT_TRUE(listHandles[1].handle==handle.handle);
399 ASSERT_TRUE(listHandles[1].handleType==handle.handleType);
402 TEST_F(routingInterfaceTest,nothingTodisconnect)
405 am_connectionID_t connectionID = 4;
406 std::vector<am_Handle_s> listHandles;
407 ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,connectionID));
408 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
409 ASSERT_TRUE(listHandles.empty());
412 TEST_F(routingInterfaceTest,setSourceStateNoChange)
415 am_sourceID_t sourceID;
417 am_domainID_t domainID;
420 am_SourceState_e state = SS_PAUSED;
421 pCF.createSource(source);
422 pCF.createDomain(domain);
423 domain.name = "mock";
424 domain.busname = "mock";
426 source.sourceState = state;
427 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
428 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
429 EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).Times(0);
430 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,sourceID,state));
433 int main(int argc, char **argv)
435 ::testing::InitGoogleTest(&argc, argv);
436 return RUN_ALL_TESTS();