add dyn_cast_or_null tests, exclude invalid dyn_cast test
authorGabor Greif <ggreif@gmail.com>
Thu, 22 Jul 2010 15:37:20 +0000 (15:37 +0000)
committerGabor Greif <ggreif@gmail.com>
Thu, 22 Jul 2010 15:37:20 +0000 (15:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109111 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/Support/Casting.cpp

index 678dec42f233a79385d0bd398e1d15008e134992..ae84693bd636dcea635b47a8aaa70179b84a3086 100644 (file)
@@ -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<foo,bar> {
+template <> struct isa_impl<foo, bar> {
   static inline bool doit(const bar &Val) {
     dbgs() << "Classof: " << &Val << "\n";
     return true;
@@ -50,10 +51,13 @@ foo *bar::caz() {
     return cast_or_null<foo>(this);
 }
 
-
-/*foo *bar::daz() {
+foo *bar::daz() {
     return dyn_cast<foo>(this);
-}*/
+}
+
+foo *bar::naz() {
+    return dyn_cast_or_null<foo>(this);
+}
 
 
 bar *fub();
@@ -115,10 +119,23 @@ TEST(CastingTest, dyn_cast) {
   EXPECT_NE(F2, null_foo);
   const foo *F3 = dyn_cast<foo>(B4);
   EXPECT_NE(F3, null_foo);
-  foo *F4 = dyn_cast<foo>(fub());
+  // foo *F4 = dyn_cast<foo>(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<foo>(B2);
+  EXPECT_NE(F1, null_foo);
+  const foo *F2 = dyn_cast_or_null<foo>(B2);
+  EXPECT_NE(F2, null_foo);
+  const foo *F3 = dyn_cast_or_null<foo>(B4);
+  EXPECT_NE(F3, null_foo);
+  foo *F4 = dyn_cast_or_null<foo>(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...