From 39285a0f02c7bc5e4bad8a684a900123b097511d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 19 Nov 2019 09:55:17 +0100 Subject: Add streaming/equality operators to DWARFAddressRange/DWARFLocationExpression The main motivation for this is being able to write simpler assertions and get better error messages in unit tests. Split off from D70394. --- llvm/unittests/DebugInfo/DWARF/CMakeLists.txt | 1 + .../DWARF/DWARFLocationExpressionTest.cpp | 30 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 llvm/unittests/DebugInfo/DWARF/DWARFLocationExpressionTest.cpp (limited to 'llvm/unittests/DebugInfo/DWARF') diff --git a/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt b/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt index d97e573ea38..2181e0543d0 100644 --- a/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt +++ b/llvm/unittests/DebugInfo/DWARF/CMakeLists.txt @@ -14,6 +14,7 @@ add_llvm_unittest(DebugInfoDWARFTests DWARFDebugInfoTest.cpp DWARFDebugLineTest.cpp DWARFFormValueTest.cpp + DWARFLocationExpressionTest.cpp ) target_link_libraries(DebugInfoDWARFTests PRIVATE LLVMTestingSupport) diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFLocationExpressionTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFLocationExpressionTest.cpp new file mode 100644 index 00000000000..fb1dc3bd280 --- /dev/null +++ b/llvm/unittests/DebugInfo/DWARF/DWARFLocationExpressionTest.cpp @@ -0,0 +1,30 @@ +//===- llvm/unittest/DebugInfo/DWARFLocationExpressionTest.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 "llvm/DebugInfo/DWARF/DWARFLocationExpression.h" +#include "llvm/Support/ScopedPrinter.h" +#include "gtest/gtest.h" + +using namespace llvm; +using object::SectionedAddress; + +TEST(DWARFLocationExpression, Equality) { + EXPECT_EQ((DWARFLocationExpression{None, {}}), + (DWARFLocationExpression{None, {}})); + EXPECT_NE((DWARFLocationExpression{DWARFAddressRange{1, 47}, {}}), + (DWARFLocationExpression{DWARFAddressRange{1, 48}, {}})); + EXPECT_NE((DWARFLocationExpression{DWARFAddressRange{1, 47}, {}}), + (DWARFLocationExpression{DWARFAddressRange{1, 47}, {42}})); +} + +TEST(DWARFLocationExpression, StreamingOperator) { + EXPECT_EQ("None: 1, 2", to_string(DWARFLocationExpression{None, {1, 2}})); + EXPECT_EQ( + "[0x0000000000000042, 0x0000000000000047): 1", + to_string(DWARFLocationExpression{DWARFAddressRange{0x42, 0x47}, {1}})); +} -- cgit v1.2.3