summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-10-24 13:42:27 +0200
committerMichael Stahl <mstahl@redhat.com>2017-10-24 13:48:58 +0200
commitf7115dc7efe7c9179a154bcda169cffe51c0bc21 (patch)
tree757caad725cb97f59aaae4b1e362ef7b401efcd1 /sfx2
parent26221dea6b05272ac6951462e9b36e27a64b1690 (diff)
sfx2: finally resolve FIXME and test custom metadata
Yay, we have assertXPath now! Change-Id: I74dedf535f5f0997dc94b3654558ccd451db813a
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/CppunitTest_sfx2_misc.mk41
-rw-r--r--sfx2/Module_sfx2.mk1
-rw-r--r--sfx2/qa/complex/sfx2/DocumentProperties.java13
-rw-r--r--sfx2/qa/cppunit/test_misc.cxx96
4 files changed, 138 insertions, 13 deletions
diff --git a/sfx2/CppunitTest_sfx2_misc.mk b/sfx2/CppunitTest_sfx2_misc.mk
new file mode 100644
index 000000000000..0919d525d3d5
--- /dev/null
+++ b/sfx2/CppunitTest_sfx2_misc.mk
@@ -0,0 +1,41 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,sfx2_misc))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sfx2_misc, \
+ sfx2/qa/cppunit/test_misc \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sfx2_misc))
+
+$(eval $(call gb_CppunitTest_use_libraries,sfx2_misc, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ test \
+ unotest \
+ vcl \
+ sal \
+ sfx \
+ utl \
+))
+
+$(eval $(call gb_CppunitTest_use_external,sfx2_misc,libxml2))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sfx2_misc))
+
+$(eval $(call gb_CppunitTest_use_ure,sfx2_misc))
+$(eval $(call gb_CppunitTest_use_vcl,sfx2_misc))
+
+$(eval $(call gb_CppunitTest_use_rdb,sfx2_misc,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sfx2_misc))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sfx2/Module_sfx2.mk b/sfx2/Module_sfx2.mk
index c547fc19072a..89b5aa419aa8 100644
--- a/sfx2/Module_sfx2.mk
+++ b/sfx2/Module_sfx2.mk
@@ -33,6 +33,7 @@ $(eval $(call gb_Module_add_l10n_targets,sfx2,\
$(eval $(call gb_Module_add_check_targets,sfx2,\
CppunitTest_sfx2_metadatable \
+ CppunitTest_sfx2_misc \
CppunitTest_sfx2_controlleritem \
CppunitTest_sfx2_classification \
))
diff --git a/sfx2/qa/complex/sfx2/DocumentProperties.java b/sfx2/qa/complex/sfx2/DocumentProperties.java
index 0d21cdb15e35..c5f84b1b79de 100644
--- a/sfx2/qa/complex/sfx2/DocumentProperties.java
+++ b/sfx2/qa/complex/sfx2/DocumentProperties.java
@@ -137,19 +137,6 @@ public class DocumentProperties
System.out.println("...done");
- System.out.println("(Not) Checking preservation of custom meta data ...");
-
- xDP2.loadFromMedium(TestDocument.getUrl("CUSTOM.odt"),
- noArgs);
- assertEquals("Author", "", xDP2.getAuthor());
- xDP2.storeToMedium(temp + "CUSTOM.odt", mimeArgs);
-
- //FIXME: now what? comparing for binary equality seems useless
- // we could unzip the written file and grep for the custom stuff
- // but would that work on windows...
-
- System.out.println("...done");
-
System.out.println("Checking loading from test document...");
String file = TestDocument.getUrl("TEST.odt");
diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx
new file mode 100644
index 000000000000..e3cbd8d4748c
--- /dev/null
+++ b/sfx2/qa/cppunit/test_misc.cxx
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/types.h>
+
+#include <memory>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <com/sun/star/beans/PropertyState.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/document/DocumentProperties.hpp>
+#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
+
+#include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
+
+#include <unotools/ucbstreamhelper.hxx>
+
+
+using namespace ::com::sun::star;
+
+
+namespace {
+
+class MiscTest
+ : public test::BootstrapFixture
+ , public XmlTestTools
+{
+public:
+ void testODFCustomMetadata();
+
+ virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override
+ {
+ // ODF
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("office"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:office:1.0"));
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("meta"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:meta:1.0"));
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dc"), BAD_CAST("http://purl.org/dc/elements/1.1/"));
+ // used in testCustomMetadata
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("foo"), BAD_CAST("http://foo.net"));
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("baz"), BAD_CAST("http://baz.net"));
+ }
+
+ CPPUNIT_TEST_SUITE(MiscTest);
+ CPPUNIT_TEST(testODFCustomMetadata);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+};
+
+void MiscTest::testODFCustomMetadata()
+{
+ uno::Reference<document::XDocumentProperties> const xProps(
+ ::com::sun::star::document::DocumentProperties::create(m_xContext));
+
+ OUString const url(m_directories.getURLFromSrc("/sfx2/qa/complex/sfx2/testdocuments/CUSTOM.odt"));
+ xProps->loadFromMedium(url, uno::Sequence<beans::PropertyValue>());
+ CPPUNIT_ASSERT_EQUAL(OUString(""), xProps->getAuthor());
+ uno::Sequence<beans::PropertyValue> mimeArgs({
+ beans::PropertyValue("MediaType", -1, uno::Any(OUString("application/vnd.oasis.opendocument.text")), beans::PropertyState_DIRECT_VALUE)
+ });
+ utl::TempFile aTempFile;
+ xProps->storeToMedium(aTempFile.GetURL(), mimeArgs);
+
+ // check that custom metadata is preserved
+ uno::Reference<packages::zip::XZipFileAccess2> const xZip(
+ packages::zip::ZipFileAccess::createWithURL(m_xContext, aTempFile.GetURL()));
+ uno::Reference<io::XInputStream> const xInputStream(xZip->getByName("meta.xml"), uno::UNO_QUERY);
+ std::shared_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
+ xmlDocPtr pXmlDoc = parseXmlStream(pStream.get());
+ assertXPathContent(pXmlDoc, "/office:document-meta/office:meta/bork", "bork");
+ assertXPath(pXmlDoc, "/office:document-meta/office:meta/foo:bar", 1);
+ assertXPath(pXmlDoc, "/office:document-meta/office:meta/foo:bar/baz:foo", 1);
+ assertXPath(pXmlDoc, "/office:document-meta/office:meta/foo:bar/baz:foo[@baz:bar='foo']");
+ assertXPathContent(pXmlDoc, "/office:document-meta/office:meta/foo:bar/foo:baz", "bar");
+
+ aTempFile.EnableKillingFile();
+}
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MiscTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */