1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "transport.h"
18 
19 #include <gtest/gtest.h>
20 
21 #include "adb.h"
22 
TEST(transport,kick_transport)23 TEST(transport, kick_transport) {
24   atransport t = {};
25   // Mutate some member so we can test that the function is run.
26   t.kick = [](atransport* trans) { trans->fd = 42; };
27   atransport expected = t;
28   expected.fd = 42;
29   expected.kicked = 1;
30   kick_transport(&t);
31   ASSERT_EQ(42, t.fd);
32   ASSERT_EQ(1, t.kicked);
33   ASSERT_EQ(0, memcmp(&expected, &t, sizeof(atransport)));
34 }
35 
TEST(transport,kick_transport_already_kicked)36 TEST(transport, kick_transport_already_kicked) {
37   // Ensure that the transport is not modified if the transport has already been
38   // kicked.
39   atransport t = {};
40   t.kicked = 1;
41   t.kick = [](atransport*) { FAIL() << "Kick should not have been called"; };
42   atransport expected = t;
43   kick_transport(&t);
44   ASSERT_EQ(0, memcmp(&expected, &t, sizeof(atransport)));
45 }
46 
47 // Disabled because the function currently segfaults for a zeroed atransport. I
48 // want to make sure I understand how this is working at all before I try fixing
49 // that.
TEST(transport,DISABLED_run_transport_disconnects_zeroed_atransport)50 TEST(transport, DISABLED_run_transport_disconnects_zeroed_atransport) {
51   atransport t = {};
52   run_transport_disconnects(&t);
53 }
54