File indexing completed on 2024-12-22 04:57:38

0001 /*
0002  *   SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
0003  *   SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0004  *
0005  *   SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  */
0008 
0009 #include "testidxreader.h"
0010 
0011 #include "../kmindexreader.h"
0012 
0013 #include "TestIdxReader_data.h"
0014 
0015 #include <Akonadi/MessageStatus>
0016 using Akonadi::MessageStatus;
0017 
0018 #include <QTemporaryFile>
0019 
0020 #include <QDebug>
0021 #include <QTest>
0022 
0023 QTEST_MAIN(TestIdxReader)
0024 
0025 TestIdxReader::TestIdxReader() = default;
0026 
0027 void TestIdxReader::testError()
0028 {
0029     KMIndexReader reader(QStringLiteral("IDoNotExist"));
0030 
0031     QVERIFY(reader.error() == true);
0032 }
0033 
0034 void TestIdxReader::testReadHeader()
0035 {
0036     QTemporaryFile tmp;
0037     if (!tmp.open()) {
0038         qDebug() << "Could not open temp file.";
0039         return;
0040     }
0041     tmp.write(QByteArray::fromBase64(mailDirOneEmail));
0042     tmp.close();
0043     KMIndexReader reader(tmp.fileName());
0044 
0045     QVERIFY(reader.error() == false);
0046 
0047     int version = 0;
0048     bool success = reader.readHeader(&version);
0049 
0050     QVERIFY(success == true);
0051     QCOMPARE(version, 1506);
0052 
0053     QVERIFY(reader.error() == false);
0054 }
0055 
0056 void TestIdxReader::testRead()
0057 {
0058     QTemporaryFile tmp;
0059     if (!tmp.open()) {
0060         qDebug() << "Could not open temp file.";
0061         return;
0062     }
0063     tmp.write(QByteArray::fromBase64(mailDirTwoEmailOneTagFlags));
0064     tmp.close();
0065     KMIndexReader reader(tmp.fileName());
0066     QVERIFY(reader.error() == false);
0067     bool success = reader.readIndex();
0068     QVERIFY(success == true);
0069 
0070     QVERIFY(reader.messages().size() == 2);
0071 
0072     KMIndexDataPtr msg = reader.messages().front();
0073 
0074     QString subject = msg->mCachedStringParts[KMIndexReader::MsgSubjectPart];
0075     MessageStatus status;
0076     status.fromQInt32(msg->mCachedLongParts[KMIndexReader::MsgStatusPart]);
0077     QCOMPARE(subject, QStringLiteral("hello from kmail"));
0078     QVERIFY(!status.isImportant());
0079     QVERIFY(!msg->status().isImportant());
0080     QVERIFY(msg->status().isRead());
0081     QVERIFY(msg->tagList().contains(QLatin1StringView("N5tUHPOZFf")));
0082 
0083     msg = reader.messages().back();
0084     status.fromQInt32(msg->mCachedLongParts[KMIndexReader::MsgStatusPart]);
0085     subject = msg->mCachedStringParts[KMIndexReader::MsgSubjectPart];
0086     QCOMPARE(subject, QStringLiteral("foo bar"));
0087     QVERIFY(status.isImportant());
0088     QVERIFY(msg->status().isImportant());
0089     QVERIFY(!msg->status().isRead());
0090     QVERIFY(msg->tagList().size() == 0);
0091 }
0092 
0093 #include "moc_testidxreader.cpp"