[Libreoffice-commits] core.git: solenv/gbuild sw/PythonTest_sw_python.mk sw/qa unotest/source

David Ostrovsky david at ostrovsky.org
Tue Jun 18 02:23:39 PDT 2013


 solenv/gbuild/PythonTest.mk                      |    7 +++
 sw/PythonTest_sw_python.mk                       |    5 ++
 sw/qa/python/check_fields.py                     |   46 +++++++++++++++++++++++
 unotest/source/python/org/libreoffice/unotest.py |   17 ++++++++
 4 files changed, 75 insertions(+)

New commits:
commit 6e8eb540c8cfe1bf663c8e4cc15e484f0d8ea0b2
Author: David Ostrovsky <david at ostrovsky.org>
Date:   Sat Jun 15 17:11:51 2013 +0200

    Migrate CheckFields unit test to python
    
    Change-Id: Ia765b37888b4095a735015e792f06fc89201d1a3
    Reviewed-on: https://gerrit.libreoffice.org/4294
    Reviewed-by: Noel Power <noel.power at suse.com>
    Tested-by: Noel Power <noel.power at suse.com>

diff --git a/solenv/gbuild/PythonTest.mk b/solenv/gbuild/PythonTest.mk
index 931af98..e6f4412 100755
--- a/solenv/gbuild/PythonTest.mk
+++ b/solenv/gbuild/PythonTest.mk
@@ -40,6 +40,7 @@ $(call gb_PythonTest_get_target,%) :
 		($(gb_PythonTest_PRECOMMAND) \
 		$(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
 		$(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \
+		$(DEFS) \
 		URE_BOOTSTRAP=vnd.sun.star.pathname:$(call gb_Helper_get_rcfile,$(gb_DEVINSTALLROOT)/program/fundamental) \
 		PYTHONPATH="$(PYPATH)" \
 		UserInstallation=$(call gb_Helper_make_url,$(dir $(call gb_PythonTest_get_target,$*))user) \
@@ -63,6 +64,11 @@ $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest)
 
 endef
 
+define gb_PythonTest_set_defs
+$(call gb_PythonTest_get_target,$(1)) : DEFS := $(2)
+
+endef
+
 # put the directory on the PYTHONPATH because the "unittest" loader
 # mysteriously fails to load modules given as absolute path unless the $PWD is
 # a prefix of the absolute path, which it is not when we go into a certain
@@ -94,6 +100,7 @@ $(call gb_Helper_make_userfriendly_targets,$(1),PythonTest)
 
 endef
 
+gb_PythonTest_set_defs :=
 gb_PythonTest_add_modules :=
 gb_PythonTest_use_customtarget :=
 
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 0b582a2..9421249 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -9,8 +9,13 @@
 
 $(eval $(call gb_PythonTest_PythonTest,sw_python))
 
+$(eval $(call gb_PythonTest_set_defs,sw_python,\
+    TDOC="$(SRCDIR)/sw/qa/complex/writer/testdocuments" \
+))
+
 $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
 	check_index \
+	check_fields \
 	get_expression \
 	set_expression \
 	var_fields \
diff --git a/sw/qa/python/check_fields.py b/sw/qa/python/check_fields.py
new file mode 100644
index 0000000..5a3c2b7
--- /dev/null
+++ b/sw/qa/python/check_fields.py
@@ -0,0 +1,46 @@
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+
+class CheckFields(unittest.TestCase):
+    _uno = None
+    _xDoc = None
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+        cls._xDoc = cls._uno.openWriterTemplateDoc("fdo39694.ott")
+        cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown()
+
+    def test_fdo39694_load(self):
+        placeholders = ["<Kadr1>", "<Kadr2>", "<Kadr3>", "<Kadr4>", "<Pnname>", "<Pvname>", "<Pgeboren>"]
+        xDoc = self.__class__._xDoc
+        xEnumerationAccess = xDoc.getTextFields()
+        xFieldEnum = xEnumerationAccess.createEnumeration()
+        while xFieldEnum.hasMoreElements():
+            xField = xFieldEnum.nextElement()
+            if xField.supportsService("com.sun.star.text.TextField.JumpEdit"):
+                xAnchor = xField.getAnchor()
+                readContent = xAnchor.getString()
+                self.assertTrue(readContent in placeholders,
+                                "field %s is not contained: " % readContent)
+
+    def test_fdo42073(self):
+        xDoc = self.__class__._xEmptyDoc
+        xBodyText = xDoc.getText()
+        xCursor = xBodyText.createTextCursor()
+        xTextField = xDoc.createInstance("com.sun.star.text.TextField.Input")
+        xBodyText.insertTextContent(xCursor, xTextField, True)
+        readContent = xTextField.getPropertyValue("Content")
+        self.assertEqual("", readContent)
+        content = "this is not surprising"
+        xTextField.setPropertyValue("Content", content)
+        readContent = xTextField.getPropertyValue("Content")
+        self.assertEqual(content, readContent)
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/unotest/source/python/org/libreoffice/unotest.py b/unotest/source/python/org/libreoffice/unotest.py
index 3ec016a..883d3a4 100644
--- a/unotest/source/python/org/libreoffice/unotest.py
+++ b/unotest/source/python/org/libreoffice/unotest.py
@@ -31,6 +31,11 @@ except ImportError:
     print("  URE_BOOTSTRAP=file:///installation/opt/program/fundamentalrc")
     raise
 
+try:
+    from urllib.parse import quote
+except ImportError:
+    from urllib import quote
+
 ### utilities ###
 
 def mkPropertyValue(name, value):
@@ -181,6 +186,18 @@ class UnoInProcess:
         assert(self.xDoc)
         return self.xDoc
 
+    def openWriterTemplateDoc(self, file):
+        assert(self.xContext)
+        smgr = self.getContext().ServiceManager
+        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
+        props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", True)]
+        loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
+        path = os.getenv("TDOC")
+        url = "file://" + quote(path) + "/" + quote(file)
+        self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
+        assert(self.xDoc)
+        return self.xDoc
+
     def checkProperties(self, obj, dict, test):
         for k,v in dict.items():
             obj.setPropertyValue(k, v)


More information about the Libreoffice-commits mailing list