tdf#173114 pyuno: Add unit test for objects with XInvocation
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 <nroberts@libreoffice.org>
This commit is contained in:
@@ -4402,6 +4402,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,org/libreoffice/embindtest, \
|
|||||||
XPassthrough \
|
XPassthrough \
|
||||||
XStringFactory \
|
XStringFactory \
|
||||||
XTest \
|
XTest \
|
||||||
|
theMethodToString \
|
||||||
thePassthrough \
|
thePassthrough \
|
||||||
theSingleton \
|
theSingleton \
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -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: */
|
||||||
@@ -14,6 +14,7 @@ $(eval $(call gb_PythonTest_add_modules,pyuno_pytests_embindtest,$(SRCDIR)/pyuno
|
|||||||
passthrough \
|
passthrough \
|
||||||
serviceconstructors \
|
serviceconstructors \
|
||||||
singleton \
|
singleton \
|
||||||
|
xinvocation \
|
||||||
))
|
))
|
||||||
|
|
||||||
# vim: set noet sw=4 ts=4:
|
# vim: set noet sw=4 ts=4:
|
||||||
|
|||||||
@@ -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:
|
||||||
@@ -11,6 +11,7 @@ $(eval $(call gb_Library_Library,embindtest))
|
|||||||
|
|
||||||
$(eval $(call gb_Library_add_exception_objects,embindtest, \
|
$(eval $(call gb_Library_add_exception_objects,embindtest, \
|
||||||
unotest/source/embindtest/embindtest \
|
unotest/source/embindtest/embindtest \
|
||||||
|
unotest/source/embindtest/methodtostring \
|
||||||
unotest/source/embindtest/passthrough \
|
unotest/source/embindtest/passthrough \
|
||||||
unotest/source/embindtest/serviceconstructors \
|
unotest/source/embindtest/serviceconstructors \
|
||||||
unotest/source/embindtest/singleton \
|
unotest/source/embindtest/singleton \
|
||||||
|
|||||||
@@ -40,4 +40,10 @@
|
|||||||
single-instance="true">
|
single-instance="true">
|
||||||
<singleton name="org.libreoffice.embindtest.thePassthrough"/>
|
<singleton name="org.libreoffice.embindtest.thePassthrough"/>
|
||||||
</implementation>
|
</implementation>
|
||||||
|
<implementation
|
||||||
|
constructor="org_libreoffice_comp_embindtest_MethodToString_get_implementation"
|
||||||
|
name="org.libreoffice.comp.embindtest.theMethodToString"
|
||||||
|
single-instance="true">
|
||||||
|
<singleton name="org.libreoffice.embindtest.theMethodToString"/>
|
||||||
|
</implementation>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -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 <sal/config.h>
|
||||||
|
|
||||||
|
#include <cppuhelper/implbase.hxx>
|
||||||
|
#include <cppuhelper/supportsservice.hxx>
|
||||||
|
|
||||||
|
#include <com/sun/star/script/XInvocation.hpp>
|
||||||
|
|
||||||
|
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<css::script::XInvocation>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
css::uno::Reference<css::beans::XIntrospectionAccess> SAL_CALL getIntrospection() override;
|
||||||
|
css::uno::Any SAL_CALL invoke(const OUString& aFunctionName,
|
||||||
|
const css::uno::Sequence<css::uno::Any>& aParams,
|
||||||
|
css::uno::Sequence<::sal_Int16>& aOutParamIndex,
|
||||||
|
css::uno::Sequence<css::uno::Any>& 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<css::beans::XIntrospectionAccess> SAL_CALL MethodToString::getIntrospection()
|
||||||
|
{
|
||||||
|
return css::uno::Reference<css::beans::XIntrospectionAccess>();
|
||||||
|
}
|
||||||
|
|
||||||
|
css::uno::Any SAL_CALL MethodToString::invoke(const OUString& aFunctionName,
|
||||||
|
const css::uno::Sequence<css::uno::Any>&,
|
||||||
|
css::uno::Sequence<::sal_Int16>&,
|
||||||
|
css::uno::Sequence<css::uno::Any>&)
|
||||||
|
{
|
||||||
|
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<css::uno::Any> const&)
|
||||||
|
{
|
||||||
|
return cppu::acquire(new MethodToString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||||
Reference in New Issue
Block a user