diff options
author | Gabor Greif <ggreif@gmail.com> | 2010-07-20 16:51:18 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2010-07-20 16:51:18 +0000 |
commit | 08993c03abed359171d12b50ab38da0ac331cfb7 (patch) | |
tree | f6f8d821bf43065d187af450fd1f611f62bd8d43 /unittests/Support | |
parent | 133e295b363c89b6a3da7aba3ac5ae6332429e46 (diff) | |
download | external_llvm-08993c03abed359171d12b50ab38da0ac331cfb7.zip external_llvm-08993c03abed359171d12b50ab38da0ac331cfb7.tar.gz external_llvm-08993c03abed359171d12b50ab38da0ac331cfb7.tar.bz2 |
extend to cast<> and cast_or_null<> tests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108854 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support')
-rw-r--r-- | unittests/Support/Casting.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp index 3a3af7e..22badb4 100644 --- a/unittests/Support/Casting.cpp +++ b/unittests/Support/Casting.cpp @@ -19,19 +19,47 @@ using namespace llvm; namespace { +const foo *null_foo = NULL; + extern bar &B1; extern const bar *B2; +// test various configurations of const +const bar &B3 = B1; +const bar *const B4 = B2; TEST(CastingTest, isa) { - // test various configurations of const - const bar &B3 = B1; - const bar *const B4 = B2; EXPECT_TRUE(isa<foo>(B1)); EXPECT_TRUE(isa<foo>(B2)); EXPECT_TRUE(isa<foo>(B3)); EXPECT_TRUE(isa<foo>(B4)); } +TEST(CastingTest, cast) { + foo &F1 = cast<foo>(B1); + EXPECT_NE(&F1, null_foo); + const foo *F3 = cast<foo>(B2); + EXPECT_NE(F3, null_foo); + const foo *F4 = cast<foo>(B2); + EXPECT_NE(F4, null_foo); + const foo &F8 = cast<foo>(B3); + EXPECT_NE(&F8, null_foo); + const foo *F9 = cast<foo>(B4); + EXPECT_NE(F9, null_foo); + foo *F10 = cast<foo>(fub()); + EXPECT_EQ(F10, null_foo); +} + +TEST(CastingTest, cast_or_null) { + const foo *F11 = cast_or_null<foo>(B2); + EXPECT_NE(F11, null_foo); + const foo *F12 = cast_or_null<foo>(B2); + EXPECT_NE(F12, null_foo); + const foo *F13 = cast_or_null<foo>(B4); + EXPECT_NE(F13, null_foo); + const foo *F14 = cast_or_null<foo>(fub()); // Shouldn't print. + EXPECT_EQ(F14, null_foo); +} + bar B; bar &B1 = B; const bar *B2 = &B; |