summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2018-10-01 09:43:59 +0300
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2018-11-23 00:08:38 +0100
commit284dd58e326e61a5d84bde367e1e4873dd738c76 (patch)
tree5e82a904966cef6c6145a8d7af184bc6621a41e1 /sw
parent28033ada111c1f08f1d5305e709803e84ab6ddae (diff)
sw: new testcase for XTextRange
Change-Id: Ia476f4f001851d0f8b51fca62b5c041b1d866cc3 Reviewed-on: https://gerrit.libreoffice.org/61174 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/PythonTest_sw_python.mk1
-rw-r--r--sw/qa/python/testdocuments/xtextrange.odtbin0 -> 10716 bytes
-rw-r--r--sw/qa/python/xtextrange.py97
3 files changed, 98 insertions, 0 deletions
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
--- /dev/null
+++ b/sw/qa/python/testdocuments/xtextrange.odt
Binary files 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: