aboutsummaryrefslogtreecommitdiff
path: root/quotest
diff options
context:
space:
mode:
Diffstat (limited to 'quotest')
-rw-r--r--quotest/CMakeLists.txt5
-rw-r--r--quotest/quotest.cpp57
2 files changed, 57 insertions, 5 deletions
diff --git a/quotest/CMakeLists.txt b/quotest/CMakeLists.txt
index cb41141d..ec305620 100644
--- a/quotest/CMakeLists.txt
+++ b/quotest/CMakeLists.txt
@@ -8,6 +8,11 @@ find_package(${Qt} COMPONENTS Concurrent)
add_executable(quotest ${quotest_SRCS})
target_link_libraries(quotest PRIVATE ${Qt}::Core ${Qt}::Test ${Qt}::Concurrent ${PROJECT_NAME})
+set_target_properties(quotest PROPERTIES
+ VISIBILITY_INLINES_HIDDEN ON
+ CXX_VISIBILITY_PRESET hidden
+)
+
if (MSVC)
target_compile_options(quotest PUBLIC /EHsc /W4
/wd4100 /wd4127 /wd4242 /wd4244 /wd4245 /wd4267 /wd4365 /wd4456 /wd4459
diff --git a/quotest/quotest.cpp b/quotest/quotest.cpp
index 7bd9c5c3..5a5642fe 100644
--- a/quotest/quotest.cpp
+++ b/quotest/quotest.cpp
@@ -101,6 +101,7 @@ private slots:
TEST_DECL(sendMessage)
TEST_DECL(sendReaction)
TEST_DECL(sendFile)
+ TEST_DECL(sendCustomEvent)
TEST_DECL(setTopic)
TEST_DECL(changeName)
TEST_DECL(sendAndRedact)
@@ -125,6 +126,7 @@ private:
[[nodiscard]] bool checkRedactionOutcome(const QByteArray& thisTest,
const QString& evtIdToRedact);
+ template <class EventT>
[[nodiscard]] bool validatePendingEvent(const QString& txnId);
[[nodiscard]] bool checkDirectChat() const;
void finishTest(const TestToken& token, bool condition, const char* file,
@@ -152,12 +154,14 @@ void TestSuite::doTest(const QByteArray& testName)
Q_ARG(TestToken, testName));
}
+template <class EventT>
bool TestSuite::validatePendingEvent(const QString& txnId)
{
auto it = targetRoom->findPendingEvent(txnId);
return it != targetRoom->pendingEvents().end()
&& it->deliveryStatus() == EventStatus::Submitted
- && (*it)->transactionId() == txnId;
+ && (*it)->transactionId() == txnId && is<EventT>(**it)
+ && (*it)->matrixType() == EventT::matrixTypeId();
}
void TestSuite::finishTest(const TestToken& token, bool condition,
@@ -341,7 +345,7 @@ TEST_IMPL(loadMembers)
TEST_IMPL(sendMessage)
{
auto txnId = targetRoom->postPlainText("Hello, " % origin % " is here");
- if (!validatePendingEvent(txnId)) {
+ if (!validatePendingEvent<RoomMessageEvent>(txnId)) {
clog << "Invalid pending event right after submitting" << endl;
FAIL_TEST();
}
@@ -367,7 +371,7 @@ TEST_IMPL(sendReaction)
const auto targetEvtId = targetRoom->messageEvents().back()->id();
const auto key = QStringLiteral("+1");
const auto txnId = targetRoom->postReaction(targetEvtId, key);
- if (!validatePendingEvent(txnId)) {
+ if (!validatePendingEvent<ReactionEvent>(txnId)) {
clog << "Invalid pending event right after submitting" << endl;
FAIL_TEST();
}
@@ -409,7 +413,7 @@ TEST_IMPL(sendFile)
clog << "Sending file " << tfName.toStdString() << endl;
const auto txnId = targetRoom->postFile(
"Test file", new EventContent::FileContent(tfi));
- if (!validatePendingEvent(txnId)) {
+ if (!validatePendingEvent<RoomMessageEvent>(txnId)) {
clog << "Invalid pending event right after submitting" << endl;
tf->deleteLater();
FAIL_TEST();
@@ -518,6 +522,50 @@ bool TestSuite::checkFileSendingOutcome(const TestToken& thisTest,
return true;
}
+class CustomEvent : public RoomEvent {
+public:
+ DEFINE_EVENT_TYPEID("quotest.custom", CustomEvent)
+
+ CustomEvent(const QJsonObject& jo)
+ : RoomEvent(typeId(), jo)
+ {}
+ CustomEvent(int testValue)
+ : RoomEvent(typeId(),
+ basicEventJson(matrixTypeId(),
+ QJsonObject { { "testValue"_ls,
+ toJson(testValue) } }))
+ {}
+
+ auto testValue() const { return contentPart<int>("testValue"_ls); }
+};
+REGISTER_EVENT_TYPE(CustomEvent)
+
+TEST_IMPL(sendCustomEvent)
+{
+ auto txnId = targetRoom->postEvent(new CustomEvent(42));
+ if (!validatePendingEvent<CustomEvent>(txnId)) {
+ clog << "Invalid pending event right after submitting" << endl;
+ FAIL_TEST();
+ }
+ connectUntil(
+ targetRoom, &Room::pendingEventAboutToMerge, this,
+ [this, thisTest, txnId](const RoomEvent* evt, int pendingIdx) {
+ const auto& pendingEvents = targetRoom->pendingEvents();
+ Q_ASSERT(pendingIdx >= 0 && pendingIdx < int(pendingEvents.size()));
+
+ if (evt->transactionId() != txnId)
+ return false;
+
+ return switchOnType(*evt,
+ [this, thisTest, &evt](const CustomEvent& e) {
+ FINISH_TEST(!evt->id().isEmpty() && e.testValue() == 42);
+ },
+ [this, thisTest] (const RoomEvent&) { FAIL_TEST(); });
+ });
+ return false;
+
+}
+
TEST_IMPL(setTopic)
{
const auto newTopic = connection()->generateTxnId(); // Just a way to make
@@ -567,7 +615,6 @@ TEST_IMPL(changeName)
return false;
}
-
TEST_IMPL(showLocalUsername)
{
auto* const localUser = connection()->user();