diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-24 09:46:42 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-24 09:46:42 +0100 |
commit | af2e92982b722ed0ea8f465649b843cb5ed4fda7 (patch) | |
tree | 4e4567ccb803c004402d4050a2317bc000335b68 /tests/teststore.cpp | |
parent | 5f17e726ad63eec6ef78d15baa8ed42625679197 (diff) | |
download | kube-af2e92982b722ed0ea8f465649b843cb5ed4fda7.tar.gz kube-af2e92982b722ed0ea8f465649b843cb5ed4fda7.zip |
Tested account setup
Diffstat (limited to 'tests/teststore.cpp')
-rw-r--r-- | tests/teststore.cpp | 51 |
1 files changed, 33 insertions, 18 deletions
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) | |||
157 | QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter) | 157 | QVariant TestStore::load(const QByteArray &type, const QVariantMap &filter) |
158 | { | 158 | { |
159 | using namespace Sink::ApplicationDomain; | 159 | using namespace Sink::ApplicationDomain; |
160 | const auto list = loadList(type, filter); | ||
161 | if (!list.isEmpty()) { | ||
162 | return list.first(); | ||
163 | } | ||
164 | return {}; | ||
165 | } | ||
166 | |||
167 | template <typename T> | ||
168 | QVariantList toVariantList(const QList<T> &list) | ||
169 | { | ||
170 | QVariantList result; | ||
171 | std::transform(list.constBegin(), list.constEnd(), std::back_inserter(result), [] (const T &m) { | ||
172 | return QVariant::fromValue(T::Ptr::create(m)); | ||
173 | }); | ||
174 | Q_ASSERT(list.size() == result.size()); | ||
175 | return result; | ||
176 | } | ||
177 | |||
178 | QVariantList TestStore::loadList(const QByteArray &type, const QVariantMap &filter) | ||
179 | { | ||
180 | using namespace Sink::ApplicationDomain; | ||
181 | Sink::Query query; | ||
182 | if (filter.contains("resource")) { | ||
183 | query.resourceFilter(filter.value("resource").toByteArray()); | ||
184 | } | ||
160 | if (type == "mail") { | 185 | if (type == "mail") { |
161 | Sink::Query query; | 186 | return toVariantList(Sink::Store::read<Mail>(query)); |
162 | if (filter.contains("resource")) { | ||
163 | query.resourceFilter(filter.value("resource").toByteArray()); | ||
164 | } | ||
165 | auto list = Sink::Store::read<Mail>(query); | ||
166 | if (!list.isEmpty()) { | ||
167 | return QVariant::fromValue(Mail::Ptr::create(list.first())); | ||
168 | } | ||
169 | return {}; | ||
170 | } | 187 | } |
171 | if (type == "folder") { | 188 | if (type == "folder") { |
172 | Sink::Query query; | 189 | return toVariantList(Sink::Store::read<Folder>(query)); |
173 | if (filter.contains("resource")) { | 190 | } |
174 | query.resourceFilter(filter.value("resource").toByteArray()); | 191 | if (type == "resource") { |
175 | } | 192 | return toVariantList(Sink::Store::read<SinkResource>(query)); |
176 | auto list = Sink::Store::read<Folder>(query); | 193 | } |
177 | if (!list.isEmpty()) { | 194 | if (type == "account") { |
178 | return QVariant::fromValue(Folder::Ptr::create(list.first())); | 195 | return toVariantList(Sink::Store::read<SinkAccount>(query)); |
179 | } | ||
180 | return {}; | ||
181 | } | 196 | } |
182 | 197 | ||
183 | Q_ASSERT(false); | 198 | Q_ASSERT(false); |