1 //===- STLForwardCompatTest.cpp - Unit tests for STLForwardCompat ---------===// 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 "llvm/ADT/STLForwardCompat.h" 10 #include "gtest/gtest.h" 11 12 namespace { 13 14 TEST(STLForwardCompatTest, NegationTest) { 15 EXPECT_TRUE((llvm::negation<std::false_type>::value)); 16 EXPECT_FALSE((llvm::negation<std::true_type>::value)); 17 } 18 19 struct incomplete_type; 20 21 TEST(STLForwardCompatTest, ConjunctionTest) { 22 EXPECT_TRUE((llvm::conjunction<>::value)); 23 EXPECT_FALSE((llvm::conjunction<std::false_type>::value)); 24 EXPECT_TRUE((llvm::conjunction<std::true_type>::value)); 25 EXPECT_FALSE((llvm::conjunction<std::false_type, incomplete_type>::value)); 26 EXPECT_FALSE((llvm::conjunction<std::false_type, std::true_type>::value)); 27 EXPECT_FALSE((llvm::conjunction<std::true_type, std::false_type>::value)); 28 EXPECT_TRUE((llvm::conjunction<std::true_type, std::true_type>::value)); 29 EXPECT_TRUE((llvm::conjunction<std::true_type, std::true_type, 30 std::true_type>::value)); 31 } 32 33 TEST(STLForwardCompatTest, DisjunctionTest) { 34 EXPECT_FALSE((llvm::disjunction<>::value)); 35 EXPECT_FALSE((llvm::disjunction<std::false_type>::value)); 36 EXPECT_TRUE((llvm::disjunction<std::true_type>::value)); 37 EXPECT_TRUE((llvm::disjunction<std::true_type, incomplete_type>::value)); 38 EXPECT_TRUE((llvm::disjunction<std::false_type, std::true_type>::value)); 39 EXPECT_TRUE((llvm::disjunction<std::true_type, std::false_type>::value)); 40 EXPECT_TRUE((llvm::disjunction<std::true_type, std::true_type>::value)); 41 EXPECT_TRUE((llvm::disjunction<std::true_type, std::true_type, 42 std::true_type>::value)); 43 } 44 45 template <typename T> 46 class STLForwardCompatRemoveCVRefTest : public ::testing::Test {}; 47 48 using STLForwardCompatRemoveCVRefTestTypes = ::testing::Types< 49 // clang-format off 50 std::pair<int, int>, 51 std::pair<int &, int>, 52 std::pair<const int, int>, 53 std::pair<volatile int, int>, 54 std::pair<const volatile int &, int>, 55 std::pair<int *, int *>, 56 std::pair<int *const, int *>, 57 std::pair<const int *, const int *>, 58 std::pair<int *&, int *> 59 // clang-format on 60 >; 61 62 TYPED_TEST_SUITE(STLForwardCompatRemoveCVRefTest, 63 STLForwardCompatRemoveCVRefTestTypes, ); 64 65 TYPED_TEST(STLForwardCompatRemoveCVRefTest, RemoveCVRef) { 66 using From = typename TypeParam::first_type; 67 using To = typename TypeParam::second_type; 68 EXPECT_TRUE( 69 (std::is_same<typename llvm::remove_cvref<From>::type, To>::value)); 70 } 71 72 TYPED_TEST(STLForwardCompatRemoveCVRefTest, RemoveCVRefT) { 73 using From = typename TypeParam::first_type; 74 EXPECT_TRUE((std::is_same<typename llvm::remove_cvref<From>::type, 75 llvm::remove_cvref_t<From>>::value)); 76 } 77 78 } // namespace 79