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
15 class XTextTable(unittest
.TestCase
):
19 cls
._uno
= UnoInProcess()
23 def tearDownClass(cls
):
26 def test_newTable(self
):
27 xDoc
= XTextTable
._uno
.openEmptyWriterDoc()
28 xTable
= xDoc
.createInstance("com.sun.star.text.TextTable")
29 xTable
.initialize(4, 3)
30 xCursor
= xDoc
.Text
.createTextCursor()
31 xDoc
.Text
.insertTextContent(xCursor
, xTable
, False)
32 xTable
.Data
= ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
34 self
.checkTable(xTable
)
37 def test_tableFromOdt(self
):
38 hasNestedTable
= False
40 xDoc
= self
._uno
.openTemplateFromTDOC("XTextTable.odt")
41 itr
= iter(xDoc
.Text
.createEnumeration())
43 if element
.supportsService("com.sun.star.text.TextTable"):
44 self
.checkTable(element
)
46 # in second table, inside B1 cell we have nested table
47 xCellB1
= element
.getCellByName("B1")
48 self
.assertIsNotNone(xCellB1
)
49 cellContent
= iter(xCellB1
.Text
.createEnumeration())
50 for cellElement
in cellContent
:
51 if cellElement
.supportsService("com.sun.star.text.TextTable"):
52 self
.checkTable(cellElement
)
55 self
.assertTrue(hasNestedTable
)
58 def checkTable(self
, xTable
):
60 xNames
= xTable
.getCellNames()
62 xCell
= xTable
.getCellByName(xName
)
63 self
.assertIsNotNone(xCell
)
66 xNames
= xTable
.getCellNames()
67 for i
in random
.sample(range(0, len(xNames
)), len(xNames
)):
69 xCell
= xTable
.getCellByName(xName
)
70 self
.assertIsNotNone(xCell
)
73 xCell
= xTable
.getCellByName('WRONG CELL NAME')
74 self
.assertIsNone(xCell
)
77 if __name__
== '__main__':
80 # vim: set shiftwidth=4 softtabstop=4 expandtab: