brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · ba9aef1 Raw
121 lines · cpp
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-exception6//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 15using namespace llvm;16using namespace lldb_dap::protocol;17using lldb_private::PrettyPrint;18using llvm::json::parse;19 20TEST(ProtocolRequestsTest, ExceptionInfoArguments) {21  llvm::Expected<ExceptionInfoArguments> expected =22      parse<ExceptionInfoArguments>(R"({23        "threadId": 343424        })");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 36TEST(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(PrettyPrint(*expected), PrettyPrint(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(PrettyPrint(*expected_opt), PrettyPrint(body));69}70 71TEST(ProtocolRequestsTest, EvaluateArguments) {72  llvm::Expected<EvaluateArguments> expected = parse<EvaluateArguments>(R"({73    "expression": "hello world",74    "context": "repl"75  })");76  ASSERT_THAT_EXPECTED(expected, llvm::Succeeded());77  EXPECT_EQ(expected->expression, "hello world");78  EXPECT_EQ(expected->context, eEvaluateContextRepl);79 80  // Check required keys;81  EXPECT_THAT_EXPECTED(parse<EvaluateArguments>(R"({})"),82                       FailedWithMessage("missing value at (root).expression"));83}84 85TEST(ProtocolRequestsTest, EvaluateResponseBody) {86  EvaluateResponseBody body;87  body.result = "hello world";88  body.variablesReference = 7;89 90  // Check required keys.91  Expected<json::Value> expected = parse(R"({92    "result": "hello world",93    "variablesReference": 794  })");95 96  ASSERT_THAT_EXPECTED(expected, llvm::Succeeded());97  EXPECT_EQ(PrettyPrint(*expected), PrettyPrint(body));98 99  // Check optional keys.100  body.result = "'abc'";101  body.type = "string";102  body.variablesReference = 42;103  body.namedVariables = 1;104  body.indexedVariables = 2;105  body.memoryReference = "0x123";106  body.valueLocationReference = 22;107 108  Expected<json::Value> expected_opt = parse(R"({109    "result": "'abc'",110    "type": "string",111    "variablesReference": 42,112    "namedVariables": 1,113    "indexedVariables": 2,114    "memoryReference": "0x123",115    "valueLocationReference": 22116  })");117 118  ASSERT_THAT_EXPECTED(expected_opt, llvm::Succeeded());119  EXPECT_EQ(PrettyPrint(*expected_opt), PrettyPrint(body));120}121