tdf#164393 Change themes UI as per UX feedback
[LibreOffice.git] / sw / qa / python / check_xtexttable.py
blob3c1f4c2282c657c2bbdd2c7023686c032ee35893
1 #! /usr/bin/env python
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/.
10 import unittest
11 from org.libreoffice.unotest import UnoInProcess
12 import random
15 class XTextTable(unittest.TestCase):
17 @classmethod
18 def setUpClass(cls):
19 cls._uno = UnoInProcess()
20 cls._uno.setUp()
22 @classmethod
23 def tearDownClass(cls):
24 cls._uno.tearDown()
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)
35 xDoc.close(True)
37 def test_tableFromOdt(self):
38 hasNestedTable = False
40 xDoc = self._uno.openTemplateFromTDOC("XTextTable.odt")
41 itr = iter(xDoc.Text.createEnumeration())
42 for element in itr:
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)
53 hasNestedTable = True
55 self.assertTrue(hasNestedTable)
56 xDoc.close(True)
58 def checkTable(self, xTable):
59 # in order
60 xNames = xTable.getCellNames()
61 for xName in xNames:
62 xCell = xTable.getCellByName(xName)
63 self.assertIsNotNone(xCell)
65 # random access
66 xNames = xTable.getCellNames()
67 for i in random.sample(range(0, len(xNames)), len(xNames)):
68 xName = xNames[i]
69 xCell = xTable.getCellByName(xName)
70 self.assertIsNotNone(xCell)
72 # wrong name
73 xCell = xTable.getCellByName('WRONG CELL NAME')
74 self.assertIsNone(xCell)
77 if __name__ == '__main__':
78 unittest.main()
80 # vim: set shiftwidth=4 softtabstop=4 expandtab: