From ebc5c48c03b6145e604da7c313b35321d0a71142 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 20 Sep 2016 17:18:21 +0200 Subject: A first draft of the threading algorithm. --- tests/CMakeLists.txt | 2 +- tests/mailthreadtest.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/mailthreadtest.h | 57 +++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 tests/mailthreadtest.cpp create mode 100644 tests/mailthreadtest.h (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 294cce2..f8fe3b3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ add_definitions(-DTESTDATAPATH="${CMAKE_CURRENT_SOURCE_DIR}/data") find_package(KF5 COMPONENTS REQUIRED Mime) -add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cpp mailsynctest.cpp) +add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cpp mailsynctest.cpp mailthreadtest.cpp) qt5_use_modules(sink_test Core Test Concurrent) target_link_libraries(sink_test sink libhawd KF5::Mime) diff --git a/tests/mailthreadtest.cpp b/tests/mailthreadtest.cpp new file mode 100644 index 0000000..1bbe713 --- /dev/null +++ b/tests/mailthreadtest.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2016 Christian Mollekopf + * + * 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 "mailthreadtest.h" + +#include + +#include +#include + +#include "store.h" +#include "resourcecontrol.h" +#include "log.h" +#include "test.h" + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +SINK_DEBUG_AREA("mailthreadtest") + +//TODO extract resource test +// +void MailThreadTest::initTestCase() +{ + Test::initTest(); + QVERIFY(isBackendAvailable()); + resetTestEnvironment(); + auto resource = createResource(); + QVERIFY(!resource.identifier().isEmpty()); + + VERIFYEXEC(Store::create(resource)); + + mResourceInstanceIdentifier = resource.identifier(); + mCapabilities = resource.getProperty("capabilities").value(); +} + +void MailThreadTest::cleanup() +{ + //TODO the shutdown job fails if the resource is already shut down + // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); + ResourceControl::shutdown(mResourceInstanceIdentifier).exec().waitForFinished(); + removeResourceFromDisk(mResourceInstanceIdentifier); +} + +void MailThreadTest::init() +{ + VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier)); +} + + +void MailThreadTest::testListThreadLeader() +{ + Sink::Query query; + query.resources << mResourceInstanceIdentifier; + query.request().request().request().request(); + query.threadLeaderOnly = true; + query.sort(); + + // Ensure all local data is processed + VERIFYEXEC(Store::synchronize(query)); + ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto job = Store::fetchAll(query).syncThen>([](const QList &mails) { + QCOMPARE(mails.size(), 1); + QVERIFY(mails.first()->getSubject().startsWith(QString("ThreadLeader"))); + const auto data = mails.first()->getMimeMessage(); + QVERIFY(!data.isEmpty()); + + KMime::Message m; + m.setContent(data); + m.parse(); + QCOMPARE(mails.first()->getSubject(), m.subject(true)->asUnicodeString()); + QVERIFY(!mails.first()->getFolder().isEmpty()); + QVERIFY(mails.first()->getDate().isValid()); + }); + VERIFYEXEC(job); +} + +#include "mailthreadtest.moc" diff --git a/tests/mailthreadtest.h b/tests/mailthreadtest.h new file mode 100644 index 0000000..d6b9c24 --- /dev/null +++ b/tests/mailthreadtest.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 Christian Mollekopf + * + * 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. + */ +#pragma once + +#include +#include + +#include +#include "testutils.h" + +namespace Sink { + +/** + * Tests if the resource can thread emails. + */ +class MailThreadTest : public QObject +{ + Q_OBJECT + +protected: + QByteArray mResourceInstanceIdentifier; + QByteArrayList mCapabilities; + + virtual bool isBackendAvailable() { return true; } + virtual void resetTestEnvironment() = 0; + virtual Sink::ApplicationDomain::SinkResource createResource() = 0; + virtual Sink::ApplicationDomain::SinkResource createFaultyResource() = 0; + virtual void removeResourceFromDisk(const QByteArray &mResourceInstanceIdentifier) = 0; + virtual QByteArray createMessage(const QStringList &folderPath, const QByteArray &message) = 0; + virtual void removeMessage(const QStringList &folderPath, const QByteArray &messageIdentifier) = 0; + +private slots: + void initTestCase(); + void init(); + void cleanup(); + + void testListThreadLeader(); +}; + +} + -- cgit v1.2.3