summaryrefslogtreecommitdiff
path: root/qt4/tests/check_attachments.cpp
blob: 537598c9be834aeb74bc54c9621cfee1c1e29e0d (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <QtTest/QtTest>

#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>

#include <QtCore/QFile>

class TestAttachments: public QObject
{
    Q_OBJECT
private slots:
    void checkNoAttachments();
    void checkAttach1();
    void checkAttach2();
    void checkAttach3();
    void checkAttach4();
};

void TestAttachments::checkNoAttachments()
{
    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/truetype.pdf");
    QVERIFY( doc );

    QCOMPARE( doc->hasEmbeddedFiles(), false );

    delete doc;
}

void TestAttachments::checkAttach1()
{

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

    QVERIFY( doc->hasEmbeddedFiles() );

    QList<Poppler::EmbeddedFile*> fileList = doc->embeddedFiles();
    QCOMPARE( fileList.size(), 2 );

    Poppler::EmbeddedFile *embfile = fileList.at(0);
    QCOMPARE( embfile->name(), QString( "kroller.png" ) );
    QCOMPARE( embfile->description(), QString("/home/bradh/coding/svn-vers/KDE/kdeartwork/wallpapers/kroller.png") );
    QCOMPARE( embfile->createDate(), QDateTime( QDate(), QTime() ) );
    QCOMPARE( embfile->modDate(), QDateTime( QDate(), QTime() ) );

    QFile file( "../../../test/unittestcases/kroller.png" );
    QVERIFY(  file.open( QIODevice::ReadOnly ) );
    QByteArray krollerData = file.readAll();
    QByteArray embdata = embfile->data();
    QCOMPARE( krollerData, embdata );
	    

    Poppler::EmbeddedFile *embfile2 = fileList.at(1);
    QCOMPARE( embfile2->name(), QString("gnome-64.gif") );
    QCOMPARE( embfile2->description(), QString("/usr/share/gnome-about/gnome-64.gif") );
    QCOMPARE( embfile2->modDate(), QDateTime( QDate(), QTime() ) );
    QCOMPARE( embfile2->createDate(), QDateTime( QDate(), QTime() ) );

    QFile file2( "../../../test/unittestcases/gnome-64.gif" );
    QVERIFY(  file2.open( QIODevice::ReadOnly ) );
    QByteArray g64Data = file2.readAll();
    QByteArray emb2data = embfile2->data();
    QCOMPARE( g64Data, emb2data );

    delete doc;
}


void TestAttachments::checkAttach2()
{

    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/A6EmbeddedFiles.pdf");
    QVERIFY( doc );

    QVERIFY( doc->hasEmbeddedFiles() );

    QList<Poppler::EmbeddedFile*> fileList;
    fileList = doc->embeddedFiles();
    QCOMPARE( fileList.size(), 3 );

    Poppler::EmbeddedFile *embfile1 = fileList.at(0);
    QCOMPARE( embfile1->name(), QString("Acro7 thoughts") );
    QCOMPARE( embfile1->description(), QString("Acro7 Thoughts") );
    QCOMPARE( embfile1->createDate(), QDateTime( QDate( 2003, 8, 4 ), QTime( 13, 54, 54), Qt::UTC ) );
    QCOMPARE( embfile1->modDate(), QDateTime( QDate( 2003, 8, 4 ), QTime( 14, 15, 27), Qt::UTC ) );

    Poppler::EmbeddedFile *embfile2 = fileList.at(1);
    QCOMPARE( embfile2->name(), QString("acro transitions 1.xls") );
    QCOMPARE( embfile2->description(), QString("AcroTransitions") );
    QCOMPARE( embfile2->createDate(), QDateTime( QDate( 2003, 7, 18 ), QTime( 21, 7, 16), Qt::UTC ) );
    QCOMPARE( embfile2->modDate(), QDateTime( QDate( 2003, 7, 22 ), QTime( 13, 4, 40), Qt::UTC ) );

    Poppler::EmbeddedFile *embfile3 = fileList.at(2);
    QCOMPARE( embfile3->name(), QString("apago_pdfe_wide.gif") );
    QCOMPARE( embfile3->description(), QString("PDFE Animation") );
    QCOMPARE( embfile3->createDate(), QDateTime( QDate( 2003, 1, 31 ), QTime( 15, 54, 29), Qt::UTC ) );
    QCOMPARE( embfile3->modDate(), QDateTime( QDate( 2003, 1, 31 ), QTime( 15, 52, 58), Qt::UTC ) );

    delete doc;
}

void TestAttachments::checkAttach3()
{

    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/shapes+attachments.pdf");
    QVERIFY( doc );

    QVERIFY( doc->hasEmbeddedFiles() );

    QList<Poppler::EmbeddedFile*> fileList;
    fileList = doc->embeddedFiles();
    QCOMPARE( fileList.size(), 1 );

    Poppler::EmbeddedFile *embfile = fileList.at(0);
    QCOMPARE( embfile->name(), QString( "ADEX1.xpdf.pgp" ) );
    QCOMPARE( embfile->description(), QString("encrypted version of document") );
    QCOMPARE( embfile->createDate(), QDateTime( QDate( 2004, 3, 29 ), QTime( 19, 37, 16), Qt::UTC ) );
    QCOMPARE( embfile->modDate(), QDateTime( QDate( 2004, 3, 29 ), QTime( 19, 37, 16), Qt::UTC ) );
    delete doc;

}

void TestAttachments::checkAttach4()
{

    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/imageretrieve+attachment.pdf");
    QVERIFY( doc );

    QVERIFY( doc->hasEmbeddedFiles() );

    QList<Poppler::EmbeddedFile*> fileList;
    fileList = doc->embeddedFiles();
    QCOMPARE( fileList.size(), 1 );

    Poppler::EmbeddedFile *embfile = fileList.at(0);
    QCOMPARE( embfile->name(), QString( "export-altona.csv" ) );
    QCOMPARE( embfile->description(), QString("Altona Export") );
    QCOMPARE( embfile->createDate(), QDateTime( QDate( 2005, 8, 30 ), QTime( 20, 49, 35), Qt::UTC ) );
    QCOMPARE( embfile->modDate(), QDateTime( QDate( 2005, 8, 30 ), QTime( 20, 49, 52), Qt::UTC ) );
    delete doc;

}

QTEST_MAIN(TestAttachments)
#include "check_attachments.moc"