From f3c4d9449a2921b6614d4957b08f2f2c569923a3 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sun, 29 Oct 2023 13:12:05 +0000 Subject: [PATCH] Move remaining tests to external Json files Title --- autotests/data/test-texthandler-sync.json | 124 +++++++++++++++++++++ autotests/neochatroomtest.cpp | 95 +--------------- autotests/texthandlertest.cpp | 130 +--------------------- 3 files changed, 135 insertions(+), 214 deletions(-) create mode 100644 autotests/data/test-texthandler-sync.json diff --git a/autotests/data/test-texthandler-sync.json b/autotests/data/test-texthandler-sync.json new file mode 100644 index 000000000..fa27df6c0 --- /dev/null +++ b/autotests/data/test-texthandler-sync.json @@ -0,0 +1,124 @@ +{ + "account_data": { + "events": [ + { + "content": { + "tags": { + "u.work": { + "order": 0.9 + } + } + }, + "type": "m.tag" + }, + { + "content": { + "custom_config_key": "custom_config_value" + }, + "type": "org.example.custom.room.config" + } + ] + }, + "ephemeral": { + "events": [ + { + "content": { + "user_ids": [ + "@alice:matrix.org", + "@bob:example.com" + ] + }, + "room_id": "!jEsUZKDJdhlrceRyVU:example.org", + "type": "m.typing" + } + ] + }, + "state": { + "events": [ + { + "content": { + "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", + "displayname": "Alice Margatroid", + "membership": "join", + "reason": "Looking for support" + }, + "event_id": "$143273582443PhrSn:example.org", + "origin_server_ts": 1432735824653, + "room_id": "!jEsUZKDJdhlrceRyVU:example.org", + "sender": "@example:example.org", + "state_key": "@alice:example.org", + "type": "m.room.member", + "unsigned": { + "age": 1234 + } + } + ] + }, + "summary": { + "m.heroes": [ + "@alice:example.com", + "@bob:example.com" + ], + "m.invited_member_count": 0, + "m.joined_member_count": 2 + }, + "timeline": { + "events": [ + { + "content": { + "body": "This is an **example** text message", + "format": "org.matrix.custom.html", + "formatted_body": "This is an example text message", + "msgtype": "m.text" + }, + "event_id": "$143273582443PhrSn:example.org", + "origin_server_ts": 1432735824654, + "room_id": "!jEsUZKDJdhlrceRyVU:example.org", + "sender": "@example:example.org", + "type": "m.room.message", + "unsigned": { + "age": 1232 + } + }, + { + "content": { + "body": "/me This is an emote.", + "format": "org.matrix.custom.html", + "formatted_body": "This is an emote.", + "msgtype": "m.emote" + }, + "event_id": "$153273582443PhrSn:example.org", + "origin_server_ts": 1532735824654, + "room_id": "!jEsUZKDJdhlrceRyVU:example.org", + "sender": "@example:example.org", + "type": "m.room.message", + "unsigned": { + "age": 1231 + } + }, + { + "content": { + "body": "tested", + "msgtype": "m.text" + }, + "event_id": "$zrCiBxBnqqTn0Z5FY78qSZAszno_w8nJJXzfBULG-3E", + "origin_server_ts": 1680948575928, + "room_id": "!jEsUZKDJdhlrceRyVU:example.org", + "sender": "@example:example.org", + "type": "m.room.message", + "unsigned": { + "age": 1747776, + "m.relations": { + "m.replace": { + "event_id": "$UX0PlpyI7vYO32iHMuuYEP7ECMh4sX3XLGiB2SwM4mQ", + "origin_server_ts": 1680948580992, + "sender": "@example:example.org" + } + } + } + } + ], + "limited": true, + "prev_batch": "t34-23535_0_0" + } +} diff --git a/autotests/neochatroomtest.cpp b/autotests/neochatroomtest.cpp index 0585481de..5190ae712 100644 --- a/autotests/neochatroomtest.cpp +++ b/autotests/neochatroomtest.cpp @@ -42,101 +42,18 @@ void NeoChatRoomTest::initTestCase() connection = Connection::makeMockConnection(QStringLiteral("@bob:kde.org")); room = new TestRoom(connection, QStringLiteral("#myroom:kde.org"), JoinState::Join); - auto json = QJsonDocument::fromJson(R"EVENT({ - "account_data": { - "events": [ - { - "content": { - "tags": { - "u.work": { - "order": 0.9 - } - } - }, - "type": "m.tag" - }, - { - "content": { - "custom_config_key": "custom_config_value" - }, - "type": "org.example.custom.room.config" - } - ] - }, - "ephemeral": { - "events": [ - { - "content": { - "user_ids": [ - "@alice:matrix.org", - "@bob:example.com" - ] - }, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "type": "m.typing" - } - ] - }, - "state": { - "events": [ - { - "content": { - "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", - "displayname": "Alice Margatroid", - "membership": "join", - "reason": "Looking for support" - }, - "event_id": "$143273582443PhrSn:example.org", - "origin_server_ts": 1432735824653, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "sender": "@example:example.org", - "state_key": "@alice:example.org", - "type": "m.room.member", - "unsigned": { - "age": 1234 - } - } - ] - }, - "summary": { - "m.heroes": [ - "@alice:example.com", - "@bob:example.com" - ], - "m.invited_member_count": 0, - "m.joined_member_count": 2 - }, - "timeline": { - "events": [ - { - "content": { - "body": "This is an **example** text message", - "format": "org.matrix.custom.html", - "formatted_body": "This is an example text message", - "msgtype": "m.text" - }, - "event_id": "$143273582443PhrSn:example.org", - "origin_server_ts": 1432735824654, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "sender": "@example:example.org", - "type": "m.room.message", - "unsigned": { - "age": 1235 - } - } - ], - "limited": true, - "prev_batch": "t34-23535_0_0" - } -})EVENT"); - SyncRoomData roomData(QStringLiteral("@bob:kde.org"), JoinState::Join, json.object()); + QFile testMinSyncFile; + testMinSyncFile.setFileName(QLatin1String(DATA_DIR) + u'/' + QLatin1String("test-min-sync.json")); + testMinSyncFile.open(QIODevice::ReadOnly); + const auto testMinSyncJson = QJsonDocument::fromJson(testMinSyncFile.readAll()); + SyncRoomData roomData(QStringLiteral("@bob:kde.org"), JoinState::Join, testMinSyncJson.object()); room->update(std::move(roomData)); } void NeoChatRoomTest::subtitleTextTest() { QCOMPARE(room->timelineSize(), 1); - QCOMPARE(room->lastEventToString(), QStringLiteral("@example:example.org: This is an example text message")); + QCOMPARE(room->lastEventToString(), QStringLiteral("@example:example.org: This is an example\ntext message")); } void NeoChatRoomTest::eventTest() diff --git a/autotests/texthandlertest.cpp b/autotests/texthandlertest.cpp index 9e54edc1f..511dd2c5b 100644 --- a/autotests/texthandlertest.cpp +++ b/autotests/texthandlertest.cpp @@ -79,131 +79,11 @@ void TextHandlerTest::initTestCase() connection = Connection::makeMockConnection(QStringLiteral("@bob:kde.org")); room = new TestRoom(connection, QStringLiteral("#myroom:kde.org"), JoinState::Join); - const auto json = QJsonDocument::fromJson(R"EVENT({ - "account_data": { - "events": [ - { - "content": { - "tags": { - "u.work": { - "order": 0.9 - } - } - }, - "type": "m.tag" - }, - { - "content": { - "custom_config_key": "custom_config_value" - }, - "type": "org.example.custom.room.config" - } - ] - }, - "ephemeral": { - "events": [ - { - "content": { - "user_ids": [ - "@alice:matrix.org", - "@bob:example.com" - ] - }, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "type": "m.typing" - } - ] - }, - "state": { - "events": [ - { - "content": { - "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", - "displayname": "Alice Margatroid", - "membership": "join", - "reason": "Looking for support" - }, - "event_id": "$143273582443PhrSn:example.org", - "origin_server_ts": 1432735824653, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "sender": "@example:example.org", - "state_key": "@alice:example.org", - "type": "m.room.member", - "unsigned": { - "age": 1234 - } - } - ] - }, - "summary": { - "m.heroes": [ - "@alice:example.com", - "@bob:example.com" - ], - "m.invited_member_count": 0, - "m.joined_member_count": 2 - }, - "timeline": { - "events": [ - { - "content": { - "body": "This is an **example** text message", - "format": "org.matrix.custom.html", - "formatted_body": "This is an example text message", - "msgtype": "m.text" - }, - "event_id": "$143273582443PhrSn:example.org", - "origin_server_ts": 1432735824654, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "sender": "@example:example.org", - "type": "m.room.message", - "unsigned": { - "age": 1232 - } - }, - { - "content": { - "body": "/me This is an emote.", - "format": "org.matrix.custom.html", - "formatted_body": "This is an emote.", - "msgtype": "m.emote" - }, - "event_id": "$153273582443PhrSn:example.org", - "origin_server_ts": 1532735824654, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "sender": "@example:example.org", - "type": "m.room.message", - "unsigned": { - "age": 1231 - } - }, - { - "content": { - "body": "tested", - "msgtype": "m.text" - }, - "event_id": "$zrCiBxBnqqTn0Z5FY78qSZAszno_w8nJJXzfBULG-3E", - "origin_server_ts": 1680948575928, - "room_id": "!jEsUZKDJdhlrceRyVU:example.org", - "sender": "@example:example.org", - "type": "m.room.message", - "unsigned": { - "age": 1747776, - "m.relations": { - "m.replace": { - "event_id": "$UX0PlpyI7vYO32iHMuuYEP7ECMh4sX3XLGiB2SwM4mQ", - "origin_server_ts": 1680948580992, - "sender": "@example:example.org" - } - } - } - } - ], - "limited": true, - "prev_batch": "t34-23535_0_0" - } -})EVENT"); - SyncRoomData roomData(QStringLiteral("@bob:kde.org"), JoinState::Join, json.object()); + QFile testTextHandlerSyncFile; + testTextHandlerSyncFile.setFileName(QLatin1String(DATA_DIR) + u'/' + QLatin1String("test-texthandler-sync.json")); + testTextHandlerSyncFile.open(QIODevice::ReadOnly); + const auto testTextHandlerSyncJson = QJsonDocument::fromJson(testTextHandlerSyncFile.readAll()); + SyncRoomData roomData(QStringLiteral("@bob:kde.org"), JoinState::Join, testTextHandlerSyncJson.object()); room->update(std::move(roomData)); }