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/.
14 from org
.libreoffice
.unotest
import UnoInProcess
15 from com
.sun
.star
.script
.provider
import ScriptFrameworkErrorException
17 class TestXScriptProvider(unittest
.TestCase
):
21 cls
._uno
= UnoInProcess()
25 def tearDownClass(cls
):
29 xMasterScriptProviderFactory
= create_master_script_provider_factory()
30 self
.xScriptProvider
= xMasterScriptProviderFactory
.createScriptProvider("")
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&"
54 self
.assertIsNotNone(xScript
, "xScript was not loaded")
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__':
80 # vim: set shiftwidth=4 softtabstop=4 expandtab: