1//===-- PlatformRemoteGDBServerTest.cpp -----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
10#include "lldb/Utility/Connection.h"
11#include "gmock/gmock.h"
12
13using namespace lldb;
14using namespace lldb_private;
15using namespace lldb_private::platform_gdb_server;
16using namespace lldb_private::process_gdb_remote;
17using namespace testing;
18
19namespace {
20
21class PlatformRemoteGDBServerHack : public PlatformRemoteGDBServer {
22public:
23 void
24 SetGDBClient(std::unique_ptr<GDBRemoteCommunicationClient> gdb_client_up) {
25 m_gdb_client_up = std::move(gdb_client_up);
26 }
27};
28
29class MockConnection : public lldb_private::Connection {
30public:
31 MOCK_METHOD(lldb::ConnectionStatus, Connect,
32 (llvm::StringRef url, Status *error_ptr), (override));
33 MOCK_METHOD(lldb::ConnectionStatus, Disconnect, (Status * error_ptr),
34 (override));
35 MOCK_METHOD(bool, IsConnected, (), (const, override));
36 MOCK_METHOD(size_t, Read,
37 (void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
38 lldb::ConnectionStatus &status, Status *error_ptr),
39 (override));
40 MOCK_METHOD(size_t, Write,
41 (const void *dst, size_t dst_len, lldb::ConnectionStatus &status,
42 Status *error_ptr),
43 (override));
44 MOCK_METHOD(std::string, GetURI, (), (override));
45 MOCK_METHOD(bool, InterruptRead, (), (override));
46};
47
48} // namespace
49
50TEST(PlatformRemoteGDBServerTest, IsConnected) {
51 bool is_connected = true;
52
53 auto connection = std::make_unique<NiceMock<MockConnection>>();
54 ON_CALL(*connection, IsConnected())
55 .WillByDefault(action: ReturnPointee(pointer: &is_connected));
56
57 auto client = std::make_unique<GDBRemoteCommunicationClient>();
58 client->SetConnection(std::move(connection));
59
60 PlatformRemoteGDBServerHack server;
61 EXPECT_FALSE(server.IsConnected());
62
63 server.SetGDBClient(std::move(client));
64 EXPECT_TRUE(server.IsConnected());
65
66 is_connected = false;
67 EXPECT_FALSE(server.IsConnected());
68}
69

source code of lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp