summaryrefslogtreecommitdiff
path: root/Build/source/libs/poppler/poppler-0.12.4/qt4/tests/check_links.cpp
blob: 2f69a828df85e28cd55ff1095413da94f4494472 (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
#include <QtTest/QtTest>

#include <poppler-qt4.h>

#include <memory>

class TestLinks : public QObject
{
    Q_OBJECT
private slots:
    void checkDocumentWithNoDests();
    void checkDests_xr01();
    void checkDests_xr02();
};

bool isDestinationValid_pageNumber( const Poppler::LinkDestination *dest, const Poppler::Document *doc )
{
    return dest->pageNumber() > 0 && dest->pageNumber() <= doc->numPages();
}

bool isDestinationValid_name( const Poppler::LinkDestination *dest )
{
    return !dest->destinationName().isEmpty();
}


void TestLinks::checkDocumentWithNoDests()
{
    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/WithAttachments.pdf");
    QVERIFY( doc );

    std::auto_ptr< Poppler::LinkDestination > dest;
    dest.reset( doc->linkDestination("no.dests.in.this.document") );
    QVERIFY( !isDestinationValid_pageNumber( dest.get(), doc ) );
    QVERIFY( isDestinationValid_name( dest.get() ) );

    delete doc;
}

void TestLinks::checkDests_xr01()
{
    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/xr01.pdf");
    QVERIFY( doc );

    Poppler::Page *page = doc->page(0);
    QVERIFY( page );

    QList< Poppler::Link* > links = page->links();
    QCOMPARE( links.count(), 2 );

    {
    QCOMPARE( links.at(0)->linkType(), Poppler::Link::Goto );
    Poppler::LinkGoto *link = static_cast< Poppler::LinkGoto * >( links.at(0) );
    const Poppler::LinkDestination dest = link->destination();
    QVERIFY( !isDestinationValid_pageNumber( &dest, doc ) );
    QVERIFY( isDestinationValid_name( &dest ) );
    QCOMPARE( dest.destinationName(), QString::fromLatin1("section.1") );
    }

    {
    QCOMPARE( links.at(1)->linkType(), Poppler::Link::Goto );
    Poppler::LinkGoto *link = static_cast< Poppler::LinkGoto * >( links.at(1) );
    const Poppler::LinkDestination dest = link->destination();
    QVERIFY( !isDestinationValid_pageNumber( &dest, doc ) );
    QVERIFY( isDestinationValid_name( &dest ) );
    QCOMPARE( dest.destinationName(), QString::fromLatin1("section.2") );
    }

    delete doc;
}

void TestLinks::checkDests_xr02()
{
    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/xr02.pdf");
    QVERIFY( doc );

    std::auto_ptr< Poppler::LinkDestination > dest;
    dest.reset( doc->linkDestination("section.1") );
    QVERIFY( isDestinationValid_pageNumber( dest.get(), doc ) );
    QVERIFY( !isDestinationValid_name( dest.get() ) );
    dest.reset( doc->linkDestination("section.2") );
    QVERIFY( isDestinationValid_pageNumber( dest.get(), doc ) );
    QVERIFY( !isDestinationValid_name( dest.get() ) );
    dest.reset( doc->linkDestination("section.3") );
    QVERIFY( !isDestinationValid_pageNumber( dest.get(), doc ) );
    QVERIFY( isDestinationValid_name( dest.get() ) );

    delete doc;
}

QTEST_MAIN(TestLinks)

#include "check_links.moc"