diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-16 16:11:20 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-16 16:11:20 +0100 |
commit | 20bf85c5cfa51ee5da0b890cfd72346373ff7c8c (patch) | |
tree | 581b5242dcbc3957d4683226224dc22301380e83 /tests/messagequeuetest.cpp | |
parent | 10977b90bffeb675650b049df6585c296c6980cb (diff) | |
download | sink-20bf85c5cfa51ee5da0b890cfd72346373ff7c8c.tar.gz sink-20bf85c5cfa51ee5da0b890cfd72346373ff7c8c.zip |
Messagequeuetest
Diffstat (limited to 'tests/messagequeuetest.cpp')
-rw-r--r-- | tests/messagequeuetest.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp index 2ea9f0c..c43b192 100644 --- a/tests/messagequeuetest.cpp +++ b/tests/messagequeuetest.cpp | |||
@@ -21,6 +21,21 @@ private Q_SLOTS: | |||
21 | { | 21 | { |
22 | } | 22 | } |
23 | 23 | ||
24 | void cleanup() | ||
25 | { | ||
26 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue", Akonadi2::Storage::ReadWrite); | ||
27 | store.removeFromDisk(); | ||
28 | } | ||
29 | |||
30 | void testEmpty() | ||
31 | { | ||
32 | MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); | ||
33 | QVERIFY(queue.isEmpty()); | ||
34 | QByteArray value("value"); | ||
35 | queue.enqueue(value.data(), value.size()); | ||
36 | QVERIFY(!queue.isEmpty()); | ||
37 | } | ||
38 | |||
24 | void testQueue() | 39 | void testQueue() |
25 | { | 40 | { |
26 | QQueue<QByteArray> values; | 41 | QQueue<QByteArray> values; |
@@ -34,14 +49,36 @@ private Q_SLOTS: | |||
34 | 49 | ||
35 | while (!queue.isEmpty()) { | 50 | while (!queue.isEmpty()) { |
36 | const auto expected = values.dequeue(); | 51 | const auto expected = values.dequeue(); |
52 | bool gotValue = false; | ||
53 | bool gotError = false; | ||
37 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { | 54 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { |
38 | QCOMPARE(QByteArray(static_cast<char*>(ptr), size), expected); | 55 | if (QByteArray(static_cast<char*>(ptr), size) == expected) { |
56 | gotValue = true; | ||
57 | } | ||
39 | callback(true); | 58 | callback(true); |
40 | }, [](const MessageQueue::Error &error) { | 59 | }, |
41 | 60 | [&](const MessageQueue::Error &error) { | |
61 | gotError = true; | ||
42 | }); | 62 | }); |
63 | QVERIFY(gotValue); | ||
64 | QVERIFY(!gotError); | ||
43 | } | 65 | } |
44 | Q_ASSERT(values.isEmpty()); | 66 | QVERIFY(values.isEmpty()); |
67 | } | ||
68 | |||
69 | void testDequeueEmpty() | ||
70 | { | ||
71 | MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); | ||
72 | bool gotValue = false; | ||
73 | bool gotError = false; | ||
74 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { | ||
75 | gotValue = true; | ||
76 | }, | ||
77 | [&](const MessageQueue::Error &error) { | ||
78 | gotError = true; | ||
79 | }); | ||
80 | QVERIFY(!gotValue); | ||
81 | QVERIFY(gotError); | ||
45 | } | 82 | } |
46 | 83 | ||
47 | }; | 84 | }; |