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"
28 using ::testing::Field;
29 using ::testing::Property;
30 using ::testing::Matcher;
31 using ::testing::Pointee;
32 using ::testing::AllOf;
33 using ::testing::SafeMatcherCast;
34 using ::testing::MatcherCast;
35 using ::testing::DefaultValue;
38 using ::testing::ElementsAreArray;
39 using ::testing::ElementsAre;
40 using ::testing::NotNull;
42 routingInterfaceTest::routingInterfaceTest()
43 :plistRoutingPluginDirs(),
44 plistCommandPluginDirs(),
45 pDatabaseHandler(std::string(":memory:")),
46 pRoutingSender(plistRoutingPluginDirs),
47 pCommandSender(plistCommandPluginDirs),
49 pRoutingInterfaceBackdoor(),
50 pCommandInterfaceBackdoor(),
51 pControlReceiver(&pDatabaseHandler,&pRoutingSender,&pCommandSender),
52 pObserver(&pCommandSender,&pRoutingSender)
54 pDatabaseHandler.registerObserver(&pObserver);
55 pRoutingInterfaceBackdoor.unloadPlugins(&pRoutingSender);
56 pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender,&pMockInterface,"mock");
57 pCommandInterfaceBackdoor.unloadPlugins(&pCommandSender);
60 routingInterfaceTest::~routingInterfaceTest()
64 void routingInterfaceTest::SetUp()
66 DLT_REGISTER_APP("Rtest","RoutingInterfacetest");
67 DLT_REGISTER_CONTEXT(AudioManager,"Main","Main Context");
68 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("RoutingSendInterface Test started "));
72 void routingInterfaceTest::TearDown()
74 DLT_UNREGISTER_CONTEXT(AudioManager);
77 TEST_F(routingInterfaceTest,abort)
82 am_domainID_t domainID;
84 am_connectionID_t connectionID;
85 std::vector<am_Handle_s>listHandles;
87 pCF.createDomain(domain);
89 domain.busname="mock";
94 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
95 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
97 //start a connect, expect a call on the routingInterface
98 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
99 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
101 //check the correctness of the handle
102 ASSERT_NE(handle.handle,0);
103 ASSERT_EQ(handle.handleType,H_CONNECT);
105 //the handle must be inside the handlelist
106 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
107 ASSERT_TRUE(listHandles[0].handle==handle.handle);
108 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
110 //send an abort expect a call on the routing interface
111 EXPECT_CALL(pMockInterface,asyncAbort(_)).WillOnce(Return(E_OK));
112 ASSERT_EQ(E_OK,pControlReceiver.abortAction(handle));
114 //the reaction on the abort is specific for every function
116 //now we try to abort a handle that does not exist
118 ASSERT_EQ(E_NON_EXISTENT,pControlReceiver.abortAction(handle));
121 TEST_F(routingInterfaceTest,abortNonExistent)
123 EXPECT_CALL(pMockInterface,asyncAbort(_)).Times(0);
125 ASSERT_EQ(E_NON_EXISTENT,pControlReceiver.abortAction(handle));
128 TEST_F(routingInterfaceTest,alreadyConnected)
133 am_domainID_t domainID;
134 pCF.createSink(sink);
135 pCF.createDomain(domain);
137 domain.busname="mock";
140 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
141 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
142 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
144 am_connectionID_t connectionID;
145 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
146 ASSERT_EQ(E_OK,pDatabaseHandler.changeConnectionFinal(connectionID));
147 ASSERT_EQ(E_ALREADY_EXISTS,pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
148 ASSERT_NE(handle.handle,0);
149 ASSERT_EQ(handle.handleType,H_CONNECT);
152 TEST_F(routingInterfaceTest,setSinkSoundPropertyNoChange)
157 am_domainID_t domainID;
159 am_SoundProperty_s soundProperty;
160 soundProperty.type=SP_TREBLE;
161 soundProperty.value=23;
162 std::vector<am_Handle_s>listHandles;
163 pCF.createSink(sink);
164 pCF.createDomain(domain);
166 domain.busname="mock";
169 sink.listSoundProperties.push_back(soundProperty);
170 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
171 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
172 EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,_,sinkID)).Times(0);
173 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty));
176 TEST_F(routingInterfaceTest,setSourceState)
179 am_sourceID_t sourceID;
181 am_domainID_t domainID;
184 am_SourceState_e state=SS_PAUSED;
185 pCF.createSource(source);
186 pCF.createDomain(domain);
188 domain.busname="mock";
190 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
191 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
192 EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).WillOnce(Return(E_OK));
193 ASSERT_EQ(E_OK,pControlReceiver.setSourceState(handle,sourceID,state));
194 ASSERT_NE(handle.handle,0);
195 ASSERT_EQ(handle.handleType,H_SETSOURCESTATE);
198 TEST_F(routingInterfaceTest,setSourceSoundProperty)
201 am_sourceID_t sourceID;
203 am_domainID_t domainID;
205 am_SoundProperty_s soundProperty;
206 std::vector<am_Handle_s>listHandles;
207 pCF.createSource(source);
208 pCF.createDomain(domain);
210 domain.busname="mock";
213 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
214 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
215 EXPECT_CALL(pMockInterface,asyncSetSourceSoundProperty(_,_,sourceID)).WillOnce(Return(E_OK));
216 ASSERT_EQ(E_OK,pControlReceiver.setSourceSoundProperty(handle,sourceID,soundProperty));
217 ASSERT_NE(handle.handle,0);
218 ASSERT_EQ(handle.handleType,H_SETSOURCESOUNDPROPERTY);
219 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
220 ASSERT_TRUE(listHandles[0].handle==handle.handle);
221 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
224 TEST_F(routingInterfaceTest,setSinkSoundProperty)
229 am_domainID_t domainID;
231 am_SoundProperty_s soundProperty;
232 std::vector<am_Handle_s>listHandles;
233 pCF.createSink(sink);
234 pCF.createDomain(domain);
236 domain.busname="mock";
239 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
240 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
241 EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,_,sinkID)).WillOnce(Return(E_OK));
242 ASSERT_EQ(E_OK,pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty));
243 ASSERT_NE(handle.handle,0);
244 ASSERT_EQ(handle.handleType,H_SETSINKSOUNDPROPERTY);
245 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
246 ASSERT_TRUE(listHandles[0].handle==handle.handle);
247 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
250 TEST_F(routingInterfaceTest,setSourceVolumeNoChange)
253 am_sourceID_t sourceID;
255 am_domainID_t domainID;
257 am_volume_t volume=34;
258 am_RampType_e rampType=RAMP_DIRECT;
259 am_time_t rampTime=300;
260 std::vector<am_Handle_s>listHandles;
261 pCF.createSource(source);
262 pCF.createDomain(domain);
264 domain.busname="mock";
267 source.volume=volume;
268 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
269 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
270 EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).Times(0);
271 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime));
272 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
273 ASSERT_TRUE(listHandles.empty());
276 TEST_F(routingInterfaceTest,setSourceVolume)
279 am_sourceID_t sourceID;
281 am_domainID_t domainID;
283 am_volume_t volume=34;
284 am_RampType_e rampType=RAMP_DIRECT;
285 am_time_t rampTime=300;
286 std::vector<am_Handle_s>listHandles;
287 pCF.createSource(source);
288 pCF.createDomain(domain);
290 domain.busname="mock";
293 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
294 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
295 EXPECT_CALL(pMockInterface,asyncSetSourceVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK));
296 ASSERT_EQ(E_OK,pControlReceiver.setSourceVolume(handle,2,volume,rampType,rampTime));
297 ASSERT_NE(handle.handle,0);
298 ASSERT_EQ(handle.handleType,H_SETSOURCEVOLUME);
299 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
300 ASSERT_TRUE(listHandles[0].handle==handle.handle);
301 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
304 TEST_F(routingInterfaceTest,setSinkVolumeNoChange)
309 am_domainID_t domainID;
311 am_volume_t volume=34;
312 am_RampType_e rampType=RAMP_DIRECT;
313 am_time_t rampTime=300;
314 std::vector<am_Handle_s>listHandles;
315 pCF.createSink(sink);
316 pCF.createDomain(domain);
318 domain.busname="mock";
322 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
323 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
324 EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).Times(0);
325 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime));
326 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
327 ASSERT_TRUE(listHandles.empty());
330 TEST_F(routingInterfaceTest,setSinkVolume)
335 am_domainID_t domainID;
337 am_volume_t volume=34;
338 am_RampType_e rampType=RAMP_DIRECT;
339 am_time_t rampTime=300;
340 std::vector<am_Handle_s>listHandles;
341 pCF.createSink(sink);
342 pCF.createDomain(domain);
344 domain.busname="mock";
347 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
348 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
349 EXPECT_CALL(pMockInterface,asyncSetSinkVolume(_,2,volume,rampType,rampTime)).WillOnce(Return(E_OK));
350 ASSERT_EQ(E_OK,pControlReceiver.setSinkVolume(handle,2,volume,rampType,rampTime));
351 ASSERT_NE(handle.handle,0);
352 ASSERT_EQ(handle.handleType,H_SETSINKVOLUME);
353 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
354 ASSERT_TRUE(listHandles[0].handle==handle.handle);
355 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
358 TEST_F(routingInterfaceTest,connect)
363 am_domainID_t domainID;
365 am_connectionID_t connectionID;
366 std::vector<am_Handle_s>listHandles;
367 pCF.createSink(sink);
368 pCF.createDomain(domain);
370 domain.busname="mock";
373 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
374 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
375 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
376 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
377 ASSERT_NE(handle.handle,0);
378 ASSERT_EQ(handle.handleType,H_CONNECT);
379 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
380 ASSERT_TRUE(listHandles[0].handle==handle.handle);
381 ASSERT_TRUE(listHandles[0].handleType==handle.handleType);
384 TEST_F(routingInterfaceTest,disconnect)
389 am_domainID_t domainID;
391 am_connectionID_t connectionID;
392 std::vector<am_Handle_s>listHandles;
393 pCF.createSink(sink);
394 pCF.createDomain(domain);
396 domain.busname="mock";
399 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
400 ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID));
401 EXPECT_CALL(pMockInterface,asyncConnect(_,_,1,sinkID,CF_ANALOG)).WillOnce(Return(E_OK));
402 ASSERT_EQ(E_OK,pControlReceiver.connect(handle,connectionID,CF_ANALOG,1,2));
403 ASSERT_EQ(E_OK,pDatabaseHandler.changeConnectionFinal(connectionID));
404 EXPECT_CALL(pMockInterface,asyncDisconnect(_,connectionID)).WillOnce(Return(E_OK));
405 ASSERT_EQ(E_OK,pControlReceiver.disconnect(handle,connectionID));
406 ASSERT_NE(handle.handle,0);
407 ASSERT_EQ(handle.handleType,H_DISCONNECT);
408 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
409 ASSERT_TRUE(listHandles[1].handle==handle.handle);
410 ASSERT_TRUE(listHandles[1].handleType==handle.handleType);
413 TEST_F(routingInterfaceTest,nothingTodisconnect)
416 am_connectionID_t connectionID=4;
417 std::vector<am_Handle_s>listHandles;
418 ASSERT_EQ(E_NON_EXISTENT,pControlReceiver.disconnect(handle,connectionID));
419 ASSERT_EQ(E_OK,pControlReceiver.getListHandles(listHandles));
420 ASSERT_TRUE(listHandles.empty());
424 TEST_F(routingInterfaceTest,setSourceStateNoChange)
427 am_sourceID_t sourceID;
429 am_domainID_t domainID;
432 am_SourceState_e state=SS_PAUSED;
433 pCF.createSource(source);
434 pCF.createDomain(domain);
436 domain.busname="mock";
438 source.sourceState=state;
439 ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID));
440 ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID));
441 EXPECT_CALL(pMockInterface,asyncSetSourceState(_,sourceID,state)).Times(0);
442 ASSERT_EQ(E_NO_CHANGE,pControlReceiver.setSourceState(handle,sourceID,state));
446 int main(int argc, char **argv)
448 ::testing::InitGoogleTest(&argc, argv);
449 return RUN_ALL_TESTS();