brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 3da3b86 Raw
61 lines · cpp
1//===- llvm/unittest/DebugInfo/PDB/PDBVariantTest.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-exception6//7//===----------------------------------------------------------------------===//8 9#include "gtest/gtest.h"10 11#include "llvm/DebugInfo/PDB/PDBTypes.h"12 13using namespace llvm;14using namespace llvm::pdb;15 16namespace {17 18template <typename T> class PDBVariantIntegerTest : public testing::Test {19public:20  std::vector<T> getTestIntegers() {21    if constexpr (std::is_same_v<T, bool>) {22      return {true, false};23    } else {24      std::vector<T> Integers{0, 1, 32, std::numeric_limits<T>::min(),25                              std::numeric_limits<T>::max()};26      if constexpr (std::is_signed_v<T>) {27        Integers.emplace_back(-1);28        Integers.emplace_back(-65);29      }30      return Integers;31    }32  }33};34 35using TestTypes = testing::Types<bool, int8_t, uint8_t, int16_t, uint16_t,36                                 int32_t, uint32_t, int64_t, uint64_t>;37 38} // namespace39 40TYPED_TEST_SUITE(PDBVariantIntegerTest, TestTypes, );41 42TYPED_TEST(PDBVariantIntegerTest, ToAPSInt) {43  for (TypeParam IntegerValue : this->getTestIntegers()) {44    const Variant VariantValue(IntegerValue);45 46    const APSInt APSIntValue = VariantValue.toAPSInt();47    EXPECT_EQ(APSIntValue.isSigned(), std::is_signed_v<TypeParam>)48        << "Unexpected 'isSigned()' result for '" << IntegerValue << "'";49    bool IsNegative = false;50    if constexpr (!std::is_same_v<TypeParam, bool>) {51      IsNegative = IntegerValue < 0;52    }53    EXPECT_EQ(APSIntValue.isNegative(), IsNegative)54        << "Unexpected 'isNegative()' result for '" << IntegerValue << "'";55 56    SmallString<20> String;57    APSIntValue.toString(String);58    EXPECT_EQ(String.str().str(), std::to_string(IntegerValue));59  }60}61