summaryrefslogtreecommitdiffstats
path: root/tests/resourcecommunicationtest.cpp
blob: f1cef5058cac0caeb0c85a0e22436a88c4a4302d (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
#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());
    }
};

QTEST_MAIN(ResourceCommunicationTest)
#include "resourcecommunicationtest.moc"