From aed5ae5d215e0b139eff5a2c49797e4dda297461 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 11 Aug 2026 17:40:37 +0200 Subject: [PATCH] tdf#173114 pyuno: Add unit test for objects with XInvocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a service to embindtest that implements XInvocation to handle all possible method names and returns the name as a string. A Python unit test then uses this. Without the fix pyuno would throw an exception when it tries to use the XInvocation object that doesn’t also implement XInvocation2 and return a valid reference for getIntrospection. Change-Id: Icb3359c788acd5eda37980252e5fc5c956b38100 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209087 Tested-by: Jenkins Reviewed-by: Neil Roberts --- offapi/UnoApi_offapi.mk | 1 + .../embindtest/theMethodToString.idl | 16 ++++ pyuno/PythonTest_pyuno_pytests_embindtest.mk | 1 + pyuno/qa/pytests/xinvocation.py | 27 +++++++ unotest/Library_embindtest.mk | 1 + .../source/embindtest/embindtest.component | 6 ++ unotest/source/embindtest/methodtostring.cxx | 75 +++++++++++++++++++ 7 files changed, 127 insertions(+) create mode 100644 offapi/org/libreoffice/embindtest/theMethodToString.idl create mode 100644 pyuno/qa/pytests/xinvocation.py create mode 100644 unotest/source/embindtest/methodtostring.cxx diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index b2a15ec14ff7..26df1a5426c8 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -4402,6 +4402,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,org/libreoffice/embindtest, \ XPassthrough \ XStringFactory \ XTest \ + theMethodToString \ thePassthrough \ theSingleton \ )) diff --git a/offapi/org/libreoffice/embindtest/theMethodToString.idl b/offapi/org/libreoffice/embindtest/theMethodToString.idl new file mode 100644 index 000000000000..834eeb1d65d4 --- /dev/null +++ b/offapi/org/libreoffice/embindtest/theMethodToString.idl @@ -0,0 +1,16 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +module org { module libreoffice { module embindtest { + +singleton theMethodToString: com::sun::star::script::XInvocation; + +}; }; }; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/pyuno/PythonTest_pyuno_pytests_embindtest.mk b/pyuno/PythonTest_pyuno_pytests_embindtest.mk index ca1411b2503e..66a9b76af450 100644 --- a/pyuno/PythonTest_pyuno_pytests_embindtest.mk +++ b/pyuno/PythonTest_pyuno_pytests_embindtest.mk @@ -14,6 +14,7 @@ $(eval $(call gb_PythonTest_add_modules,pyuno_pytests_embindtest,$(SRCDIR)/pyuno passthrough \ serviceconstructors \ singleton \ + xinvocation \ )) # vim: set noet sw=4 ts=4: diff --git a/pyuno/qa/pytests/xinvocation.py b/pyuno/qa/pytests/xinvocation.py new file mode 100644 index 000000000000..61ae20c8cfde --- /dev/null +++ b/pyuno/qa/pytests/xinvocation.py @@ -0,0 +1,27 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +import unittest +import org.libreoffice.unotest +from org.libreoffice.embindtest import theMethodToString + + +class XInvocationTest(unittest.TestCase): + # Tests that pyuno can handle an object that implements XInvocation. See tdf#173114 + def test_xinvocation(self): + ctx = org.libreoffice.unotest.pyuno.getComponentContext() + + xMethodToString = theMethodToString.get(ctx) + + # The MethodToString service implements all methods via XInvocation and just returns the + # name of the method as a string. + self.assertEqual(xMethodToString.myMadeUpMethod(), "myMadeUpMethod") + + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/unotest/Library_embindtest.mk b/unotest/Library_embindtest.mk index 2afb9600d9dc..d64a42400dbc 100644 --- a/unotest/Library_embindtest.mk +++ b/unotest/Library_embindtest.mk @@ -11,6 +11,7 @@ $(eval $(call gb_Library_Library,embindtest)) $(eval $(call gb_Library_add_exception_objects,embindtest, \ unotest/source/embindtest/embindtest \ + unotest/source/embindtest/methodtostring \ unotest/source/embindtest/passthrough \ unotest/source/embindtest/serviceconstructors \ unotest/source/embindtest/singleton \ diff --git a/unotest/source/embindtest/embindtest.component b/unotest/source/embindtest/embindtest.component index 875a315c2f09..c2d822915f4f 100644 --- a/unotest/source/embindtest/embindtest.component +++ b/unotest/source/embindtest/embindtest.component @@ -40,4 +40,10 @@ single-instance="true"> + + + diff --git a/unotest/source/embindtest/methodtostring.cxx b/unotest/source/embindtest/methodtostring.cxx new file mode 100644 index 000000000000..961a4bd65559 --- /dev/null +++ b/unotest/source/embindtest/methodtostring.cxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include + +#include + +namespace com::sun::star::uno +{ +class XComponentContext; +} + +namespace +{ +// A service that accepts any method calls and returns the name of the method as a string. This is +// intended to test that language bindings can handle objects that implement XInvocation. This +// should intentionally not implement XInvocation2 so that we can be sure that the language bindings +// handle that common case. +class MethodToString : public cppu::WeakImplHelper +{ +public: + css::uno::Reference SAL_CALL getIntrospection() override; + css::uno::Any SAL_CALL invoke(const OUString& aFunctionName, + const css::uno::Sequence& aParams, + css::uno::Sequence<::sal_Int16>& aOutParamIndex, + css::uno::Sequence& aOutParam) override; + void SAL_CALL setValue(const OUString& aPropertyName, const css::uno::Any& aValue) override; + css::uno::Any SAL_CALL getValue(const OUString& aPropertyName) override; + sal_Bool SAL_CALL hasMethod(const OUString& aName) override; + sal_Bool SAL_CALL hasProperty(const OUString& aName) override; +}; + +css::uno::Reference SAL_CALL MethodToString::getIntrospection() +{ + return css::uno::Reference(); +} + +css::uno::Any SAL_CALL MethodToString::invoke(const OUString& aFunctionName, + const css::uno::Sequence&, + css::uno::Sequence<::sal_Int16>&, + css::uno::Sequence&) +{ + return css::uno::Any(aFunctionName); +} + +void SAL_CALL MethodToString::setValue(const OUString&, const css::uno::Any&) {} + +css::uno::Any SAL_CALL MethodToString::getValue(const OUString&) { return css::uno::Any(); } + +sal_Bool SAL_CALL MethodToString::hasMethod(const OUString&) +{ + // All methods are available + return true; +} + +sal_Bool SAL_CALL MethodToString::hasProperty(const OUString&) { return false; } +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +org_libreoffice_comp_embindtest_MethodToString_get_implementation( + css::uno::XComponentContext*, css::uno::Sequence const&) +{ + return cppu::acquire(new MethodToString); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */