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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Sep 28 08:26:46 UTC 2018


 sw/PythonTest_sw_python.mk              |    1 
 sw/qa/python/check_xtextrangecompare.py |  167 ++++++++++++++++++++++++++++++++
 2 files changed, 168 insertions(+)

New commits:
commit e9efc76f90291ba54dd2c6359f6fecef8c540841
Author:     Serge Krot <Serge.Krot at cib.de>
AuthorDate: Wed Sep 26 16:28:19 2018 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Sep 28 10:26:24 2018 +0200

    sw: new unit test for XTextRangeCompare
    
    Change-Id: Ia0d216b94f8090c3479c6e4c593baf84cb28e5e2
    Reviewed-on: https://gerrit.libreoffice.org/61005
    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 a2d677045367..6c5a4c818fe8 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
 	check_xtexttable \
 	check_table \
 	check_xnamedgraph \
+	check_xtextrangecompare \
 	get_expression \
 	set_expression \
 	text_portion_enumeration_test \
diff --git a/sw/qa/python/check_xtextrangecompare.py b/sw/qa/python/check_xtextrangecompare.py
new file mode 100644
index 000000000000..002e54c40a14
--- /dev/null
+++ b/sw/qa/python/check_xtextrangecompare.py
@@ -0,0 +1,167 @@
+#! /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
+from com.sun.star.lang import IllegalArgumentException
+
+
+class XTextRangeCompare(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown()
+
+    def test_compareRegionStarts(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+
+        cursor = xDoc.Text.createTextCursor()
+        xDoc.Text.insertString(cursor, "The first paragraph", 0)
+
+        self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor, cursor))
+
+        with self.assertRaises(IllegalArgumentException):
+            xDoc.Text.compareRegionStarts(cursor, None)
+
+        with self.assertRaises(IllegalArgumentException):
+            xDoc.Text.compareRegionStarts(None, cursor)
+
+        with self.assertRaises(IllegalArgumentException):
+            xDoc.Text.compareRegionStarts(None, None)
+
+        xDoc.close(True)
+
+    def test_compareRegionEnds(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+
+        cursor = xDoc.Text.createTextCursor()
+        xDoc.Text.insertString(cursor, "The first paragraph", 0)
+
+        self.assertEqual(0, xDoc.Text.compareRegionEnds(cursor, cursor))
+
+        with self.assertRaises(IllegalArgumentException):
+            xDoc.Text.compareRegionEnds(cursor, None)
+
+        with self.assertRaises(IllegalArgumentException):
+            xDoc.Text.compareRegionEnds(None, cursor)
+
+        with self.assertRaises(IllegalArgumentException):
+            xDoc.Text.compareRegionEnds(None, None)
+
+        xDoc.close(True)
+
+    def test_compareRegionStarts_Different(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+
+        cursor1 = xDoc.Text.createTextCursor()
+        cursor2 = xDoc.Text.createTextCursor()
+
+        xDoc.Text.insertString(cursor1, "The first paragraph", 0)
+
+        cursor1.gotoStart(False)
+        cursor2.gotoEnd(False)
+
+        self.assertTrue(cursor1.isCollapsed())
+        self.assertTrue(cursor1.isCollapsed())
+
+        self.assertEqual(1, xDoc.Text.compareRegionStarts(cursor1, cursor2))
+        self.assertEqual(-1, xDoc.Text.compareRegionStarts(cursor2, cursor1))
+
+        xDoc.close(True)
+
+    def test_compareRegionStarts_DiffSelection(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+
+        cursor1 = xDoc.Text.createTextCursor()
+        cursor2 = xDoc.Text.createTextCursor()
+
+        xDoc.Text.insertString(cursor1, "The first paragraph", 0)
+
+        cursor1.gotoStart(False)
+        cursor1.gotoEnd(True)
+        cursor2.gotoEnd(False)
+        cursor2.gotoStart(True)
+
+        self.assertFalse(cursor1.isCollapsed())
+        self.assertFalse(cursor1.isCollapsed())
+
+        self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor1, cursor2))
+        self.assertEqual(0, xDoc.Text.compareRegionEnds(cursor1, cursor2))
+
+        xDoc.close(True)
+
+    def test_compareRegionStarts_DiffSelection(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+
+        cursor1 = xDoc.Text.createTextCursor()
+        cursor2 = xDoc.Text.createTextCursor()
+
+        xDoc.Text.insertString(cursor1, "The first paragraph", 0)
+
+        cursor1.gotoStart(False)
+        cursor1.gotoEnd(True)
+        cursor1.goLeft(2, True)
+        cursor2.gotoEnd(False)
+        cursor2.gotoStart(True)
+        cursor2.goRight(2, True)
+
+        self.assertFalse(cursor1.isCollapsed())
+        self.assertFalse(cursor1.isCollapsed())
+
+        # whole text:  123456789
+        # cursor1:     1234567
+        # cursor2:       3456789
+
+        self.assertEqual(1, xDoc.Text.compareRegionStarts(cursor1, cursor2))
+        self.assertEqual(1, xDoc.Text.compareRegionEnds(cursor1, cursor2))
+
+        self.assertEqual(-1, xDoc.Text.compareRegionStarts(cursor2, cursor1))
+        self.assertEqual(-1, xDoc.Text.compareRegionEnds(cursor2, cursor1))
+
+        xDoc.close(True)
+
+    def test_compareRegionStarts_SameStart(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+
+        cursor1 = xDoc.Text.createTextCursor()
+        cursor2 = xDoc.Text.createTextCursor()
+
+        xDoc.Text.insertString(cursor1, "The first paragraph", 0)
+
+        cursor1.gotoStart(False)
+        cursor1.goRight(2, False)
+        cursor1.goRight(5, True)
+
+        cursor2.gotoStart(False)
+        cursor2.goRight(2, False)
+        cursor2.goRight(7, True)
+
+        self.assertFalse(cursor1.isCollapsed())
+        self.assertFalse(cursor1.isCollapsed())
+
+        # whole text:  123456789
+        # cursor1:       34567
+        # cursor2:       3456789
+
+        self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor1, cursor2))
+        self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor2, cursor1))
+
+        self.assertEqual(1, xDoc.Text.compareRegionEnds(cursor1, cursor2))
+        self.assertEqual(-1, xDoc.Text.compareRegionEnds(cursor2, cursor1))
+
+        xDoc.close(True)
+
+
+if __name__ == '__main__':
+    unittest.main()


More information about the Libreoffice-commits mailing list