Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / xscriptprovider.py
blobb63812a590d3ec5ba05c7b037a26563478f1a677
1 #! /usr/bin/env python
2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 import unittest
12 import uno
14 from org.libreoffice.unotest import UnoInProcess
15 from com.sun.star.script.provider import ScriptFrameworkErrorException
17 class TestXScriptProvider(unittest.TestCase):
19 @classmethod
20 def setUpClass(cls):
21 cls._uno = UnoInProcess()
22 cls._uno.setUp()
24 @classmethod
25 def tearDownClass(cls):
26 cls._uno.tearDown()
28 def setUp(self):
29 xMasterScriptProviderFactory = create_master_script_provider_factory()
30 self.xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
32 def tearDown(self):
33 del self.xScriptProvider
35 def test_get_script_application(self):
36 #getScript for built-in StarBasic function
37 xScript = self.xScriptProvider.getScript(
38 "vnd.sun.star.script:Tools.Misc.CreateNewDocument?language=Basic&"
39 "location=application")
41 self.assertIsNotNone(xScript, "xScript was not loaded")
43 def test_get_script_document(self):
44 #getScript for StarBasic function in loaded document
45 x_doc = self.__class__._uno.openTemplateFromTDOC("xscriptprovider.odt")
47 xMasterScriptProviderFactory = create_master_script_provider_factory()
48 xScriptProvider = xMasterScriptProviderFactory.createScriptProvider(x_doc)
50 xScript = xScriptProvider.getScript(
51 "vnd.sun.star.script:Standard.Module1.Main?language=Basic&"
52 "location=document")
54 self.assertIsNotNone(xScript, "xScript was not loaded")
56 x_doc.close(True)
58 def test_get_script_invalid_uri(self):
59 # getScript fails with invalid URI
60 with self.assertRaises(ScriptFrameworkErrorException):
61 self.xScriptProvider.getScript("invalid URI, isn't it?")
63 def test_get_script_not_found(self):
64 # getScript fails when script not found
65 with self.assertRaises(ScriptFrameworkErrorException):
66 self.xScriptProvider.getScript(
67 "vnd.sun.star.script:NotExisting.NotExisting.NotExisting?"
68 "language=Basic&location=document")
70 def create_master_script_provider_factory():
71 xServiceManager = uno.getComponentContext().ServiceManager
73 return xServiceManager.createInstanceWithContext(
74 "com.sun.star.script.provider.MasterScriptProviderFactory",
75 uno.getComponentContext())
77 if __name__ == '__main__':
78 unittest.main()
80 # vim: set shiftwidth=4 softtabstop=4 expandtab: