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