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 {
29 TEST_F(PointerUnionTest, Comparison) {
36 TEST_F(PointerUnionTest, Null) {
37 EXPECT_FALSE(a.isNull());
38 EXPECT_FALSE(b.isNull());
39 EXPECT_TRUE(n.isNull());
43 // workaround an issue with EXPECT macros and explicit bool
49 TEST_F(PointerUnionTest, Is) {
50 EXPECT_FALSE(a.is<int*>());
51 EXPECT_TRUE(a.is<float*>());
52 EXPECT_TRUE(b.is<int*>());
53 EXPECT_FALSE(b.is<float*>());
54 EXPECT_TRUE(n.is<int*>());
55 EXPECT_FALSE(n.is<float*>());
58 TEST_F(PointerUnionTest, Get) {
59 EXPECT_EQ(a.get<float*>(), &f);
60 EXPECT_EQ(b.get<int*>(), &i);
61 EXPECT_EQ(n.get<int*>(), (int*)0);
64 } // end anonymous namespace