diff --git a/scripting/Module_scripting.mk b/scripting/Module_scripting.mk index 285d694fbca3..044432db72a4 100644 --- a/scripting/Module_scripting.mk +++ b/scripting/Module_scripting.mk @@ -52,6 +52,10 @@ $(eval $(call gb_Module_add_check_targets,scripting,\ $(if $(ENABLE_SCRIPTING_BEANSHELL),CppunitTest_scripting_beanshell) \ )) +$(eval $(call gb_Module_add_subsequentcheck_targets,scripting,\ + PythonTest_scripting_provider \ +)) + endif # vim: set noet sw=4 ts=4: diff --git a/scripting/PythonTest_scripting_provider.mk b/scripting/PythonTest_scripting_provider.mk new file mode 100644 index 000000000000..e231c53a87b2 --- /dev/null +++ b/scripting/PythonTest_scripting_provider.mk @@ -0,0 +1,16 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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/. +# + +$(eval $(call gb_PythonTest_PythonTest,scripting_provider)) + +$(eval $(call gb_PythonTest_add_modules,scripting_provider,$(SRCDIR)/scripting/qa/pytests,\ + provider_expandall \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/scripting/qa/pytests/provider_expandall.py b/scripting/qa/pytests/provider_expandall.py new file mode 100644 index 000000000000..cc70f75ea583 --- /dev/null +++ b/scripting/qa/pytests/provider_expandall.py @@ -0,0 +1,81 @@ +# -*- 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 + +from org.libreoffice.unotest import pyuno +from com.sun.star.script.provider import theMasterScriptProviderFactory, ScriptURIHelper +from com.sun.star.ucb import UniversalContentBroker +from com.sun.star.uri import UriReferenceFactory +import uno + +import os +import tempfile + + +testEnvironmentInitialized = False + + +def get_user_script_directory(context, language): + uriHelper = ScriptURIHelper.create(context, language, "user") + uri = uriHelper.getRootStorageURI() + return uno.fileUrlToSystemPath(uri) + + +class ProviderExpandAllTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.context = pyuno.getComponentContext() + global testEnvironmentInitialized + if not testEnvironmentInitialized: + pyuno.private_initTestEnvironment() + testEnvironmentInitialized = True + + # The ExpandContentProvider is needed for ScriptURIHelper to work + xUcb = UniversalContentBroker.create(cls.context) + xExpandProvider = cls.context.getServiceManager().createInstance( + "com.sun.star.ucb.ExpandContentProvider") + xUcb.registerContentProvider(xExpandProvider, "vnd.sun.star.expand", True) + + # Tries retrieving all nodes from the master script provider to make sure all of the providers + # are accessible from Python. See tdf#172532 + def test_expand_all(self): + # Create a dummy JavaScript macro to make sure the JavaScript provider is triggered. + js_path = get_user_script_directory(self.context, "JavaScript") + os.makedirs(js_path, exist_ok=True) + with tempfile.TemporaryDirectory(dir=js_path) as js_dir: + with open(os.path.join(js_dir, "dummy_js_script.js"), 'w'): + pass + + xMasterProviderFactory = theMasterScriptProviderFactory.get(self.context) + + found_js_script = False + + for provider_context in ['user', 'share']: + xMasterProvider = xMasterProviderFactory.createScriptProvider(provider_context) + + stack = [xMasterProvider] + + while True: + try: + node = stack.pop() + except IndexError: + break + + if node.getName() == "dummy_js_script": + found_js_script = True + + # Add all of the children to the stack + if node.hasChildNodes(): + stack.extend(node.getChildNodes()) + + self.assertTrue(found_js_script) + + +# vim: set shiftwidth=4 softtabstop=4 expandtab: