| 
 | 1 | +//===-- ProtocolTypesTest.cpp -----------------------------------*- C++ -*-===//  | 
 | 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/ProtocolTypes.h"  | 
 | 10 | +#include "llvm/Testing/Support/Error.h"  | 
 | 11 | +#include "gtest/gtest.h"  | 
 | 12 | + | 
 | 13 | +using namespace lldb;  | 
 | 14 | +using namespace lldb_dap;  | 
 | 15 | +using namespace lldb_dap::protocol;  | 
 | 16 | + | 
 | 17 | +template <typename T> static llvm::Expected<T> roundtrip(const T &input) {  | 
 | 18 | +  llvm::json::Value value = toJSON(input);  | 
 | 19 | +  llvm::json::Path::Root root;  | 
 | 20 | +  T output;  | 
 | 21 | +  if (!fromJSON(value, output, root))  | 
 | 22 | +    return root.getError();  | 
 | 23 | +  return output;  | 
 | 24 | +}  | 
 | 25 | + | 
 | 26 | +TEST(ProtocolTypesTest, ExceptionBreakpointsFilter) {  | 
 | 27 | +  ExceptionBreakpointsFilter filter;  | 
 | 28 | +  filter.filter = "testFilter";  | 
 | 29 | +  filter.label = "Test Filter";  | 
 | 30 | +  filter.description = "This is a test filter";  | 
 | 31 | +  filter.defaultState = true;  | 
 | 32 | +  filter.supportsCondition = true;  | 
 | 33 | +  filter.conditionDescription = "Condition for test filter";  | 
 | 34 | + | 
 | 35 | +  llvm::Expected<ExceptionBreakpointsFilter> deserialized_filter =  | 
 | 36 | +      roundtrip(filter);  | 
 | 37 | +  ASSERT_THAT_EXPECTED(deserialized_filter, llvm::Succeeded());  | 
 | 38 | + | 
 | 39 | +  EXPECT_EQ(filter.filter, deserialized_filter->filter);  | 
 | 40 | +  EXPECT_EQ(filter.label, deserialized_filter->label);  | 
 | 41 | +  EXPECT_EQ(filter.description, deserialized_filter->description);  | 
 | 42 | +  EXPECT_EQ(filter.defaultState, deserialized_filter->defaultState);  | 
 | 43 | +  EXPECT_EQ(filter.supportsCondition, deserialized_filter->supportsCondition);  | 
 | 44 | +  EXPECT_EQ(filter.conditionDescription,  | 
 | 45 | +            deserialized_filter->conditionDescription);  | 
 | 46 | +}  | 
 | 47 | + | 
 | 48 | +TEST(ProtocolTypesTest, Source) {  | 
 | 49 | +  Source source;  | 
 | 50 | +  source.name = "testName";  | 
 | 51 | +  source.path = "/path/to/source";  | 
 | 52 | +  source.sourceReference = 12345;  | 
 | 53 | +  source.presentationHint = ePresentationHintEmphasize;  | 
 | 54 | + | 
 | 55 | +  llvm::Expected<Source> deserialized_source = roundtrip(source);  | 
 | 56 | +  ASSERT_THAT_EXPECTED(deserialized_source, llvm::Succeeded());  | 
 | 57 | + | 
 | 58 | +  EXPECT_EQ(source.name, deserialized_source->name);  | 
 | 59 | +  EXPECT_EQ(source.path, deserialized_source->path);  | 
 | 60 | +  EXPECT_EQ(source.sourceReference, deserialized_source->sourceReference);  | 
 | 61 | +  EXPECT_EQ(source.presentationHint, deserialized_source->presentationHint);  | 
 | 62 | +}  | 
0 commit comments