File indexing completed on 2024-05-12 16:25:32

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "roomtest.h"
0008 #include "model/usersforroommodel.h"
0009 #include "rocketchataccount.h"
0010 #include "room.h"
0011 #include "ruqola_autotest_helper.h"
0012 #include <QCborMap>
0013 #include <QCborValue>
0014 #include <QJsonDocument>
0015 #include <QSignalSpy>
0016 
0017 QTEST_GUILESS_MAIN(RoomTest)
0018 
0019 RoomTest::RoomTest(QObject *parent)
0020     : QObject(parent)
0021 {
0022 }
0023 
0024 void RoomTest::shouldHaveDefaultValue()
0025 {
0026     Room input(nullptr);
0027     QVERIFY(input.usersModelForRoom());
0028 
0029     QVERIFY(input.messageModel());
0030     QVERIFY(input.inputMessage().isEmpty());
0031 
0032     QVERIFY(input.description().isEmpty());
0033     QVERIFY(input.announcement().isEmpty());
0034     QVERIFY(!input.readOnly());
0035     // Add more
0036     QCOMPARE(input.userMentions(), 0);
0037     QCOMPARE(input.unread(), 0);
0038     QCOMPARE(input.blocked(), false);
0039     QCOMPARE(input.blocker(), false);
0040     QVERIFY(input.roles().isEmpty());
0041     QVERIFY(!input.archived());
0042     QVERIFY(input.name().isEmpty());
0043     QVERIFY(input.ignoredUsers().isEmpty());
0044     QVERIFY(input.e2EKey().isEmpty());
0045     QVERIFY(input.e2eKeyId().isEmpty());
0046     QVERIFY(!input.encrypted());
0047     QVERIFY(!input.alert());
0048     QVERIFY(!input.readOnly());
0049     QVERIFY(!input.joinCodeRequired());
0050     QVERIFY(!input.wasInitialized());
0051     QVERIFY(input.rolesForRooms().isEmpty());
0052     QVERIFY(input.parentRid().isEmpty());
0053     QVERIFY(!input.broadcast());
0054     QVERIFY(input.fName().isEmpty());
0055     QVERIFY(input.autoTranslateLanguage().isEmpty());
0056     QVERIFY(!input.autoTranslate());
0057     QCOMPARE(input.lastSeenAt(), -1);
0058     QVERIFY(input.directChannelUserId().isEmpty());
0059     QVERIFY(input.displaySystemMessageTypes().isEmpty());
0060     QVERIFY(input.highlightsWord().isEmpty());
0061     QCOMPARE(input.lastMessageAt(), -1);
0062     QCOMPARE(input.numberMessages(), 0);
0063     QVERIFY(input.uids().isEmpty());
0064 
0065     const RetentionInfo info = input.retentionInfo();
0066     QVERIFY(!info.enabled());
0067     QVERIFY(!info.overrideGlobal());
0068     QVERIFY(!info.excludePinned());
0069     QVERIFY(!info.filesOnly());
0070     QCOMPARE(info.maxAge(), -1);
0071 
0072     const TeamInfo teamInfo = input.teamInfo();
0073     QVERIFY(teamInfo.teamId().isEmpty());
0074     QVERIFY(!teamInfo.mainTeam());
0075     QVERIFY(!teamInfo.autoJoin());
0076     QVERIFY(!teamInfo.isValid());
0077     QVERIFY(!teamInfo.hasTeamRoom());
0078     QCOMPARE(teamInfo.roomsCount(), 0);
0079 
0080     const NotificationOptions w = input.notificationOptions();
0081     QVERIFY(w.desktopNotifications().isEmpty());
0082     QVERIFY(w.mobilePushNotification().isEmpty());
0083     QVERIFY(w.emailNotifications().isEmpty());
0084     QVERIFY(w.unreadTrayIconAlert().isEmpty());
0085     QVERIFY(!w.disableNotifications());
0086     QVERIFY(!w.hideUnreadStatus());
0087     QVERIFY(!w.muteGroupMentions());
0088     QVERIFY(w.audioNotificationValue().isEmpty());
0089 }
0090 
0091 void RoomTest::shouldSerialized()
0092 {
0093     {
0094         Room input(nullptr);
0095         input.setRoomId(QStringLiteral("foo"));
0096         input.setChannelType(Room::roomTypeFromString(QStringLiteral("p")));
0097         input.setName(QStringLiteral("d"));
0098         input.setAnnouncement(QStringLiteral("AA"));
0099         input.setRoomCreatorUserName(QStringLiteral("pp"));
0100         input.setRoomCreatorUserId(QStringLiteral("sdfsdfs"));
0101         input.setTopic(QStringLiteral("topic"));
0102         input.setMutedUsers(QStringList{QStringLiteral("mutedUsers"), QStringLiteral("muted2")});
0103         input.setJitsiTimeout(55);
0104         input.setReadOnly(true);
0105         input.setUnread(66);
0106         input.setSelected(true);
0107         input.setFavorite(true);
0108         input.setAlert(true);
0109         input.setOpen(true);
0110         input.setBlocker(true);
0111         input.setBlocked(true);
0112         input.setArchived(true);
0113         input.setDescription(QStringLiteral("dd"));
0114         input.setUserMentions(3);
0115         input.setRoles({QStringLiteral("foo"), QStringLiteral("bla")});
0116         input.setIgnoredUsers({QStringLiteral("gg"), QStringLiteral("gg2")});
0117         input.setJoinCodeRequired(true);
0118         input.setAutoTranslateLanguage(QStringLiteral("blss"));
0119         input.setAutoTranslate(true);
0120         input.setLastSeenAt(253);
0121 
0122         // RetentionInfo
0123         RetentionInfo info;
0124         info.setEnabled(true);
0125         info.setOverrideGlobal(true);
0126         info.setExcludePinned(true);
0127         info.setFilesOnly(true);
0128         info.setMaxAge(12);
0129         input.setRetentionInfo(info);
0130 
0131         const QByteArray ba = Room::serialize(&input);
0132         // qDebug() << QJsonObject(QJsonDocument::fromBinaryData(ba).object());
0133         // Room *output = Room::fromJSon(QJsonObject(QJsonDocument::fromBinaryData(ba).object()));
0134         auto output = Room::deserialize(QCborValue::fromCbor(ba).toMap().toJsonObject());
0135         // qDebug() << "after" << QJsonObject(QJsonDocument::fromBinaryData(Room::serialize(output)).object());
0136         // qDebug() << "input  " << input;
0137         // qDebug() << "output  " << *output;
0138         QVERIFY(input.isEqual(*output));
0139     }
0140     {
0141         Room input(nullptr);
0142         input.setRoomId(QStringLiteral("foo"));
0143         input.setChannelType(Room::roomTypeFromString(QStringLiteral("p")));
0144         input.setName(QStringLiteral("p"));
0145         input.setAnnouncement(QStringLiteral("AA"));
0146         input.setRoomCreatorUserName(QStringLiteral("pp"));
0147         input.setRoomCreatorUserId(QStringLiteral("sdfsdfs"));
0148         input.setTopic(QStringLiteral("topic"));
0149         input.setMutedUsers(QStringList{QStringLiteral("mutedUsers"), QStringLiteral("muted2")});
0150         input.setJitsiTimeout(55);
0151         input.setReadOnly(true);
0152         input.setUnread(66);
0153         input.setSelected(true);
0154         input.setFavorite(true);
0155         input.setAlert(true);
0156         input.setOpen(true);
0157         input.setBlocker(true);
0158         input.setBlocked(true);
0159         input.setArchived(true);
0160         input.setDescription(QStringLiteral("dd"));
0161         input.setUserMentions(3);
0162         input.setRoles({QStringLiteral("foo"), QStringLiteral("bla")});
0163         input.setIgnoredUsers({QStringLiteral("gg"), QStringLiteral("gg2")});
0164         input.setJoinCodeRequired(true);
0165         input.setAutoTranslateLanguage(QStringLiteral("blss"));
0166         input.setAutoTranslate(true);
0167         input.setLastSeenAt(253);
0168 
0169         // RetentionInfo
0170         RetentionInfo info;
0171         info.setEnabled(true);
0172         info.setOverrideGlobal(false);
0173         info.setExcludePinned(false);
0174         info.setFilesOnly(false);
0175         info.setMaxAge(12);
0176         input.setRetentionInfo(info);
0177 
0178         // TeamInfo
0179         TeamInfo teamInfo;
0180         teamInfo.setTeamId(QStringLiteral("dddd"));
0181         teamInfo.setMainTeam(true);
0182         teamInfo.setAutoJoin(true);
0183         teamInfo.setRoomsCount(12);
0184         input.setTeamInfo(teamInfo);
0185 
0186         // Notification
0187         NotificationOptions w;
0188         NotificationOptions::NotificationValue w1;
0189         w1.value = QStringLiteral("notification1");
0190         w.setDesktopNotifications(w1);
0191         NotificationOptions::NotificationValue w2;
0192         w2.value = QStringLiteral("notification2");
0193         w.setMobilePushNotification(w2);
0194         NotificationOptions::NotificationValue w3;
0195         w3.value = QStringLiteral("notification3");
0196         w.setEmailNotifications(w3);
0197         w.setUnreadTrayIconAlert(QStringLiteral("ssssf"));
0198         w.setDisableNotifications(false);
0199         w.setHideUnreadStatus(true);
0200         w.setMuteGroupMentions(true);
0201         w.setAudioNotificationValue(QStringLiteral("test1"));
0202         input.setNotificationOptions(w);
0203 
0204         // setParentRid
0205         input.setParentRid(QStringLiteral("parentId1"));
0206 
0207         // Avatar
0208         input.setAvatarETag(QStringLiteral("avatar1"));
0209 
0210         // setE2EKey
0211         input.setE2EKey(QStringLiteral("e2ekey-1"));
0212         input.setE2eKeyId(QStringLiteral("e2ekey-id-1"));
0213 
0214         // setEncrypted
0215         input.setEncrypted(true);
0216 
0217         // setBroadcast
0218         input.setBroadcast(true);
0219 
0220         // setDisplaySystemMessageTypes
0221         input.setDisplaySystemMessageTypes({QStringLiteral("bla"), QStringLiteral("foo")});
0222 
0223         // setNumberMessages
0224         input.setNumberMessages(5);
0225 
0226         // setUpdatedAt
0227         input.setUpdatedAt(5555);
0228 
0229         // setHighlightsWord
0230         input.setHighlightsWord({QStringLiteral("highlight-bla"), QStringLiteral("highlight-foo")});
0231 
0232         // uids
0233         input.setUids({QStringLiteral("uids-bla"), QStringLiteral("uids-foo")});
0234 
0235         const QByteArray ba = Room::serialize(&input);
0236         // qDebug() << QJsonObject(QJsonDocument::fromBinaryData(ba).object());
0237         // Room *output = Room::fromJSon(QJsonObject(QJsonDocument::fromBinaryData(ba).object()));
0238         auto output = Room::deserialize(QCborValue::fromCbor(ba).toMap().toJsonObject());
0239         // qDebug() << "after" << QJsonObject(QJsonDocument::fromBinaryData(Room::serialize(output)).object());
0240         // qDebug() << "input  " << input;
0241         // qDebug() << "output  " << *output;
0242         QVERIFY(input.isEqual(*output));
0243     }
0244 }
0245 
0246 void RoomTest::shouldEmitSignals()
0247 {
0248     Room input(nullptr);
0249     QSignalSpy spyNameChanged(&input, &Room::nameChanged);
0250     QSignalSpy spyannouncementChanged(&input, &Room::announcementChanged);
0251     QSignalSpy spytopicChanged(&input, &Room::topicChanged);
0252     QSignalSpy spyfavoriteChanged(&input, &Room::favoriteChanged);
0253     QSignalSpy spyalertChanged(&input, &Room::alertChanged);
0254     QSignalSpy spyreadOnlyChanged(&input, &Room::readOnlyChanged);
0255     QSignalSpy spyunreadChanged(&input, &Room::unreadChanged);
0256     QSignalSpy spyblockerChanged(&input, &Room::blockerChanged);
0257     QSignalSpy spyarchivedChanged(&input, &Room::archivedChanged);
0258     QSignalSpy spydescriptionChanged(&input, &Room::descriptionChanged);
0259     QSignalSpy spyblockedChanged(&input, &Room::blockedChanged);
0260     QSignalSpy spyrolesChanged(&input, &Room::rolesChanged);
0261     QSignalSpy spyignoredUsersChanged(&input, &Room::ignoredUsersChanged);
0262     QSignalSpy spymutedUsersChanged(&input, &Room::mutedUsersChanged);
0263     QSignalSpy spyencryptedChanged(&input, &Room::encryptedChanged);
0264     QSignalSpy spyjoinCodeRequiredChanged(&input, &Room::joinCodeRequiredChanged);
0265     QSignalSpy spychannelTypeChanged(&input, &Room::channelTypeChanged);
0266     QSignalSpy spyparentRidChanged(&input, &Room::parentRidChanged);
0267     QSignalSpy spyautoTranslateLanguageChanged(&input, &Room::autoTranslateLanguageChanged);
0268     QSignalSpy spyautoTranslateChanged(&input, &Room::autoTranslateChanged);
0269     QSignalSpy spydirectChannelUserIdChanged(&input, &Room::directChannelUserIdChanged);
0270     QSignalSpy spylastMessageAtChanged(&input, &Room::lastMessageAtChanged);
0271 
0272     input.setRoomId(QStringLiteral("foo"));
0273     input.setChannelType(Room::roomTypeFromString(QStringLiteral("p")));
0274     input.setName(QStringLiteral("d"));
0275     input.setAnnouncement(QStringLiteral("AA"));
0276     input.setRoomCreatorUserName(QStringLiteral("pp"));
0277     input.setRoomCreatorUserId(QStringLiteral("sdfsdfs"));
0278     input.setTopic(QStringLiteral("topic"));
0279     input.setMutedUsers(QStringList{QStringLiteral("mutedUsers"), QStringLiteral("muted2")});
0280     input.setJitsiTimeout(55);
0281     input.setReadOnly(true);
0282     input.setUnread(66);
0283     input.setSelected(true);
0284     input.setFavorite(true);
0285     input.setAlert(true);
0286     input.setOpen(true);
0287     input.setBlocker(true);
0288     input.setBlocked(true);
0289     input.setArchived(true);
0290     input.setEncrypted(true);
0291     input.setJoinCodeRequired(true);
0292     input.setDescription(QStringLiteral("ddd"));
0293     input.setRoles({QStringLiteral("bla"), QStringLiteral("blu")});
0294     input.setIgnoredUsers({QStringLiteral("bla"), QStringLiteral("blu3")});
0295     input.setParentRid(QStringLiteral("bla"));
0296     input.setAutoTranslateLanguage(QStringLiteral("bli"));
0297     input.setAutoTranslate(true);
0298     input.setDirectChannelUserId(QStringLiteral("naninani"));
0299     input.setLastMessageAt(QDateTime::currentMSecsSinceEpoch());
0300 
0301     QCOMPARE(spyNameChanged.count(), 1);
0302     QCOMPARE(spyannouncementChanged.count(), 1);
0303     QCOMPARE(spytopicChanged.count(), 1);
0304     QCOMPARE(spyfavoriteChanged.count(), 1);
0305     QCOMPARE(spyalertChanged.count(), 1);
0306     QCOMPARE(spyreadOnlyChanged.count(), 1);
0307     QCOMPARE(spyunreadChanged.count(), 1);
0308     QCOMPARE(spyblockerChanged.count(), 1);
0309     QCOMPARE(spyarchivedChanged.count(), 1);
0310     QCOMPARE(spyblockedChanged.count(), 1);
0311     QCOMPARE(spydescriptionChanged.count(), 1);
0312     QCOMPARE(spyrolesChanged.count(), 1);
0313     QCOMPARE(spyignoredUsersChanged.count(), 1);
0314     QCOMPARE(spymutedUsersChanged.count(), 1);
0315     QCOMPARE(spyencryptedChanged.count(), 1);
0316     QCOMPARE(spyjoinCodeRequiredChanged.count(), 1);
0317     QCOMPARE(spychannelTypeChanged.count(), 1);
0318     QCOMPARE(spyparentRidChanged.count(), 1);
0319     QCOMPARE(spyautoTranslateLanguageChanged.count(), 1);
0320     QCOMPARE(spyautoTranslateChanged.count(), 1);
0321     QCOMPARE(spydirectChannelUserIdChanged.count(), 1);
0322     QCOMPARE(spylastMessageAtChanged.count(), 1);
0323 }
0324 
0325 void RoomTest::shouldChangeInputMessage()
0326 {
0327     Room input(nullptr);
0328     QString inputMsg = QStringLiteral("Foo");
0329     input.setInputMessage(inputMsg);
0330     QCOMPARE(input.inputMessage(), inputMsg);
0331 
0332     inputMsg = QString();
0333     input.setInputMessage(inputMsg);
0334     QCOMPARE(input.inputMessage(), inputMsg);
0335 
0336     inputMsg = QStringLiteral("foo");
0337     input.setInputMessage(inputMsg);
0338     QCOMPARE(input.inputMessage(), inputMsg);
0339 }
0340 
0341 void RoomTest::shouldParseRoom_data()
0342 {
0343     QTest::addColumn<QString>("fileName");
0344     // Missing _updatedAt/ts/_id/groupMentions/ls/roles (implement roles ! )
0345     QTest::newRow("notification-room") << QStringLiteral("notification-room");
0346 
0347     QTest::newRow("unread-usermentions-room") << QStringLiteral("unread-usermentions-room");
0348     QTest::newRow("muted-users") << QStringLiteral("muted-users");
0349     QTest::newRow("userignored-room") << QStringLiteral("userignored-room");
0350     QTest::newRow("autotranslatelanguage") << QStringLiteral("autotranslatelanguage");
0351     QTest::newRow("direct-room") << QStringLiteral("direct-room");
0352     QTest::newRow("retention-room") << QStringLiteral("retention-room");
0353     QTest::newRow("team-room") << QStringLiteral("team-room");
0354 }
0355 
0356 void RoomTest::shouldParseRoom()
0357 {
0358     QFETCH(QString, fileName);
0359 
0360     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/room/") + fileName + QLatin1String(".json");
0361     const QJsonObject fields = AutoTestHelper::loadJsonObject(originalJsonFile);
0362 
0363     Room r;
0364     r.parseSubscriptionRoom(fields);
0365     // qDebug() << " fields"<<fields;
0366 
0367     const QByteArray ba = Room::serialize(&r, false);
0368     // qDebug() << " ba " << ba;
0369     const QJsonDocument docSerialized = QJsonDocument::fromJson(ba);
0370 
0371     const QByteArray jsonIndented = docSerialized.toJson(QJsonDocument::Indented);
0372     AutoTestHelper::compareFile(QStringLiteral("/room/"), jsonIndented, fileName);
0373 
0374     auto m = Room::deserialize(docSerialized.object());
0375     QCOMPARE(r, *m);
0376 }
0377 
0378 void RoomTest::shouldParseRoomAndUpdate_data()
0379 {
0380     QTest::addColumn<QString>("fileNameinit");
0381     QTest::addColumn<QStringList>("fileNameupdate");
0382     // Missing _updatedAt/ts/_id/groupMentions/ls/roles (implement roles ! )
0383     QTest::newRow("notification-roomupdate") << QStringLiteral("notification-room") << (QStringList() << QStringLiteral("notification-roomupdate1"));
0384     QTest::newRow("room-update") << QStringLiteral("room-update") << (QStringList() << QStringLiteral("room-update1"));
0385     QTest::newRow("room-without-owner") << QStringLiteral("room-without-owner") << (QStringList() << QStringLiteral("room-without-owner1"));
0386     QTest::newRow("room-mute-unmute") << QStringLiteral("room-mute-unmute")
0387                                       << (QStringList() << QStringLiteral("muted-users") << QStringLiteral("unmuted-users"));
0388     QTest::newRow("userignored-room") << QStringLiteral("userignored-room") << (QStringList() << QStringLiteral("userignored-room-update"));
0389     QTest::newRow("room-requiredjoincode-owner") << QStringLiteral("room-requiredjoincode-owner")
0390                                                  << (QStringList() << QStringLiteral("room-requiredjoincode-update"));
0391     QTest::newRow("autotranslatelanguage") << QStringLiteral("autotranslatelanguage") << (QStringList() << QStringLiteral("autotranslatelanguage-update"));
0392     QTest::newRow("direct-room") << QStringLiteral("direct-room") << (QStringList() << QStringLiteral("direct-room-update"));
0393     QTest::newRow("room-retention") << QStringLiteral("room-retention") << (QStringList() << QStringLiteral("room-retention-update"));
0394     QTest::newRow("room-team") << QStringLiteral("room-team") << (QStringList() << QStringLiteral("room-team"));
0395 }
0396 
0397 void RoomTest::shouldParseRoomAndUpdate()
0398 {
0399     QFETCH(QString, fileNameinit);
0400     QFETCH(QStringList, fileNameupdate);
0401 
0402     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/room-updated/") + fileNameinit + QLatin1String(".json");
0403     QFile f(originalJsonFile);
0404     bool opened = f.open(QIODevice::ReadOnly);
0405     if (!opened) {
0406         qWarning() << " impossible to open " << originalJsonFile;
0407     }
0408     QVERIFY(opened);
0409     const QByteArray content = f.readAll();
0410     f.close();
0411     const QJsonDocument doc = QJsonDocument::fromJson(content);
0412     const QJsonObject fields = doc.object();
0413 
0414     RocketChatAccount account;
0415     account.setUserId(QStringLiteral("uKK39zoewTkdacidH"));
0416     Room r(&account);
0417     r.parseSubscriptionRoom(fields);
0418 
0419     for (const QString &updateFile : fileNameupdate) {
0420         const QString originalUpdateJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/room-updated/") + updateFile + QLatin1String(".json");
0421         const QJsonObject fields = AutoTestHelper::loadJsonObject(originalUpdateJsonFile);
0422 
0423         r.parseUpdateRoom(fields);
0424     }
0425 
0426     // qDebug() << " fields"<<fields;
0427 
0428     const QByteArray ba = Room::serialize(&r, false);
0429     // qDebug() << " ba " << ba;
0430     const QJsonDocument docSerialized = QJsonDocument::fromJson(ba);
0431 
0432     const QByteArray jsonIndented = docSerialized.toJson(QJsonDocument::Indented);
0433     AutoTestHelper::compareFile(QStringLiteral("/room-updated/"), jsonIndented, fileNameinit);
0434 
0435     auto m = Room::deserialize(docSerialized.object());
0436     QCOMPARE(r, *m);
0437 }
0438 
0439 void RoomTest::shouldParseRoomAndUpdateSubscription_data()
0440 {
0441     QTest::addColumn<QString>("fileNameinit");
0442     QTest::addColumn<QStringList>("UpdateRoomfileNames");
0443     QTest::addColumn<QStringList>("UpdateSubscriptionFileNames");
0444     // Missing _updatedAt/ts/_id/groupMentions/ls/roles (implement roles ! )
0445     QTest::newRow("notification-roomupdate") << QStringLiteral("notification-room") << (QStringList() << QStringLiteral("notification-roomupdate1"))
0446                                              << (QStringList() << QStringLiteral("notification-roomsubscription1"));
0447 
0448     QTest::newRow("room-blocked") << QStringLiteral("room-blocked") << (QStringList() << QStringLiteral("room-blockedupdate1")) << QStringList();
0449 
0450     QTest::newRow("room-encryption") << QStringLiteral("room-encryption") << (QStringList() << QStringLiteral("room-encryptionupdate1")) << QStringList();
0451 
0452     QTest::newRow("room-broadcasted") << QStringLiteral("room-broadcasted") << (QStringList() << QStringLiteral("room-broadcastedupdate1")) << QStringList();
0453 }
0454 
0455 void RoomTest::shouldParseRoomAndUpdateSubscription()
0456 {
0457     QFETCH(QString, fileNameinit);
0458     QFETCH(QStringList, UpdateRoomfileNames);
0459     QFETCH(QStringList, UpdateSubscriptionFileNames);
0460 
0461     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/room-updated/") + fileNameinit + QLatin1String(".json");
0462     QFile f(originalJsonFile);
0463     QVERIFY(f.open(QIODevice::ReadOnly));
0464     const QByteArray content = f.readAll();
0465     f.close();
0466     const QJsonDocument doc = QJsonDocument::fromJson(content);
0467     const QJsonObject fields = doc.object();
0468 
0469     Room r;
0470     r.parseSubscriptionRoom(fields);
0471 
0472     for (const QString &updateFile : UpdateRoomfileNames) {
0473         const QString originalUpdateJsonFile =
0474             QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/room-update-subscription/") + updateFile + QLatin1String(".json");
0475         QFile f(originalUpdateJsonFile);
0476         QVERIFY(f.open(QIODevice::ReadOnly));
0477         const QByteArray content = f.readAll();
0478         f.close();
0479         const QJsonDocument doc = QJsonDocument::fromJson(content);
0480         const QJsonObject fields = doc.object();
0481 
0482         r.parseUpdateRoom(fields);
0483     }
0484 
0485     for (const QString &updateFile : UpdateSubscriptionFileNames) {
0486         const QString originalUpdateJsonFile =
0487             QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/room-update-subscription/") + updateFile + QLatin1String(".json");
0488         const QJsonObject fields = AutoTestHelper::loadJsonObject(originalUpdateJsonFile);
0489 
0490         r.updateSubscriptionRoom(fields);
0491     }
0492 
0493     // qDebug() << " fields"<<fields;
0494 
0495     const QByteArray ba = Room::serialize(&r, false);
0496     // qDebug() << " ba " << ba;
0497     const QJsonDocument docSerialized = QJsonDocument::fromJson(ba);
0498 
0499     const QByteArray jsonIndented = docSerialized.toJson(QJsonDocument::Indented);
0500     AutoTestHelper::compareFile(QStringLiteral("/room-update-subscription/"), jsonIndented, fileNameinit);
0501 
0502     auto m = Room::deserialize(docSerialized.object());
0503     QCOMPARE(r, *m);
0504 }
0505 
0506 // TODO add more autotests signal and co.
0507 
0508 #include "moc_roomtest.cpp"