diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-01-22 13:43:15 +0100 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-01-22 14:45:53 +0100 |
commit | 63c953800330017ebb2afbabf41e5c4932c4d640 (patch) | |
tree | 0532616fd9de757c9bccd1830ed39af91d06e0b0 /quotest/quotest.cpp | |
parent | 59590c44716e0bbb4499b8ca9844ecd75d638a01 (diff) | |
download | libquotient-63c953800330017ebb2afbabf41e5c4932c4d640.tar.gz libquotient-63c953800330017ebb2afbabf41e5c4932c4d640.zip |
Quotest: fix changeName test
This test was very unreliable because memberRenamed() signal was emitted
upon lazy-loading of past member renames. The new code connects to
aboutToAddNewMessages() instead, which should only contain the latest
renaming event (past events are delivered in the 'state' object).
Diffstat (limited to 'quotest/quotest.cpp')
-rw-r--r-- | quotest/quotest.cpp | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/quotest/quotest.cpp b/quotest/quotest.cpp index 40bc456b..792faabd 100644 --- a/quotest/quotest.cpp +++ b/quotest/quotest.cpp @@ -14,6 +14,7 @@ #include "events/reactionevent.h" #include "events/redactionevent.h" #include "events/simplestateevents.h" +#include "events/roommemberevent.h" #include <QtTest/QSignalSpy> #include <QtCore/QCoreApplication> @@ -592,25 +593,31 @@ TEST_IMPL(changeName) clog << "Renaming the user to " << newName.toStdString() << " in the target room" << endl; localUser->rename(newName, targetRoom); - connectUntil(targetRoom, &Room::memberRenamed, this, - [this, thisTest, localUser, newName](const User* u) { - if (localUser != u) - return false; - if (localUser->name(targetRoom) != newName) - FAIL_TEST(); - - clog - << "Member rename successful, renaming the account" + connectUntil( + targetRoom, &Room::aboutToAddNewMessages, this, + [this, thisTest, localUser, newName](const RoomEventsRange& evts) { + for (const auto& e : evts) { + if (const auto* rme = eventCast<const RoomMemberEvent>(e)) { + if (rme->stateKey() != localUser->id() + || !rme->isRename()) + continue; + if (!rme->newDisplayName() + || *rme->newDisplayName() != newName) + FAIL_TEST(); + clog << "Member rename successful, renaming the account" << endl; - const auto newN = newName.mid(0, 5); - localUser->rename(newN); - connectUntil(localUser, &User::defaultNameChanged, - this, [this, thisTest, localUser, newN] { - targetRoom->localUser()->rename({}); - FINISH_TEST(localUser->name() == newN); - }); - return true; - }); + const auto newN = newName.mid(0, 5); + localUser->rename(newN); + connectUntil(localUser, &User::defaultNameChanged, this, + [this, thisTest, localUser, newN] { + targetRoom->localUser()->rename({}); + FINISH_TEST(localUser->name() == newN); + }); + return true; + } + } + return false; + }); }); return false; } |