diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-01-10 16:52:31 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-01-13 18:20:23 +0900 |
commit | bdbdaff756cbd1402339d75faddc6c2beebc6eed (patch) | |
tree | 557eeafb55c38796dc15d95ddd60b2e21ecd686c /examples/qmc-example.cpp | |
parent | ebe43ac929393787a9a55cf7569b540c73f8048c (diff) | |
download | libquotient-bdbdaff756cbd1402339d75faddc6c2beebc6eed.tar.gz libquotient-bdbdaff756cbd1402339d75faddc6c2beebc6eed.zip |
qmc-example: add setTopic test for true and fake state changes
Diffstat (limited to 'examples/qmc-example.cpp')
-rw-r--r-- | examples/qmc-example.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/qmc-example.cpp b/examples/qmc-example.cpp index 9c86d4a9..206501a5 100644 --- a/examples/qmc-example.cpp +++ b/examples/qmc-example.cpp @@ -5,6 +5,7 @@ #include "csapi/room_send.h" #include "csapi/joining.h" #include "csapi/leaving.h" +#include "events/simplestateevents.h" #include <QtCore/QCoreApplication> #include <QtCore/QStringBuilder> @@ -27,6 +28,7 @@ class QMCTest : public QObject void onNewRoom(Room* r); void startTests(); void sendMessage(); + void setTopic(); void addAndRemoveTag(); void sendAndRedact(); void checkRedactionOutcome(const QString& evtIdToRedact, @@ -143,6 +145,7 @@ void QMCTest::startTests() { cout << "Starting tests" << endl; sendMessage(); + setTopic(); addAndRemoveTag(); sendAndRedact(); markDirectChat(); @@ -168,6 +171,49 @@ void QMCTest::sendMessage() // Independently, check when it shows up in the timeline. } +void QMCTest::setTopic() +{ + running.push_back("State setting test"); + running.push_back("Fake state event immunity test"); + auto initialTopic = targetRoom->topic(); + + const auto newTopic = c->generateTxnId(); + targetRoom->setTopic(newTopic); // Sets the state by proper means + const auto fakeTopic = c->generateTxnId(); + targetRoom->postJson(RoomTopicEvent::matrixTypeId(), // Fake state event + RoomTopicEvent(fakeTopic).contentJson()); + + { + auto* context = new QObject; + connect(targetRoom, &Room::topicChanged, context, + [this,newTopic,fakeTopic,initialTopic,context] { + if (targetRoom->topic() == newTopic) + { + QMC_CHECK("State setting test", true); + // Don't reset the topic yet if the negative test still runs + if (!running.contains("Fake state event immunity test")) + targetRoom->setTopic(initialTopic); + + context->deleteLater(); + } + }); + } + + { + auto* context = new QObject; + connect(targetRoom, &Room::pendingEventAboutToMerge, context, + [this,fakeTopic,initialTopic,context] (const RoomEvent* e, int) { + if (e->contentJson().value("topic").toString() != fakeTopic) + return; // Wait on for the right event + + QMC_CHECK("Fake state event immunity test", !e->isStateEvent()); + if (!running.contains("State setting test")) + targetRoom->setTopic(initialTopic); + context->deleteLater(); + }); + } +} + void QMCTest::addAndRemoveTag() { running.push_back("Tagging test"); |