Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

119 lines
3.8 KiB
C++

//===-- JSONUtilsTest.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 "JSONUtils.h"
#include "lldb/lldb-defines.h"
#include "llvm/Support/JSON.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
#include <optional>
using namespace llvm;
using namespace lldb;
using namespace lldb_dap;
TEST(JSONUtilsTest, GetInteger_Ref) {
json::Object obj;
obj.try_emplace("key", 123);
auto result = GetInteger<int>(obj, "key");
ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value(), 123);
result = GetInteger<int>(obj, "nonexistent_key");
EXPECT_FALSE(result.has_value());
obj.try_emplace("key_float", 123.45);
result = GetInteger<int>(obj, "key_float");
EXPECT_FALSE(result.has_value());
obj.try_emplace("key_string", "123");
result = GetInteger<int>(obj, "key_string");
EXPECT_FALSE(result.has_value());
}
TEST(JSONUtilsTest, GetInteger_DifferentTypes) {
json::Object obj;
obj.try_emplace("key", 789);
auto result = GetInteger<int64_t>(obj, "key");
ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value(), 789);
result = GetInteger<uint32_t>(obj, "key");
ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value(), 789U);
result = GetInteger<int16_t>(obj, "key");
ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value(), static_cast<int16_t>(789));
}
TEST(JSONUtilsTest, DecodeMemoryReference) {
EXPECT_EQ(DecodeMemoryReference(""), std::nullopt);
EXPECT_EQ(DecodeMemoryReference("123"), std::nullopt);
EXPECT_EQ(DecodeMemoryReference("0o123"), std::nullopt);
EXPECT_EQ(DecodeMemoryReference("0b1010101"), std::nullopt);
EXPECT_EQ(DecodeMemoryReference("0x123"), 291u);
{
addr_t addr = LLDB_INVALID_ADDRESS;
json::Path::Root root;
EXPECT_TRUE(DecodeMemoryReference(json::Object{{"mem_ref", "0x123"}},
"mem_ref", addr, root,
/*required=*/true));
EXPECT_EQ(addr, 291u);
}
{
addr_t addr = LLDB_INVALID_ADDRESS;
json::Path::Root root;
EXPECT_TRUE(DecodeMemoryReference(json::Object{}, "mem_ref", addr, root,
/*required=*/false));
}
{
addr_t addr = LLDB_INVALID_ADDRESS;
json::Path::Root root;
EXPECT_FALSE(DecodeMemoryReference(json::Value{"string"}, "mem_ref", addr,
root,
/*required=*/true));
EXPECT_THAT_ERROR(root.getError(), FailedWithMessage("expected object"));
}
{
addr_t addr = LLDB_INVALID_ADDRESS;
json::Path::Root root;
EXPECT_FALSE(DecodeMemoryReference(json::Object{}, "mem_ref", addr, root,
/*required=*/true));
EXPECT_THAT_ERROR(root.getError(),
FailedWithMessage("missing value at (root).mem_ref"));
}
{
addr_t addr = LLDB_INVALID_ADDRESS;
json::Path::Root root;
EXPECT_FALSE(DecodeMemoryReference(json::Object{{"mem_ref", 123}},
"mem_ref", addr, root,
/*required=*/true));
EXPECT_THAT_ERROR(root.getError(),
FailedWithMessage("expected string at (root).mem_ref"));
}
{
addr_t addr = LLDB_INVALID_ADDRESS;
json::Path::Root root;
EXPECT_FALSE(DecodeMemoryReference(json::Object{{"mem_ref", "123"}},
"mem_ref", addr, root,
/*required=*/true));
EXPECT_THAT_ERROR(
root.getError(),
FailedWithMessage("malformed memory reference at (root).mem_ref"));
}
}