parsertest.cpp 3.5 KB
Newer Older
Volker Krause's avatar
Volker Krause committed
1
2
/*
    Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3
    Copyright (c) 2015 Andreas Cord-Landwehr <cordlandwehr@kde.org>
Volker Krause's avatar
Volker Krause committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#include "parsertest.h"

#include "config-ktnef-tests.h"

Laurent Montel's avatar
Laurent Montel committed
25
26
27
#include <ktnef/ktnefparser.h>
#include <ktnef/ktnefmessage.h>
#include <ktnef/ktnefattach.h>
Volker Krause's avatar
Volker Krause committed
28

29
#include <QString>
30
#include <QTest>
Volker Krause's avatar
Volker Krause committed
31
32
33

using namespace KTnef;

Laurent Montel's avatar
Laurent Montel committed
34
QTEST_GUILESS_MAIN(ParserTest)
Volker Krause's avatar
Volker Krause committed
35
36
37

void ParserTest::testSingleAttachment()
{
Laurent Montel's avatar
Laurent Montel committed
38
39
    KTNEFParser parser;
    QVERIFY(parser.openFile(QString(QLatin1String(TESTSOURCEDIR) + QLatin1String("one-file.tnef"))) == true);
Volker Krause's avatar
Volker Krause committed
40

Laurent Montel's avatar
Laurent Montel committed
41
    KTNEFMessage *msg = parser.message();
Laurent Montel's avatar
Laurent Montel committed
42
    QVERIFY(msg != nullptr);
Volker Krause's avatar
Volker Krause committed
43

Laurent Montel's avatar
Laurent Montel committed
44
45
    QList<KTNEFAttach *> atts = msg->attachmentList();
    QVERIFY(atts.count() == 1);
Volker Krause's avatar
Volker Krause committed
46

Laurent Montel's avatar
Laurent Montel committed
47
    KTNEFAttach *att = atts.first();
Laurent Montel's avatar
Laurent Montel committed
48
    QVERIFY(att != nullptr);
Laurent Montel's avatar
Laurent Montel committed
49
50
    QVERIFY(att->size() == 244);
    QVERIFY(att->name() == QLatin1String("AUTHORS"));
Volker Krause's avatar
Volker Krause committed
51
52
53
54
}

void ParserTest::testTwoAttachments()
{
Laurent Montel's avatar
Laurent Montel committed
55
56
    KTNEFParser parser;
    QVERIFY(parser.openFile(QString(QLatin1String(TESTSOURCEDIR) + QLatin1String("two-files.tnef"))) == true);
Volker Krause's avatar
Volker Krause committed
57

Laurent Montel's avatar
Laurent Montel committed
58
    KTNEFMessage *msg = parser.message();
Laurent Montel's avatar
Laurent Montel committed
59
    QVERIFY(msg != nullptr);
Volker Krause's avatar
Volker Krause committed
60

Laurent Montel's avatar
Laurent Montel committed
61
62
    QList<KTNEFAttach *> atts = msg->attachmentList();
    QVERIFY(atts.count() == 2);
Volker Krause's avatar
Volker Krause committed
63

Laurent Montel's avatar
Laurent Montel committed
64
    KTNEFAttach *att = atts.takeFirst();
Laurent Montel's avatar
Laurent Montel committed
65
    QVERIFY(att != nullptr);
Laurent Montel's avatar
Laurent Montel committed
66
67
    QVERIFY(att->size() == 244);
    QVERIFY(att->name() == QLatin1String("AUTHORS"));
Volker Krause's avatar
Volker Krause committed
68

Laurent Montel's avatar
Laurent Montel committed
69
    att = atts.takeFirst();
Laurent Montel's avatar
Laurent Montel committed
70
    QVERIFY(att != nullptr);
Laurent Montel's avatar
Laurent Montel committed
71
72
    QVERIFY(att->size() == 893);
    QVERIFY(att->name() == QLatin1String("README"));
Volker Krause's avatar
Volker Krause committed
73
74
75
76
}

void ParserTest::testMAPIAttachments()
{
Laurent Montel's avatar
Laurent Montel committed
77
78
    KTNEFParser parser;
    QVERIFY(parser.openFile(QString(QLatin1String(TESTSOURCEDIR) + QLatin1String("mapi_attach_data_obj.tnef"))) == true);
Volker Krause's avatar
Volker Krause committed
79

Laurent Montel's avatar
Laurent Montel committed
80
    KTNEFMessage *msg = parser.message();
Laurent Montel's avatar
Laurent Montel committed
81
    QVERIFY(msg != nullptr);
Volker Krause's avatar
Volker Krause committed
82

Laurent Montel's avatar
Laurent Montel committed
83
84
    QList<KTNEFAttach *> atts = msg->attachmentList();
    QVERIFY(atts.count() == 3);
Volker Krause's avatar
Volker Krause committed
85

Laurent Montel's avatar
Laurent Montel committed
86
    KTNEFAttach *att = atts.takeFirst();
Laurent Montel's avatar
Laurent Montel committed
87
    QVERIFY(att != nullptr);
Laurent Montel's avatar
Laurent Montel committed
88
89
    QVERIFY(att->size() == 61952);
    QVERIFY(att->name() == QLatin1String("VIA_Nytt_1402.doc"));
Volker Krause's avatar
Volker Krause committed
90

Laurent Montel's avatar
Laurent Montel committed
91
    att = atts.takeFirst();
Laurent Montel's avatar
Laurent Montel committed
92
    QVERIFY(att != nullptr);
Laurent Montel's avatar
Laurent Montel committed
93
94
    QVERIFY(att->size() == 213688);
    QVERIFY(att->name() == QLatin1String("VIA_Nytt_1402.pdf"));
Volker Krause's avatar
Volker Krause committed
95

Laurent Montel's avatar
Laurent Montel committed
96
    att = atts.takeFirst();
Laurent Montel's avatar
Laurent Montel committed
97
    QVERIFY(att != nullptr);
Laurent Montel's avatar
Laurent Montel committed
98
99
    QVERIFY(att->size() == 68920);
    QVERIFY(att->name() == QLatin1String("VIA_Nytt_14021.htm"));
Volker Krause's avatar
Volker Krause committed
100
}
101
102
103
104
105
106
107

void ParserTest::testUmlautAttachmentFilenames()
{
    KTNEFParser parser;
    QVERIFY(parser.openFile(QString(QLatin1String(TESTSOURCEDIR) + QLatin1String("umlaut-filename.tnef"))) == true);

    KTNEFMessage *msg = parser.message();
Laurent Montel's avatar
Laurent Montel committed
108
    QVERIFY(msg != nullptr);
109
110
111
112
113
114
115
116

    QList<KTNEFAttach*> atts = msg->attachmentList();
    QVERIFY(atts.count() == 1);

    KTNEFAttach *att = atts.first();
    QCOMPARE(att->fileName(), QString::fromUtf8("döcument.pdf"));
}