Skip to content

Commit

Permalink
qmc-example: add setTopic test for true and fake state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal committed Jan 13, 2019
1 parent ebe43ac commit bdbdaff
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/qmc-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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,
Expand Down Expand Up @@ -143,6 +145,7 @@ void QMCTest::startTests()
{
cout << "Starting tests" << endl;
sendMessage();
setTopic();
addAndRemoveTag();
sendAndRedact();
markDirectChat();
Expand All @@ -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");
Expand Down

0 comments on commit bdbdaff

Please sign in to comment.