sw/PythonTest_sw_python.mk | 1 sw/qa/python/check_xtexttable.py | 78 ++++++++++++++++++++++++++++++ sw/qa/python/testdocuments/XTextTable.odt |binary 3 files changed, 79 insertions(+)
New commits: commit 0a853def66bdaa9fbf2a6025aeb4351388235671 Author: Serge Krot <serge.k...@cib.de> AuthorDate: Tue Sep 18 17:52:35 2018 +0200 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Tue Sep 25 17:16:17 2018 +0200 sw: new unit test for XTextTable Change-Id: Ide5e7dd75ddb30eb1db61406c6811c6846d603bd Reviewed-on: https://gerrit.libreoffice.org/60694 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk index b9d8d509ced3..2e2ef509add2 100644 --- a/sw/PythonTest_sw_python.mk +++ b/sw/PythonTest_sw_python.mk @@ -23,6 +23,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\ check_named_property_values \ check_indexed_property_values \ check_styles \ + check_xtexttable \ check_table \ get_expression \ set_expression \ diff --git a/sw/qa/python/check_xtexttable.py b/sw/qa/python/check_xtexttable.py new file mode 100644 index 000000000000..9823ed86909b --- /dev/null +++ b/sw/qa/python/check_xtexttable.py @@ -0,0 +1,78 @@ +#! /usr/bin/env python +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +import unittest +from org.libreoffice.unotest import UnoInProcess +import random + + +class XTextTable(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls._uno = UnoInProcess() + cls._uno.setUp() + + @classmethod + def tearDownClass(cls): + cls._uno.tearDown() + + def test_newTable(self): + xDoc = XTextTable._uno.openEmptyWriterDoc() + xTable = xDoc.createInstance("com.sun.star.text.TextTable") + xTable.initialize(4, 3) + xCursor = xDoc.Text.createTextCursor() + xDoc.Text.insertTextContent(xCursor, xTable, False) + xTable.Data = ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12)) + + self.checkTable(xTable) + xDoc.close(True) + + def test_tableFromOdt(self): + hasNestedTable = False + + xDoc = self._uno.openTemplateFromTDOC("XTextTable.odt") + itr = iter(xDoc.Text.createEnumeration()) + for element in itr: + if element.supportsService("com.sun.star.text.TextTable"): + self.checkTable(element) + + # in second table, inside B1 cell we have nested table + xCellB1 = element.getCellByName("B1") + self.assertIsNotNone(xCellB1) + cellContent = iter(xCellB1.Text.createEnumeration()) + for cellElement in cellContent: + if cellElement.supportsService("com.sun.star.text.TextTable"): + self.checkTable(cellElement) + hasNestedTable = True + + self.assertTrue(hasNestedTable) + xDoc.close(True) + + def checkTable(self, xTable): + # in order + xNames = xTable.getCellNames() + for xName in xNames: + xCell = xTable.getCellByName(xName) + self.assertIsNotNone(xCell) + + # random access + xNames = xTable.getCellNames() + for i in random.sample(range(0, len(xNames)), len(xNames)): + xName = xNames[i] + xCell = xTable.getCellByName(xName) + self.assertIsNotNone(xCell) + + # wrong name + xCell = xTable.getCellByName('WRONG CELL NAME') + self.assertIsNone(xCell) + + +if __name__ == '__main__': + unittest.main() diff --git a/sw/qa/python/testdocuments/XTextTable.odt b/sw/qa/python/testdocuments/XTextTable.odt new file mode 100644 index 000000000000..2c15fc781a52 Binary files /dev/null and b/sw/qa/python/testdocuments/XTextTable.odt differ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits