summaryrefslogtreecommitdiff
path: root/xmloff/qa/unit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-07-23 13:41:27 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-07-23 14:34:35 +0200
commitee3d408fd6c909556d1671d28591cde4c0122979 (patch)
treefbd524a11840527aa461899b511a7a9046a1d4b0 /xmloff/qa/unit
parentdaffec714ef28f52ae2d70e5553500046b8b26c2 (diff)
sw bibliography, local copy: add ODF filter
Map it to <text:bibliography-mark loext:local-url="...">. Note how this can be a relative URL, while the text:url attribute is typically a http(s) URL. Change-Id: If16171c9761221841ff07824cb0466fd42911480 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119407 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff/qa/unit')
-rw-r--r--xmloff/qa/unit/text.cxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index d3b1fcc84a2c..22d1d3c15fcf 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -14,8 +14,11 @@
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/BibliographyDataType.hpp>
#include <comphelper/propertysequence.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <comphelper/sequenceashashmap.hxx>
#include <unotools/tempfile.hxx>
using namespace ::com::sun::star;
@@ -99,6 +102,57 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentResolved)
CPPUNIT_ASSERT(bResolved);
}
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testBibliographyLocalUrl)
+{
+ // Given a document with a biblio field, with non-empty LocalURL:
+ getComponent() = loadFromDesktop("private:factory/swriter");
+ uno::Reference<lang::XMultiServiceFactory> xFactory(getComponent(), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xField(
+ xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aFields = {
+ comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW),
+ comphelper::makePropertyValue("Identifier", OUString("AT")),
+ comphelper::makePropertyValue("Author", OUString("Author")),
+ comphelper::makePropertyValue("Title", OUString("Title")),
+ comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")),
+ comphelper::makePropertyValue("LocalURL", OUString("file:///home/me/test.pdf")),
+ };
+ xField->setPropertyValue("Fields", uno::makeAny(aFields));
+ uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+ uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY);
+ xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false);
+
+ // When invoking ODT export + import on it:
+ uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProps = {
+ comphelper::makePropertyValue("FilterName", OUString("writer8")),
+ };
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ // Without the accompanying fix in place, this test would have resulted in an assertion failure,
+ // as LocalURL was mapped to XML_TOKEN_INVALID.
+ xStorable->storeToURL(aTempFile.GetURL(), aStoreProps);
+ getComponent()->dispose();
+ validate(aTempFile.GetFileName(), test::ODF);
+ getComponent() = loadFromDesktop(aTempFile.GetURL());
+
+ // Then make sure that LocalURL is preserved:
+ xTextDocument.set(getComponent(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xPortionEnum = xPara->createEnumeration();
+ uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY);
+ xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY);
+ comphelper::SequenceAsHashMap aMap(xField->getPropertyValue("Fields"));
+ CPPUNIT_ASSERT(aMap.find("LocalURL") != aMap.end());
+ auto aActual = aMap["LocalURL"].get<OUString>();
+ CPPUNIT_ASSERT_EQUAL(OUString("file:///home/me/test.pdf"), aActual);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */