diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-03 09:01:05 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-03 09:01:05 +0100 |
commit | 4d9746c828558c9f872e0aed52442863affb25d5 (patch) | |
tree | 507d7c2ba67f47d3cbbcf01a722236ff1b48426b /tests/messagequeuetest.cpp | |
parent | 9cea920b7dd51867a0be0fed2f461b6be73c103e (diff) | |
download | sink-4d9746c828558c9f872e0aed52442863affb25d5.tar.gz sink-4d9746c828558c9f872e0aed52442863affb25d5.zip |
Fromatted the whole codebase with clang-format.
clang-format -i */**{.cpp,.h}
Diffstat (limited to 'tests/messagequeuetest.cpp')
-rw-r--r-- | tests/messagequeuetest.cpp | 85 |
1 files changed, 37 insertions, 48 deletions
diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp index 06a4ae6..484ff86 100644 --- a/tests/messagequeuetest.cpp +++ b/tests/messagequeuetest.cpp | |||
@@ -45,12 +45,7 @@ private slots: | |||
45 | MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); | 45 | MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); |
46 | bool gotValue = false; | 46 | bool gotValue = false; |
47 | bool gotError = false; | 47 | bool gotError = false; |
48 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { | 48 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { gotValue = true; }, [&](const MessageQueue::Error &error) { gotError = true; }); |
49 | gotValue = true; | ||
50 | }, | ||
51 | [&](const MessageQueue::Error &error) { | ||
52 | gotError = true; | ||
53 | }); | ||
54 | QVERIFY(!gotValue); | 49 | QVERIFY(!gotValue); |
55 | QVERIFY(!gotError); | 50 | QVERIFY(!gotError); |
56 | } | 51 | } |
@@ -69,9 +64,7 @@ private slots: | |||
69 | QSignalSpy spy(&queue, SIGNAL(drained())); | 64 | QSignalSpy spy(&queue, SIGNAL(drained())); |
70 | queue.enqueue("value1"); | 65 | queue.enqueue("value1"); |
71 | 66 | ||
72 | queue.dequeue([](void *ptr, int size, std::function<void(bool success)> callback) { | 67 | queue.dequeue([](void *ptr, int size, std::function<void(bool success)> callback) { callback(true); }, [](const MessageQueue::Error &error) {}); |
73 | callback(true); | ||
74 | }, [](const MessageQueue::Error &error) {}); | ||
75 | QCOMPARE(spy.size(), 1); | 68 | QCOMPARE(spy.size(), 1); |
76 | } | 69 | } |
77 | 70 | ||
@@ -91,15 +84,14 @@ private slots: | |||
91 | const auto expected = values.dequeue(); | 84 | const auto expected = values.dequeue(); |
92 | bool gotValue = false; | 85 | bool gotValue = false; |
93 | bool gotError = false; | 86 | bool gotError = false; |
94 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { | 87 | queue.dequeue( |
95 | if (QByteArray(static_cast<char*>(ptr), size) == expected) { | 88 | [&](void *ptr, int size, std::function<void(bool success)> callback) { |
96 | gotValue = true; | 89 | if (QByteArray(static_cast<char *>(ptr), size) == expected) { |
97 | } | 90 | gotValue = true; |
98 | callback(true); | 91 | } |
99 | }, | 92 | callback(true); |
100 | [&](const MessageQueue::Error &error) { | 93 | }, |
101 | gotError = true; | 94 | [&](const MessageQueue::Error &error) { gotError = true; }); |
102 | }); | ||
103 | QVERIFY(gotValue); | 95 | QVERIFY(gotValue); |
104 | QVERIFY(!gotError); | 96 | QVERIFY(!gotError); |
105 | } | 97 | } |
@@ -123,22 +115,21 @@ private slots: | |||
123 | bool gotValue = false; | 115 | bool gotValue = false; |
124 | bool gotError = false; | 116 | bool gotError = false; |
125 | 117 | ||
126 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { | 118 | queue.dequeue( |
127 | if (QByteArray(static_cast<char*>(ptr), size) == expected) { | 119 | [&](void *ptr, int size, std::function<void(bool success)> callback) { |
128 | gotValue = true; | 120 | if (QByteArray(static_cast<char *>(ptr), size) == expected) { |
129 | } | 121 | gotValue = true; |
130 | auto timer = new QTimer(); | 122 | } |
131 | timer->setSingleShot(true); | 123 | auto timer = new QTimer(); |
132 | QObject::connect(timer, &QTimer::timeout, [timer, callback, &eventLoop]() { | 124 | timer->setSingleShot(true); |
133 | delete timer; | 125 | QObject::connect(timer, &QTimer::timeout, [timer, callback, &eventLoop]() { |
134 | callback(true); | 126 | delete timer; |
135 | eventLoop.exit(); | 127 | callback(true); |
136 | }); | 128 | eventLoop.exit(); |
137 | timer->start(0); | 129 | }); |
138 | }, | 130 | timer->start(0); |
139 | [&](const MessageQueue::Error &error) { | 131 | }, |
140 | gotError = true; | 132 | [&](const MessageQueue::Error &error) { gotError = true; }); |
141 | }); | ||
142 | eventLoop.exec(); | 133 | eventLoop.exec(); |
143 | QVERIFY(gotValue); | 134 | QVERIFY(gotValue); |
144 | QVERIFY(!gotError); | 135 | QVERIFY(!gotError); |
@@ -155,13 +146,12 @@ private slots: | |||
155 | queue.enqueue("value1"); | 146 | queue.enqueue("value1"); |
156 | 147 | ||
157 | bool gotError = false; | 148 | bool gotError = false; |
158 | queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { | 149 | queue.dequeue( |
159 | queue.enqueue("value3"); | 150 | [&](void *ptr, int size, std::function<void(bool success)> callback) { |
160 | callback(true); | 151 | queue.enqueue("value3"); |
161 | }, | 152 | callback(true); |
162 | [&](const MessageQueue::Error &error) { | 153 | }, |
163 | gotError = true; | 154 | [&](const MessageQueue::Error &error) { gotError = true; }); |
164 | }); | ||
165 | QVERIFY(!gotError); | 155 | QVERIFY(!gotError); |
166 | } | 156 | } |
167 | 157 | ||
@@ -174,15 +164,15 @@ private slots: | |||
174 | 164 | ||
175 | int count = 0; | 165 | int count = 0; |
176 | queue.dequeueBatch(2, [&count](const QByteArray &data) { | 166 | queue.dequeueBatch(2, [&count](const QByteArray &data) { |
177 | count++; | 167 | count++; |
178 | return KAsync::null<void>(); | 168 | return KAsync::null<void>(); |
179 | }).exec().waitForFinished(); | 169 | }).exec().waitForFinished(); |
180 | QCOMPARE(count, 2); | 170 | QCOMPARE(count, 2); |
181 | 171 | ||
182 | queue.dequeueBatch(1, [&count](const QByteArray &data) { | 172 | queue.dequeueBatch(1, [&count](const QByteArray &data) { |
183 | count++; | 173 | count++; |
184 | return KAsync::null<void>(); | 174 | return KAsync::null<void>(); |
185 | }).exec().waitForFinished(); | 175 | }).exec().waitForFinished(); |
186 | QCOMPARE(count, 3); | 176 | QCOMPARE(count, 3); |
187 | } | 177 | } |
188 | 178 | ||
@@ -203,7 +193,6 @@ private slots: | |||
203 | QVERIFY(!queue.isEmpty()); | 193 | QVERIFY(!queue.isEmpty()); |
204 | QCOMPARE(spy.count(), 1); | 194 | QCOMPARE(spy.count(), 1); |
205 | } | 195 | } |
206 | |||
207 | }; | 196 | }; |
208 | 197 | ||
209 | QTEST_MAIN(MessageQueueTest) | 198 | QTEST_MAIN(MessageQueueTest) |