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 from org
.libreoffice
.unotest
import UnoInProcess
12 from com
.sun
.star
.container
import NoSuchElementException
15 class TestXTextFieldsSupplier(unittest
.TestCase
):
19 cls
._uno
= UnoInProcess()
23 def tearDownClass(cls
):
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
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!")
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
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
)
87 if __name__
== '__main__':
90 # vim: set shiftwidth=4 softtabstop=4 expandtab: