summaryrefslogtreecommitdiff
path: root/sw/qa/extras/pdf/HybridPdfTest.cxx
blob: 0ec4e7ae385b8f2133ca40a7d8fa5b39aedd8373 (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
/* -*- 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 <swmodeltestbase.hxx>
#include <docsh.hxx>
#include <unotxdoc.hxx>

namespace
{
class HybridPdfTest : public SwModelTestBase
{
public:
    HybridPdfTest()
        : SwModelTestBase(u"/sw/qa/extras/pdf/data/"_ustr)
    {
    }

    void testNoHybridDataInPDF();
    void testHybridWithAdditionalStreams();
    void testHybridWithAdditionalStreamsAndAttachedFile();

    CPPUNIT_TEST_SUITE(HybridPdfTest);
    CPPUNIT_TEST(testNoHybridDataInPDF);
    CPPUNIT_TEST(testHybridWithAdditionalStreams);
    CPPUNIT_TEST(testHybridWithAdditionalStreamsAndAttachedFile);
    CPPUNIT_TEST_SUITE_END();
};

void HybridPdfTest::testNoHybridDataInPDF()
{
    // Load PDF document without attached ODT document
    loadFromFile(u"PDFOnly.pdf");
    uno::Reference<lang::XServiceInfo> xServiceInfo(mxComponent, uno::UNO_QUERY_THROW);
    // Draw document is expected in this case - default when importing PDF
    CPPUNIT_ASSERT(xServiceInfo->supportsService(u"com.sun.star.drawing.DrawingDocument"_ustr));
}

void HybridPdfTest::testHybridWithAdditionalStreams()
{
    // Load PDF document with an embedded ODT document
    // The ODT document is embedded in "/AdditionalStreams" structure that is in the PDF trailer
    createSwDoc("Hybrid_AdditionalStreamsOnly.pdf");

    // We can access the document text in a single paragraph that spans multiple rows
    // This wouldn't be possible with a PDF, so the opened document has to be ODT
    CPPUNIT_ASSERT_EQUAL(u"He heard quiet steps behind him. \nThat didn't bode well."_ustr,
                         getParagraph(1)->getString());
}

void HybridPdfTest::testHybridWithAdditionalStreamsAndAttachedFile()
{
    // Load PDF document with an embedded ODT document
    // The ODT document is embedded in "/AdditionalStreams" structure that is in the PDF trailer
    // and is included as an attached file conforming to the PDF specs
    createSwDoc("Hybrid_AdditionalStreamsAndPDFAttachedFile.pdf");

    // We can access the document text in a single paragraph that spans multiple rows
    // This wouldn't be possible with a PDF, so the opened document has to be ODT
    CPPUNIT_ASSERT_EQUAL(u"He heard quiet steps behind him. \nThat didn't bode well."_ustr,
                         getParagraph(1)->getString());
}

} // end of anonymous namespace
CPPUNIT_TEST_SUITE_REGISTRATION(HybridPdfTest);
CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */