testidxreader.cpp 3.15 KB
Newer Older
1
2
/*
 *   Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com>
Casey Link's avatar
Casey Link committed
3
 *   Copyright (c) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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 General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "testidxreader.h"

#include "../kmindexreader.h"

25
26
#include "TestIdxReader_data.h"

27
28
#include <akonadi/kmime/messagestatus.h>
using Akonadi::MessageStatus;
29
30
31
32
33
34
#include <QTemporaryFile>

#include <qtest_kde.h>
#include <QtTest/QTest>
#include <QDebug>

35
36
#include <boost/shared_ptr.hpp>

Casey Link's avatar
Casey Link committed
37
QTEST_MAIN ( TestIdxReader )
38
39


Casey Link's avatar
Casey Link committed
40
TestIdxReader::TestIdxReader() {
41
42
}

Casey Link's avatar
Casey Link committed
43
44
void TestIdxReader::testError() {
    KMIndexReader reader ( "IDoNotExist" );
Casey Link's avatar
Casey Link committed
45

Casey Link's avatar
Casey Link committed
46
    QVERIFY ( reader.error() == true );
47
48
}

Casey Link's avatar
Casey Link committed
49
50
51
52
53
54
55
56
57
void TestIdxReader::testReadHeader() {
    QTemporaryFile tmp;
    if ( !tmp.open() ) {
        qDebug() << "Could not open temp file.";
        return;
    }
    tmp.write ( QByteArray::fromBase64 ( mailDirOneEmail ) );
    tmp.close();
    KMIndexReader reader ( tmp.fileName() );
Casey Link's avatar
Casey Link committed
58

Casey Link's avatar
Casey Link committed
59
    QVERIFY ( reader.error() == false );
Casey Link's avatar
Casey Link committed
60

Casey Link's avatar
Casey Link committed
61
62
    int version = 0;
    bool success = reader.readHeader ( &version );
Casey Link's avatar
Casey Link committed
63

Casey Link's avatar
Casey Link committed
64
65
    QVERIFY ( success == true );
    QCOMPARE ( version, 1506 );
Casey Link's avatar
Casey Link committed
66

Casey Link's avatar
Casey Link committed
67
    QVERIFY ( reader.error() == false );
68
}
69

Casey Link's avatar
Casey Link committed
70
71
72
73
74
75
void TestIdxReader::testRead() {
    QTemporaryFile tmp;
    if ( !tmp.open() ) {
        qDebug() << "Could not open temp file.";
        return;
    }
Casey Link's avatar
Casey Link committed
76
    tmp.write ( QByteArray::fromBase64 ( mailDirTwoEmailOneTagFlags ) );
Casey Link's avatar
Casey Link committed
77
78
79
80
81
82
83
84
    tmp.close();
    KMIndexReader reader ( tmp.fileName() );
    QVERIFY ( reader.error() == false );
    bool success = reader.readIndex();
    QVERIFY ( success == true );

    QVERIFY ( reader.messages().size() == 2 );

85
    KMIndexDataPtr msg = reader.messages().front();
Casey Link's avatar
Casey Link committed
86
87
88
89
90
91
92
93

    QString subject = msg->mCachedStringParts[KMIndexReader::MsgSubjectPart];
    MessageStatus status;
    status.fromQInt32 ( msg->mCachedLongParts[KMIndexReader::MsgStatusPart] );
    QCOMPARE ( subject, QString ( "hello from kmail" ) );
    QVERIFY ( !status.isImportant() );
    QVERIFY ( !msg->status().isImportant() );
    QVERIFY ( msg->status().isRead() );
94
    QVERIFY ( msg->tagList().contains("N5tUHPOZFf") );
Casey Link's avatar
Casey Link committed
95
96
97
98
99
100
101

    msg = reader.messages().back();
    status.fromQInt32 ( msg->mCachedLongParts[KMIndexReader::MsgStatusPart] );
    subject = msg->mCachedStringParts[KMIndexReader::MsgSubjectPart];
    QCOMPARE ( subject, QString ( "foo bar" ) );
    QVERIFY ( status.isImportant() );
    QVERIFY ( msg->status().isImportant() );
102
    QVERIFY ( !msg->status().isRead() );
103
    QVERIFY ( msg->tagList().size() == 0 );
104
105
}