aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp
blob: 2ea4dac006cd831e15090c12faa910692a4a0ddf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//===-- PlatformRemoteGDBServerTest.cpp -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
#include "lldb/Utility/Connection.h"
#include "gmock/gmock.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::platform_gdb_server;
using namespace lldb_private::process_gdb_remote;
using namespace testing;

namespace {

class PlatformRemoteGDBServerHack : public PlatformRemoteGDBServer {
public:
  void
  SetGDBClient(std::unique_ptr<GDBRemoteCommunicationClient> gdb_client_up) {
    m_gdb_client_up = std::move(gdb_client_up);
  }
};

class MockConnection : public lldb_private::Connection {
public:
  MOCK_METHOD(lldb::ConnectionStatus, Connect,
              (llvm::StringRef url, Status *error_ptr), (override));
  MOCK_METHOD(lldb::ConnectionStatus, Disconnect, (Status * error_ptr),
              (override));
  MOCK_METHOD(bool, IsConnected, (), (const, override));
  MOCK_METHOD(size_t, Read,
              (void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
               lldb::ConnectionStatus &status, Status *error_ptr),
              (override));
  MOCK_METHOD(size_t, Write,
              (const void *dst, size_t dst_len, lldb::ConnectionStatus &status,
               Status *error_ptr),
              (override));
  MOCK_METHOD(std::string, GetURI, (), (override));
  MOCK_METHOD(bool, InterruptRead, (), (override));
};

} // namespace

TEST(PlatformRemoteGDBServerTest, IsConnected) {
  bool is_connected = true;

  auto connection = std::make_unique<NiceMock<MockConnection>>();
  ON_CALL(*connection, IsConnected())
      .WillByDefault(ReturnPointee(&is_connected));

  auto client = std::make_unique<GDBRemoteCommunicationClient>();
  client->SetConnection(std::move(connection));

  PlatformRemoteGDBServerHack server;
  EXPECT_FALSE(server.IsConnected());

  server.SetGDBClient(std::move(client));
  EXPECT_TRUE(server.IsConnected());

  is_connected = false;
  EXPECT_FALSE(server.IsConnected());
}