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"
29 using namespace testing;
31 DLT_DECLARE_CONTEXT(DLT_CONTEXT);
33 routingInterfaceTest::routingInterfaceTest() :
34 plistRoutingPluginDirs(), //
35 plistCommandPluginDirs(), //
36 pDatabaseHandler(std::string(":memory:")), //
37 pRoutingSender(plistRoutingPluginDirs), //
38 pCommandSender(plistCommandPluginDirs), //
40 pRoutingInterfaceBackdoor(), //
41 pCommandInterfaceBackdoor(), //
42 pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender), //
43 pObserver(&pCommandSender, &pRoutingSender)
45 pDatabaseHandler.registerObserver(&pObserver);
46 pRoutingInterfaceBackdoor.unloadPlugins(&pRoutingSender);
47 pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockInterface, "mock");
48 pCommandInterfaceBackdoor.unloadPlugins(&pCommandSender);
51 routingInterfaceTest::~routingInterfaceTest()
55 void routingInterfaceTest::SetUp()
57 DLT_REGISTER_APP("Rtest", "RoutingInterfacetest");
58 DLT_REGISTER_CONTEXT(DLT_CONTEXT, "Main", "Main Context");
59 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("RoutingSendInterface Test started "));
63 void routingInterfaceTest::TearDown()
65 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
68 TEST_F(routingInterfaceTest,abort)
73 am_domainID_t domainID;
75 am_connectionID_t connectionID;
76 std::vector<am_Handle_s> listHandles;
78 pCF.createDomain(domain);
80 domain.busname = "mock";
85 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
86 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
88 //start a connect, expect a call on the routingInterface
89 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
90 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
92 //check the correctness of the handle
93 ASSERT_NE(handle.handle, 0);
94 ASSERT_EQ(handle.handleType, H_CONNECT);
96 //the handle must be inside the handlelist
97 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
98 ASSERT_TRUE(listHandles[0].handle==handle.handle);
99 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
101 //send an abort expect a call on the routing interface
102 EXPECT_CALL(pMockInterface,asyncAbort(_)).WillOnce(Return(E_OK));
103 ASSERT_EQ(E_OK, pControlReceiver.abortAction(handle));
105 //the reaction on the abort is specific for every function
107 //now we try to abort a handle that does not exist
109 ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle));
112 TEST_F(routingInterfaceTest,abortNonExistent)
114 EXPECT_CALL(pMockInterface,asyncAbort(_)).Times(0);
116 ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.abortAction(handle));
119 TEST_F(routingInterfaceTest,alreadyConnected)
124 am_domainID_t domainID;
125 pCF.createSink(sink);
126 pCF.createDomain(domain);
127 domain.name = "mock";
128 domain.busname = "mock";
131 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
132 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
133 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
135 am_connectionID_t connectionID;
136 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
137 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
138 ASSERT_EQ(E_ALREADY_EXISTS, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
139 ASSERT_NE(handle.handle, 0);
140 ASSERT_EQ(handle.handleType, H_CONNECT);
143 TEST_F(routingInterfaceTest,setSinkSoundPropertyNoChange)
148 am_domainID_t domainID;
150 am_SoundProperty_s soundProperty;
151 soundProperty.type = SP_TREBLE;
152 soundProperty.value = 23;
153 std::vector<am_Handle_s> listHandles;
154 pCF.createSink(sink);
155 pCF.createDomain(domain);
156 domain.name = "mock";
157 domain.busname = "mock";
160 sink.listSoundProperties.push_back(soundProperty);
161 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
162 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
163 EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,_,sinkID)).Times(0);
164 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty));
167 TEST_F(routingInterfaceTest,setSourceState)
170 am_sourceID_t sourceID;
172 am_domainID_t domainID;
175 am_SourceState_e state = SS_PAUSED;
176 pCF.createSource(source);
177 pCF.createDomain(domain);
178 domain.name = "mock";
179 domain.busname = "mock";
181 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
182 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
183 EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).WillOnce(Return(E_OK));
184 ASSERT_EQ(E_OK, pControlReceiver.setSourceState(handle,sourceID,state));
185 ASSERT_NE(handle.handle, 0);
186 ASSERT_EQ(handle.handleType, H_SETSOURCESTATE);
189 TEST_F(routingInterfaceTest,setSourceSoundProperty)
192 am_sourceID_t sourceID;
194 am_domainID_t domainID;
196 am_SoundProperty_s soundProperty;
197 std::vector<am_Handle_s> listHandles;
198 pCF.createSource(source);
199 pCF.createDomain(domain);
200 domain.name = "mock";
201 domain.busname = "mock";
204 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
205 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
206 EXPECT_CALL(pMockInterface,asyncSetSourceSoundProperty(_,_,sourceID)).WillOnce(Return(E_OK));
207 ASSERT_EQ(E_OK, pControlReceiver.setSourceSoundProperty(handle,sourceID,soundProperty));
208 ASSERT_NE(handle.handle, 0);
209 ASSERT_EQ(handle.handleType, H_SETSOURCESOUNDPROPERTY);
210 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
211 ASSERT_TRUE(listHandles[0].handle==handle.handle);
212 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
215 TEST_F(routingInterfaceTest,setSinkSoundProperty)
220 am_domainID_t domainID;
222 am_SoundProperty_s soundProperty;
223 std::vector<am_Handle_s> listHandles;
224 pCF.createSink(sink);
225 pCF.createDomain(domain);
226 domain.name = "mock";
227 domain.busname = "mock";
230 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
231 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
232 EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,_,sinkID)).WillOnce(Return(E_OK));
233 ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty));
234 ASSERT_NE(handle.handle, 0);
235 ASSERT_EQ(handle.handleType, H_SETSINKSOUNDPROPERTY);
236 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
237 ASSERT_TRUE(listHandles[0].handle==handle.handle);
238 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
241 TEST_F(routingInterfaceTest,setSourceVolumeNoChange)
244 am_sourceID_t sourceID;
246 am_domainID_t domainID;
248 am_volume_t volume = 34;
249 am_RampType_e rampType = RAMP_DIRECT;
250 am_time_t rampTime = 300;
251 std::vector<am_Handle_s> listHandles;
252 pCF.createSource(source);
253 pCF.createDomain(domain);
254 domain.name = "mock";
255 domain.busname = "mock";
258 source.volume = volume;
259 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
260 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
261 EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).Times(0);
262 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime));
263 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
264 ASSERT_TRUE(listHandles.empty());
267 TEST_F(routingInterfaceTest,setSourceVolume)
270 am_sourceID_t sourceID;
272 am_domainID_t domainID;
274 am_volume_t volume = 34;
275 am_RampType_e rampType = RAMP_DIRECT;
276 am_time_t rampTime = 300;
277 std::vector<am_Handle_s> listHandles;
278 pCF.createSource(source);
279 pCF.createDomain(domain);
280 domain.name = "mock";
281 domain.busname = "mock";
284 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
285 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
286 EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK));
287 ASSERT_EQ(E_OK, pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime));
288 ASSERT_NE(handle.handle, 0);
289 ASSERT_EQ(handle.handleType, H_SETSOURCEVOLUME);
290 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
291 ASSERT_TRUE(listHandles[0].handle==handle.handle);
292 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
295 TEST_F(routingInterfaceTest,setSinkVolumeNoChange)
300 am_domainID_t domainID;
302 am_volume_t volume = 34;
303 am_RampType_e rampType = RAMP_DIRECT;
304 am_time_t rampTime = 300;
305 std::vector<am_Handle_s> listHandles;
306 pCF.createSink(sink);
307 pCF.createDomain(domain);
308 domain.name = "mock";
309 domain.busname = "mock";
312 sink.volume = volume;
313 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
314 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
315 EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).Times(0);
316 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime));
317 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
318 ASSERT_TRUE(listHandles.empty());
321 TEST_F(routingInterfaceTest,setSinkVolume)
326 am_domainID_t domainID;
328 am_volume_t volume = 34;
329 am_RampType_e rampType = RAMP_DIRECT;
330 am_time_t rampTime = 300;
331 std::vector<am_Handle_s> listHandles;
332 pCF.createSink(sink);
333 pCF.createDomain(domain);
334 domain.name = "mock";
335 domain.busname = "mock";
338 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
339 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
340 EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK));
341 ASSERT_EQ(E_OK, pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime));
342 ASSERT_NE(handle.handle, 0);
343 ASSERT_EQ(handle.handleType, H_SETSINKVOLUME);
344 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
345 ASSERT_TRUE(listHandles[0].handle==handle.handle);
346 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
349 TEST_F(routingInterfaceTest,connect)
354 am_domainID_t domainID;
356 am_connectionID_t connectionID;
357 std::vector<am_Handle_s> listHandles;
358 pCF.createSink(sink);
359 pCF.createDomain(domain);
360 domain.name = "mock";
361 domain.busname = "mock";
364 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
365 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
366 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
367 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
368 ASSERT_NE(handle.handle, 0);
369 ASSERT_EQ(handle.handleType, H_CONNECT);
370 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
371 ASSERT_TRUE(listHandles[0].handle==handle.handle);
372 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
375 TEST_F(routingInterfaceTest,disconnect)
380 am_domainID_t domainID;
382 am_connectionID_t connectionID;
383 std::vector<am_Handle_s> listHandles;
384 pCF.createSink(sink);
385 pCF.createDomain(domain);
386 domain.name = "mock";
387 domain.busname = "mock";
390 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
391 ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
392 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
393 ASSERT_EQ(E_OK, pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
394 ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID));
395 EXPECT_CALL(pMockInterface,asyncDisconnect(_,connectionID)).WillOnce(Return(E_OK));
396 ASSERT_EQ(E_OK, pControlReceiver.disconnect(handle,connectionID));
397 ASSERT_NE(handle.handle, 0);
398 ASSERT_EQ(handle.handleType, H_DISCONNECT);
399 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
400 ASSERT_TRUE(listHandles[1].handle==handle.handle);
401 ASSERT_TRUE(listHandles[1].handleType==handle.handleType);
404 TEST_F(routingInterfaceTest,nothingTodisconnect)
407 am_connectionID_t connectionID = 4;
408 std::vector<am_Handle_s> listHandles;
409 ASSERT_EQ(E_NON_EXISTENT, pControlReceiver.disconnect(handle,connectionID));
410 ASSERT_EQ(E_OK, pControlReceiver.getListHandles(listHandles));
411 ASSERT_TRUE(listHandles.empty());
414 TEST_F(routingInterfaceTest,setSourceStateNoChange)
417 am_sourceID_t sourceID;
419 am_domainID_t domainID;
422 am_SourceState_e state = SS_PAUSED;
423 pCF.createSource(source);
424 pCF.createDomain(domain);
425 domain.name = "mock";
426 domain.busname = "mock";
428 source.sourceState = state;
429 ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
430 ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
431 EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).Times(0);
432 ASSERT_EQ(E_NO_CHANGE, pControlReceiver.setSourceState(handle,sourceID,state));
435 int main(int argc, char **argv)
437 ::testing::InitGoogleTest(&argc, argv);
438 return RUN_ALL_TESTS();