summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2010-07-22 15:37:20 +0000
committerGabor Greif <ggreif@gmail.com>2010-07-22 15:37:20 +0000
commitf06eb3719aef56a31fb5c56e5b086995aefafef5 (patch)
tree5cc5e6c654392c6427319ebd47fa83006dc316ad /unittests
parent46a35015f5268bf72150eb1b1517337e245e38e5 (diff)
downloadllvm-f06eb3719aef56a31fb5c56e5b086995aefafef5.tar.gz
llvm-f06eb3719aef56a31fb5c56e5b086995aefafef5.tar.bz2
llvm-f06eb3719aef56a31fb5c56e5b086995aefafef5.tar.xz
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
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/Casting.cpp33
1 files changed, 25 insertions, 8 deletions
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<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...