Skip to content

Commit 79fbef1

Browse files
committed
[lldb-dap] Add unit tests for LLDBUtils (NFC)
1 parent e62fc14 commit 79fbef1

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lldb/unittests/DAP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_lldb_unittest(DAPTests
22
JSONUtilsTest.cpp
3+
LLDBUtilsTest.cpp
34

45
LINK_LIBS
56
lldbDAP

lldb/unittests/DAP/LLDBUtilsTest.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)