From af2e92982b722ed0ea8f465649b843cb5ed4fda7 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 24 Jan 2018 09:46:42 +0100 Subject: Tested account setup --- tests/teststore.cpp | 51 +++++++++++++++++++++++++++++++++------------------ tests/teststore.h | 1 + 2 files changed, 34 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/teststore.cpp b/tests/teststore.cpp index 4716fa2e..07310640 100644 --- a/tests/teststore.cpp +++ b/tests/teststore.cpp @@ -157,27 +157,42 @@ void TestStore::setup(const QVariantMap &map) QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter) { using namespace Sink::ApplicationDomain; + const auto list = loadList(type, filter); + if (!list.isEmpty()) { + return list.first(); + } + return {}; +} + +template +QVariantList toVariantList(const QList &list) +{ + QVariantList result; + std::transform(list.constBegin(), list.constEnd(), std::back_inserter(result), [] (const T &m) { + return QVariant::fromValue(T::Ptr::create(m)); + }); + Q_ASSERT(list.size() == result.size()); + return result; +} + +QVariantList TestStore::loadList(const QByteArray &type, const QVariantMap &filter) +{ + using namespace Sink::ApplicationDomain; + Sink::Query query; + if (filter.contains("resource")) { + query.resourceFilter(filter.value("resource").toByteArray()); + } if (type == "mail") { - Sink::Query query; - if (filter.contains("resource")) { - query.resourceFilter(filter.value("resource").toByteArray()); - } - auto list = Sink::Store::read(query); - if (!list.isEmpty()) { - return QVariant::fromValue(Mail::Ptr::create(list.first())); - } - return {}; + return toVariantList(Sink::Store::read(query)); } if (type == "folder") { - Sink::Query query; - if (filter.contains("resource")) { - query.resourceFilter(filter.value("resource").toByteArray()); - } - auto list = Sink::Store::read(query); - if (!list.isEmpty()) { - return QVariant::fromValue(Folder::Ptr::create(list.first())); - } - return {}; + return toVariantList(Sink::Store::read(query)); + } + if (type == "resource") { + return toVariantList(Sink::Store::read(query)); + } + if (type == "account") { + return toVariantList(Sink::Store::read(query)); } Q_ASSERT(false); diff --git a/tests/teststore.h b/tests/teststore.h index 5df20416..1a6a2563 100644 --- a/tests/teststore.h +++ b/tests/teststore.h @@ -28,6 +28,7 @@ class TestStore : public QObject { public: Q_INVOKABLE void setup(const QVariantMap &); Q_INVOKABLE QVariant load(const QByteArray &type, const QVariantMap &); + Q_INVOKABLE QVariantList loadList(const QByteArray &type, const QVariantMap &); Q_INVOKABLE QVariantMap read(const QVariant &); }; -- cgit v1.2.3