Author: Jonas Devlieghere Date: 2025-05-11T16:42:42-07:00 New Revision: 79fbef17128340923be177f8c4e841fc2cc8a9e9
URL: https://github.com/llvm/llvm-project/commit/79fbef17128340923be177f8c4e841fc2cc8a9e9 DIFF: https://github.com/llvm/llvm-project/commit/79fbef17128340923be177f8c4e841fc2cc8a9e9.diff LOG: [lldb-dap] Add unit tests for LLDBUtils (NFC) Added: lldb/unittests/DAP/LLDBUtilsTest.cpp Modified: lldb/unittests/DAP/CMakeLists.txt Removed: ################################################################################ diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt index f61c4006072a3..4bbb552be9f34 100644 --- a/lldb/unittests/DAP/CMakeLists.txt +++ b/lldb/unittests/DAP/CMakeLists.txt @@ -1,5 +1,6 @@ add_lldb_unittest(DAPTests JSONUtilsTest.cpp + LLDBUtilsTest.cpp LINK_LIBS lldbDAP diff --git a/lldb/unittests/DAP/LLDBUtilsTest.cpp b/lldb/unittests/DAP/LLDBUtilsTest.cpp new file mode 100644 index 0000000000000..37c21bdef8abc --- /dev/null +++ b/lldb/unittests/DAP/LLDBUtilsTest.cpp @@ -0,0 +1,46 @@ +//===-- LLDBUtilsTest.cpp -------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "LLDBUtils.h" +#include "lldb/API/SBStructuredData.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace lldb; +using namespace lldb_dap; + +TEST(LLDBUtilsTest, GetStringValue) { + // Create an SBStructuredData object from JSON. + const char *json_data = R"("test_string")"; + SBStructuredData data; + SBError error = data.SetFromJSON(json_data); + + // Ensure the JSON was parsed successfully. + ASSERT_TRUE(error.Success()); + ASSERT_TRUE(data.IsValid()); + + // Call GetStringValue and verify the result. + std::string result = GetStringValue(data); + EXPECT_EQ(result, "test_string"); + + // Test with invalid SBStructuredData. + SBStructuredData invalid_data; + result = GetStringValue(invalid_data); + EXPECT_EQ(result, ""); + + // Test with empty JSON. + const char *empty_json = R"("")"; + SBStructuredData empty_data; + error = empty_data.SetFromJSON(empty_json); + + ASSERT_TRUE(error.Success()); + ASSERT_TRUE(empty_data.IsValid()); + + result = GetStringValue(empty_data); + EXPECT_EQ(result, ""); +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits