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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include <QtTest>
#include <QString>
#include "testimplementations.h"
#include "event_generated.h"
#include "entity_generated.h"
#include "metadata_generated.h"
#include "createentity_generated.h"
#include "commands.h"
#include "entitybuffer.h"
#include "pipeline.h"
#include "genericresource.h"
#include "definitions.h"
/**
* Test of the generic resource implementation.
*
* This test relies on a working pipeline implementation, and writes to storage.
*/
class GenericResourceTest : public QObject
{
Q_OBJECT
private slots:
void init()
{
Sink::GenericResource::removeFromDisk("org.kde.test.instance1");
Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
}
/// Ensure the resource can process messages
void testProcessCommand()
{
flatbuffers::FlatBufferBuilder eventFbb;
eventFbb.Clear();
{
auto summary = eventFbb.CreateString("summary");
Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb);
eventBuilder.add_summary(summary);
auto eventLocation = eventBuilder.Finish();
Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation);
}
flatbuffers::FlatBufferBuilder localFbb;
{
auto uid = localFbb.CreateString("testuid");
auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb);
localBuilder.add_uid(uid);
auto location = localBuilder.Finish();
Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location);
}
flatbuffers::FlatBufferBuilder entityFbb;
Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize());
flatbuffers::FlatBufferBuilder fbb;
auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>().toStdString().data());
auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize());
Sink::Commands::CreateEntityBuilder builder(fbb);
builder.add_domainType(type);
builder.add_delta(delta);
auto location = builder.Finish();
Sink::Commands::FinishCreateEntityBuffer(fbb, location);
const QByteArray command(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
{
flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command.data()), command.size());
QVERIFY(Sink::Commands::VerifyCreateEntityBuffer(verifyer));
}
// Actual test
auto pipeline = QSharedPointer<Sink::Pipeline>::create("org.kde.test.instance1");
QSignalSpy revisionSpy(pipeline.data(), SIGNAL(revisionUpdated(qint64)));
QVERIFY(revisionSpy.isValid());
TestResource resource("org.kde.test.instance1", pipeline);
resource.processCommand(Sink::Commands::CreateEntityCommand, command);
resource.processCommand(Sink::Commands::CreateEntityCommand, command);
resource.processAllMessages().exec().waitForFinished();
QCOMPARE(revisionSpy.last().at(0).toInt(), 2);
}
};
QTEST_MAIN(GenericResourceTest)
#include "genericresourcetest.moc"
|