summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsolenv/gbuild/PythonTest.mk7
-rw-r--r--sw/PythonTest_sw_python.mk5
-rw-r--r--sw/qa/python/check_fields.py46
-rw-r--r--unotest/source/python/org/libreoffice/unotest.py17
4 files changed, 75 insertions, 0 deletions
diff --git a/solenv/gbuild/PythonTest.mk b/solenv/gbuild/PythonTest.mk
index 931af98a7e70..e6f4412ea2f8 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 0b582a2b1c05..94212491f444 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 000000000000..5a3c2b74f0fc
--- /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 3ec016adfda4..883d3a40e47e 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)