]>
git.proxmox.com Git - rustc.git/blob - src/llvm/unittests/ADT/PointerUnionTest.cpp
1 //===- llvm/unittest/ADT/PointerUnionTest.cpp - Optional unit tests -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/PointerUnion.h"
16 typedef PointerUnion
<int *, float *> PU
;
18 struct PointerUnionTest
: public testing::Test
{
24 PointerUnionTest() : f(3.14f
), i(42), a(&f
), b(&i
), c(&i
), n() {}
27 TEST_F(PointerUnionTest
, Comparison
) {
38 TEST_F(PointerUnionTest
, Null
) {
39 EXPECT_FALSE(a
.isNull());
40 EXPECT_FALSE(b
.isNull());
41 EXPECT_TRUE(n
.isNull());
45 // workaround an issue with EXPECT macros and explicit bool
57 TEST_F(PointerUnionTest
, Is
) {
58 EXPECT_FALSE(a
.is
<int *>());
59 EXPECT_TRUE(a
.is
<float *>());
60 EXPECT_TRUE(b
.is
<int *>());
61 EXPECT_FALSE(b
.is
<float *>());
62 EXPECT_TRUE(n
.is
<int *>());
63 EXPECT_FALSE(n
.is
<float *>());
66 TEST_F(PointerUnionTest
, Get
) {
67 EXPECT_EQ(a
.get
<float *>(), &f
);
68 EXPECT_EQ(b
.get
<int *>(), &i
);
69 EXPECT_EQ(n
.get
<int *>(), (int *)nullptr);
72 } // end anonymous namespace