summaryrefslogtreecommitdiff
path: root/pyuno/qa/pytests/testcollections_base.py
blob: 4dd3f26ea0590ba8be6a7771b01e29d5c1d2cf73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
#
# 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.beans import PropertyValue

testEnvironmentInitialized = False

class CollectionsTestBase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.context = pyuno.getComponentContext()
        global testEnvironmentInitialized
        if not testEnvironmentInitialized:
            pyuno.private_initTestEnvironment()
            testEnvironmentInitialized = True

    def setUp(self):
        self._components = []

    def tearDown(self):
        for component in self._components:
            try:
                component.close(True)
            except Exception:
                pass

    def createHiddenWindow(self, url):
        service_manager = self.context.ServiceManager
        desktop = service_manager.createInstanceWithContext('com.sun.star.frame.Desktop', self.context)
        load_props = (
          PropertyValue(Name='Hidden', Value=True),
          PropertyValue(Name='ReadOnly', Value=False)
        )
        component = desktop.loadComponentFromURL(url, '_blank', 0, load_props)
        return component

    def createBlankTextDocument(self):
        component = self.createHiddenWindow('private:factory/swriter')
        self._components.append(component)
        return component

    def createBlankSpreadsheet(self):
        component = self.createHiddenWindow('private:factory/scalc')
        self._components.append(component)
        return component

    def createBlankDrawing(self):
        component = self.createHiddenWindow('private:factory/sdraw')
        self._components.append(component)
        return component

# vim:set shiftwidth=4 softtabstop=4 expandtab: