Debian Codegraph @

lldb/unittests/DAP/TestBase.h

raw
1 //===-- TestBase.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 "DAP.h"
10 #include "Protocol/ProtocolBase.h"
11 #include "TestingSupport/Host/PipeTestUtilities.h"
12 #include "Transport.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
16
17 namespace lldb_dap_tests {
18
19 /// A base class for tests that need transport configured for communicating DAP
20 /// messages.
21 class TransportBase : public PipePairTest {
22 protected:
23 std::unique_ptr<lldb_dap::Transport> to_dap;
24 std::unique_ptr<lldb_dap::Transport> from_dap;
25
26 void SetUp() override;
27 };
28
29 /// Matches an "output" event.
30 inline auto OutputMatcher(const llvm::StringRef output,
31 const llvm::StringRef category = "console") {
32 return testing::VariantWith<lldb_dap::protocol::Event>(testing::FieldsAre(
33 /*event=*/"output", /*body=*/testing::Optional<llvm::json::Value>(
34 llvm::json::Object{{"category", category}, {"output", output}})));
35 }
36
37 /// A base class for tests that interact with a `lldb_dap::DAP` instance.
38 class DAPTestBase : public TransportBase {
39 protected:
40 std::unique_ptr<lldb_dap::DAP> dap;
41 std::optional<llvm::sys::fs::TempFile> core;
42 std::optional<llvm::sys::fs::TempFile> binary;
43
44 static constexpr llvm::StringLiteral k_linux_binary = "linux-x86_64.out.yaml";
45 static constexpr llvm::StringLiteral k_linux_core = "linux-x86_64.core.yaml";
46
47 static void SetUpTestSuite();
48 static void TeatUpTestSuite();
49 void SetUp() override;
50 void TearDown() override;
51
52 bool GetDebuggerSupportsTarget(llvm::StringRef platform);
53 void CreateDebugger();
54 void LoadCore();
55
56 /// Closes the DAP output pipe and returns the remaining protocol messages in
57 /// the buffer.
58 std::vector<lldb_dap::protocol::Message> DrainOutput();
59 };
60
61 } // namespace lldb_dap_tests