|
9 | 9 | #include "JSONUtils.h"
|
10 | 10 | #include "lldb/API/SBModule.h"
|
11 | 11 | #include "lldb/API/SBTarget.h"
|
| 12 | +#include "llvm/Support/JSON.h" |
12 | 13 | #include "gtest/gtest.h"
|
| 14 | +#include <optional> |
13 | 15 |
|
14 | 16 | using namespace llvm;
|
15 | 17 | using namespace lldb;
|
@@ -84,6 +86,59 @@ TEST(JSONUtilsTest, GetBoolean_Pointer) {
|
84 | 86 | EXPECT_FALSE(result.has_value());
|
85 | 87 | }
|
86 | 88 |
|
| 89 | +TEST(JSONUtilsTest, GetInteger_Ref) { |
| 90 | + json::Object obj; |
| 91 | + obj.try_emplace("key", 123); |
| 92 | + |
| 93 | + auto result = GetInteger<int>(obj, "key"); |
| 94 | + ASSERT_TRUE(result.has_value()); |
| 95 | + EXPECT_EQ(result.value(), 123); |
| 96 | + |
| 97 | + result = GetInteger<int>(obj, "nonexistent_key"); |
| 98 | + EXPECT_FALSE(result.has_value()); |
| 99 | + |
| 100 | + obj.try_emplace("key_float", 123.45); |
| 101 | + result = GetInteger<int>(obj, "key_float"); |
| 102 | + EXPECT_FALSE(result.has_value()); |
| 103 | + |
| 104 | + obj.try_emplace("key_string", "123"); |
| 105 | + result = GetInteger<int>(obj, "key_string"); |
| 106 | + EXPECT_FALSE(result.has_value()); |
| 107 | +} |
| 108 | + |
| 109 | +TEST(JSONUtilsTest, GetInteger_Pointer) { |
| 110 | + json::Object obj; |
| 111 | + obj.try_emplace("key", 456); |
| 112 | + |
| 113 | + auto result = GetInteger<int>(&obj, "key"); |
| 114 | + ASSERT_TRUE(result.has_value()); |
| 115 | + EXPECT_EQ(result.value(), 456); |
| 116 | + |
| 117 | + result = GetInteger<int>(nullptr, "key"); |
| 118 | + EXPECT_FALSE(result.has_value()); |
| 119 | + |
| 120 | + obj.try_emplace("key_invalid", "not_an_integer"); |
| 121 | + result = GetInteger<int>(&obj, "key_invalid"); |
| 122 | + EXPECT_FALSE(result.has_value()); |
| 123 | +} |
| 124 | + |
| 125 | +TEST(JSONUtilsTest, GetInteger_DifferentTypes) { |
| 126 | + json::Object obj; |
| 127 | + obj.try_emplace("key", 789); |
| 128 | + |
| 129 | + auto result = GetInteger<int64_t>(obj, "key"); |
| 130 | + ASSERT_TRUE(result.has_value()); |
| 131 | + EXPECT_EQ(result.value(), 789); |
| 132 | + |
| 133 | + result = GetInteger<uint32_t>(obj, "key"); |
| 134 | + ASSERT_TRUE(result.has_value()); |
| 135 | + EXPECT_EQ(result.value(), 789U); |
| 136 | + |
| 137 | + result = GetInteger<int16_t>(obj, "key"); |
| 138 | + ASSERT_TRUE(result.has_value()); |
| 139 | + EXPECT_EQ(result.value(), static_cast<int16_t>(789)); |
| 140 | +} |
| 141 | + |
87 | 142 | TEST(JSONUtilsTest, CreateModule) {
|
88 | 143 | SBTarget target;
|
89 | 144 | SBModule module;
|
|
0 commit comments