[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Nov 22 23:10:29 UTC 2018
sw/PythonTest_sw_python.mk | 1
sw/qa/python/testdocuments/xtextcursor.odt |binary
sw/qa/python/xtextcursor.py | 107 +++++++++++++++++++++++++++++
3 files changed, 108 insertions(+)
New commits:
commit 19923ea1d1608044e101b1875b47f6d4fbccf2d7
Author: Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Sep 28 13:53:46 2018 +0300
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 23 00:09:57 2018 +0100
sw: new unit test for XTextCursor
Change-Id: I5b70f6dc8f7399be78daefa95d6d98687d99ec18
Reviewed-on: https://gerrit.libreoffice.org/61098
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 ad479f527504..4f97724d835c 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -42,6 +42,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
xtextcontent \
xtextrange \
xtext \
+ xtextcursor \
))
# vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xtextcursor.odt b/sw/qa/python/testdocuments/xtextcursor.odt
new file mode 100644
index 000000000000..1fdcfb9b77f9
Binary files /dev/null and b/sw/qa/python/testdocuments/xtextcursor.odt differ
diff --git a/sw/qa/python/xtextcursor.py b/sw/qa/python/xtextcursor.py
new file mode 100644
index 000000000000..30d0518690a7
--- /dev/null
+++ b/sw/qa/python/xtextcursor.py
@@ -0,0 +1,107 @@
+#! /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 TestXTextCursor(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls._uno = UnoInProcess()
+ cls._uno.setUp()
+ cls._uno.openDocFromTDOC("xtextcursor.odt")
+
+ @classmethod
+ def tearDownClass(cls):
+ cls._uno.tearDown()
+
+ def createTextCursorInFrame(self, frameName):
+ xTextFrames = self._uno.getDoc().getTextFrames()
+ self.assertIsNotNone(xTextFrames)
+ xTextFrame = xTextFrames[frameName]
+ self.assertIsNotNone(xTextFrame)
+ xCursor = xTextFrame.getText().createTextCursor()
+ self.assertIsNotNone(xCursor)
+ return xCursor
+
+ def test_cursorMoveInText(self):
+ # Create cursor in frame with simple text (to avoid moving beyond)
+ xCursor = self.createTextCursorInFrame("FrameSimple")
+
+ xCursor.collapseToStart()
+ self.assertTrue(xCursor.isCollapsed())
+ self.assertTrue(xCursor.goRight(1, True))
+ self.assertFalse(xCursor.isCollapsed())
+ # Try to move right 10 characters, but we really can just 3, so partial move
+ self.assertFalse(xCursor.goRight(10, True))
+ self.assertFalse(xCursor.isCollapsed())
+ # Ensure that all line text is selected
+ self.assertEqual(xCursor.getString(), "1234")
+
+ self.assertFalse(xCursor.goRight(-10, True))
+ self.assertEqual(xCursor.getString(), "1234")
+
+ xCursor.collapseToEnd()
+ self.assertTrue(xCursor.isCollapsed())
+ self.assertTrue(xCursor.goLeft(2, True))
+ self.assertFalse(xCursor.isCollapsed())
+ self.assertEqual(xCursor.getString(), "34")
+
+ # Move to start without selection
+ self.assertTrue(xCursor.goLeft(2, False))
+ self.assertEqual(xCursor.getString(), "")
+
+ self.assertTrue(xCursor.isCollapsed())
+
+ # Select all text
+ xCursor.gotoStart(False)
+ self.assertTrue(xCursor.isCollapsed())
+ xCursor.gotoEnd(True)
+ self.assertFalse(xCursor.isCollapsed())
+ self.assertEqual(xCursor.getString(), "1234")
+
+ # Select all text from behind
+ xCursor.gotoEnd(False)
+ self.assertTrue(xCursor.isCollapsed())
+ xCursor.gotoStart(True)
+ self.assertFalse(xCursor.isCollapsed())
+ self.assertEqual(xCursor.getString(), "1234")
+
+ # Select all text, alternative way via gotoRange
+ xCursor2 = self.createTextCursorInFrame("FrameSimple")
+ xCursor2.gotoEnd(False)
+ xCursor2.gotoStart(True)
+ xCursor.gotoEnd(False)
+ self.assertTrue(xCursor.isCollapsed())
+ xCursor.gotoRange(xCursor2, True)
+ self.assertFalse(xCursor.isCollapsed())
+ self.assertEqual(xCursor.getString(), "1234")
+
+ def test_cursorMoveInTable(self):
+ # Create cursor in frame with table
+ xCursor = self.createTextCursorInFrame("FrameTable")
+
+ # Nothing is selected
+ xCursor.collapseToEnd()
+ self.assertTrue(xCursor.isCollapsed())
+ self.assertEqual(xCursor.getString(), "")
+ self.assertFalse(xCursor.goLeft(1, False))
+ self.assertFalse(xCursor.goLeft(1, True))
+ self.assertEqual(xCursor.getString(), "")
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
More information about the Libreoffice-commits
mailing list