diff options
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
5 files changed, 65 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp new file mode 100644 index 00000000000..4fde4ec3e14 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.cpp @@ -0,0 +1,5 @@ +#include "ExtBase.h" + +char ExtBase::bar() { + return 'x'; +} diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h new file mode 100644 index 00000000000..28e139d3284 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/ExtBase.h @@ -0,0 +1,3 @@ +class ExtBase { + virtual char bar(); +}; diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile new file mode 100644 index 00000000000..e1afdbd9ac9 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../../make +CXX_SOURCES := main.cpp ExtBase.cpp +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py new file mode 100644 index 00000000000..4c9058c1538 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/TestDynamicCast.py @@ -0,0 +1,3 @@ +from lldbsuite.test import lldbinline + +lldbinline.MakeInlineTest(__file__, globals(), []) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp new file mode 100644 index 00000000000..dd2a07b9927 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/dynamic_cast/main.cpp @@ -0,0 +1,51 @@ +#include "ExtBase.h" + +class Base { +public: + virtual char foo() { + return 'b'; + } +}; + +class Derived : public Base { +public: + char foo() override { + return 'd'; + } +}; + +class NonOverrideDerived : public Base { +}; + +class ExtDerived : public ExtBase { +public: + char bar() override { + return 'y'; + } +}; + +int main() { + Derived d; + NonOverrideDerived d2; + Base *b = &d; + Base *real_base = new Base(); + char c = dynamic_cast<Derived *>(b)->foo(); + + ExtDerived ext_d; + ExtBase *ext_b = &ext_d; + ExtBase *ext_real_base = new ExtBase(); + c = dynamic_cast<ExtDerived *>(ext_b)->bar(); + + + return 0; //% self.expect("expression dynamic_cast<class Derived *>(b) == (Derived*)b", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class Base *>(b) == (Base*)b", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class Derived *>(real_base) == nullptr", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class NonOverrideDerived *>(&d) == nullptr", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class ExtDerived *>(real_base) == nullptr", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class Derived *>(&d2) == nullptr", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class NonOverrideDerived *>(&d2) == (NonOverrideDerived *)&d2", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class Derived *>(&ext_d) == nullptr", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class ExtDerived *>(ext_b) == (class ExtDerived*)ext_b", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class ExtBase *>(ext_real_base) == (class ExtBase*)ext_real_base", substrs = ["bool", " = true"]) + //% self.expect("expression dynamic_cast<class ExtDerived *>(ext_real_base) == nullptr", substrs = ["bool", " = true"]) +} |