diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-04-30 18:25:35 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-05-07 07:14:41 +0000 |
commit | 904b3d1fceee5827076758ed2a81f80cb73493ca (patch) | |
tree | 0fb9188cb3c7bb0076c98be1c4766cbf1254b508 /cppu | |
parent | 493c1e4628d2c2927ce0657497d51a1fcc37c2b3 (diff) |
Up-cast conversion constructor for css::uno::Reference
Based on a previous patch by Noel Grandin,
<https://gerrit.libreoffice.org/#/c/3613/>, 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 <gerrit@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/qa/test_reference.cxx | 43 |
1 files changed, 43 insertions, 0 deletions
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: */ |