diff options
Diffstat (limited to 'sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 91 |
1 files changed, 88 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx index 094a9262ace7..2ef6c105902b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx @@ -11,11 +11,14 @@ #include <xmloff/odffields.hxx> #include <IDocumentMarkAccess.hxx> #include <IMark.hxx> +#include <com/sun/star/text/XTextField.hpp> + +char const DATA_DIRECTORY[] = "/sw/qa/extras/ooxmlexport/data/"; class Test : public SwModelTestBase { public: - Test() : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") {} + Test() : SwModelTestBase(DATA_DIRECTORY, "Office Open XML Text") {} protected: /** @@ -477,7 +480,7 @@ DECLARE_OOXMLEXPORT_TEST(testParagraphSdt, "paragraph-sdt.docx") if (xmlDocPtr pXmlDoc = parseExport()) { // The path to w:sdt contained a w:p. - assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:sdt"); + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc//w:p/w:sdt"); } } @@ -615,7 +618,8 @@ DECLARE_OOXMLEXPORT_TEST(testSdtCompanyMultipara, "sdt-company-multipara.docx") if (xmlDocPtr pXmlDoc = parseExport("word/document.xml")) { // This was 3, but multiple paragraphs inside "Company" SDT is now allowed. - assertXPath(pXmlDoc, "//w:sdtContent/w:p", 1); + assertXPath(pXmlDoc, "//w:sdtContent/w:p", 0); + assertXPath(pXmlDoc, "//w:sdtContent/w:r", 1); } } @@ -758,6 +762,87 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testConditionalText, "conditional-text.fodt" assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText", aExpected); } +DECLARE_OOXMLEXPORT_TEST( testSdtDatePicker, "test_sdt_datepicker.docx" ) +{ + // Check that roundtrip for date picker field does not lose essential data + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + if (!pXmlDoc) + return; // initial import, no futher checks + + // Placeholder is here + OUString sDocPart = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:placeholder/w:docPart", "val"); + CPPUNIT_ASSERT_EQUAL(OUString("DefaultPlaceholder_-1854013437"), sDocPart); + + // Ensure that we have data binding stuff + OUString sDBprefix = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "prefixMappings"); + CPPUNIT_ASSERT_EQUAL(OUString("xmlns:ns0='http://schemas.microsoft.com/vsto/samples' "), sDBprefix); + + OUString sDBxpath = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "xpath"); + CPPUNIT_ASSERT_EQUAL(OUString("/ns0:employees[1]/ns0:employee[1]/ns0:hireDate[1]"), sDBxpath); + + OUString sDBstoreid = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "storeItemID"); + CPPUNIT_ASSERT_EQUAL(OUString("{241A8A02-7FFD-488D-8827-63FBE74E8BC9}"), sDBstoreid); + + OUString sColor = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w15:color", "val"); + CPPUNIT_ASSERT_EQUAL(OUString("008000"), sColor); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf104823) +{ + // Test how we can roundtrip sdt plain text with databindings support + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf104823.docx"; + loadURL(aURL, nullptr); + + css::uno::Reference<css::text::XTextFieldsSupplier> xTextFieldsSupplier( + mxComponent, css::uno::UNO_QUERY_THROW); + auto xFields(xTextFieldsSupplier->getTextFields()->createEnumeration()); + + // FIXME: seems order of fields is different than in source document + // so feel free to modify testcase if order is changed + + // First field: content from core properties + uno::Reference<text::XTextField> xField1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + // Check field value (it should be value from data source) and set new + CPPUNIT_ASSERT_EQUAL(OUString("True Core Property Value"), xField1->getPresentation(false)); + uno::Reference<beans::XPropertySet> xField1Props(xField1, uno::UNO_QUERY); + xField1Props->setPropertyValue("Content", uno::makeAny(OUString("New Core Property Value"))); + + // Third field: content from custom properties + uno::Reference<text::XTextField> xField2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xFields->hasMoreElements()); + // Check field value (it should be value from data source) and set new + CPPUNIT_ASSERT_EQUAL(OUString("True Custom XML Value"), xField2->getPresentation(false)); + uno::Reference<beans::XPropertySet> xField2Props(xField2, uno::UNO_QUERY); + xField2Props->setPropertyValue("Content", uno::makeAny(OUString("New Custom XML Value"))); + + // Second field: content from extended properties + uno::Reference<text::XTextField> xField3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT(!xFields->hasMoreElements()); + // Check field value (it should be value from data source) and set new + CPPUNIT_ASSERT_EQUAL(OUString("True Extended Property Value"), xField3->getPresentation(false)); + uno::Reference<beans::XPropertySet> xField3Props(xField3, uno::UNO_QUERY); + xField3Props->setPropertyValue("Content", uno::makeAny(OUString("New Extended Property Value"))); + + // Save and check saved data + save("Office Open XML Text", maTempFile); + mbExported = true; + xmlDocPtr pXmlCustomPropsDoc = parseExport("customXml/item1.xml"); + CPPUNIT_ASSERT(pXmlCustomPropsDoc); + // FIXME: strange it won't run simple /employees/employee/name xpath query. Does not like namespaces? + assertXPathContent(pXmlCustomPropsDoc, "//*/*[local-name()='name']", "New Custom XML Value"); + + xmlDocPtr pXmlAppPropsDoc = parseExport("docProps/app.xml"); + CPPUNIT_ASSERT(pXmlAppPropsDoc); + // TODO: extended properties are not written yet + assertXPathContent(pXmlAppPropsDoc, "//*/*[local-name()='Company']", "True Extended Property Value"); + + xmlDocPtr pXmlCorePropsDoc = parseExport("docProps/core.xml"); + CPPUNIT_ASSERT(pXmlCorePropsDoc); + // TODO: core properties are not written yet + assertXPathContent(pXmlCorePropsDoc, "//*/*[local-name()='creator']", "True Core Property Value"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |