diff options
Diffstat (limited to 'tests/genericresourcetest.cpp')
-rw-r--r-- | tests/genericresourcetest.cpp | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp deleted file mode 100644 index 77a901d..0000000 --- a/tests/genericresourcetest.cpp +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | |||
5 | #include "testimplementations.h" | ||
6 | |||
7 | #include "event_generated.h" | ||
8 | #include "entity_generated.h" | ||
9 | #include "metadata_generated.h" | ||
10 | #include "createentity_generated.h" | ||
11 | #include "commands.h" | ||
12 | #include "entitybuffer.h" | ||
13 | #include "pipeline.h" | ||
14 | #include "genericresource.h" | ||
15 | #include "definitions.h" | ||
16 | |||
17 | /** | ||
18 | * Test of the generic resource implementation. | ||
19 | * | ||
20 | * This test relies on a working pipeline implementation, and writes to storage. | ||
21 | */ | ||
22 | class GenericResourceTest : public QObject | ||
23 | { | ||
24 | Q_OBJECT | ||
25 | private slots: | ||
26 | |||
27 | void init() | ||
28 | { | ||
29 | Sink::GenericResource::removeFromDisk("sink.test.instance1"); | ||
30 | } | ||
31 | |||
32 | /// Ensure the resource can process messages | ||
33 | void testProcessCommand() | ||
34 | { | ||
35 | flatbuffers::FlatBufferBuilder eventFbb; | ||
36 | eventFbb.Clear(); | ||
37 | { | ||
38 | auto summary = eventFbb.CreateString("summary"); | ||
39 | Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
40 | eventBuilder.add_summary(summary); | ||
41 | auto eventLocation = eventBuilder.Finish(); | ||
42 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
43 | } | ||
44 | |||
45 | flatbuffers::FlatBufferBuilder localFbb; | ||
46 | { | ||
47 | auto uid = localFbb.CreateString("testuid"); | ||
48 | auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); | ||
49 | localBuilder.add_uid(uid); | ||
50 | auto location = localBuilder.Finish(); | ||
51 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | ||
52 | } | ||
53 | |||
54 | flatbuffers::FlatBufferBuilder entityFbb; | ||
55 | Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); | ||
56 | |||
57 | flatbuffers::FlatBufferBuilder fbb; | ||
58 | auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>().toStdString().data()); | ||
59 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
60 | Sink::Commands::CreateEntityBuilder builder(fbb); | ||
61 | builder.add_domainType(type); | ||
62 | builder.add_delta(delta); | ||
63 | auto location = builder.Finish(); | ||
64 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
65 | |||
66 | const QByteArray command(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
67 | { | ||
68 | flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command.data()), command.size()); | ||
69 | QVERIFY(Sink::Commands::VerifyCreateEntityBuffer(verifyer)); | ||
70 | } | ||
71 | |||
72 | // Actual test | ||
73 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.test.instance1"); | ||
74 | QSignalSpy revisionSpy(pipeline.data(), SIGNAL(revisionUpdated(qint64))); | ||
75 | QVERIFY(revisionSpy.isValid()); | ||
76 | TestResource resource("sink.test.instance1", pipeline); | ||
77 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
78 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
79 | resource.processAllMessages().exec().waitForFinished(); | ||
80 | QCOMPARE(revisionSpy.last().at(0).toInt(), 2); | ||
81 | } | ||
82 | }; | ||
83 | |||
84 | QTEST_MAIN(GenericResourceTest) | ||
85 | #include "genericresourcetest.moc" | ||