[llvm] r194320 - Test the polymorphic behavior of this utility.
Chandler Carruth
chandlerc at gmail.com
Fri Nov 8 20:58:14 PST 2013
Author: chandlerc
Date: Fri Nov 8 22:58:13 2013
New Revision: 194320
URL: http://llvm.org/viewvc/llvm-project?rev=194320&view=rev
Log:
Test the polymorphic behavior of this utility.
Modified:
llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp
Modified: llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp?rev=194320&r1=194319&r2=194320&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp (original)
+++ llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp Fri Nov 8 22:58:13 2013
@@ -22,7 +22,8 @@ struct S {
};
// A function that forces the return of a copy.
-polymorphic_ptr<S> dummy_copy(const polymorphic_ptr<S> &arg) { return arg; }
+template <typename T>
+T dummy_copy(const T &arg) { return arg; }
TEST(polymorphic_ptr_test, Basic) {
polymorphic_ptr<S> null;
@@ -83,4 +84,35 @@ TEST(polymorphic_ptr_test, Basic) {
EXPECT_EQ(42, p3->x);
}
+struct Base {
+ virtual ~Base() {}
+ virtual Base *clone() = 0;
+ virtual StringRef name() { return "Base"; }
+};
+
+struct DerivedA : Base {
+ virtual DerivedA *clone() { return new DerivedA(); }
+ virtual StringRef name() { return "DerivedA"; }
+};
+struct DerivedB : Base {
+ virtual DerivedB *clone() { return new DerivedB(); }
+ virtual StringRef name() { return "DerivedB"; }
+};
+
+TEST(polymorphic_ptr_test, Polymorphism) {
+ polymorphic_ptr<Base> a(new DerivedA());
+ polymorphic_ptr<Base> b(new DerivedB());
+
+ EXPECT_EQ("DerivedA", a->name());
+ EXPECT_EQ("DerivedB", b->name());
+
+ polymorphic_ptr<Base> copy = dummy_copy(a);
+ EXPECT_NE(a, copy);
+ EXPECT_EQ("DerivedA", copy->name());
+
+ copy = dummy_copy(b);
+ EXPECT_NE(b, copy);
+ EXPECT_EQ("DerivedB", copy->name());
+}
+
}
More information about the llvm-commits
mailing list