|
| 1 | +//===-- ProtocolRequestsTest.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 "Protocol/ProtocolRequests.h" |
| 10 | +#include "Protocol/ProtocolTypes.h" |
| 11 | +#include "TestingSupport/TestUtilities.h" |
| 12 | +#include "llvm/Testing/Support/Error.h" |
| 13 | +#include <gtest/gtest.h> |
| 14 | + |
| 15 | +using namespace llvm; |
| 16 | +using namespace lldb_dap::protocol; |
| 17 | +using lldb_private::pprint; |
| 18 | +using llvm::json::parse; |
| 19 | + |
| 20 | +TEST(ProtocolRequestsTest, ExceptionInfoArguments) { |
| 21 | + llvm::Expected<ExceptionInfoArguments> expected = |
| 22 | + parse<ExceptionInfoArguments>(R"({ |
| 23 | + "threadId": 3434 |
| 24 | + })"); |
| 25 | + ASSERT_THAT_EXPECTED(expected, llvm::Succeeded()); |
| 26 | + EXPECT_EQ(expected->threadId, 3434U); |
| 27 | + |
| 28 | + // Check required keys; |
| 29 | + EXPECT_THAT_EXPECTED(parse<ExceptionInfoArguments>(R"({})"), |
| 30 | + FailedWithMessage("missing value at (root).threadId")); |
| 31 | + |
| 32 | + EXPECT_THAT_EXPECTED(parse<ExceptionInfoArguments>(R"({"id": 10})"), |
| 33 | + FailedWithMessage("missing value at (root).threadId")); |
| 34 | +} |
| 35 | + |
| 36 | +TEST(ProtocolRequestsTest, ExceptionInfoResponseBody) { |
| 37 | + ExceptionInfoResponseBody body; |
| 38 | + body.exceptionId = "signal"; |
| 39 | + body.breakMode = eExceptionBreakModeAlways; |
| 40 | + |
| 41 | + // Check required keys. |
| 42 | + Expected<json::Value> expected = parse( |
| 43 | + R"({ |
| 44 | + "exceptionId": "signal", |
| 45 | + "breakMode": "always" |
| 46 | + })"); |
| 47 | + |
| 48 | + ASSERT_THAT_EXPECTED(expected, llvm::Succeeded()); |
| 49 | + EXPECT_EQ(pprint(*expected), pprint(body)); |
| 50 | + |
| 51 | + // Check optional keys. |
| 52 | + body.description = "SIGNAL SIGWINCH"; |
| 53 | + body.breakMode = eExceptionBreakModeNever; |
| 54 | + body.details = ExceptionDetails{}; |
| 55 | + body.details->message = "some message"; |
| 56 | + |
| 57 | + Expected<json::Value> expected_opt = parse( |
| 58 | + R"({ |
| 59 | + "exceptionId": "signal", |
| 60 | + "description": "SIGNAL SIGWINCH", |
| 61 | + "breakMode": "never", |
| 62 | + "details": { |
| 63 | + "message": "some message" |
| 64 | + } |
| 65 | + })"); |
| 66 | + |
| 67 | + ASSERT_THAT_EXPECTED(expected_opt, llvm::Succeeded()); |
| 68 | + EXPECT_EQ(pprint(*expected_opt), pprint(body)); |
| 69 | +} |
0 commit comments