summaryrefslogtreecommitdiff
path: root/xmloff/qa/unit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-04-11 11:27:13 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-04-22 14:58:44 +0200
commit1790cc337fc1b72eab5e6254baf7030b51c6c875 (patch)
treefa2ed9ba623629d24c19df89d04ea0a046581f22 /xmloff/qa/unit
parent4e31fc026cdd841c8ab263a81cdb9a163f4db4d8 (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. (cherry picked from commit d1649e5d38b51cd422302e566719a2c5aff42b2f) Change-Id: I9a915868160ebcc0e98ded61bfab72f32864bd76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133316 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff/qa/unit')
-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 5e5f24b64975..9ab19785028f 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -352,6 +352,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: */