tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sw / qa / uitest / styleInspector / styleInspector.py
blobe4fe8e0259c7bc3e9dedf1f46ab367a4743ff28b
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from com.sun.star.rdf.URIs import LO_EXT_SHADING
14 class styleNavigator(UITestCase):
16 def test_listbox_is_updated(self):
17 with self.ui_test.load_file(get_url_for_data_file("styles.odt")):
18 xWriterDoc = self.xUITest.getTopFocusWindow()
19 xWriterEdit = xWriterDoc.getChild("writer_edit")
21 self.xUITest.executeCommand(".uno:Sidebar")
22 xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "InspectorTextPanel"}))
24 xListBox = xWriterEdit.getChild('listbox_fonts')
26 # The cursor is on text without formatting and default style
27 self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
28 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
29 self.assertEqual(143, len(xListBox.getChild('0').getChild('0').getChildren()))
30 self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
31 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
32 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
34 self.xUITest.executeCommand(".uno:GoDown")
36 # The cursor is on text with direct formatting
37 self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
38 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
39 self.assertEqual(143, len(xListBox.getChild('0').getChild('0').getChildren()))
40 self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
41 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
43 xDirFormatting = xListBox.getChild('3')
44 self.assertEqual(5, len(xDirFormatting.getChildren()))
45 self.assertEqual("Char Back Color\t0xffff00", get_state_as_dict(xDirFormatting.getChild('0'))['Text'])
46 self.assertEqual("Char Back Transparent\tFalse", get_state_as_dict(xDirFormatting.getChild('1'))['Text'])
47 self.assertEqual("Char Color\t0xc9211e", get_state_as_dict(xDirFormatting.getChild('2'))['Text'])
48 self.assertEqual("Char Shading Value\t0", get_state_as_dict(xDirFormatting.getChild('3'))['Text'])
49 self.assertEqual("Char Transparence\t0", get_state_as_dict(xDirFormatting.getChild('4'))['Text'])
52 self.xUITest.executeCommand(".uno:GoDown")
54 # The cursor is on text with paragraph direct formatting
55 self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
56 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
57 self.assertEqual(143, len(xListBox.getChild('0').getChild('0').getChildren()))
59 xParDirFormatting = xListBox.getChild('1')
60 self.assertEqual(7, len(xParDirFormatting.getChildren()))
61 self.assertEqual("Fill Color\t0xff0000", get_state_as_dict(xParDirFormatting.getChild('0'))['Text'])
62 self.assertEqual("Para Back Color\t0xff0000", get_state_as_dict(xParDirFormatting.getChild('1'))['Text'])
63 self.assertEqual("Para Back Transparent\tFalse", get_state_as_dict(xParDirFormatting.getChild('2'))['Text'])
64 self.assertEqual("Para First Line Indent\t0", get_state_as_dict(xParDirFormatting.getChild('3'))['Text'])
65 self.assertEqual("Para is Auto First Line Indent\tFalse", get_state_as_dict(xParDirFormatting.getChild('4'))['Text'])
66 self.assertEqual("Para Left Margin\t1482", get_state_as_dict(xParDirFormatting.getChild('5'))['Text'])
67 self.assertEqual("Para Right Margin\t0", get_state_as_dict(xParDirFormatting.getChild('6'))['Text'])
69 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
70 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
72 self.xUITest.executeCommand(".uno:GoDown")
74 # The cursor is on text with 'Title' style
75 xParStyle = xListBox.getChild('0')
76 self.assertEqual(3, len(xParStyle.getChildren()))
77 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xParStyle.getChild('0'))['Text'])
78 self.assertEqual(143, len(xParStyle.getChild('0').getChildren()))
79 self.assertEqual("Heading\t", get_state_as_dict(xParStyle.getChild('1'))['Text'])
80 self.assertEqual(28, len(xParStyle.getChild('1').getChildren()))
82 xTitleStyle = xParStyle.getChild('2')
83 self.assertEqual("Title\t", get_state_as_dict(xTitleStyle)['Text'])
84 self.assertEqual(16, len(xTitleStyle.getChildren()))
85 self.assertEqual("Char Difference Height\t0", get_state_as_dict(xTitleStyle.getChild('0'))['Text'])
86 self.assertEqual("Char Difference Height Asian\t0", get_state_as_dict(xTitleStyle.getChild('1'))['Text'])
87 self.assertEqual("Char Difference Height Complex\t0", get_state_as_dict(xTitleStyle.getChild('2'))['Text'])
88 self.assertEqual("Char Height\t28", get_state_as_dict(xTitleStyle.getChild('3'))['Text'])
89 self.assertEqual("Char Height Asian\t28", get_state_as_dict(xTitleStyle.getChild('4'))['Text'])
90 self.assertEqual("Char Height Complex\t28", get_state_as_dict(xTitleStyle.getChild('5'))['Text'])
91 self.assertEqual("Char Property Height\t100", get_state_as_dict(xTitleStyle.getChild('6'))['Text'])
92 self.assertEqual("Char Property Height Asian\t100", get_state_as_dict(xTitleStyle.getChild('7'))['Text'])
93 self.assertEqual("Char Property Height Complex\t100", get_state_as_dict(xTitleStyle.getChild('8'))['Text'])
94 self.assertEqual("Char Weight\tBold", get_state_as_dict(xTitleStyle.getChild('9'))['Text'])
95 self.assertEqual("Char Weight Asian\tBold", get_state_as_dict(xTitleStyle.getChild('10'))['Text'])
96 self.assertEqual("Char Weight Complex\tBold", get_state_as_dict(xTitleStyle.getChild('11'))['Text'])
97 self.assertEqual("Follow Style\tText body", get_state_as_dict(xTitleStyle.getChild('12'))['Text'])
98 self.assertEqual("Para Adjust\t3", get_state_as_dict(xTitleStyle.getChild('13'))['Text'])
99 self.assertEqual("Para Expand Single Word\tFalse", get_state_as_dict(xTitleStyle.getChild('14'))['Text'])
100 self.assertEqual("Para Last Line Adjust\t0", get_state_as_dict(xTitleStyle.getChild('15'))['Text'])
102 self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
103 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
104 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
106 self.xUITest.executeCommand(".uno:GoDown")
108 # The cursor is on text with custom style
109 xParStyle = xListBox.getChild('0')
110 self.assertEqual(3, len(xParStyle.getChildren()))
111 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xParStyle.getChild('0'))['Text'])
112 self.assertEqual(143, len(xParStyle.getChild('0').getChildren()))
113 self.assertEqual("Body Text\t", get_state_as_dict(xParStyle.getChild('1'))['Text'])
114 self.assertEqual(6, len(xParStyle.getChild('1').getChildren()))
116 xCustomStyle = xParStyle.getChild('2')
117 self.assertEqual("Custom_Style\t", get_state_as_dict(xCustomStyle)['Text'])
118 self.assertEqual(7, len(xCustomStyle.getChildren()))
119 self.assertEqual("Char Color\t0xff5429", get_state_as_dict(xCustomStyle.getChild('0'))['Text'])
120 self.assertEqual("Char Difference Height\t0", get_state_as_dict(xCustomStyle.getChild('1'))['Text'])
121 self.assertEqual("Char Height\t20", get_state_as_dict(xCustomStyle.getChild('2'))['Text'])
122 self.assertEqual("Char Property Height\t100", get_state_as_dict(xCustomStyle.getChild('3'))['Text'])
123 self.assertEqual("Char Transparence\t0", get_state_as_dict(xCustomStyle.getChild('4'))['Text'])
124 self.assertEqual("Char Weight\tBold", get_state_as_dict(xCustomStyle.getChild('5'))['Text'])
125 self.assertEqual("Follow Style\tCustom_Style", get_state_as_dict(xCustomStyle.getChild('6'))['Text'])
127 self.assertEqual(7, len(xListBox.getChild('0').getChild('2').getChildren()))
128 self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
129 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
130 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
132 self.xUITest.executeCommand(".uno:Sidebar")
134 def test_metadata(self):
135 with self.ui_test.load_file(get_url_for_data_file("metadata.odt")):
136 xWriterDoc = self.xUITest.getTopFocusWindow()
137 xWriterEdit = xWriterDoc.getChild("writer_edit")
139 self.xUITest.executeCommand(".uno:Sidebar")
140 xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "InspectorTextPanel"}))
142 xListBox = xWriterEdit.getChild('listbox_fonts')
144 # The cursor is on text without metadata
145 self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
146 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
147 self.assertEqual(143, len(xListBox.getChild('0').getChild('0').getChildren()))
148 self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
149 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
150 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
152 self.xUITest.executeCommand(".uno:GoDown")
154 # The cursor is on text with paragraph metadata showed under direct paragraph formatting
155 self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
156 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
157 self.assertEqual(143, len(xListBox.getChild('0').getChild('0').getChildren()))
159 xParDirFormatting = xListBox.getChild('1')
160 self.assertEqual(1, len(xParDirFormatting.getChildren()))
161 self.assertEqual("Metadata Reference\t", get_state_as_dict(xParDirFormatting.getChild('0'))['Text'])
163 xMetadata = xParDirFormatting.getChild('0')
164 self.assertEqual(4, len(xMetadata.getChildren()))
165 self.assertEqual("xml:id\tpara1", get_state_as_dict(xMetadata.getChild('0'))['Text'])
166 self.assertEqual("http://www.w3.org/1999/02/22-rdf-syntax-ns#type\tParagraph", get_state_as_dict(xMetadata.getChild('1'))['Text'])
167 self.assertEqual("http://www.w3.org/2000/01/rdf-schema#comment\tAbout this paragraph...", get_state_as_dict(xMetadata.getChild('2'))['Text'])
168 self.assertEqual("http://www.w3.org/2000/01/rdf-schema#label\tAnnotated paragraph", get_state_as_dict(xMetadata.getChild('3'))['Text'])
170 self.xUITest.executeCommand(".uno:GoDown")
171 # FIXME jump over the control character (not visible in getString(), but it affects
172 # cursor position and availability of NestedTextContent)
173 self.xUITest.executeCommand(".uno:GoRight")
175 # The cursor is on text with annotated text range
176 xDirFormatting = xListBox.getChild('0')
177 self.assertEqual("Fields\t", get_state_as_dict(xListBox.getChild('0'))['Text'])
178 self.assertEqual(1, len(xDirFormatting.getChildren()))
179 self.assertEqual("Metadata Reference\t", get_state_as_dict(xDirFormatting.getChild('0'))['Text'])
181 xMetadata = xDirFormatting.getChild('0')
182 self.assertEqual(4, len(xMetadata.getChildren()))
183 self.assertEqual("xml:id\tid2758386667", get_state_as_dict(xMetadata.getChild('0'))['Text'])
184 self.assertEqual("http://www.w3.org/1999/02/22-rdf-syntax-ns#type\tText span", get_state_as_dict(xMetadata.getChild('1'))['Text'])
185 self.assertEqual("http://www.w3.org/2000/01/rdf-schema#comment\tComment...", get_state_as_dict(xMetadata.getChild('2'))['Text'])
186 self.assertEqual("http://www.w3.org/2000/01/rdf-schema#label\tAnnotated paragraph portion", get_state_as_dict(xMetadata.getChild('3'))['Text'])
188 xDirFormatting = xListBox.getChild('4')
189 self.assertEqual(1, len(xDirFormatting.getChildren()))
190 self.assertEqual("Nested Text Content\tAnnotated text range", get_state_as_dict(xDirFormatting.getChild('0'))['Text'])
192 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
193 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
195 self.xUITest.executeCommand(".uno:Sidebar")
197 def test_bookmark_metadata(self):
198 with self.ui_test.load_file(get_url_for_data_file("bookmark-metadata.odt")):
199 xWriterDoc = self.xUITest.getTopFocusWindow()
200 xWriterEdit = xWriterDoc.getChild("writer_edit")
202 self.xUITest.executeCommand(".uno:Sidebar")
203 xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "InspectorTextPanel"}))
205 xListBox = xWriterEdit.getChild('listbox_fonts')
207 # The cursor is on text without metadata
208 self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
209 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
210 self.assertEqual(143, len(xListBox.getChild('0').getChild('0').getChildren()))
211 self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
212 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
213 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
215 self.xUITest.executeCommand(".uno:GoDown")
217 # The cursor is on text with paragraph metadata showed under direct paragraph formatting
218 self.assertEqual(1, len(xListBox.getChild('1').getChildren()))
219 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('1').getChild('0'))['Text'])
220 self.assertEqual(143, len(xListBox.getChild('1').getChild('0').getChildren()))
222 # Outer bookmark
223 xBookmarkFormatting = xListBox.getChild('0')
224 self.assertEqual("Bookmarks\t", get_state_as_dict(xBookmarkFormatting)['Text'])
225 self.assertEqual(1, len(xBookmarkFormatting.getChildren()))
226 self.assertEqual("Bookmark 1\t", get_state_as_dict(xBookmarkFormatting.getChild('0'))['Text'])
228 self.xUITest.executeCommand(".uno:GoDown")
230 # Inner bookmark
231 xBookmarkFormatting = xListBox.getChild('0')
232 self.assertEqual(2, len(xBookmarkFormatting.getChildren()))
234 self.assertEqual("Bookmark 1\t", get_state_as_dict(xBookmarkFormatting.getChild('0'))['Text'])
235 xMetadata = xBookmarkFormatting.getChild('0').getChild('0')
236 self.assertEqual(2, len(xMetadata.getChildren()))
237 self.assertEqual("xml:id\tID-566430c5-9857-4ff2-be6d-57d127368d88", get_state_as_dict(xMetadata.getChild('0'))['Text'])
238 self.assertEqual("http://www.w3.org/1999/02/22-rdf-syntax-ns#type\tBookmark", get_state_as_dict(xMetadata.getChild('1'))['Text'])
240 self.assertEqual("Bookmark 2\t", get_state_as_dict(xBookmarkFormatting.getChild('1'))['Text'])
241 xMetadata = xBookmarkFormatting.getChild('1').getChild('0')
242 self.assertEqual(2, len(xMetadata.getChildren()))
243 self.assertEqual("xml:id\tID-941142c3-924d-4884-a521-cb6a2dd26f04", get_state_as_dict(xMetadata.getChild('0'))['Text'])
244 self.assertEqual("http://www.w3.org/1999/02/22-rdf-syntax-ns#type\tBookmark", get_state_as_dict(xMetadata.getChild('1'))['Text'])
246 # Only in outer bookmark again
247 self.xUITest.executeCommand(".uno:GoDown")
248 xBookmarkFormatting = xListBox.getChild('0')
249 self.assertEqual(1, len(xBookmarkFormatting.getChildren()))
250 self.assertEqual("Bookmark 1\t", get_state_as_dict(xBookmarkFormatting.getChild('0'))['Text'])
252 self.xUITest.executeCommand(".uno:Sidebar")
254 def test_metadata_shading_color(self):
255 with self.ui_test.load_file(get_url_for_data_file("metacolor.odt")) as writer_doc:
256 xWriterDoc = self.xUITest.getTopFocusWindow()
257 xWriterEdit = xWriterDoc.getChild("writer_edit")
259 self.xUITest.executeCommand(".uno:Sidebar")
260 xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "InspectorTextPanel"}))
262 xListBox = xWriterEdit.getChild('listbox_fonts')
264 # The cursor is on text without metadata
265 self.assertEqual(1, len(xListBox.getChild('0').getChildren()))
266 self.assertEqual("Default Paragraph Style\t", get_state_as_dict(xListBox.getChild('0').getChild('0'))['Text'])
267 self.assertEqual(143, len(xListBox.getChild('0').getChild('0').getChildren()))
268 self.assertEqual(0, len(xListBox.getChild('1').getChildren()))
269 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
271 # go to next word with RDF annotation
272 self.xUITest.executeCommand(".uno:GoToNextWord")
273 self.xUITest.executeCommand(".uno:GoRight")
275 # FIXME jump over the control character (not visible in getString(), but it affects
276 # cursor position and availability of NestedTextContent)
277 self.xUITest.executeCommand(".uno:GoRight")
279 # The cursor is on text with annotated text range
280 xDirFormatting = xListBox.getChild('0')
281 self.assertEqual(1, len(xDirFormatting.getChildren()))
282 self.assertEqual("Metadata Reference\t", get_state_as_dict(xDirFormatting.getChild('0'))['Text'])
283 self.assertEqual("Nested Text Content\tipsum", get_state_as_dict(xListBox.getChild(4).getChild('0'))['Text'])
285 xMetadata = xDirFormatting.getChild('0')
286 self.assertEqual(2, len(xMetadata.getChildren()))
287 self.assertEqual("xml:id\tID-f1a8a096-7a43-4bda-a462-d73c2800dd9a", get_state_as_dict(xMetadata.getChild('0'))['Text'])
288 # RGB code of the custom shading color of the annotated text range is FFB7E9
289 self.assertEqual("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading\tFFB7E9", get_state_as_dict(xMetadata.getChild('1'))['Text'])
291 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
292 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
294 # go to next word with RDF annotation
295 self.xUITest.executeCommand(".uno:GoToNextWord")
296 self.xUITest.executeCommand(".uno:GoToNextWord")
297 self.xUITest.executeCommand(".uno:GoToNextWord")
298 self.xUITest.executeCommand(".uno:GoRight")
300 # The cursor is on text with annotated text range
301 xDirFormatting = xListBox.getChild('0')
302 self.assertEqual(1, len(xDirFormatting.getChildren()))
303 self.assertEqual("Metadata Reference\t", get_state_as_dict(xDirFormatting.getChild('0'))['Text'])
304 self.assertEqual("Nested Text Content\tames", get_state_as_dict(xListBox.getChild(4).getChild('0'))['Text'])
306 xMetadata = xDirFormatting.getChild('0')
307 self.assertEqual(2, len(xMetadata.getChildren()))
308 self.assertEqual("xml:id\tID-24478193-9630-4d03-8976-9e097c843a0b", get_state_as_dict(xMetadata.getChild('0'))['Text'])
309 # RGB code of the custom shading color of the annotated text range is 97E1E9 (the code can be lower case, see STRtoRGB)
310 self.assertEqual("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading\t97e1e9", get_state_as_dict(xMetadata.getChild('1'))['Text'])
312 self.assertEqual(0, len(xListBox.getChild('2').getChildren()))
313 self.assertEqual(0, len(xListBox.getChild('3').getChildren()))
315 # add a new annotated text range and check it in the Style Inspector
316 self.xUITest.executeCommand(".uno:GoToStartOfDoc")
318 # create annotated text range on "Lorem"
319 viewCursor = writer_doc.CurrentController.getViewCursor()
320 viewCursor.goRight(5, True)
321 rdf = writer_doc.createInstance("com.sun.star.text.InContentMetadata")
322 writer_doc.Text.insertTextContent(viewCursor, rdf, True)
324 # set its custom shading color using the new URI const LO_EXT_SHADING
325 repository = writer_doc.getRDFRepository()
326 # get metadata graph of file "custom.rdf" stored in the test document
327 xCustomGraph = [repository.getGraph(i) for i in repository.getGraphNames() if i.LocalName == "custom.rdf"]
328 self.assertEqual(1, len(xCustomGraph))
330 smgr = self.xContext.ServiceManager
331 xShadingURI = smgr.createInstance('com.sun.star.rdf.URI')
332 xShadingURI.initialize((LO_EXT_SHADING,))
333 xShadingColor = smgr.createInstance('com.sun.star.rdf.Literal')
334 xShadingColor.initialize(('BBFF88',))
335 xCustomGraph[0].addStatement(rdf, xShadingURI, xShadingColor)
337 # remove the selection
338 self.xUITest.executeCommand(".uno:GoLeft")
340 # FIXME: neither LO_EXT_SHADING, nor odf:prefix/odf:suffix changes update the View,
341 # so add a temporary bookmark to the text range to trigger the color change immediately
342 with self.ui_test.execute_dialog_through_command(".uno:InsertBookmark", close_button="insert"):
343 pass
345 self.xUITest.executeCommand(".uno:Undo")
347 xDirFormatting = xListBox.getChild('0')
348 xMetadata = xDirFormatting.getChild('0')
349 self.assertEqual(2, len(xMetadata.getChildren()))
350 # RGB code of the custom shading color of the annotated text range is BBFF88
351 self.assertEqual("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#shading\tBBFF88", get_state_as_dict(xMetadata.getChild('1'))['Text'])
353 self.xUITest.executeCommand(".uno:Sidebar")
357 # vim: set shiftwidth=4 softtabstop=4 expandtab: