[cleanup] Make this test use a proper fixture rather than globals.
[oota-llvm.git] / unittests / ADT / PointerUnionTest.cpp
1 //===- llvm/unittest/ADT/PointerUnionTest.cpp - Optional unit tests -------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/PointerUnion.h"
12 using namespace llvm;
13
14 namespace {
15
16 typedef PointerUnion<int *, float *> PU;
17
18 struct PointerUnionTest : public testing::Test {
19   float f;
20   int i;
21
22   PU a, b, n;
23
24   PointerUnionTest() : f(3.14f), i(42), a(&f), b(&i), n() {}
25 };
26
27 TEST_F(PointerUnionTest, Comparison) {
28   EXPECT_TRUE(a != b);
29   EXPECT_FALSE(a == b);
30   EXPECT_TRUE(b != n);
31   EXPECT_FALSE(b == n);
32 }
33
34 TEST_F(PointerUnionTest, Null) {
35   EXPECT_FALSE(a.isNull());
36   EXPECT_FALSE(b.isNull());
37   EXPECT_TRUE(n.isNull());
38   EXPECT_FALSE(!a);
39   EXPECT_FALSE(!b);
40   EXPECT_TRUE(!n);
41   // workaround an issue with EXPECT macros and explicit bool
42   EXPECT_TRUE((bool)a);
43   EXPECT_TRUE((bool)b);
44   EXPECT_FALSE(n);
45 }
46
47 TEST_F(PointerUnionTest, Is) {
48   EXPECT_FALSE(a.is<int *>());
49   EXPECT_TRUE(a.is<float *>());
50   EXPECT_TRUE(b.is<int *>());
51   EXPECT_FALSE(b.is<float *>());
52   EXPECT_TRUE(n.is<int *>());
53   EXPECT_FALSE(n.is<float *>());
54 }
55
56 TEST_F(PointerUnionTest, Get) {
57   EXPECT_EQ(a.get<float *>(), &f);
58   EXPECT_EQ(b.get<int *>(), &i);
59   EXPECT_EQ(n.get<int *>(), (int *)0);
60 }
61
62 } // end anonymous namespace