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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 12 11:12:15 UTC 2018


 sw/PythonTest_sw_python.mk                  |    1 
 sw/qa/python/testdocuments/xtextcontent.odt |binary
 sw/qa/python/xtextcontent.py                |   80 ++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)

New commits:
commit 50c2effdf7f2f209d8d256b9c48580c79ece7fbd
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Thu Oct 4 10:03:59 2018 +0300
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Fri Oct 12 13:11:51 2018 +0200

    sw: new unit test for XTextContent
    
    Change-Id: Ic5f6740b145a473f69052489ce6c48894f33c74d
    Reviewed-on: https://gerrit.libreoffice.org/61351
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 573ebbc95182..b7c66bba7bfe 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -37,6 +37,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
 	xscriptprovider \
 	xtextfieldssupplier \
 	xcontrolshape \
+	xtextcontent \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xtextcontent.odt b/sw/qa/python/testdocuments/xtextcontent.odt
new file mode 100644
index 000000000000..a1eb82741b69
Binary files /dev/null and b/sw/qa/python/testdocuments/xtextcontent.odt differ
diff --git a/sw/qa/python/xtextcontent.py b/sw/qa/python/xtextcontent.py
new file mode 100644
index 000000000000..bae9b79f898e
--- /dev/null
+++ b/sw/qa/python/xtextcontent.py
@@ -0,0 +1,80 @@
+#! /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
+from com.sun.star.lang import IllegalArgumentException
+import uno
+
+
+class TestXTextContent(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown()
+
+    def test_anchorOperations(self):
+        xDoc = self._uno.openDocFromTDOC("xtextcontent.odt")
+        self.assertIsNotNone(xDoc)
+
+        # getAnchor for both text frames and ensure we receive ranges we expect
+        xFrame1 = self.getTextFrame("Frame1")
+        xRange1 = xFrame1.getAnchor()
+        self.assertIsNotNone(xRange1)
+        self.compareRange(xRange1, "String1")
+
+        xFrame2 = self.getTextFrame("Frame2")
+        xRange2 = xFrame2.getAnchor()
+        self.assertIsNotNone(xRange2)
+        self.compareRange(xRange2, "String2")
+
+        # Check how XTextContent::attach works. Try to exchange anchors
+        xFrame1.attach(xRange2)
+        xFrame2.attach(xRange1)
+        self.compareRange(xFrame1.getAnchor(), "String2")
+        self.compareRange(xFrame2.getAnchor(), "String1")
+
+        # Try to attach to None
+        with self.assertRaises(IllegalArgumentException):
+            xFrame1.attach(None)
+
+        # Trying to attach frame to range from other document
+        xDoc2 = self._uno.openDocFromTDOC("xcontrolshape.odt")
+        with self.assertRaises(IllegalArgumentException):
+            xFrame1.attach(xDoc2.getText())
+
+        xDoc2.close(True)
+        xDoc.close(True)
+
+    def getTextFrame(self, frameName):
+        xTextFrames = self._uno.getDoc().getTextFrames()
+        self.assertIsNotNone(xTextFrames)
+        xTextFrame = xTextFrames[frameName]
+        self.assertIsNotNone(xTextFrame)
+        return xTextFrame
+
+    # Helper to extract text content from range and compare to expected string
+    def compareRange(self, xRange, expectedContent):
+        xCursor = xRange.getText().createTextCursor()
+        self.assertIsNotNone(xCursor)
+        xCursor.collapseToStart()
+        xCursor.goRight(len(expectedContent), True)
+        self.assertEqual(xCursor.getString(), expectedContent)
+
+
+if __name__ == '__main__':
+    unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list