sw/qa/extras/ooxmlexport/data/textinput.odt |binary sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 67 ++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-)
New commits: commit feff6668d8e978f37b37fe043858297eb3b4a2d4 Author: Jan-Marek Glogowski <jan-marek.glogow...@extern.cib.de> AuthorDate: Sun Nov 17 20:07:45 2019 +0100 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Mon Nov 18 21:26:38 2019 +0100 Extend DOCX input field export test for round-trip This expands the test from tdf#125103 to include more use cases and validate the import of the exported document (tdf#128460). Change-Id: Ifb8615b6b90931996becb8cb44d846eb30956971 Reviewed-on: https://gerrit.libreoffice.org/83038 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/sw/qa/extras/ooxmlexport/data/textinput.odt b/sw/qa/extras/ooxmlexport/data/textinput.odt index 04b8d054c354..3a5da684a0a0 100644 Binary files a/sw/qa/extras/ooxmlexport/data/textinput.odt and b/sw/qa/extras/ooxmlexport/data/textinput.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index 0d9cd773ef9a..e59df2a5ca53 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -465,10 +465,69 @@ DECLARE_OOXMLEXPORT_TEST(testTextInput, "textinput.odt") xmlDocPtr pXmlDoc = parseExport("word/document.xml"); if (!pXmlDoc) return; - // Ensure we have a formfield - assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:instrText", " FILLIN \"\""); - // and it's content is not gone - assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[5]/w:t", "SomeText"); + + // test the exported DOCX + + // no hint, empty + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:instrText", " FILLIN \"\""); + assertXPathChildren(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[5]", 1); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[5]/w:rPr", 1); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[6]/w:fldChar", "fldCharType", "end"); + + // no hint, content + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[3]/w:instrText", " FILLIN \"\""); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[5]/w:t", "content without hint"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[6]/w:fldChar", "fldCharType", "end"); + + // hint, empty + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[3]/w:instrText", " FILLIN \"hint empty\""); + assertXPathChildren(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[5]", 1); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[5]/w:rPr", 1); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[6]/w:fldChar", "fldCharType", "end"); + + // hint, content + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[4]/w:r[3]/w:instrText", " FILLIN \"hint content\""); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[4]/w:r[5]/w:t", "content with hint"); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[4]/w:r[6]/w:fldChar", "fldCharType", "end"); + + // test the imported DOCX + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + int nElements = 0; + + do + { + uno::Any aField = xFields->nextElement(); + uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.textfield.Input")); + uno::Reference<beans::XPropertySet> xPropertySet(aField, uno::UNO_QUERY); + uno::Reference<text::XTextContent> xText(aField, uno::UNO_QUERY); + + // why is the enumeration not in the same order then the fields in the document? + // it seems to be stable and the navigation in the GUI is actually correct. + OUString sContent, sHint; + switch (nElements) + { + case 1: + sContent = "content with hint"; + sHint = "hint content"; + break; + case 2: + sHint = "hint empty"; + break; + case 3: + sContent = "content without hint"; + break; + } + CPPUNIT_ASSERT_EQUAL(uno::makeAny(sContent), xPropertySet->getPropertyValue("Content")); + CPPUNIT_ASSERT_EQUAL(sContent, xText->getAnchor()->getString()); + CPPUNIT_ASSERT_EQUAL(uno::makeAny(sHint), xPropertySet->getPropertyValue("Hint")); + nElements++; + } + while (xFields->hasMoreElements()); + CPPUNIT_ASSERT_EQUAL(4, nElements); } DECLARE_OOXMLIMPORT_TEST(testTdf123460, "tdf123460.docx") _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits