diff options
author | Hubert Chathi <uhoreg@debian.org> | 2019-01-14 11:21:45 -0500 |
---|---|---|
committer | Hubert Chathi <uhoreg@debian.org> | 2019-01-14 11:21:45 -0500 |
commit | d488348d41b1abecd858a2625099dc94a8b05eac (patch) | |
tree | 8736c10809e5fac1dd7527e2562e948f09d109ae /examples/qmc-example.cpp | |
parent | 34da172eadf142cb13825086ab10e5627fff2668 (diff) | |
parent | 863848b2158e3278ae65d25de0b189a6008c60d1 (diff) | |
download | libquotient-d488348d41b1abecd858a2625099dc94a8b05eac.tar.gz libquotient-d488348d41b1abecd858a2625099dc94a8b05eac.zip |
Merge branch 'upstream' (v0.4.2.1)
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"); |