* removed all documentation to new place
[profile/ivi/genivi/genivi-audio-manager.git] / PluginControlInterface / test / CAmControlReceiverShadowTest.cpp
1 /**
2  *  Copyright (c) 2012 BMW
3  *
4  *  \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
5  *
6  *  \copyright
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.
14  *
15  *  For further information see http://www.genivi.org/.
16  */
17
18 #include "CAmControlReceiverShadowTest.h"
19
20 using namespace testing;
21 using namespace am;
22
23 CAmControlReceiverShadowTest::CAmControlReceiverShadowTest() :
24         psocketHandler(), //
25         pMockReceive(), //
26         pShadow(&pMockReceive, &psocketHandler), //
27         ptimerCallback(this, &CAmControlReceiverShadowTest::timerCallback)
28 {
29     DefaultValue<am_Error_e>::Set(E_OK); // Sets the default value to be returned.
30 }
31
32 CAmControlReceiverShadowTest::~CAmControlReceiverShadowTest()
33 {
34 }
35
36 void CAmControlReceiverShadowTest::SetUp()
37 {
38     timespec t;
39     t.tv_nsec = 10000;
40     t.tv_sec = 0;
41
42     sh_timerHandle_t handle;
43
44     IAmShTimerCallBack *buf = &ptimerCallback;
45     //lets use a timeout so the test will finish
46     psocketHandler.addTimer(t, buf, handle, (void*) NULL);
47 }
48
49 void CAmControlReceiverShadowTest::timerCallback(sh_timerHandle_t handle, void* userData)
50 {
51     (void)handle;
52     (void)userData;
53     psocketHandler.stop_listening();
54 }
55
56 void CAmControlReceiverShadowTest::TearDown()
57 {
58 }
59
60 void* run_the_loop(void* socketHandlerPtr)
61 {
62     CAmSocketHandler* socketHandler = static_cast<CAmSocketHandler*>(socketHandlerPtr);
63     socketHandler->start_listenting();
64     return (NULL);
65 }
66
67 TEST_F(CAmControlReceiverShadowTest,getRoute)
68 {
69     pthread_t ptestThread;
70     bool onlyfree(true);
71     am_sourceID_t sourceID(1);
72     am_sinkID_t sinkID(2);
73     am_Route_s route;
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);
82     route.sinkID = 1;
83     route.sourceID = 2;
84     route.route = route_;
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);
90 }
91
92 TEST_F(CAmControlReceiverShadowTest,connect)
93 {
94     pthread_t ptestThread;
95     am_Handle_s handle, handleReturn;
96     handle.handle = 1;
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);
102
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);
110 }
111
112 TEST_F(CAmControlReceiverShadowTest,disconnect)
113 {
114     pthread_t ptestThread;
115     am_Handle_s handle, handleReturn;
116     handle.handle = 1;
117     handle.handleType = H_CONNECT;
118     am_connectionID_t connectionID(3);
119
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);
126 }
127
128 //todo: implement more tests !
129
130 int main(int argc, char **argv)
131 {
132     ::testing::InitGoogleTest(&argc, argv);
133     return RUN_ALL_TESTS();
134 }
135