summaryrefslogtreecommitdiff
path: root/xmloff/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-04-11 11:27:13 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-04-11 12:43:45 +0200
commitd1649e5d38b51cd422302e566719a2c5aff42b2f (patch)
tree5c5505bc4af35d76f7e267264de5f3255eacfe90 /xmloff/qa
parent431a0399bb050e65dedb2e9280e744699a724227 (diff)
sw content controls: add ODT import
Map <loext:content-control loext:showing-place-holder="..."> to com.sun.star.text.ContentControl and set its ShowingPlaceHolder property based on the XML attribute. This requires moving XMLImpSpanContext_Impl to txtparai.hxx, otherwise XMLContentControlContext would have to be in txtparai.cxx, which is already large. Change-Id: I9a915868160ebcc0e98ded61bfab72f32864bd76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132804 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff/qa')
-rw-r--r--xmloff/qa/unit/data/content-control.fodt8
-rw-r--r--xmloff/qa/unit/text.cxx34
2 files changed, 42 insertions, 0 deletions
diff --git a/xmloff/qa/unit/data/content-control.fodt b/xmloff/qa/unit/data/content-control.fodt
new file mode 100644
index 000000000000..97769c662b66
--- /dev/null
+++ b/xmloff/qa/unit/data/content-control.fodt
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+ <office:text>
+ <text:p><loext:content-control loext:showing-place-holder="true">test</loext:content-control></text:p>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index a7765e214066..5efe9cd91a2d 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -419,6 +419,40 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlExport)
assertXPath(pXmlDoc, "//loext:content-control", "showing-place-holder", "true");
}
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContentControlImport)
+{
+ // Given an ODF document with a content control:
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control.fodt";
+
+ // When loading that document:
+ getComponent() = loadFromDesktop(aURL);
+
+ // Then make sure that the content control is not lost on import:
+ uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xTextDocument->getText(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration();
+ uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY);
+ OUString aPortionType;
+ xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType;
+ // Without the accompanying fix in place, this failed with:
+ // - Expected: ContentControl
+ // - Actual : Text
+ // i.e. the content control was lost on import.
+ CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType);
+ uno::Reference<text::XTextContent> xContentControl;
+ xTextPortion->getPropertyValue("ContentControl") >>= xContentControl;
+ uno::Reference<text::XTextRange> xContentControlRange(xContentControl, uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xContentControlRange->getText();
+ uno::Reference<container::XEnumerationAccess> xContentEnumAccess(xText, uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xContentEnum = xContentEnumAccess->createEnumeration();
+ uno::Reference<text::XTextRange> xContent(xContentEnum->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("test"), xContent->getString());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */