1 //===---------- llvm/unittest/Support/Casting.cpp - Casting 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 "llvm/Support/raw_ostream.h"
11 #include "llvm/Support/Debug.h"
12 #define DEBUG_CAST_OPERATORS
13 #include "llvm/Support/Casting.h"
15 #include "gtest/gtest.h"
22 const foo *null_foo = NULL;
26 // test various configurations of const
28 const bar *const B4 = B2;
30 TEST(CastingTest, isa) {
31 EXPECT_TRUE(isa<foo>(B1));
32 EXPECT_TRUE(isa<foo>(B2));
33 EXPECT_TRUE(isa<foo>(B3));
34 EXPECT_TRUE(isa<foo>(B4));
37 TEST(CastingTest, cast) {
38 foo &F1 = cast<foo>(B1);
39 EXPECT_NE(&F1, null_foo);
40 const foo *F3 = cast<foo>(B2);
41 EXPECT_NE(F3, null_foo);
42 const foo *F4 = cast<foo>(B2);
43 EXPECT_NE(F4, null_foo);
44 const foo &F8 = cast<foo>(B3);
45 EXPECT_NE(&F8, null_foo);
46 const foo *F9 = cast<foo>(B4);
47 EXPECT_NE(F9, null_foo);
48 foo *F10 = cast<foo>(fub());
49 EXPECT_EQ(F10, null_foo);
52 TEST(CastingTest, cast_or_null) {
53 const foo *F11 = cast_or_null<foo>(B2);
54 EXPECT_NE(F11, null_foo);
55 const foo *F12 = cast_or_null<foo>(B2);
56 EXPECT_NE(F12, null_foo);
57 const foo *F13 = cast_or_null<foo>(B4);
58 EXPECT_NE(F13, null_foo);
59 const foo *F14 = cast_or_null<foo>(fub()); // Shouldn't print.
60 EXPECT_EQ(F14, null_foo);
66 } // anonymous namespace