diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-11 00:44:44 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-11 00:44:44 +0100 |
commit | fdd74a41929b4343902f1d1dfcd5116534a79f4f (patch) | |
tree | 312524c2f1a8431742d6a2575dc3c497b66cc795 /tests/dummyresourcefacadetest.cpp | |
parent | fbd35044dc343dbd17d475b860c6019077271efc (diff) | |
download | sink-fdd74a41929b4343902f1d1dfcd5116534a79f4f.tar.gz sink-fdd74a41929b4343902f1d1dfcd5116534a79f4f.zip |
Dummyresourcefacade test.
Huzaa, we can read a value!
Diffstat (limited to 'tests/dummyresourcefacadetest.cpp')
-rw-r--r-- | tests/dummyresourcefacadetest.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/dummyresourcefacadetest.cpp b/tests/dummyresourcefacadetest.cpp new file mode 100644 index 0000000..26daa23 --- /dev/null +++ b/tests/dummyresourcefacadetest.cpp | |||
@@ -0,0 +1,73 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <iostream> | ||
4 | |||
5 | #include <QDebug> | ||
6 | #include <QString> | ||
7 | #include <QtConcurrent/QtConcurrentRun> | ||
8 | |||
9 | #include "common/storage.h" | ||
10 | #include "dummyresource/facade.h" | ||
11 | |||
12 | class DummyResourceFacadeTest : public QObject | ||
13 | { | ||
14 | Q_OBJECT | ||
15 | private: | ||
16 | QString testDataPath; | ||
17 | QString dbName; | ||
18 | const char *keyPrefix = "key"; | ||
19 | |||
20 | void populate(int count) | ||
21 | { | ||
22 | Storage storage(testDataPath, dbName, Storage::ReadWrite); | ||
23 | for (int i = 0; i < count; i++) { | ||
24 | storage.write(keyPrefix + std::to_string(i), keyPrefix + std::to_string(i)); | ||
25 | } | ||
26 | storage.commitTransaction(); | ||
27 | } | ||
28 | |||
29 | private Q_SLOTS: | ||
30 | void initTestCase() | ||
31 | { | ||
32 | testDataPath = Akonadi2::Store::storageLocation(); | ||
33 | dbName = "dummyresource"; | ||
34 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::Domain::Event, DummyResourceFacade>("dummyresource", []() { | ||
35 | return new DummyResourceFacade(); | ||
36 | }); | ||
37 | } | ||
38 | |||
39 | void cleanupTestCase() | ||
40 | { | ||
41 | Storage storage(testDataPath, dbName); | ||
42 | storage.removeFromDisk(); | ||
43 | } | ||
44 | |||
45 | void testScan() | ||
46 | { | ||
47 | const int count = 100; | ||
48 | populate(count); | ||
49 | |||
50 | Akonadi2::Query query; | ||
51 | query.ids << "key50"; | ||
52 | query.resources << "dummyresource"; | ||
53 | |||
54 | auto result = Akonadi2::Store::load<Akonadi2::Domain::Event>(query); | ||
55 | bool complete = false; | ||
56 | QVector<Akonadi2::Domain::Event::Ptr> results; | ||
57 | result->onAdded([&results](const Akonadi2::Domain::Event::Ptr &e) { | ||
58 | results << e; | ||
59 | }); | ||
60 | result->onComplete([&complete]() { | ||
61 | complete = true; | ||
62 | }); | ||
63 | QTRY_VERIFY(complete); | ||
64 | QCOMPARE(results.size(), 1); | ||
65 | |||
66 | Storage storage(testDataPath, dbName); | ||
67 | storage.removeFromDisk(); | ||
68 | } | ||
69 | |||
70 | }; | ||
71 | |||
72 | QTEST_MAIN(DummyResourceFacadeTest) | ||
73 | #include "dummyresourcefacadetest.moc" | ||