blob: ab1ca51c855b1a2b8773251866513a401bb39956 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/* -*- 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 <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/implbase.hxx>
#include <test/bootstrapfixture.hxx>
#include <unotest/macros_test.hxx>
#include <unotools/mediadescriptor.hxx>
#include <unotools/tempfile.hxx>
using namespace ::com::sun::star;
namespace
{
char const DATA_DIRECTORY[] = "/writerperfect/qa/unit/data/writer/epubexport/";
/// Tests the EPUB export filter.
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();
};
void EPUBExportTest::setUp()
{
test::BootstrapFixture::setUp();
mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
mxDesktop.set(frame::Desktop::create(mxComponentContext));
}
void EPUBExportTest::tearDown()
{
if (mxComponent.is())
mxComponent->dispose();
test::BootstrapFixture::tearDown();
}
void EPUBExportTest::createDoc(const OUString &rFile)
{
// Import the bugdoc and export as EPUB.
OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFile;
mxComponent = loadFromDesktop(aURL);
CPPUNIT_ASSERT(mxComponent.is());
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
maTempFile.EnableKillingFile();
utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor["FilterName"] <<= OUString("EPUB");
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, 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);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|