|
| 1 | +//===-- LLDBUtilsTest.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 "LLDBUtils.h" |
| 10 | +#include "lldb/API/SBStructuredData.h" |
| 11 | +#include "gtest/gtest.h" |
| 12 | + |
| 13 | +using namespace llvm; |
| 14 | +using namespace lldb; |
| 15 | +using namespace lldb_dap; |
| 16 | + |
| 17 | +TEST(LLDBUtilsTest, GetStringValue) { |
| 18 | + // Create an SBStructuredData object from JSON. |
| 19 | + const char *json_data = R"("test_string")"; |
| 20 | + SBStructuredData data; |
| 21 | + SBError error = data.SetFromJSON(json_data); |
| 22 | + |
| 23 | + // Ensure the JSON was parsed successfully. |
| 24 | + ASSERT_TRUE(error.Success()); |
| 25 | + ASSERT_TRUE(data.IsValid()); |
| 26 | + |
| 27 | + // Call GetStringValue and verify the result. |
| 28 | + std::string result = GetStringValue(data); |
| 29 | + EXPECT_EQ(result, "test_string"); |
| 30 | + |
| 31 | + // Test with invalid SBStructuredData. |
| 32 | + SBStructuredData invalid_data; |
| 33 | + result = GetStringValue(invalid_data); |
| 34 | + EXPECT_EQ(result, ""); |
| 35 | + |
| 36 | + // Test with empty JSON. |
| 37 | + const char *empty_json = R"("")"; |
| 38 | + SBStructuredData empty_data; |
| 39 | + error = empty_data.SetFromJSON(empty_json); |
| 40 | + |
| 41 | + ASSERT_TRUE(error.Success()); |
| 42 | + ASSERT_TRUE(empty_data.IsValid()); |
| 43 | + |
| 44 | + result = GetStringValue(empty_data); |
| 45 | + EXPECT_EQ(result, ""); |
| 46 | +} |
0 commit comments