summaryrefslogtreecommitdiffstats
path: root/sw/qa/python/check_xtextrangecompare.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sw/qa/python/check_xtextrangecompare.py
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/qa/python/check_xtextrangecompare.py')
-rw-r--r--sw/qa/python/check_xtextrangecompare.py169
1 files changed, 169 insertions, 0 deletions
diff --git a/sw/qa/python/check_xtextrangecompare.py b/sw/qa/python/check_xtextrangecompare.py
new file mode 100644
index 000000000..181e97ff6
--- /dev/null
+++ b/sw/qa/python/check_xtextrangecompare.py
@@ -0,0 +1,169 @@
+#! /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()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab: