[llvm-commits] [llvm] r109109 - /llvm/trunk/unittests/Support/Casting.cpp
Gabor Greif
ggreif at gmail.com
Thu Jul 22 08:24:48 PDT 2010
Author: ggreif
Date: Thu Jul 22 10:24:48 2010
New Revision: 109109
URL: http://llvm.org/viewvc/llvm-project?rev=109109&view=rev
Log:
add dyn_cast tests and beef up others a bit
Modified:
llvm/trunk/unittests/Support/Casting.cpp
Modified: llvm/trunk/unittests/Support/Casting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Casting.cpp?rev=109109&r1=109108&r2=109109&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Casting.cpp (original)
+++ llvm/trunk/unittests/Support/Casting.cpp Thu Jul 22 10:24:48 2010
@@ -21,7 +21,9 @@
//
struct bar {
bar() {}
- //struct foo *baz();
+ struct foo *baz();
+ struct foo *caz();
+ // struct foo *daz();
private:
bar(const bar &);
};
@@ -40,8 +42,17 @@
}
};
-/*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 @@
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 @@
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...
More information about the llvm-commits
mailing list