diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 10:34:07 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 16:26:38 +0100 |
commit | 3ac6cf5ffae2247719730f328d1363c498e4ee83 (patch) | |
tree | dbef67a345ec412c58eff6275111df29de7fa742 /tests | |
parent | e6f83f7b5af1ed3467d12f551fb7401238b7855e (diff) | |
download | kube-3ac6cf5ffae2247719730f328d1363c498e4ee83.tar.gz kube-3ac6cf5ffae2247719730f328d1363c498e4ee83.zip |
Dynamically setup initial test state
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/kubetestrunner.cpp | 22 | ||||
-rw-r--r-- | tests/teststore.cpp | 59 | ||||
-rw-r--r-- | tests/teststore.h | 31 |
4 files changed, 103 insertions, 14 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ce7915c..ca394d9e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -1,9 +1,10 @@ | |||
1 | find_package(Qt5 REQUIRED NO_MODULE COMPONENTS QuickTest Network) | 1 | find_package(Qt5 REQUIRED NO_MODULE COMPONENTS QuickTest Network Quick) |
2 | find_package(Sink CONFIG REQUIRED) | 2 | find_package(Sink CONFIG REQUIRED) |
3 | find_package(KAsync CONFIG REQUIRED) | 3 | find_package(KAsync CONFIG REQUIRED) |
4 | 4 | ||
5 | add_executable(kubetestrunner kubetestrunner.cpp) | 5 | add_executable(kubetestrunner kubetestrunner.cpp teststore.cpp) |
6 | target_link_libraries(kubetestrunner | 6 | target_link_libraries(kubetestrunner |
7 | Qt5::QuickTest | 7 | Qt5::QuickTest |
8 | Qt5::Quick | ||
8 | sink | 9 | sink |
9 | ) | 10 | ) |
diff --git a/tests/kubetestrunner.cpp b/tests/kubetestrunner.cpp index 3bf06d44..dd022091 100644 --- a/tests/kubetestrunner.cpp +++ b/tests/kubetestrunner.cpp | |||
@@ -17,25 +17,23 @@ | |||
17 | 02110-1301, USA. | 17 | 02110-1301, USA. |
18 | */ | 18 | */ |
19 | #include <QtQuickTest/quicktest.h> | 19 | #include <QtQuickTest/quicktest.h> |
20 | #include <QQmlEngine> | ||
20 | #include <sink/test.h> | 21 | #include <sink/test.h> |
21 | #include <sink/store.h> | 22 | #include "teststore.h" |
23 | |||
24 | static QObject *teststore(QQmlEngine *engine, QJSEngine *scriptEngine) | ||
25 | { | ||
26 | Q_UNUSED(engine) | ||
27 | Q_UNUSED(scriptEngine) | ||
28 | return new Kube::TestStore; | ||
29 | } | ||
22 | 30 | ||
23 | int main(int argc, char **argv) | 31 | int main(int argc, char **argv) |
24 | { | 32 | { |
25 | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); | 33 | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); |
26 | Sink::Test::initTest(); | 34 | Sink::Test::initTest(); |
27 | 35 | ||
28 | auto resource = Sink::ApplicationDomain::DummyResource::create("account1"); | 36 | qmlRegisterSingletonType<Kube::TestStore>("org.kube.test", 1, 0, "TestStore", teststore); |
29 | Sink::Store::create(resource).exec().waitForFinished(); | ||
30 | |||
31 | auto transportResource = Sink::ApplicationDomain::MailtransportResource::create("account1"); | ||
32 | Sink::Store::create(transportResource).exec().waitForFinished(); | ||
33 | |||
34 | auto identity = Sink::ApplicationDomain::Identity{}; | ||
35 | identity.setAccount("account1"); | ||
36 | identity.setAddress("identity@example.org"); | ||
37 | identity.setName("Identity Name"); | ||
38 | Sink::Store::create(identity).exec().waitForFinished(); | ||
39 | 37 | ||
40 | QTEST_ADD_GPU_BLACKLIST_SUPPORT | 38 | QTEST_ADD_GPU_BLACKLIST_SUPPORT |
41 | QTEST_SET_MAIN_SOURCE_PATH | 39 | QTEST_SET_MAIN_SOURCE_PATH |
diff --git a/tests/teststore.cpp b/tests/teststore.cpp new file mode 100644 index 00000000..a8cd0b2d --- /dev/null +++ b/tests/teststore.cpp | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "teststore.h" | ||
20 | |||
21 | #include <sink/store.h> | ||
22 | |||
23 | #include <QDebug> | ||
24 | #include <QVariant> | ||
25 | |||
26 | using namespace Kube; | ||
27 | |||
28 | static void iterateOverObjects(const QVariantList &list, std::function<void(const QVariantMap &)> callback) | ||
29 | { | ||
30 | for (const auto &entry : list) { | ||
31 | auto object = entry.toMap(); | ||
32 | callback(object); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | void TestStore::setup(const QVariantMap &map) | ||
37 | { | ||
38 | iterateOverObjects(map.value("resources").toList(), [] (const QVariantMap &object) { | ||
39 | auto resource = [&] { | ||
40 | if (object["type"] == "dummy") { | ||
41 | return Sink::ApplicationDomain::DummyResource::create(object["account"].toByteArray()); | ||
42 | } | ||
43 | if (object["type"] == "mailtransport") { | ||
44 | return Sink::ApplicationDomain::MailtransportResource::create(object["account"].toByteArray()); | ||
45 | } | ||
46 | Q_ASSERT(false); | ||
47 | return Sink::ApplicationDomain::SinkResource{}; | ||
48 | }(); | ||
49 | Sink::Store::create(resource).exec().waitForFinished(); | ||
50 | }); | ||
51 | |||
52 | iterateOverObjects(map.value("identities").toList(), [] (const QVariantMap &object) { | ||
53 | auto identity = Sink::ApplicationDomain::Identity{}; | ||
54 | identity.setAccount(object["account"].toByteArray()); | ||
55 | identity.setAddress(object["address"].toString()); | ||
56 | identity.setName(object["name"].toString()); | ||
57 | Sink::Store::create(identity).exec().waitForFinished(); | ||
58 | }); | ||
59 | } | ||
diff --git a/tests/teststore.h b/tests/teststore.h new file mode 100644 index 00000000..f0578ca5 --- /dev/null +++ b/tests/teststore.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | |||
23 | namespace Kube { | ||
24 | |||
25 | class TestStore : public QObject { | ||
26 | Q_OBJECT | ||
27 | public: | ||
28 | Q_INVOKABLE void setup(const QVariantMap &); | ||
29 | }; | ||
30 | |||
31 | } | ||