summaryrefslogtreecommitdiff
path: root/xmloff/qa/unit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-04-08 11:32:22 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-04-22 14:58:27 +0200
commit4e31fc026cdd841c8ab263a81cdb9a163f4db4d8 (patch)
tree502dd41a356bcd12dcba40020e8127fc3daa8571 /xmloff/qa/unit
parenta11754d55024d55574d227a1c1c3e9e1c6124d54 (diff)
sw content controls: add ODT export
Wrap the text portions inside the content control in a <loext:content-control> XML element. Also map the (so far) single UNO property of it to <loext:content-control loext:showing-place-holder="...">. This is just initial export for inline text content controls, more properties are to be added in follow-up commits. (cherry picked from commit cf5bbe3fce4a250ab25998053965bdc604c6114e) Conflicts: include/xmloff/xmltoken.hxx xmloff/qa/unit/text.cxx xmloff/source/core/xmltoken.cxx xmloff/source/token/tokens.txt Change-Id: I5d928255b925ed7e08fb635ba39f546e9a4879de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133315 Tested-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff/qa/unit')
-rw-r--r--xmloff/qa/unit/text.cxx36
1 files changed, 36 insertions, 0 deletions
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index a386df28acbd..5e5f24b64975 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -316,6 +316,42 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testClearingBreakImport)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(3), eClear);
}
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlExport)
+{
+ // Given a document with a content control around one or more text portions:
+ getComponent() = loadFromDesktop("private:factory/swriter");
+ uno::Reference<lang::XMultiServiceFactory> xMSF(getComponent(), uno::UNO_QUERY);
+ uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+ xText->insertString(xCursor, "test", /*bAbsorb=*/false);
+ xCursor->gotoStart(/*bExpand=*/false);
+ xCursor->gotoEnd(/*bExpand=*/true);
+ uno::Reference<text::XTextContent> xContentControl(
+ xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
+ xContentControlProps->setPropertyValue("ShowingPlaceHolder", uno::makeAny(true));
+ xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+ // When exporting to ODT:
+ uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({
+ { "FilterName", uno::makeAny(OUString("writer8")) },
+ });
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ xStorable->storeToURL(aTempFile.GetURL(), aStoreProps);
+ validate(aTempFile.GetFileName(), test::ODF);
+
+ // Then make sure the expected markup is used:
+ std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, "content.xml");
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
+ // Without the accompanying fix in place, this failed with:
+ // - XPath '//loext:content-control' number of nodes is incorrect
+ // i.e. the content control was lost on export.
+ assertXPath(pXmlDoc, "//loext:content-control", "showing-place-holder", "true");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */