tdf#172532 scripting: Add Python unit test accessing all provider nodes
Adds a Python unit test that just tries to retrieve all child nodes from the master script provider in order to check that they are all accessible from Python. Change-Id: I97185b7f21f38a79fdda4078a69d8e88b10cbaed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207349 Tested-by: Jenkins Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
Reference in New Issue
Block a user