fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sw / qa / python / var_fields.py
blob3222f179eaba2ea825f0257944b61b1d8cfaac5b
1 import unittest
2 import os
3 from org.libreoffice.unotest import UnoInProcess
4 from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
6 class TestVarFields(unittest.TestCase):
7 _uno = None
8 _xDoc = None
10 @classmethod
11 def setUpClass(cls):
12 cls._uno = UnoInProcess()
13 cls._uno.setUp()
14 cls._xDoc = cls._uno.openEmptyWriterDoc()
16 @classmethod
17 def tearDownClass(cls):
18 cls._uno.tearDown()
20 def test_var_fields(self):
21 """Reproduce fdo#55814.
23 Note: this test was migrated from java (the steps numbering too)
24 sw/qa/complex/writer/VarFields.java
26 """
27 xDoc = self.__class__._xDoc
28 xBodyText = xDoc.getText()
29 xCursor = xBodyText.createTextCursor()
30 # 0. create text field
31 xField = xDoc.createInstance("com.sun.star.text.textfield.SetExpression")
32 # 1. fill it with properties
33 self.__class__._uno.setProperties(xField,
34 {"Content": "0",
35 "IsVisible": True,
36 "Hint": "trying to reproduce fdo#55814",
37 "SubType": 0, # VAR
38 "Value": 0.0
40 # 2. create master field
41 xMaster = xDoc.createInstance("com.sun.star.text.fieldmaster.SetExpression")
42 # 3. set name of the master field to "foo"
43 xMaster.setPropertyValue("Name", "foo")
44 # 4. get Dependent Field
45 # no op in python ;-)
46 # 5. connect real field to the master
47 xField.attachTextFieldMaster(xMaster)
48 # 6. insert text field into the document
49 xBodyText.insertTextContent(xCursor, xField, False)
50 # 7. retrieve paragraph cursor
51 xParagraphCursor = xCursor
52 xParagraphCursor.gotoEndOfParagraph(False) # not selectd
53 # 8. enter new line
54 xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False)
55 # 9. create new text section
56 xTextSection = xDoc.createInstance("com.sun.star.text.TextSection")
57 # 10. fill the properties of section
58 self.__class__._uno.checkProperties(
59 xTextSection,
60 {"Condition": "foo EQ 1",
61 "IsVisible": False,
63 self
65 # 11. Insert some text to be content on the section
66 xBodyText.insertString(xCursor,
67 "The quick brown fox jumps over the lazy dog",
68 True)
69 # 12. insert section
70 xBodyText.insertTextContent(xCursor, xTextSection, True)
71 # 12.1 insert new paragraph. Note: that's here the difference
72 xParagraphCursor.gotoEndOfParagraph(False) # not select
73 # TODO: how to leave the section now?
74 xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False )
75 xBodyText.insertString(xCursor, "new paragraph", False)
76 # 13. Access fields to refresh the document
77 xEnumerationAccess = xDoc.getTextFields()
78 # 14. refresh document to update the fields
79 xEnumerationAccess.refresh()
80 # 15. retrieve the field
81 xFieldEnum = xEnumerationAccess.createEnumeration()
82 # Note: we have only one field here, that why nextElement() is just fine here
83 xPropSet = xFieldEnum.nextElement()
84 # check
85 readContent = xPropSet.getPropertyValue("Content")
86 self.assertEqual("0", readContent)
87 readContent = xPropSet.getPropertyValue("Value")
88 self.assertEqual(0.0, readContent)
89 # 16. change the value of the field from 0 to 1 and check
90 self.__class__._uno.checkProperties(
91 xPropSet,
92 {"Value": 1.0,
93 "Content": "1"
95 self
97 # 17. refresh document to update the fields again
98 xEnumerationAccess.refresh()
99 # 18. store document
100 url = os.path.join(os.environ["TestUserDir"], "VarFields.odt")
101 xDoc.storeToURL(url, tuple(list(range(0))))
102 # 19. retrieve the section
103 xPropSet = xDoc.getTextSections().getByIndex(0)
104 # 20. retrieve the condition property of that section
105 readContent = xPropSet.getPropertyValue("Condition")
106 # 21. check
107 # expected:
108 #self.assertEqual("foo EQ 1", readContent)
109 # reality:
110 self.assertEqual("0", readContent)
112 if __name__ == '__main__':
113 unittest.main()