From f06eb3719aef56a31fb5c56e5b086995aefafef5 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 22 Jul 2010 15:37:20 +0000 Subject: add dyn_cast_or_null tests, exclude invalid dyn_cast test git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109111 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Support/Casting.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'unittests') diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp index 678dec42f2..ae84693bd6 100644 --- a/unittests/Support/Casting.cpp +++ b/unittests/Support/Casting.cpp @@ -23,7 +23,8 @@ struct bar { bar() {} struct foo *baz(); struct foo *caz(); - // struct foo *daz(); + struct foo *daz(); + struct foo *naz(); private: bar(const bar &); }; @@ -35,7 +36,7 @@ struct foo { }*/ }; -template <> struct isa_impl { +template <> struct isa_impl { static inline bool doit(const bar &Val) { dbgs() << "Classof: " << &Val << "\n"; return true; @@ -50,10 +51,13 @@ foo *bar::caz() { return cast_or_null(this); } - -/*foo *bar::daz() { +foo *bar::daz() { return dyn_cast(this); -}*/ +} + +foo *bar::naz() { + return dyn_cast_or_null(this); +} bar *fub(); @@ -115,10 +119,23 @@ TEST(CastingTest, dyn_cast) { EXPECT_NE(F2, null_foo); const foo *F3 = dyn_cast(B4); EXPECT_NE(F3, null_foo); - foo *F4 = dyn_cast(fub()); + // foo *F4 = dyn_cast(fub()); // not permittible + // EXPECT_EQ(F4, null_foo); + foo *F5 = B1.daz(); + EXPECT_NE(F5, null_foo); +} + +TEST(CastingTest, dyn_cast_or_null) { + const foo *F1 = dyn_cast_or_null(B2); + EXPECT_NE(F1, null_foo); + const foo *F2 = dyn_cast_or_null(B2); + EXPECT_NE(F2, null_foo); + const foo *F3 = dyn_cast_or_null(B4); + EXPECT_NE(F3, null_foo); + foo *F4 = dyn_cast_or_null(fub()); EXPECT_EQ(F4, null_foo); - // foo *F5 = B1.daz(); - // EXPECT_NE(F5, null_foo); + foo *F5 = B1.naz(); + EXPECT_NE(F5, null_foo); } // These lines are errors... -- cgit v1.2.3