2 * Copyright (c) 2012 BMW
4 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
12 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
13 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 * For further information see http://www.genivi.org/.
18 #include "CAmControlReceiverShadowTest.h"
20 using namespace testing;
23 CAmControlReceiverShadowTest::CAmControlReceiverShadowTest() :
26 pShadow(&pMockReceive, &psocketHandler), //
27 ptimerCallback(this, &CAmControlReceiverShadowTest::timerCallback)
29 DefaultValue<am_Error_e>::Set(E_OK); // Sets the default value to be returned.
32 CAmControlReceiverShadowTest::~CAmControlReceiverShadowTest()
36 void CAmControlReceiverShadowTest::SetUp()
42 sh_timerHandle_t handle;
44 IAmShTimerCallBack *buf = &ptimerCallback;
45 //lets use a timeout so the test will finish
46 psocketHandler.addTimer(t, buf, handle, (void*) NULL);
49 void CAmControlReceiverShadowTest::timerCallback(sh_timerHandle_t handle, void* userData)
53 psocketHandler.stop_listening();
56 void CAmControlReceiverShadowTest::TearDown()
60 void* run_the_loop(void* socketHandlerPtr)
62 CAmSocketHandler* socketHandler = static_cast<CAmSocketHandler*>(socketHandlerPtr);
63 socketHandler->start_listenting();
67 TEST_F(CAmControlReceiverShadowTest,getRoute)
69 pthread_t ptestThread;
71 am_sourceID_t sourceID(1);
72 am_sinkID_t sinkID(2);
74 am_RoutingElement_s routingElement;
75 std::vector<am_RoutingElement_s> route_;
76 std::vector<am_Route_s> returnList, List;
77 routingElement.sinkID = 1;
78 routingElement.sourceID = 2;
79 routingElement.domainID = 3;
80 routingElement.connectionFormat = CF_GENIVI_ANALOG;
81 route_.push_back(routingElement);
85 returnList.push_back(route);
86 EXPECT_CALL(pMockReceive,getRoute(onlyfree,sourceID,sinkID,_)).WillOnce(DoAll(SetArgReferee<3>(returnList),Return(E_OK)));
87 pthread_create(&ptestThread, NULL, run_the_loop, (void*) &psocketHandler);
88 ASSERT_EQ(E_OK, pShadow.getRoute(onlyfree, sourceID, sinkID, List));
89 pthread_join(ptestThread, NULL);
92 TEST_F(CAmControlReceiverShadowTest,connect)
94 pthread_t ptestThread;
95 am_Handle_s handle, handleReturn;
97 handle.handleType = H_CONNECT;
98 am_connectionID_t connectionID(3), connectionIDReturn;
99 am_ConnectionFormat_e connectionFormat(CF_GENIVI_ANALOG);
100 am_sourceID_t sourceID(1);
101 am_sinkID_t sinkID(2);
103 EXPECT_CALL(pMockReceive, connect(_,_, connectionFormat, sourceID, sinkID)).WillOnce(DoAll(SetArgReferee<0>(handle),SetArgReferee<1>(connectionID),Return(E_OK)));
104 pthread_create(&ptestThread, NULL, run_the_loop, (void*) &psocketHandler);
105 ASSERT_EQ(E_OK,pShadow.connect(handleReturn,connectionIDReturn, connectionFormat, sourceID, sinkID));
106 ASSERT_EQ(handleReturn.handle,handle.handle);
107 ASSERT_EQ(handleReturn.handleType,handle.handleType);
108 ASSERT_EQ(connectionIDReturn,connectionID);
109 pthread_join(ptestThread, NULL);
112 TEST_F(CAmControlReceiverShadowTest,disconnect)
114 pthread_t ptestThread;
115 am_Handle_s handle, handleReturn;
117 handle.handleType = H_CONNECT;
118 am_connectionID_t connectionID(3);
120 EXPECT_CALL(pMockReceive, disconnect(_,connectionID)).WillOnce(DoAll(SetArgReferee<0>(handle),Return(E_OK)));
121 pthread_create(&ptestThread, NULL, run_the_loop, (void*) &psocketHandler);
122 ASSERT_EQ(E_OK,pShadow.disconnect(handleReturn,connectionID));
123 ASSERT_EQ(handleReturn.handle,handle.handle);
124 ASSERT_EQ(handleReturn.handleType,handle.handleType);
125 pthread_join(ptestThread, NULL);
128 //todo: implement more tests !
130 int main(int argc, char **argv)
132 ::testing::InitGoogleTest(&argc, argv);
133 return RUN_ALL_TESTS();