Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / xtextfieldssupplier.py
blob76004a095f261b0e3274ab1f4a3628688451611a
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/.
10 import unittest
11 from org.libreoffice.unotest import UnoInProcess
12 from com.sun.star.container import NoSuchElementException
15 class TestXTextFieldsSupplier(unittest.TestCase):
17 @classmethod
18 def setUpClass(cls):
19 cls._uno = UnoInProcess()
20 cls._uno.setUp()
22 @classmethod
23 def tearDownClass(cls):
24 cls._uno.tearDown()
26 def test_getTextFields(self):
27 xDoc = self.__class__._uno.openDocFromTDOC("xtextfieldssupplier.odt")
28 self.assertIsNotNone(xDoc, "document was not loaded")
29 xTextFieldsSupplier = xDoc
31 # Get text fields collection
32 xTextFields = xTextFieldsSupplier.getTextFields()
33 self.assertIsNotNone(xTextFields, "getTextFields fails")
35 # Iterate through collection and ensure that we receive expected fields
36 fieldTypesList = [
37 "com.sun.star.text.textfield.PageNumber",
38 "com.sun.star.text.textfield.Annotation",
39 "com.sun.star.text.textfield.docinfo.CreateDateTime"
41 xFieldEnum = xTextFields.createEnumeration()
42 for fieldType, xField in zip(fieldTypesList, xFieldEnum):
43 self.assertTrue(xField.supportsService(fieldType),
44 "field " + xField.getPresentation(True) +
45 " does not support " + fieldType + " service!")
47 xDoc.close(True)
49 def test_getTextFieldMasters(self):
50 xDoc = self.__class__._uno.openDocFromTDOC("xtextfieldssupplier.odt")
51 self.assertIsNotNone(xDoc, "document was not loaded")
52 xTextFieldsSupplier = xDoc
54 # Get text fields master
55 xFieldMasters = xTextFieldsSupplier.getTextFieldMasters()
56 self.assertIsNotNone(xFieldMasters, "getTextFieldMasters fails")
57 self.assertTrue(xFieldMasters.hasElements(), "TextFieldMaster has no elements")
59 # Check elements in TextFieldsMaster collection
60 masterNames = [
61 "com.sun.star.text.fieldmaster.SetExpression.Illustration",
62 "com.sun.star.text.fieldmaster.SetExpression.Table",
63 "com.sun.star.text.fieldmaster.SetExpression.Text",
64 "com.sun.star.text.fieldmaster.SetExpression.Drawing",
65 "com.sun.star.text.fieldmaster.SetExpression.Figure",
67 for masterName in masterNames:
68 self.assertTrue(xFieldMasters.hasByName(masterName),
69 "TextFieldMaster has no element " + masterName)
70 master = xFieldMasters.getByName(masterName)
71 self.assertIsNotNone(master,
72 "can't get " + masterName + " from TextFieldMaster")
73 self.assertIsNotNone(master.getPropertyValue("Name"),
74 "can't get Name property from TextFieldMaster " + masterName)
76 # Ensure that invalid elements are not accessible
77 invalidMasterName = "com.sun.star.text.fieldmaster.SetExpression.NoSuchMaster"
78 self.assertFalse(xFieldMasters.hasByName(invalidMasterName),
79 "TextFieldMaster has element " + invalidMasterName)
81 with self.assertRaises(NoSuchElementException):
82 xFieldMasters.getByName(invalidMasterName)
84 xDoc.close(True)
87 if __name__ == '__main__':
88 unittest.main()
90 # vim: set shiftwidth=4 softtabstop=4 expandtab: