File indexing completed on 2025-01-05 04:58:39

0001 /*
0002  *   Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU General Public License as published by
0006  *   the Free Software Foundation; either version 2 of the License, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details.
0013  *
0014  *   You should have received a copy of the GNU General Public License
0015  *   along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
0018  */
0019 #include <QTest>
0020 
0021 #include <tests/mailsynctest.h>
0022 #include "../maildirresource.h"
0023 #include "../libmaildir/maildir.h"
0024 
0025 #include "test.h"
0026 
0027 #include "utils.h"
0028 
0029 using namespace Sink;
0030 using namespace Sink::ApplicationDomain;
0031 
0032 /**
0033  * Test of complete system using the maildir resource.
0034  *
0035  * This test requires the maildir resource installed.
0036  */
0037 class MaildirMailSyncTest : public Sink::MailSyncTest
0038 {
0039     Q_OBJECT
0040 
0041     QTemporaryDir tempDir;
0042     QString targetPath;
0043 
0044 protected:
0045     void resetTestEnvironment() Q_DECL_OVERRIDE
0046     {
0047         targetPath = tempDir.path() + "/maildir1/";
0048         QDir dir(targetPath);
0049         dir.removeRecursively();
0050         copyRecursively(TESTDATAPATH "/maildir1", targetPath);
0051         QDir{}.mkpath(targetPath + "/test/cur");
0052     }
0053 
0054     Sink::ApplicationDomain::SinkResource createResource() Q_DECL_OVERRIDE
0055     {
0056         auto resource = ApplicationDomain::MaildirResource::create("account1");
0057         resource.setProperty("path", targetPath);
0058         return resource;
0059     }
0060 
0061     Sink::ApplicationDomain::SinkResource createFaultyResource() Q_DECL_OVERRIDE
0062     {
0063         auto resource = ApplicationDomain::MaildirResource::create("account1");
0064         resource.setProperty("path", "");
0065         return resource;
0066     }
0067 
0068     void removeResourceFromDisk(const QByteArray &identifier) Q_DECL_OVERRIDE
0069     {
0070         ::MaildirResource::removeFromDisk(identifier);
0071     }
0072 
0073     void createFolder(const QStringList &folderPath) Q_DECL_OVERRIDE
0074     {
0075         auto rootPath = tempDir.path() + "/maildir1/";
0076         KPIM::Maildir maildir(rootPath + folderPath.join('/'), false);
0077         maildir.create();
0078     }
0079 
0080     void removeFolder(const QStringList &folderPath) Q_DECL_OVERRIDE
0081     {
0082         auto rootPath = tempDir.path() + "/maildir1/";
0083         KPIM::Maildir maildir(rootPath + folderPath.join('/'), false);
0084         maildir.remove();
0085         QDir dir(rootPath + folderPath.join('/'));
0086         dir.removeRecursively();
0087         // QVERIFY(maildir.removeSubFolder(name));
0088     }
0089 
0090     QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE
0091     {
0092         auto rootPath = tempDir.path() + "/maildir1/";
0093         KPIM::Maildir maildir(rootPath + folderPath.join('/'));
0094         return maildir.addEntry(message).toUtf8();
0095     }
0096 
0097     void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE
0098     {
0099         auto rootPath = tempDir.path() + "/maildir1/";
0100         KPIM::Maildir maildir(rootPath + folderPath.join('/'));
0101         maildir.removeEntry(messageIdentifier);
0102     }
0103 
0104     void markAsImportant(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE
0105     {
0106         auto rootPath = tempDir.path() + "/maildir1/";
0107         KPIM::Maildir maildir(rootPath + folderPath.join('/'));
0108         maildir.changeEntryFlags(messageIdentifier, KPIM::Maildir::Flagged);
0109     }
0110 };
0111 
0112 QTEST_MAIN(MaildirMailSyncTest)
0113 
0114 #include "maildirmailsynctest.moc"