[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Nov 22 23:09:11 UTC 2018


 sw/PythonTest_sw_python.mk                |    1 
 sw/qa/python/testdocuments/xtextrange.odt |binary
 sw/qa/python/xtextrange.py                |   97 ++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+)

New commits:
commit 284dd58e326e61a5d84bde367e1e4873dd738c76
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Mon Oct 1 09:43:59 2018 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 23 00:08:38 2018 +0100

    sw: new testcase for XTextRange
    
    Change-Id: Ia476f4f001851d0f8b51fca62b5c041b1d866cc3
    Reviewed-on: https://gerrit.libreoffice.org/61174
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 0dc15f929de0..cd73e90f199a 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -40,6 +40,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
 	xtextfieldssupplier \
 	xcontrolshape \
 	xtextcontent \
+	xtextrange \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xtextrange.odt b/sw/qa/python/testdocuments/xtextrange.odt
new file mode 100644
index 000000000000..5881ea44a447
Binary files /dev/null and b/sw/qa/python/testdocuments/xtextrange.odt differ
diff --git a/sw/qa/python/xtextrange.py b/sw/qa/python/xtextrange.py
new file mode 100644
index 000000000000..e6875fadc097
--- /dev/null
+++ b/sw/qa/python/xtextrange.py
@@ -0,0 +1,97 @@
+#! /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
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+import uno
+import time
+
+
+class TestXTextRange(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+        cls._uno.openDocFromTDOC("xtextrange.odt")
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown()
+
+    def test_textRangesInPlainText(self):
+        xCursor = self._uno.getDoc().getText().createTextCursor()
+        xCursor.goRight(10, True)
+        xTextRange = xCursor
+        self.assertEqual(xTextRange.getString(), "0123456789")
+
+        # getStart
+        xTextRangeStart = xTextRange.getStart()
+        self.assertIsNotNone(xTextRangeStart)
+        self.assertEqual(xTextRangeStart.getString(), "")
+        xTextRangeStart.setString("before")
+        self.assertEqual(xTextRangeStart.getString(), "before")
+
+        # Owerwrite strings
+        xTextRangeStart.setString("beforebeforebeforebefore")
+        xTextRangeStart.setString("before2")
+        xTextRangeStart.setString("before3")
+        xTextRangeStart.setString("before")
+        self.assertEqual(xTextRangeStart.getString(), "before")
+        xCursor = self._uno.getDoc().getText().createTextCursor()
+        xCursor.goRight(16, True)
+        self.assertEqual(xCursor.getString(), "before0123456789")
+
+        # getEnd
+        xTextRangeEnd = xTextRange.getEnd()
+        self.assertIsNotNone(xTextRangeEnd)
+        self.assertEqual(xTextRangeEnd.getString(), "")
+        xTextRangeEnd.setString("after")
+        self.assertEqual(xTextRangeEnd.getString(), "after")
+
+        # getText
+        xText = xTextRange.getText()
+        self.assertIsNotNone(xText)
+
+        # Final check of what we have inserted
+        xCursor = self._uno.getDoc().getText().createTextCursor()
+        xCursor.goRight(21, True)
+        self.assertEqual(xCursor.getString(), "before0123456789after")
+
+    def test_textRangesInTable(self):
+        xTextTables = self._uno.getDoc().getTextTables()
+        self.assertIsNotNone(xTextTables)
+        xTextTable = xTextTables[0]
+        self.assertIsNotNone(xTextTable)
+
+        xTextRange = xTextTable.getCellByName("A1")
+        self.assertIsNotNone(xTextRange)
+        self.assertEqual(xTextRange.getString(), "C1")
+
+        xTextRangeStart = xTextRange.getStart()
+        self.assertIsNotNone(xTextRangeStart)
+        self.assertEqual(xTextRangeStart.getString(), "")
+        xTextRangeStart.setString("before")
+        self.assertEqual(xTextRangeStart.getString(), "before")
+
+        xTextRangeEnd = xTextRange.getEnd()
+        self.assertIsNotNone(xTextRangeEnd)
+        self.assertEqual(xTextRangeEnd.getString(), "")
+        xTextRangeEnd.setString("after")
+        self.assertEqual(xTextRangeEnd.getString(), "after")
+
+        # Ensure that what we inserted is in cell
+        xTextRange2 = xTextTable.getCellByName("A1")
+        self.assertEqual(xTextRange2.getString(), "beforeC1after")
+
+if __name__ == '__main__':
+    unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list