From 904b3d1fceee5827076758ed2a81f80cb73493ca Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 30 Apr 2013 18:25:35 +0200 Subject: Up-cast conversion constructor for css::uno::Reference Based on a previous patch by Noel Grandin, , and borrowing from boost::is_base_and_derived (see comment in include/com/sun/star/uno/Reference.h) to avoid including Boost headers in URE headers. Change-Id: Iade5af144dd73ef03bd7d96000134c7a66a5e591 Reviewed-on: https://gerrit.libreoffice.org/3699 Tested-by: LibreOffice gerrit bot Reviewed-by: Stephan Bergmann Tested-by: Stephan Bergmann --- cppu/qa/test_reference.cxx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'cppu/qa/test_reference.cxx') diff --git a/cppu/qa/test_reference.cxx b/cppu/qa/test_reference.cxx index b998238f6b39..a6e393692043 100644 --- a/cppu/qa/test_reference.cxx +++ b/cppu/qa/test_reference.cxx @@ -149,4 +149,47 @@ CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); +// Check that the up-casting Reference conversion constructor catches the +// intended cases: + +namespace { + +struct Base1: public css::uno::XInterface { virtual ~Base1() {} }; +struct Base2: public Base1 { virtual ~Base2() {} }; +struct Base3: public Base1 { virtual ~Base3() {} }; +struct Derived: public Base2, public Base3 { virtual ~Derived() {} }; + +} + +// The special case using the conversion operator instead: +css::uno::Reference< css::uno::XInterface > testUpcast1( + css::uno::Reference< Derived > const & ref) +{ return ref; } + +// The normal up-cast case: +css::uno::Reference< Base1 > testUpcast2( + css::uno::Reference< Base2 > const & ref) +{ return ref; } + +// Commenting this in should cause a compiler error due to an ambiguous up-cast: +/* +css::uno::Reference< Base1 > testFailingUpcast3( + css::uno::Reference< Derived > const & ref) +{ return ref; } +*/ + +// Commenting this in should cause a compiler error due to a down-cast: +/* +css::uno::Reference< Base2 > testFailingUpcast4( + css::uno::Reference< Base1 > const & ref) +{ return ref; } +*/ + +// Commenting this in should cause a compiler error due to a down-cast: +/* +css::uno::Reference< Base1 > testFailingUpcast5( + css::uno::Reference< css::uno::XInterface > const & ref) +{ return ref; } +*/ + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3