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;
19 class PointerUnionTest : public testing::Test {};
28 TEST_F(PointerUnionTest, Comparison) {
35 TEST_F(PointerUnionTest, Null) {
36 EXPECT_FALSE(a.isNull());
37 EXPECT_FALSE(b.isNull());
38 EXPECT_TRUE(n.isNull());
42 // workaround an issue with EXPECT macros and explicit bool
48 TEST_F(PointerUnionTest, Is) {
49 EXPECT_FALSE(a.is<int *>());
50 EXPECT_TRUE(a.is<float *>());
51 EXPECT_TRUE(b.is<int *>());
52 EXPECT_FALSE(b.is<float *>());
53 EXPECT_TRUE(n.is<int *>());
54 EXPECT_FALSE(n.is<float *>());
57 TEST_F(PointerUnionTest, Get) {
58 EXPECT_EQ(a.get<float *>(), &f);
59 EXPECT_EQ(b.get<int *>(), &i);
60 EXPECT_EQ(n.get<int *>(), (int *)0);
63 } // end anonymous namespace