blob: 1ab516a191be5c3bd21b8dac678c74a66d6084bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <QtTest>
#include "resourceaccess.h"
#include "listener.h"
#include "commands.h"
#include "handshake_generated.h"
class ResourceCommunicationTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testConnect()
{
const QByteArray resourceIdentifier("test");
Listener listener(resourceIdentifier);
Akonadi2::ResourceAccess resourceAccess(resourceIdentifier);
QSignalSpy spy(&resourceAccess, &Akonadi2::ResourceAccess::ready);
resourceAccess.open();
QTRY_COMPARE(spy.size(), 1);
}
void testHandshake()
{
const QByteArray resourceIdentifier("test");
Listener listener(resourceIdentifier);
Akonadi2::ResourceAccess resourceAccess(resourceIdentifier);
resourceAccess.open();
flatbuffers::FlatBufferBuilder fbb;
auto name = fbb.CreateString("test");
auto command = Akonadi2::CreateHandshake(fbb, name);
Akonadi2::FinishHandshakeBuffer(fbb, command);
auto result = resourceAccess.sendCommand(Akonadi2::Commands::HandshakeCommand, fbb).exec();
result.waitForFinished();
QVERIFY(!result.errorCode());
}
void testCommandLoop()
{
const QByteArray resourceIdentifier("test");
Listener listener(resourceIdentifier);
Akonadi2::ResourceAccess resourceAccess(resourceIdentifier);
resourceAccess.open();
const int count = 500;
int complete = 0;
int errors = 0;
for (int i = 0; i < count; i++) {
auto result = resourceAccess.sendCommand(Akonadi2::Commands::PingCommand)
.then<void>([&complete]() {
complete++;
},
[&errors, &complete](int error, const QString &msg) {
qWarning() << msg;
errors++;
complete++;
}).exec();
}
QTRY_COMPARE(complete, count);
QVERIFY(!errors);
}
};
QTEST_MAIN(ResourceCommunicationTest)
#include "resourcecommunicationtest.moc"
|