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/.
14 from org
.libreoffice
.unotest
import UnoInProcess
15 from com
.sun
.star
.beans
import PropertyValue
16 from com
.sun
.star
.uno
import RuntimeException
17 from com
.sun
.star
.table
import BorderLine
18 from com
.sun
.star
.table
import BorderLine2
19 from com
.sun
.star
.table
.BorderLineStyle
import (DOUBLE
, SOLID
, EMBOSSED
,
20 THICKTHIN_LARGEGAP
, DASHED
, DOTTED
)
21 from com
.sun
.star
.lang
import Locale
23 class CheckTable(unittest
.TestCase
):
24 def _fill_table(self
, xTable
):
27 xTable
[y
, x
].String
= 'Cell %d %d' % (x
, y
)
29 def _check_table(self
, xTable
):
32 self
.assertEqual('Cell %d %d' % (x
, y
), xTable
[y
, x
].String
)
36 cls
._uno
= UnoInProcess()
38 cls
.OOLineVeryThin
= 18
41 def tearDownClass(cls
):
44 def __test_borderAsserts(self
, xBorderLine
, line_valid
):
45 self
.assertTrue(line_valid
)
46 self
.assertEqual(0, xBorderLine
.InnerLineWidth
)
47 self
.assertEqual(self
.OOLineVeryThin
, xBorderLine
.OuterLineWidth
)
48 self
.assertEqual(0, xBorderLine
.LineDistance
)
49 self
.assertEqual(0, xBorderLine
.Color
)
51 def __test_borderAssertsWithLineStyle(self
, xBorderLine
, line_valid
):
52 self
.__test
_borderAsserts
(xBorderLine
, line_valid
)
53 self
.assertEqual(self
.OOLineVeryThin
, xBorderLine
.LineWidth
)
54 self
.assertEqual(SOLID
, xBorderLine
.LineStyle
)
56 def __test_borderDistance(self
, border
):
57 self
.assertTrue(border
.IsDistanceValid
)
58 self
.assertEqual(97, border
.Distance
)
60 def test_tableborder(self
):
61 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
63 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
64 xTable
.initialize(3, 3)
65 xText
= xDoc
.getText()
66 xCursor
= xText
.createTextCursor()
67 xText
.insertTextContent(xCursor
, xTable
, False)
69 border_distances
= xTable
.TableBorderDistances
71 self
.assertEqual(97, border_distances
.TopDistance
)
72 self
.assertEqual(97, border_distances
.BottomDistance
)
73 self
.assertEqual(97, border_distances
.LeftDistance
)
74 self
.assertEqual(97, border_distances
.RightDistance
)
76 self
.assertEqual(True, border_distances
.IsTopDistanceValid
)
77 self
.assertEqual(True, border_distances
.IsBottomDistanceValid
)
78 self
.assertEqual(True, border_distances
.IsLeftDistanceValid
)
79 self
.assertEqual(True, border_distances
.IsRightDistanceValid
)
81 border
= xTable
.getPropertyValue("TableBorder")
83 self
.__test
_borderAsserts
(border
.TopLine
, border
.IsTopLineValid
)
84 self
.__test
_borderAsserts
(border
.BottomLine
, border
.IsBottomLineValid
)
85 self
.__test
_borderAsserts
(border
.LeftLine
, border
.IsLeftLineValid
)
86 self
.__test
_borderAsserts
(border
.RightLine
, border
.IsRightLineValid
)
87 self
.__test
_borderAsserts
(border
.HorizontalLine
, border
.IsHorizontalLineValid
)
88 self
.__test
_borderAsserts
(border
.VerticalLine
, border
.IsVerticalLineValid
)
90 self
.__test
_borderDistance
(border
)
93 border
.TopLine
= BorderLine(0, 11, 19, 19)
94 border
.BottomLine
= BorderLine(0xFF, 00, 11, 00)
95 border
.HorizontalLine
= BorderLine(0xFF00, 00, 90, 00)
96 xTable
.setPropertyValue("TableBorder", border
)
99 border
= xTable
.getPropertyValue("TableBorder")
101 self
.assertTrue(border
.IsTopLineValid
)
102 self
.assertEqual(11, border
.TopLine
.InnerLineWidth
)
103 self
.assertEqual(19, border
.TopLine
.OuterLineWidth
)
104 self
.assertEqual(19, border
.TopLine
.LineDistance
)
105 self
.assertEqual(0, border
.TopLine
.Color
)
107 self
.assertTrue(border
.IsBottomLineValid
)
108 self
.assertEqual(0, border
.BottomLine
.InnerLineWidth
)
109 self
.assertEqual(11, border
.BottomLine
.OuterLineWidth
)
110 self
.assertEqual(0, border
.BottomLine
.LineDistance
)
111 self
.assertEqual(0xFF, border
.BottomLine
.Color
)
113 self
.__test
_borderAsserts
(border
.LeftLine
, border
.IsLeftLineValid
)
115 self
.__test
_borderAsserts
(border
.RightLine
, border
.IsRightLineValid
)
117 self
.assertTrue(border
.IsHorizontalLineValid
)
118 self
.assertEqual(0, border
.HorizontalLine
.InnerLineWidth
)
119 self
.assertEqual(90, border
.HorizontalLine
.OuterLineWidth
)
120 self
.assertEqual(0, border
.HorizontalLine
.LineDistance
)
121 self
.assertEqual(0xFF00, border
.HorizontalLine
.Color
)
123 self
.__test
_borderAsserts
(border
.VerticalLine
, border
.IsVerticalLineValid
)
125 self
.__test
_borderDistance
(border
)
127 border2
= xTable
.getPropertyValue("TableBorder2")
129 self
.assertTrue(border2
.IsTopLineValid
)
130 self
.assertEqual(11, border2
.TopLine
.InnerLineWidth
)
131 self
.assertEqual(19, border2
.TopLine
.OuterLineWidth
)
132 self
.assertEqual(19, border2
.TopLine
.LineDistance
)
133 self
.assertEqual(0, border2
.TopLine
.Color
)
134 self
.assertEqual(DOUBLE
, border2
.TopLine
.LineStyle
)
135 self
.assertEqual(49, border2
.TopLine
.LineWidth
)
137 self
.assertTrue(border2
.IsBottomLineValid
)
138 self
.assertEqual(0, border2
.BottomLine
.InnerLineWidth
)
139 self
.assertEqual(11, border2
.BottomLine
.OuterLineWidth
)
140 self
.assertEqual(0, border2
.BottomLine
.LineDistance
)
141 self
.assertEqual(0xFF, border2
.BottomLine
.Color
)
142 self
.assertEqual(SOLID
, border2
.BottomLine
.LineStyle
)
143 self
.assertEqual(11, border2
.BottomLine
.LineWidth
)
145 self
.__test
_borderAssertsWithLineStyle
(border2
.LeftLine
, border2
.IsLeftLineValid
)
147 self
.__test
_borderAssertsWithLineStyle
(border2
.RightLine
, border2
.IsRightLineValid
)
149 self
.assertTrue(border2
.IsHorizontalLineValid
)
150 self
.assertEqual(0, border2
.HorizontalLine
.InnerLineWidth
)
151 self
.assertEqual(90, border2
.HorizontalLine
.OuterLineWidth
)
152 self
.assertEqual(0, border2
.HorizontalLine
.LineDistance
)
153 self
.assertEqual(0xFF00, border2
.HorizontalLine
.Color
)
154 self
.assertEqual(SOLID
, border2
.HorizontalLine
.LineStyle
)
155 self
.assertEqual(90, border2
.HorizontalLine
.LineWidth
)
157 self
.__test
_borderAssertsWithLineStyle
(border2
.VerticalLine
, border2
.IsVerticalLineValid
)
159 self
.__test
_borderDistance
(border2
)
162 border2
.RightLine
= BorderLine2(0, 0, 0, 0, THICKTHIN_LARGEGAP
, 120)
163 border2
.LeftLine
= BorderLine2(0, 0, 0, 0, EMBOSSED
, 90)
164 border2
.VerticalLine
= BorderLine2(0xFF, 0, 90, 0, DOTTED
, 0)
165 border2
.HorizontalLine
= BorderLine2(0xFF00, 0, 0, 0, DASHED
, 11)
166 xTable
.setPropertyValue("TableBorder2", border2
)
169 border2
= xTable
.getPropertyValue("TableBorder2")
171 self
.assertTrue(border2
.IsTopLineValid
)
172 self
.assertEqual(11, border2
.TopLine
.InnerLineWidth
)
173 self
.assertEqual(19, border2
.TopLine
.OuterLineWidth
)
174 self
.assertEqual(19, border2
.TopLine
.LineDistance
)
175 self
.assertEqual(0, border2
.TopLine
.Color
)
176 self
.assertEqual(DOUBLE
, border2
.TopLine
.LineStyle
)
177 self
.assertEqual(49, border2
.TopLine
.LineWidth
)
179 self
.assertTrue(border2
.IsBottomLineValid
)
180 self
.assertEqual(0, border2
.BottomLine
.InnerLineWidth
)
181 self
.assertEqual(11, border2
.BottomLine
.OuterLineWidth
)
182 self
.assertEqual(0, border2
.BottomLine
.LineDistance
)
183 self
.assertEqual(0xFF, border2
.BottomLine
.Color
)
184 self
.assertEqual(SOLID
, border2
.BottomLine
.LineStyle
)
185 self
.assertEqual(11, border2
.BottomLine
.LineWidth
)
187 self
.assertTrue(border2
.IsLeftLineValid
)
188 self
.assertEqual(23, border2
.LeftLine
.InnerLineWidth
)
189 self
.assertEqual(23, border2
.LeftLine
.OuterLineWidth
)
190 self
.assertEqual(46, border2
.LeftLine
.LineDistance
)
191 self
.assertEqual(0, border2
.LeftLine
.Color
)
192 self
.assertEqual(EMBOSSED
, border2
.LeftLine
.LineStyle
)
193 self
.assertEqual(90, border2
.LeftLine
.LineWidth
)
195 self
.assertTrue(border2
.IsRightLineValid
)
196 self
.assertEqual(53, border2
.RightLine
.InnerLineWidth
)
197 self
.assertEqual(26, border2
.RightLine
.OuterLineWidth
)
198 self
.assertEqual(41, border2
.RightLine
.LineDistance
)
199 self
.assertEqual(0, border2
.RightLine
.Color
)
200 self
.assertEqual(THICKTHIN_LARGEGAP
, border2
.RightLine
.LineStyle
)
201 self
.assertEqual(120, border2
.RightLine
.LineWidth
)
203 self
.assertTrue(border2
.IsHorizontalLineValid
)
204 self
.assertEqual(0, border2
.HorizontalLine
.InnerLineWidth
)
205 self
.assertEqual(11, border2
.HorizontalLine
.OuterLineWidth
)
206 self
.assertEqual(0, border2
.HorizontalLine
.LineDistance
)
207 self
.assertEqual(0xFF00, border2
.HorizontalLine
.Color
)
208 self
.assertEqual(DASHED
, border2
.HorizontalLine
.LineStyle
)
209 self
.assertEqual(11, border2
.HorizontalLine
.LineWidth
)
211 self
.assertTrue(border2
.IsVerticalLineValid
)
212 self
.assertEqual(0, border2
.VerticalLine
.InnerLineWidth
)
213 self
.assertEqual(90, border2
.VerticalLine
.OuterLineWidth
)
214 self
.assertEqual(0, border2
.VerticalLine
.LineDistance
)
215 self
.assertEqual(0xFF, border2
.VerticalLine
.Color
)
216 self
.assertEqual(DOTTED
, border2
.VerticalLine
.LineStyle
)
217 self
.assertEqual(90, border2
.VerticalLine
.LineWidth
)
219 self
.__test
_borderDistance
(border2
)
224 def test_fdo58242(self
):
225 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
227 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
228 xTable
.initialize(3, 3)
229 xText
= xDoc
.getText()
230 xCursor
= xText
.createTextCursor()
231 xText
.insertTextContent(xCursor
, xTable
, False)
233 xAnchor
= xTable
.getAnchor()
235 # check all properties on the anchor - shouldn't crash despite
236 # pointing to a non-SwTextNode
237 xPropsInfo
= xAnchor
.getPropertySetInfo()
238 for i
in xPropsInfo
.getProperties():
240 xAnchor
.getPropertyValue(i
.Name
)
241 except RuntimeException
:
247 def test_descriptions(self
):
248 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
250 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
251 xTable
.initialize(3, 3)
252 xCursor
= xDoc
.Text
.createTextCursor()
253 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
254 self
.assertEqual(3, xTable
.Rows
.Count
)
255 self
.assertEqual(3, xTable
.Columns
.Count
)
256 xTable
.TableName
= "foo"
257 self
.assertEqual("foo", xTable
.TableName
)
258 xTable
.TableTemplateName
= "bar"
259 self
.assertEqual("bar", xTable
.TableTemplateName
)
262 self
._fill
_table
(xTable
)
263 self
._check
_table
(xTable
)
265 # check without labels first
266 xTable
.ChartColumnAsLabel
= False
267 xTable
.ChartRowAsLabel
= False
268 self
.assertEqual(0, len(xTable
.RowDescriptions
))
269 self
.assertEqual(0, len(xTable
.ColumnDescriptions
))
270 self
.RowDescriptions
= ('foo', 'bar', 'baz') # no labels, thus noop
271 self
.ColumnDescriptions
= ('foo', 'bar', 'baz') # no labels, thus noop
272 self
._check
_table
(xTable
)
274 # now check with labels
275 xTable
.ChartColumnAsLabel
= True
276 xTable
.ChartRowAsLabel
= True
277 self
.assertEqual(2, len(xTable
.RowDescriptions
))
278 self
.assertEqual('Cell 0 1', xTable
.RowDescriptions
[0])
279 self
.assertEqual('Cell 0 2', xTable
.RowDescriptions
[1])
280 self
.assertEqual(2, len(xTable
.ColumnDescriptions
))
281 self
.assertEqual('Cell 1 0', xTable
.ColumnDescriptions
[0])
282 self
.assertEqual('Cell 2 0', xTable
.ColumnDescriptions
[1])
284 with self
.assertRaises(Exception):
285 xTable
.RowDescriptions
= ('foo',) # too short
287 with self
.assertRaises(Exception):
288 xTable
.ColumnDescriptions
= ('foo',) # too short
290 self
._check
_table
(xTable
)
291 xTable
.RowDescriptions
= ('fooRow', 'bazRow')
292 xTable
.ColumnDescriptions
= ('fooColumn', 'bazColumn')
293 self
.assertEqual('fooRow', xTable
[1, 0].String
)
294 self
.assertEqual('bazRow', xTable
[2, 0].String
)
295 self
.assertEqual('fooColumn', xTable
[0, 1].String
)
296 self
.assertEqual('bazColumn', xTable
[0, 2].String
)
297 xTable
[1, 0].String
= 'Cell 0 1' # reset changes values ...
298 xTable
[2, 0].String
= 'Cell 0 2'
299 xTable
[0, 1].String
= 'Cell 1 0'
300 xTable
[0, 2].String
= 'Cell 2 0'
301 self
._check
_table
(xTable
) # ... to ensure the rest was untouched
303 # check disconnected table excepts, but doesn't crash
304 xTable2
= xDoc
.createInstance("com.sun.star.text.TextTable")
305 xTable2
.initialize(3, 3)
307 with self
.assertRaises(Exception):
308 xTable2
.RowDescriptions
310 with self
.assertRaises(Exception):
311 xTable2
.ColumnDescriptions
315 def test_getset_data(self
):
316 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
319 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
320 xTable
.initialize(4, 3)
321 xCursor
= xDoc
.Text
.createTextCursor()
322 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
323 xTable
.ChartColumnAsLabel
= False
324 xTable
.ChartRowAsLabel
= False
327 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
328 self
.assertEqual(xTable
.Data
, ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12)))
331 with self
.assertRaises(Exception):
332 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9))
335 with self
.assertRaises(Exception):
336 xTable
.Data
= ((1, 2), (4, 5), (7, 8), (10, 11))
339 xTable
.ChartColumnAsLabel
= True
340 xTable
.ChartRowAsLabel
= True
341 self
.assertEqual(xTable
.Data
, ((5, 6), (8, 9), (11, 12)))
342 xTable
.Data
= ((55, 66), (88, 99), (1111, 1212))
343 xTable
.ChartColumnAsLabel
= True
344 xTable
.ChartRowAsLabel
= False
345 self
.assertEqual(xTable
.Data
, ((2, 3), (55, 66), (88, 99), (1111, 1212)))
346 xTable
.ChartColumnAsLabel
= False
347 xTable
.ChartRowAsLabel
= True
348 self
.assertEqual(xTable
.Data
, ((4, 55, 66), (7, 88, 99), (10, 1111, 1212)))
349 xTable
.ChartColumnAsLabel
= False
350 xTable
.ChartRowAsLabel
= False
351 self
.assertEqual(xTable
.Data
, ((1, 2, 3), (4, 55, 66), (7, 88, 99), (10, 1111, 1212)))
354 def test_remove_colrow(self
):
355 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
356 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
357 xTable
.initialize(4, 3)
358 xCursor
= xDoc
.Text
.createTextCursor()
359 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
360 xTable
.ChartColumnAsLabel
= False
361 xTable
.ChartRowAsLabel
= False
362 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
364 self
.assertEqual(xRows
.ImplementationName
, 'SwXTableRows')
365 self
.assertTrue(xRows
.supportsService('com.sun.star.text.TableRows'))
366 self
.assertFalse(xRows
.supportsService('foo'))
367 self
.assertIn('com.sun.star.text.TableRows', xRows
.SupportedServiceNames
)
368 self
.assertNotIn('foo', xRows
.SupportedServiceNames
)
369 xRows
.removeByIndex(1, 2)
370 self
.assertEqual(xTable
.Data
, ((1, 2, 3), (10, 11, 12)))
371 xCols
= xTable
.Columns
372 self
.assertEqual(xCols
.ImplementationName
, 'SwXTableColumns')
373 self
.assertTrue(xCols
.supportsService('com.sun.star.text.TableColumns'))
374 self
.assertFalse(xCols
.supportsService('foo'))
375 self
.assertIn('com.sun.star.text.TableColumns', xCols
.SupportedServiceNames
)
376 self
.assertNotIn('foo', xCols
.SupportedServiceNames
)
377 xCols
.removeByIndex(1, 1)
378 self
.assertEqual(xTable
.Data
, ((1, 3), (10, 12)))
381 def test_insert_colrow(self
):
382 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
383 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
384 xTable
.initialize(4, 3)
385 xCursor
= xDoc
.Text
.createTextCursor()
386 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
387 xTable
.ChartColumnAsLabel
= False
388 xTable
.ChartRowAsLabel
= False
389 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
391 xRows
.insertByIndex(1, 2)
392 self
.assertEqual(xTable
.Data
[0], (1, 2, 3))
393 self
.assertEqual(xTable
.Data
[3], (4, 5, 6))
394 self
.assertEqual(xTable
.Data
[4], (7, 8, 9))
395 self
.assertEqual(xTable
.Data
[5], (10, 11, 12))
398 self
.assertTrue(math
.isnan(xTable
.Data
[1][x
]))
399 self
.assertTrue(math
.isnan(xTable
.Data
[2][x
]))
401 xCols
= xTable
.Columns
402 xCols
.insertByIndex(1, 1)
403 self
.assertEqual(xTable
.Data
[0][0], 1)
404 self
.assertTrue(math
.isnan(xTable
.Data
[0][1]))
405 self
.assertEqual(xTable
.Data
[0][2], 2)
406 self
.assertEqual(xTable
.Data
[0][3], 3)
407 self
.assertEqual(xTable
.Data
[3][0], 4)
408 self
.assertTrue(math
.isnan(xTable
.Data
[3][1]))
409 self
.assertEqual(xTable
.Data
[3][2], 5)
410 self
.assertEqual(xTable
.Data
[3][3], 6)
411 self
.assertEqual(xTable
.Data
[4][0], 7)
412 self
.assertTrue(math
.isnan(xTable
.Data
[4][1]))
413 self
.assertEqual(xTable
.Data
[4][2], 8)
414 self
.assertEqual(xTable
.Data
[4][3], 9)
415 self
.assertEqual(xTable
.Data
[5][0], 10)
416 self
.assertTrue(math
.isnan(xTable
.Data
[5][1]))
417 self
.assertEqual(xTable
.Data
[5][2], 11)
418 self
.assertEqual(xTable
.Data
[5][3], 12)
421 self
.assertTrue(math
.isnan(xTable
.Data
[1][x
]))
422 self
.assertTrue(math
.isnan(xTable
.Data
[2][x
]))
425 def test_chartdataprovider(self
):
426 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
427 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
428 xTable
.initialize(4, 3)
429 xCursor
= xDoc
.Text
.createTextCursor()
430 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
431 xTable
.ChartColumnAsLabel
= False
432 xTable
.ChartRowAsLabel
= False
433 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
434 self
.assertTrue(xTable
.Name
== 'Table1')
435 self
.assertIn('com.sun.star.text.GenericTextDocument', xDoc
.SupportedServiceNames
)
436 xChartdataprovider
= xDoc
.createInstance('com.sun.star.chart2.data.DataProvider')
437 self
.assertEqual(xChartdataprovider
.ImplementationName
, 'SwChartDataProvider')
438 self
.assertTrue(xChartdataprovider
.supportsService('com.sun.star.chart2.data.DataProvider'))
439 self
.assertFalse(xChartdataprovider
.supportsService('foo'))
440 self
.assertIn('com.sun.star.chart2.data.DataProvider', xChartdataprovider
.SupportedServiceNames
)
442 pv
.Name
= 'CellRangeRepresentation'
443 pv
.Value
= 'Table1.A1:C2'
444 xDataSource
= xChartdataprovider
.createDataSource((pv
,))
445 self
.assertEqual(len(xDataSource
.DataSequences
), 3)
446 expected_values
= ((1, 4), (2, 5), (3, 6))
447 expected_cellrange
= ('A1:A2', 'B1:B2', 'C1:C2')
450 xSeq
= xDataSource
.DataSequences
[col
].Values
451 self
.assertEqual(xSeq
.ImplementationName
, 'SwChartDataSequence')
452 self
.assertTrue(xSeq
.supportsService('com.sun.star.chart2.data.DataSequence'))
453 self
.assertFalse(xSeq
.supportsService('foo'))
454 self
.assertIn('com.sun.star.chart2.data.DataSequence', xSeq
.SupportedServiceNames
)
455 self
.assertEqual(xSeq
.SourceRangeRepresentation
, 'Table1.%s' % expected_cellrange
[col
])
456 self
.assertEqual(xSeq
.Data
, expected_values
[col
])
457 self
.assertEqual(xSeq
.NumericalData
, expected_values
[col
])
458 self
.assertEqual([int(txtval
) for txtval
in xSeq
.TextualData
],
459 [val
for val
in expected_values
[col
]])
461 xSeq
.Role
= "One xSeq to rule them all"
462 self
.assertEqual("One xSeq to rule them all", xSeq
.Role
)
464 xSeqClone
= xSeq
.createClone()
465 self
.assertEqual(xSeq
.Role
, xSeqClone
.Role
)
469 def test_tdf32082(self
):
470 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
471 xDocFrame
= xDoc
.CurrentController
.Frame
472 xContext
= CheckTable
._uno
.getContext()
473 xServiceManager
= xContext
.ServiceManager
474 xDispatcher
= xServiceManager
.createInstanceWithContext('com.sun.star.frame.DispatchHelper',
477 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
478 xTable
.initialize(1, 1)
479 xCursor
= xDoc
.Text
.createTextCursor()
480 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
482 # Setup numberformat for the cell
483 xNumberFormats
= xDoc
.NumberFormats
484 xLocale
= Locale('en', 'US', '')
485 format_string
= '#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]'
486 key
= xNumberFormats
.queryKey(format_string
, xLocale
, True)
489 key
= xNumberFormats
.addNew(format_string
, xLocale
)
491 # Apply the format on the first cell
492 xTable
[0, 0].NumberFormat
= key
493 xDispatcher
.executeDispatch(xDocFrame
, '.uno:GoToStartOfDoc', '', 0, ())
494 xDispatcher
.executeDispatch(xDocFrame
, '.uno:InsertText', '', 0,
495 (PropertyValue('Text', 0, '3', 0),))
496 xDispatcher
.executeDispatch(xDocFrame
, '.uno:JumpToNextCell', '', 0, ())
498 # Check that the formatting we set up is not destroyed
499 self
.assertEqual(xTable
[0, 0].getString(), '3.00 €')
500 self
.assertEqual(xTable
[0, 0].getValue(), 3)
502 # Verify that it works with number recognition turned on as well
503 xDispatcher
.executeDispatch(xDocFrame
, '.uno:TableNumberRecognition', '', 0,
504 (PropertyValue('TableNumberRecognition', 0, True, 0),))
505 xDispatcher
.executeDispatch(xDocFrame
, '.uno:InsertText', '', 0,
506 (PropertyValue('Text', 0, '4', 0),))
507 xDispatcher
.executeDispatch(xDocFrame
, '.uno:JumpToNextCell', '', 0, ())
508 self
.assertEqual(xTable
[1, 0].getString(), '4.00 €')
509 self
.assertEqual(xTable
[1, 0].getValue(), 4)
512 def test_numberRecognition(self
):
513 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
514 xDocFrame
= xDoc
.CurrentController
.Frame
515 xContext
= CheckTable
._uno
.getContext()
516 xServiceManager
= xContext
.ServiceManager
517 xDispatcher
= xServiceManager
.createInstanceWithContext('com.sun.star.frame.DispatchHelper',
520 xTable
= xDoc
.createInstance('com.sun.star.text.TextTable')
521 xTable
.initialize(2, 1)
522 xCursor
= xDoc
.Text
.createTextCursor()
523 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
524 xDispatcher
.executeDispatch(xDocFrame
, '.uno:GoToStartOfDoc', '', 0, ())
525 xDispatcher
.executeDispatch(xDocFrame
, '.uno:InsertText', '', 0,
526 (PropertyValue('Text', 0, '2015-10-30', 0),))
527 xDispatcher
.executeDispatch(xDocFrame
, '.uno:JumpToNextCell', '', 0, ())
529 # Without number recognition 2015-10-30 should not be interpreted as a date
530 self
.assertEqual(xTable
[0, 0].getString(), '2015-10-30')
531 self
.assertEqual(xTable
[0, 0].getValue(), 0)
533 # Activate number recognition
534 xDispatcher
.executeDispatch(xDocFrame
, '.uno:TableNumberRecognition', '', 0,
535 (PropertyValue('TableNumberRecognition', 0, True, 0),))
536 xDispatcher
.executeDispatch(xDocFrame
, '.uno:InsertText', '', 0,
537 (PropertyValue('Text', 0, '2015-10-30', 0),))
538 xDispatcher
.executeDispatch(xDocFrame
, '.uno:JumpToNextCell', '', 0, ())
540 # With number recognition it should now be a date, confirm by checking
541 # the string and value of the cell.
542 self
.assertEqual(xTable
[1, 0].getString(), '2015-10-30')
543 self
.assertEqual(xTable
[1, 0].getValue(), 42307.0)
546 def test_tableTemplate(self
):
547 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
548 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
549 xTable
.initialize(1, 1)
550 xCursor
= xDoc
.Text
.createTextCursor()
551 xDoc
.Text
.insertTextContent(xCursor
, xTable
, True)
552 # should return programmatic name, even though UI name was set.
553 xTable
.setPropertyValue("TableTemplateName", "Default Table Style")
554 self
.assertEqual(xTable
.getPropertyValue("TableTemplateName"), "Default Style")
555 xTable
.setPropertyValue("TableTemplateName", "Default")
556 self
.assertEqual(xTable
.getPropertyValue("TableTemplateName"), "Default")
557 xTable
.setPropertyValue("TableTemplateName", "other_style")
558 self
.assertEqual(xTable
.getPropertyValue("TableTemplateName"), "other_style")
559 xTable
.setPropertyValue("TableTemplateName", "")
560 self
.assertEqual(xTable
.getPropertyValue("TableTemplateName"), "")
563 def test_unoNames(self
):
564 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
565 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
566 xTable
.initialize(3, 3)
567 xText
= xDoc
.getText()
568 xCursor
= xText
.createTextCursor()
569 xText
.insertTextContent(xCursor
, xTable
, False)
571 self
.assertEqual("SwXTextTable", xTable
.ImplementationName
)
572 self
.assertEqual(("com.sun.star.document.LinkTarget",
573 "com.sun.star.text.TextTable",
574 "com.sun.star.text.TextContent",
575 "com.sun.star.text.TextSortable"), xTable
.SupportedServiceNames
)
576 self
.assertEqual(b
'', xTable
.ImplementationId
.value
)
579 self
.assertEqual("SwXCell", xCell
.ImplementationName
)
580 self
.assertEqual(("com.sun.star.text.CellProperties",), xCell
.SupportedServiceNames
)
581 self
.assertEqual(b
'', xCell
.ImplementationId
.value
)
583 xRow
= xTable
.Rows
[0]
584 self
.assertEqual("SwXTextTableRow", xRow
.ImplementationName
)
585 self
.assertEqual(("com.sun.star.text.TextTableRow",), xRow
.SupportedServiceNames
)
586 self
.assertEqual(b
'', xRow
.ImplementationId
.value
)
588 xTableCursor
= xTable
.createCursorByCellName("A1")
589 self
.assertEqual("SwXTextTableCursor", xTableCursor
.ImplementationName
)
590 self
.assertEqual(("com.sun.star.text.TextTableCursor",), xTableCursor
.SupportedServiceNames
)
591 self
.assertEqual(b
'', xTableCursor
.ImplementationId
.value
)
595 def test_xmlRangeConversions(self
):
596 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
597 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
598 xTable
.initialize(4, 3)
599 xCursor
= xDoc
.Text
.createTextCursor()
600 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
601 xTable
.ChartColumnAsLabel
= False
602 xTable
.ChartRowAsLabel
= False
603 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
605 xChartDataProvider
= xDoc
.createInstance('com.sun.star.chart2.data.DataProvider')
607 self
.assertEqual('', xChartDataProvider
.convertRangeToXML(''))
608 self
.assertEqual('', xChartDataProvider
.convertRangeFromXML(''))
609 self
.assertEqual('.A1;.A1', xChartDataProvider
.convertRangeFromXML('<some xml>'))
611 xml
= xChartDataProvider
.convertRangeToXML('Table1.A1:C3')
613 self
.assertEqual("Table1.$A$1:.$C$3", xml
)
615 xCellRangeString
= xChartDataProvider
.convertRangeFromXML("Table1.$A$1:.$C$3")
616 self
.assertEqual("Table1.A1:C3", xCellRangeString
)
620 def test_splitRangeHorizontal(self
):
621 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
622 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
623 xTable
.initialize(2, 2)
624 xText
= xDoc
.getText()
625 xCursor
= xText
.createTextCursor()
626 xText
.insertTextContent(xCursor
, xTable
, False)
627 xTable
.Data
= ((1, 2), (3, 4))
628 xCursor
= xTable
.createCursorByCellName("A1")
629 xCursor
.splitRange(2, True)
630 self
.assertEqual(len(xTable
.Data
), 4)
631 self
.assertEqual(xTable
.Data
[0], (float(1), float(2)))
632 self
.assertEqual(xTable
.Data
[3], (float(3), float(4)))
633 self
.assertTrue(math
.isnan(xTable
.Data
[1][0]))
634 self
.assertTrue(math
.isnan(xTable
.Data
[1][1]))
635 self
.assertTrue(math
.isnan(xTable
.Data
[2][0]))
636 self
.assertTrue(math
.isnan(xTable
.Data
[2][1]))
639 def test_mergeRangeHorizontal(self
):
640 xDoc
= CheckTable
._uno
.openEmptyWriterDoc()
641 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
642 xTable
.initialize(3, 3)
643 xText
= xDoc
.getText()
644 xCursor
= xText
.createTextCursor()
645 xText
.insertTextContent(xCursor
, xTable
, False)
646 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9))
647 xCursor
= xTable
.createCursorByCellName("A1")
648 xCursor
.goDown(1, True)
650 self
.assertEqual(len(xTable
.Data
), 3)
651 self
.assertEqual(xTable
.Data
[0], (float(1), float(2), float(3)))
652 self
.assertTrue(math
.isnan(xTable
.Data
[1][0]))
653 self
.assertEqual(xTable
.Data
[1][1], float(5))
654 self
.assertEqual(xTable
.Data
[1][2], float(6))
655 self
.assertEqual(xTable
.Data
[2], (float(7), float(8), float(9)))
658 if __name__
== '__main__':
661 # vim: set shiftwidth=4 softtabstop=4 expandtab: