xref: /llvm-project/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp (revision 0642cd768b80665585c8500bed2933a3b99123dc)
1 //===-- GDBRemoteCommunicationServerTest.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 #include "gmock/gmock.h"
9 #include "gtest/gtest.h"
10 
11 #include "GDBRemoteTestUtils.h"
12 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
13 #include "lldb/Utility/Connection.h"
14 #include "lldb/Utility/UnimplementedError.h"
15 
16 namespace lldb_private {
17 namespace process_gdb_remote {
18 
19 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorNumber) {
20   MockServerWithMockConnection server;
21   server.SendErrorResponse(0x42);
22 
23   EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$E42#ab"));
24 }
25 
26 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_Status) {
27   MockServerWithMockConnection server;
28   Status status(0x42, lldb::eErrorTypeGeneric, "Test error message");
29   server.SendErrorResponse(status);
30 
31   EXPECT_THAT(
32       server.GetPackets(),
33       testing::ElementsAre("$E42;54657374206572726f72206d657373616765#ad"));
34 }
35 
36 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_UnimplementedError) {
37   MockServerWithMockConnection server;
38 
39   auto error = llvm::make_error<UnimplementedError>();
40   server.SendErrorResponse(std::move(error));
41 
42   EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$#00"));
43 }
44 
45 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_StringError) {
46   MockServerWithMockConnection server;
47 
48   auto error = llvm::createStringError(llvm::inconvertibleErrorCode(),
49                                        "String error test");
50   server.SendErrorResponse(std::move(error));
51 
52   EXPECT_THAT(
53       server.GetPackets(),
54       testing::ElementsAre("$Eff;537472696e67206572726f722074657374#b0"));
55 }
56 
57 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorList) {
58   MockServerWithMockConnection server;
59 
60   auto error = llvm::joinErrors(llvm::make_error<UnimplementedError>(),
61                                 llvm::make_error<UnimplementedError>());
62 
63   server.SendErrorResponse(std::move(error));
64   // Make sure only one packet is sent even when there are multiple errors.
65   EXPECT_EQ(server.GetPackets().size(), 1UL);
66 }
67 
68 } // namespace process_gdb_remote
69 } // namespace lldb_private
70