aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/Casting.cpp
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2010-07-22 15:24:48 +0000
committerGabor Greif <ggreif@gmail.com>2010-07-22 15:24:48 +0000
commitb9e69778a4ad061bb126e210f271b3e569c2e6f3 (patch)
tree86652c379db8573ac548b11dcacbbfdfecd36f7a /llvm/unittests/Support/Casting.cpp
parent4e2e9f45174e3e0da6c8b74a91bc18d2768410d9 (diff)
downloadllvm-b9e69778a4ad061bb126e210f271b3e569c2e6f3.zip
llvm-b9e69778a4ad061bb126e210f271b3e569c2e6f3.tar.gz
llvm-b9e69778a4ad061bb126e210f271b3e569c2e6f3.tar.bz2
add dyn_cast tests and beef up others a bit
llvm-svn: 109109
Diffstat (limited to 'llvm/unittests/Support/Casting.cpp')
-rw-r--r--llvm/unittests/Support/Casting.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/llvm/unittests/Support/Casting.cpp b/llvm/unittests/Support/Casting.cpp
index 68019dd..962215c 100644
--- a/llvm/unittests/Support/Casting.cpp
+++ b/llvm/unittests/Support/Casting.cpp
@@ -21,7 +21,9 @@ namespace llvm {
//
struct bar {
bar() {}
- //struct foo *baz();
+ struct foo *baz();
+ struct foo *caz();
+ // struct foo *daz();
private:
bar(const bar &);
};
@@ -40,8 +42,17 @@ template <> struct isa_impl<foo,bar> {
}
};
-/*foo *bar::baz() {
+foo *bar::baz() {
return cast<foo>(this);
+}
+
+foo *bar::caz() {
+ return cast_or_null<foo>(this);
+}
+
+
+/*foo *bar::daz() {
+ return dyn_cast<foo>(this);
}*/
@@ -80,9 +91,8 @@ TEST(CastingTest, cast) {
EXPECT_NE(F6, null_foo);
foo *F7 = cast<foo>(fub());
EXPECT_EQ(F7, null_foo);
-
-/* foo *F8 = B1.baz();
- EXPECT_NE(F8, null_foo);*/
+ foo *F8 = B1.baz();
+ EXPECT_NE(F8, null_foo);
}
TEST(CastingTest, cast_or_null) {
@@ -94,6 +104,25 @@ TEST(CastingTest, cast_or_null) {
EXPECT_NE(F13, null_foo);
const foo *F14 = cast_or_null<foo>(fub()); // Shouldn't print.
EXPECT_EQ(F14, null_foo);
+ foo *F15 = B1.caz();
+ EXPECT_NE(F15, null_foo);
+}
+
+TEST(CastingTest, dyn_cast) {
+ // foo &F1 = dyn_cast<foo>(B1);
+ // EXPECT_NE(&F1, null_foo);
+ const foo *F3 = dyn_cast<foo>(B2);
+ EXPECT_NE(F3, null_foo);
+ const foo *F4 = dyn_cast<foo>(B2);
+ EXPECT_NE(F4, null_foo);
+ // const foo &F5 = dyn_cast<foo>(B3);
+ // EXPECT_NE(&F5, null_foo);
+ const foo *F6 = dyn_cast<foo>(B4);
+ EXPECT_NE(F6, null_foo);
+ foo *F7 = dyn_cast<foo>(fub());
+ EXPECT_EQ(F7, null_foo);
+ // foo *F8 = B1.daz();
+ // EXPECT_NE(F8, null_foo);
}
// These lines are errors...