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/mailthreadtest.h>
0022 #include "../maildirresource.h"
0023 #include "../libmaildir/maildir.h"
0024 
0025 #include "common/test.h"
0026 #include "applicationdomaintype.h"
0027 
0028 #include "utils.h"
0029 
0030 using namespace Sink;
0031 using namespace Sink::ApplicationDomain;
0032 
0033 /**
0034  * Test of complete system using the maildir resource.
0035  *
0036  * This test requires the maildir resource installed.
0037  */
0038 class MaildirThreadTest : public Sink::MailThreadTest
0039 {
0040     Q_OBJECT
0041 
0042     QTemporaryDir tempDir;
0043     QString targetPath;
0044 
0045 protected:
0046     void resetTestEnvironment() Q_DECL_OVERRIDE
0047     {
0048         targetPath = tempDir.path() + "/maildir2/";
0049         QDir dir(targetPath);
0050         dir.removeRecursively();
0051         copyRecursively(TESTDATAPATH "/maildir2", targetPath);
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     QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) Q_DECL_OVERRIDE
0074     {
0075         auto rootPath = tempDir.path() + "/maildir2/";
0076         KPIM::Maildir maildir(rootPath + folderPath.join('/'));
0077         return maildir.addEntry(message).toUtf8();
0078     }
0079 
0080     void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) Q_DECL_OVERRIDE
0081     {
0082         auto rootPath = tempDir.path() + "/maildir2/";
0083         KPIM::Maildir maildir(rootPath + folderPath.join('/'));
0084         maildir.removeEntry(messageIdentifier);
0085     }
0086 };
0087 
0088 QTEST_MAIN(MaildirThreadTest)
0089 
0090 #include "maildirthreadtest.moc"