
This abstracts the base Transport handler to have a MessageHandler component and allows us to generalize both JSON-RPC 2.0 for MCP (or an LSP) and DAP format. This should allow us to create clearly defined clients and servers for protocols, both for testing and for RPC between the lldb instances and an lldb-mcp multiplexer. This basic model is inspiried by the clangd/Transport.h file and the mlir/lsp-server-support/Transport.h that are both used for LSP servers within the llvm project. Additionally, this helps with testing by subclassing `Transport` to allow us to simplify sending/receiving messages without needing to use a toJSON/fromJSON and a pair of pipes, see `TestTransport` in DAP/TestBase.h.
41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
//===-- DAPTest.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 "DAP.h"
|
|
#include "Protocol/ProtocolBase.h"
|
|
#include "TestBase.h"
|
|
#include "llvm/Testing/Support/Error.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
#include <optional>
|
|
|
|
using namespace llvm;
|
|
using namespace lldb;
|
|
using namespace lldb_dap;
|
|
using namespace lldb_dap_tests;
|
|
using namespace lldb_dap::protocol;
|
|
using namespace testing;
|
|
|
|
class DAPTest : public TransportBase {};
|
|
|
|
TEST_F(DAPTest, SendProtocolMessages) {
|
|
DAP dap{
|
|
/*log=*/nullptr,
|
|
/*default_repl_mode=*/ReplMode::Auto,
|
|
/*pre_init_commands=*/{},
|
|
/*client_name=*/"test_client",
|
|
/*transport=*/*transport,
|
|
/*loop=*/loop,
|
|
};
|
|
dap.Send(Event{/*event=*/"my-event", /*body=*/std::nullopt});
|
|
loop.AddPendingCallback(
|
|
[](lldb_private::MainLoopBase &loop) { loop.RequestTermination(); });
|
|
EXPECT_CALL(client, Received(IsEvent("my-event", std::nullopt)));
|
|
ASSERT_THAT_ERROR(dap.Loop(), llvm::Succeeded());
|
|
}
|