From bdbdaff756cbd1402339d75faddc6c2beebc6eed Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 10 Jan 2019 16:52:31 +0900 Subject: qmc-example: add setTopic test for true and fake state changes --- examples/qmc-example.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'examples') 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 #include @@ -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"); -- cgit v1.2.3