diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-24 18:08:11 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-25 09:23:13 +0200 |
commit | 8d411f38badc7adc61fdfc5c08fdbda247bce37a (patch) | |
tree | b79afd41e8bd6b584f2eaf24228c721d5388d693 /writerperfect | |
parent | 2ea022ec2101703a7034dbb640553165eb0ff224 (diff) |
EPUB export: make sure that the mimetype stream is not compressed
Similar to ODF, the spec mandates this, and recent enough epubcheck
validator asserts this.
Also backport 2 libepubgen commits that fix other validator errors
around missing mimetypes / malformed URLs.
Change-Id: I29f0524465a30d26585cea92ec27bd336f6a17d8
Reviewed-on: https://gerrit.libreoffice.org/41526
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/qa/unit/EPUBExportTest.cxx | 36 | ||||
-rw-r--r-- | writerperfect/qa/unit/data/writer/epubexport/hello.fodt | 8 | ||||
-rw-r--r-- | writerperfect/source/writer/EPUBPackage.cxx | 5 |
3 files changed, 43 insertions, 6 deletions
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index ef65012daca9..ab1ca51c855b 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -30,14 +30,18 @@ class EPUBExportTest : public test::BootstrapFixture, public unotest::MacrosTest { uno::Reference<uno::XComponentContext> mxComponentContext; uno::Reference<lang::XComponent> mxComponent; + utl::TempFile maTempFile; public: virtual void setUp() override; virtual void tearDown() override; + void createDoc(const OUString &rFile); void testOutlineLevel(); + void testMimetype(); CPPUNIT_TEST_SUITE(EPUBExportTest); CPPUNIT_TEST(testOutlineLevel); + CPPUNIT_TEST(testMimetype); CPPUNIT_TEST_SUITE_END(); }; @@ -57,28 +61,48 @@ void EPUBExportTest::tearDown() test::BootstrapFixture::tearDown(); } -void EPUBExportTest::testOutlineLevel() +void EPUBExportTest::createDoc(const OUString &rFile) { // Import the bugdoc and export as EPUB. - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "outline-level.fodt"; + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFile; mxComponent = loadFromDesktop(aURL); CPPUNIT_ASSERT(mxComponent.is()); uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - utl::TempFile aTempFile; - aTempFile.EnableKillingFile(); + maTempFile.EnableKillingFile(); utl::MediaDescriptor aMediaDescriptor; aMediaDescriptor["FilterName"] <<= OUString("EPUB"); - xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); +} + +void EPUBExportTest::testOutlineLevel() +{ + createDoc("outline-level.fodt"); // Make sure that the output is split into two. - uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL()); + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, maTempFile.GetURL()); CPPUNIT_ASSERT(xNameAccess->hasByName("OEBPS/sections/section0001.xhtml")); // This failed, output was a single section. CPPUNIT_ASSERT(xNameAccess->hasByName("OEBPS/sections/section0002.xhtml")); CPPUNIT_ASSERT(!xNameAccess->hasByName("OEBPS/sections/section0003.xhtml")); } +void EPUBExportTest::testMimetype() +{ + createDoc("hello.fodt"); + + // Check that the mime type is written uncompressed at the expected location. + SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ); + SvMemoryStream aMemoryStream; + aMemoryStream.WriteStream(aFileStream); + OString aExpected("application/epub+zip"); + CPPUNIT_ASSERT(aMemoryStream.GetSize() > static_cast<sal_uInt64>(38 + aExpected.getLength())); + + OString aActual(static_cast<const char *>(aMemoryStream.GetBuffer()) + 38, aExpected.getLength()); + // This failed: actual data was some garbage, not the uncompressed mime type. + CPPUNIT_ASSERT_EQUAL(aExpected, aActual); +} + CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest); } diff --git a/writerperfect/qa/unit/data/writer/epubexport/hello.fodt b/writerperfect/qa/unit/data/writer/epubexport/hello.fodt new file mode 100644 index 000000000000..b245e9d7abce --- /dev/null +++ b/writerperfect/qa/unit/data/writer/epubexport/hello.fodt @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document office:mimetype="application/vnd.oasis.opendocument.text" office:version="1.2" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"> + <office:body> + <office:text> + <text:p><text:span>Hello world!</text:span></text:p> + </office:text> + </office:body> +</office:document> diff --git a/writerperfect/source/writer/EPUBPackage.cxx b/writerperfect/source/writer/EPUBPackage.cxx index 3a33dedac3eb..0e34400171da 100644 --- a/writerperfect/source/writer/EPUBPackage.cxx +++ b/writerperfect/source/writer/EPUBPackage.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/xml/sax/Writer.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <comphelper/storagehelper.hxx> #include <unotools/mediadescriptor.hxx> @@ -39,6 +40,10 @@ EPUBPackage::EPUBPackage(const uno::Reference<uno::XComponentContext> &xContext, mxOutputStream->writeBytes(aData); uno::Reference<embed::XTransactedObject> xTransactedObject(mxOutputStream, uno::UNO_QUERY); xTransactedObject->commit(); + + // MIME type must be uncompressed. + uno::Reference<beans::XPropertySet> xPropertySet(mxOutputStream, uno::UNO_QUERY); + xPropertySet->setPropertyValue("Compressed", uno::makeAny(false)); mxOutputStream.clear(); } |