From 9def76aa0877af373c0b293811c029e268913dc2 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 24 Sep 2017 17:39:06 +0300 Subject: [PATCH] Linting --- src/MainWindow.cc | 4 +- tests/event_collection.cc | 150 ++++---- tests/events.cc | 787 +++++++++++++++++++------------------- tests/message_events.cc | 424 ++++++++++---------- 4 files changed, 669 insertions(+), 696 deletions(-) diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 364e6d66..531bae8b 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -18,12 +18,12 @@ #include "MainWindow.h" #include "Config.h" +#include #include #include #include -#include #include -#include +#include MainWindow *MainWindow::instance_ = nullptr; diff --git a/tests/event_collection.cc b/tests/event_collection.cc index 40b9ff13..0ba7d227 100644 --- a/tests/event_collection.cc +++ b/tests/event_collection.cc @@ -22,94 +22,90 @@ using namespace matrix::events; TEST(EventCollection, Deserialize) { - auto events = QJsonArray{ - QJsonObject{ - {"content", QJsonObject{{"name", "Name"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"prev_content", QJsonObject{{"name", "Previous Name"}}}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"state_key", ""}, - {"type", "m.room.name"}}, - QJsonObject{ - {"content", QJsonObject{{"topic", "Topic"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"prev_content", QJsonObject{{"topic", "Previous Topic"}}}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"state_key", ""}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.topic"}}, - }; + auto events = QJsonArray{ + QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "prev_content", QJsonObject{ { "name", "Previous Name" } } }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "state_key", "" }, + { "type", "m.room.name" } }, + QJsonObject{ { "content", QJsonObject{ { "topic", "Topic" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "prev_content", QJsonObject{ { "topic", "Previous Topic" } } }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "state_key", "" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.topic" } }, + }; - for (const auto &event : events) { - EventType ty = extractEventType(event.toObject()); + for (const auto &event : events) { + EventType ty = extractEventType(event.toObject()); - if (ty == EventType::RoomName) { - StateEvent name_event; - name_event.deserialize(event); + if (ty == EventType::RoomName) { + StateEvent name_event; + name_event.deserialize(event); - EXPECT_EQ(name_event.content().name(), "Name"); - EXPECT_EQ(name_event.previousContent().name(), "Previous Name"); - } else if (ty == EventType::RoomTopic) { - StateEvent topic_event; - topic_event.deserialize(event); + EXPECT_EQ(name_event.content().name(), "Name"); + EXPECT_EQ(name_event.previousContent().name(), "Previous Name"); + } else if (ty == EventType::RoomTopic) { + StateEvent topic_event; + topic_event.deserialize(event); - EXPECT_EQ(topic_event.content().topic(), "Topic"); - EXPECT_EQ(topic_event.previousContent().topic(), "Previous Topic"); - } else { - ASSERT_EQ(false, true); - } - } + EXPECT_EQ(topic_event.content().topic(), "Topic"); + EXPECT_EQ(topic_event.previousContent().topic(), "Previous Topic"); + } else { + ASSERT_EQ(false, true); + } + } } TEST(EventCollection, DeserializationException) { - // Using wrong event types. - auto events = QJsonArray{ - QJsonObject{ - {"content", QJsonObject{{"name", "Name"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"prev_content", QJsonObject{{"name", "Previous Name"}}}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"state_key", ""}, - {"type", "m.room.topic"}}, - QJsonObject{ - {"content", QJsonObject{{"topic", "Topic"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"prev_content", QJsonObject{{"topic", "Previous Topic"}}}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"state_key", ""}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.name"}}, - }; + // Using wrong event types. + auto events = QJsonArray{ + QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "prev_content", QJsonObject{ { "name", "Previous Name" } } }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "state_key", "" }, + { "type", "m.room.topic" } }, + QJsonObject{ { "content", QJsonObject{ { "topic", "Topic" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "prev_content", QJsonObject{ { "topic", "Previous Topic" } } }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "state_key", "" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.name" } }, + }; - for (const auto &event : events) { - EventType ty = extractEventType(event.toObject()); + for (const auto &event : events) { + EventType ty = extractEventType(event.toObject()); - if (ty == EventType::RoomName) { - StateEvent name_event; + if (ty == EventType::RoomName) { + StateEvent name_event; - try { - name_event.deserialize(event); - } catch (const DeserializationException &e) { - ASSERT_STREQ("name key is missing", e.what()); - } + try { + name_event.deserialize(event); + } catch (const DeserializationException &e) { + ASSERT_STREQ("name key is missing", e.what()); + } - } else if (ty == EventType::RoomTopic) { - StateEvent topic_event; + } else if (ty == EventType::RoomTopic) { + StateEvent topic_event; - try { - topic_event.deserialize(event); - } catch (const DeserializationException &e) { - ASSERT_STREQ("topic key is missing", e.what()); - } - } else { - ASSERT_EQ(false, true); - } - } + try { + topic_event.deserialize(event); + } catch (const DeserializationException &e) { + ASSERT_STREQ("topic key is missing", e.what()); + } + } else { + ASSERT_EQ(false, true); + } + } } diff --git a/tests/events.cc b/tests/events.cc index 7712255c..ee1f9560 100644 --- a/tests/events.cc +++ b/tests/events.cc @@ -1,6 +1,6 @@ -#include #include #include +#include #include "Event.h" #include "RoomEvent.h" @@ -21,674 +21,675 @@ using namespace matrix::events; TEST(BaseEvent, Deserialization) { - // NameEventContent - auto data = QJsonObject{ - {"content", QJsonObject{{"name", "Room Name"}}}, - {"type", "m.room.name"}}; + // NameEventContent + auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Room Name" } } }, + { "type", "m.room.name" } }; - Event name_event; - name_event.deserialize(data); - EXPECT_EQ(name_event.content().name(), "Room Name"); - EXPECT_EQ(name_event.serialize(), data); + Event name_event; + name_event.deserialize(data); + EXPECT_EQ(name_event.content().name(), "Room Name"); + EXPECT_EQ(name_event.serialize(), data); - // TopicEventContent - data = QJsonObject{ - {"content", QJsonObject{{"topic", "Room Topic"}}}, - {"type", "m.room.topic"}}; + // TopicEventContent + data = QJsonObject{ { "content", QJsonObject{ { "topic", "Room Topic" } } }, + { "type", "m.room.topic" } }; - Event topic_event; - topic_event.deserialize(data); - EXPECT_EQ(topic_event.content().topic(), "Room Topic"); - EXPECT_EQ(topic_event.serialize(), data); + Event topic_event; + topic_event.deserialize(data); + EXPECT_EQ(topic_event.content().topic(), "Room Topic"); + EXPECT_EQ(topic_event.serialize(), data); - // AvatarEventContent - data = QJsonObject{ - {"content", QJsonObject{{"url", "https://matrix.org"}}}, - {"type", "m.room.avatar"}}; + // AvatarEventContent + data = QJsonObject{ { "content", QJsonObject{ { "url", "https://matrix.org" } } }, + { "type", "m.room.avatar" } }; - Event avatar_event; - avatar_event.deserialize(data); - EXPECT_EQ(avatar_event.content().url().toString(), "https://matrix.org"); - EXPECT_EQ(avatar_event.serialize(), data); + Event avatar_event; + avatar_event.deserialize(data); + EXPECT_EQ(avatar_event.content().url().toString(), "https://matrix.org"); + EXPECT_EQ(avatar_event.serialize(), data); - // AliasesEventContent - data = QJsonObject{ - {"content", QJsonObject{{"aliases", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}}, - {"type", "m.room.aliases"}}; + // AliasesEventContent + data = + QJsonObject{ { "content", + QJsonObject{ + { "aliases", QJsonArray{ "#test:matrix.org", "#test2:matrix.org" } } } }, + { "type", "m.room.aliases" } }; - Event aliases_event; - aliases_event.deserialize(data); - EXPECT_EQ(aliases_event.content().aliases().size(), 2); - EXPECT_EQ(aliases_event.serialize(), data); + Event aliases_event; + aliases_event.deserialize(data); + EXPECT_EQ(aliases_event.content().aliases().size(), 2); + EXPECT_EQ(aliases_event.serialize(), data); - // CreateEventContent - data = QJsonObject{ - {"content", QJsonObject{{"creator", "@alice:matrix.org"}}}, - {"type", "m.room.create"}}; + // CreateEventContent + data = QJsonObject{ { "content", QJsonObject{ { "creator", "@alice:matrix.org" } } }, + { "type", "m.room.create" } }; - Event create_event; - create_event.deserialize(data); - EXPECT_EQ(create_event.content().creator(), "@alice:matrix.org"); - EXPECT_EQ(create_event.serialize(), data); + Event create_event; + create_event.deserialize(data); + EXPECT_EQ(create_event.content().creator(), "@alice:matrix.org"); + EXPECT_EQ(create_event.serialize(), data); - // JoinRulesEventContent - data = QJsonObject{ - {"content", QJsonObject{{"join_rule", "private"}}}, - {"type", "m.room.join_rules"}}; + // JoinRulesEventContent + data = QJsonObject{ { "content", QJsonObject{ { "join_rule", "private" } } }, + { "type", "m.room.join_rules" } }; - Event join_rules_event; - join_rules_event.deserialize(data); - EXPECT_EQ(join_rules_event.content().joinRule(), JoinRule::Private); - EXPECT_EQ(join_rules_event.serialize(), data); + Event join_rules_event; + join_rules_event.deserialize(data); + EXPECT_EQ(join_rules_event.content().joinRule(), JoinRule::Private); + EXPECT_EQ(join_rules_event.serialize(), data); } TEST(BaseEvent, DeserializationException) { - auto data = QJsonObject{ - {"content", QJsonObject{{"rule", "private"}}}, - {"type", "m.room.join_rules"}}; + auto data = QJsonObject{ { "content", QJsonObject{ { "rule", "private" } } }, + { "type", "m.room.join_rules" } }; - Event event1; - ASSERT_THROW(event1.deserialize(data), DeserializationException); + Event event1; + ASSERT_THROW(event1.deserialize(data), DeserializationException); - data = QJsonObject{ - {"contents", QJsonObject{{"join_rule", "private"}}}, - {"type", "m.room.join_rules"}}; + data = QJsonObject{ { "contents", QJsonObject{ { "join_rule", "private" } } }, + { "type", "m.room.join_rules" } }; - Event event2; - ASSERT_THROW(event2.deserialize(data), DeserializationException); + Event event2; + ASSERT_THROW(event2.deserialize(data), DeserializationException); } TEST(RoomEvent, Deserialization) { - auto data = QJsonObject{ - {"content", QJsonObject{{"name", "Name"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.name"}}; + auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.name" } }; - RoomEvent event; - event.deserialize(data); + RoomEvent event; + event.deserialize(data); - EXPECT_EQ(event.eventId(), "$asdfafdf8af:matrix.org"); - EXPECT_EQ(event.roomId(), "!aasdfaeae23r9:matrix.org"); - EXPECT_EQ(event.sender(), "@alice:matrix.org"); - EXPECT_EQ(event.timestamp(), 1323238293289323); - EXPECT_EQ(event.content().name(), "Name"); - EXPECT_EQ(event.serialize(), data); + EXPECT_EQ(event.eventId(), "$asdfafdf8af:matrix.org"); + EXPECT_EQ(event.roomId(), "!aasdfaeae23r9:matrix.org"); + EXPECT_EQ(event.sender(), "@alice:matrix.org"); + EXPECT_EQ(event.timestamp(), 1323238293289323); + EXPECT_EQ(event.content().name(), "Name"); + EXPECT_EQ(event.serialize(), data); } TEST(RoomEvent, DeserializationException) { - auto data = QJsonObject{ - {"content", QJsonObject{{"name", "Name"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.name"}}; + auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.name" } }; - RoomEvent event; + RoomEvent event; - try { - event.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("sender key is missing", e.what()); - } + try { + event.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("sender key is missing", e.what()); + } } TEST(StateEvent, Deserialization) { - auto data = QJsonObject{ - {"content", QJsonObject{{"name", "Name"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"state_key", "some_state_key"}, - {"prev_content", QJsonObject{{"name", "Previous Name"}}}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.name"}}; + auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "state_key", "some_state_key" }, + { "prev_content", QJsonObject{ { "name", "Previous Name" } } }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.name" } }; - StateEvent event; - event.deserialize(data); + StateEvent event; + event.deserialize(data); - EXPECT_EQ(event.eventId(), "$asdfafdf8af:matrix.org"); - EXPECT_EQ(event.roomId(), "!aasdfaeae23r9:matrix.org"); - EXPECT_EQ(event.sender(), "@alice:matrix.org"); - EXPECT_EQ(event.timestamp(), 1323238293289323); - EXPECT_EQ(event.content().name(), "Name"); - EXPECT_EQ(event.stateKey(), "some_state_key"); - EXPECT_EQ(event.previousContent().name(), "Previous Name"); - EXPECT_EQ(event.serialize(), data); + EXPECT_EQ(event.eventId(), "$asdfafdf8af:matrix.org"); + EXPECT_EQ(event.roomId(), "!aasdfaeae23r9:matrix.org"); + EXPECT_EQ(event.sender(), "@alice:matrix.org"); + EXPECT_EQ(event.timestamp(), 1323238293289323); + EXPECT_EQ(event.content().name(), "Name"); + EXPECT_EQ(event.stateKey(), "some_state_key"); + EXPECT_EQ(event.previousContent().name(), "Previous Name"); + EXPECT_EQ(event.serialize(), data); } TEST(StateEvent, DeserializationException) { - auto data = QJsonObject{ - {"content", QJsonObject{{"name", "Name"}}}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"prev_content", QJsonObject{{"name", "Previous Name"}}}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.name"}}; + auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "prev_content", QJsonObject{ { "name", "Previous Name" } } }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.name" } }; - StateEvent event; + StateEvent event; - try { - event.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("state_key key is missing", e.what()); - } + try { + event.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("state_key key is missing", e.what()); + } } TEST(EventType, Mapping) { - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.aliases"}}), EventType::RoomAliases); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.avatar"}}), EventType::RoomAvatar); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.canonical_alias"}}), EventType::RoomCanonicalAlias); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.create"}}), EventType::RoomCreate); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.history_visibility"}}), EventType::RoomHistoryVisibility); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.join_rules"}}), EventType::RoomJoinRules); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.member"}}), EventType::RoomMember); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.message"}}), EventType::RoomMessage); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.name"}}), EventType::RoomName); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.power_levels"}}), EventType::RoomPowerLevels); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.topic"}}), EventType::RoomTopic); - EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.unknown"}}), EventType::Unsupported); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.aliases" } }), + EventType::RoomAliases); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.avatar" } }), + EventType::RoomAvatar); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.canonical_alias" } }), + EventType::RoomCanonicalAlias); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.create" } }), + EventType::RoomCreate); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.history_visibility" } }), + EventType::RoomHistoryVisibility); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.join_rules" } }), + EventType::RoomJoinRules); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.member" } }), + EventType::RoomMember); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.message" } }), + EventType::RoomMessage); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.name" } }), EventType::RoomName); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.power_levels" } }), + EventType::RoomPowerLevels); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.topic" } }), + EventType::RoomTopic); + EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.unknown" } }), + EventType::Unsupported); } TEST(AliasesEventContent, Deserialization) { - auto data = QJsonObject{ - {"aliases", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}; + auto data = + QJsonObject{ { "aliases", QJsonArray{ "#test:matrix.org", "#test2:matrix.org" } } }; - AliasesEventContent content; - content.deserialize(data); + AliasesEventContent content; + content.deserialize(data); - EXPECT_EQ(content.aliases().size(), 2); - EXPECT_EQ(content.serialize(), data); + EXPECT_EQ(content.aliases().size(), 2); + EXPECT_EQ(content.serialize(), data); } TEST(AliasesEventContent, NotAnObject) { - auto data = QJsonArray{"#test:matrix.org", "#test2:matrix.org"}; + auto data = QJsonArray{ "#test:matrix.org", "#test2:matrix.org" }; - AliasesEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + AliasesEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(AliasesEventContent, MissingKey) { - auto data = QJsonObject{ - {"key", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}; + auto data = QJsonObject{ { "key", QJsonArray{ "#test:matrix.org", "#test2:matrix.org" } } }; - AliasesEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + AliasesEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("aliases key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("aliases key is missing", e.what()); + } } TEST(AvatarEventContent, Deserialization) { - auto data = QJsonObject{{"url", "https://matrix.org/avatar.png"}}; + auto data = QJsonObject{ { "url", "https://matrix.org/avatar.png" } }; - AvatarEventContent content; - content.deserialize(data); + AvatarEventContent content; + content.deserialize(data); - EXPECT_EQ(content.url().toString(), "https://matrix.org/avatar.png"); - EXPECT_EQ(content.serialize(), data); + EXPECT_EQ(content.url().toString(), "https://matrix.org/avatar.png"); + EXPECT_EQ(content.serialize(), data); } TEST(AvatarEventContent, NotAnObject) { - auto data = QJsonArray{"key", "url"}; + auto data = QJsonArray{ "key", "url" }; - AvatarEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + AvatarEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(AvatarEventContent, MissingKey) { - auto data = QJsonObject{{"key", "https://matrix.org"}}; + auto data = QJsonObject{ { "key", "https://matrix.org" } }; - AvatarEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + AvatarEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("url key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("url key is missing", e.what()); + } } TEST(CreateEventContent, Deserialization) { - auto data = QJsonObject{{"creator", "@alice:matrix.org"}}; + auto data = QJsonObject{ { "creator", "@alice:matrix.org" } }; - CreateEventContent content; - content.deserialize(data); + CreateEventContent content; + content.deserialize(data); - EXPECT_EQ(content.creator(), "@alice:matrix.org"); - EXPECT_EQ(content.serialize(), data); + EXPECT_EQ(content.creator(), "@alice:matrix.org"); + EXPECT_EQ(content.serialize(), data); } TEST(CreateEventContent, NotAnObject) { - auto data = QJsonArray{"creator", "alice"}; + auto data = QJsonArray{ "creator", "alice" }; - CreateEventContent content; + CreateEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(CreateEventContent, MissingKey) { - auto data = QJsonObject{{"key", "@alice:matrix.org"}}; + auto data = QJsonObject{ { "key", "@alice:matrix.org" } }; - CreateEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + CreateEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("creator key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("creator key is missing", e.what()); + } } TEST(HistoryVisibilityEventContent, Deserialization) { - auto data = QJsonObject{{"history_visibility", "invited"}}; + auto data = QJsonObject{ { "history_visibility", "invited" } }; - HistoryVisibilityEventContent content; - content.deserialize(data); - EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Invited); + HistoryVisibilityEventContent content; + content.deserialize(data); + EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Invited); - data = QJsonObject{{"history_visibility", "joined"}}; + data = QJsonObject{ { "history_visibility", "joined" } }; - content.deserialize(data); - EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Joined); + content.deserialize(data); + EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Joined); - data = QJsonObject{{"history_visibility", "shared"}}; + data = QJsonObject{ { "history_visibility", "shared" } }; - content.deserialize(data); - EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Shared); + content.deserialize(data); + EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Shared); - data = QJsonObject{{"history_visibility", "world_readable"}}; + data = QJsonObject{ { "history_visibility", "world_readable" } }; - content.deserialize(data); - EXPECT_EQ(content.historyVisibility(), HistoryVisibility::WorldReadable); + content.deserialize(data); + EXPECT_EQ(content.historyVisibility(), HistoryVisibility::WorldReadable); } TEST(HistoryVisibilityEventContent, NotAnObject) { - auto data = QJsonArray{"history_visibility", "alice"}; + auto data = QJsonArray{ "history_visibility", "alice" }; - HistoryVisibilityEventContent content; + HistoryVisibilityEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(HistoryVisibilityEventContent, InvalidHistoryVisibility) { - auto data = QJsonObject{{"history_visibility", "wrong"}}; + auto data = QJsonObject{ { "history_visibility", "wrong" } }; - HistoryVisibilityEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + HistoryVisibilityEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("Unknown history_visibility value: wrong", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("Unknown history_visibility value: wrong", e.what()); + } } TEST(HistoryVisibilityEventContent, MissingKey) { - auto data = QJsonObject{{"key", "joined"}}; + auto data = QJsonObject{ { "key", "joined" } }; - HistoryVisibilityEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + HistoryVisibilityEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("history_visibility key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("history_visibility key is missing", e.what()); + } } TEST(JoinRulesEventContent, Deserialization) { - auto data = QJsonObject{{"join_rule", "invite"}}; + auto data = QJsonObject{ { "join_rule", "invite" } }; - JoinRulesEventContent content; - content.deserialize(data); - EXPECT_EQ(content.joinRule(), JoinRule::Invite); + JoinRulesEventContent content; + content.deserialize(data); + EXPECT_EQ(content.joinRule(), JoinRule::Invite); - data = QJsonObject{{"join_rule", "knock"}}; + data = QJsonObject{ { "join_rule", "knock" } }; - content.deserialize(data); - EXPECT_EQ(content.joinRule(), JoinRule::Knock); + content.deserialize(data); + EXPECT_EQ(content.joinRule(), JoinRule::Knock); - data = QJsonObject{{"join_rule", "private"}}; + data = QJsonObject{ { "join_rule", "private" } }; - content.deserialize(data); - EXPECT_EQ(content.joinRule(), JoinRule::Private); + content.deserialize(data); + EXPECT_EQ(content.joinRule(), JoinRule::Private); - data = QJsonObject{{"join_rule", "public"}}; + data = QJsonObject{ { "join_rule", "public" } }; - content.deserialize(data); - EXPECT_EQ(content.joinRule(), JoinRule::Public); + content.deserialize(data); + EXPECT_EQ(content.joinRule(), JoinRule::Public); } TEST(JoinRulesEventContent, NotAnObject) { - auto data = QJsonArray{"rule", "alice"}; + auto data = QJsonArray{ "rule", "alice" }; - JoinRulesEventContent content; + JoinRulesEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(JoinRulesEventContent, InvalidHistoryVisibility) { - auto data = QJsonObject{{"join_rule", "wrong"}}; + auto data = QJsonObject{ { "join_rule", "wrong" } }; - JoinRulesEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + JoinRulesEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("Unknown join_rule value: wrong", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("Unknown join_rule value: wrong", e.what()); + } } TEST(JoinRulesEventContent, MissingKey) { - auto data = QJsonObject{{"key", "invite"}}; + auto data = QJsonObject{ { "key", "invite" } }; - JoinRulesEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + JoinRulesEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("join_rule key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("join_rule key is missing", e.what()); + } } TEST(CanonicalAliasEventContent, Deserialization) { - auto data = QJsonObject{{"alias", "Room Alias"}}; + auto data = QJsonObject{ { "alias", "Room Alias" } }; - CanonicalAliasEventContent content; - content.deserialize(data); + CanonicalAliasEventContent content; + content.deserialize(data); - EXPECT_EQ(content.alias(), "Room Alias"); - EXPECT_EQ(content.serialize(), data); + EXPECT_EQ(content.alias(), "Room Alias"); + EXPECT_EQ(content.serialize(), data); } TEST(CanonicalAliasEventContent, NotAnObject) { - auto data = QJsonArray{"alias", "Room Alias"}; + auto data = QJsonArray{ "alias", "Room Alias" }; - CanonicalAliasEventContent content; + CanonicalAliasEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(CanonicalAliasEventContent, MissingKey) { - auto data = QJsonObject{{"key", "alias"}}; + auto data = QJsonObject{ { "key", "alias" } }; - CanonicalAliasEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + CanonicalAliasEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("alias key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("alias key is missing", e.what()); + } } TEST(MemberEventContent, Deserialization) { - MemberEventContent content; + MemberEventContent content; - auto data = QJsonObject{{"membership", "join"}}; + auto data = QJsonObject{ { "membership", "join" } }; - content.deserialize(data); - EXPECT_EQ(content.membershipState(), Membership::Join); + content.deserialize(data); + EXPECT_EQ(content.membershipState(), Membership::Join); - data = QJsonObject{{"membership", "invite"}, {"displayname", "Username"}}; + data = QJsonObject{ { "membership", "invite" }, { "displayname", "Username" } }; - content.deserialize(data); - EXPECT_EQ(content.membershipState(), Membership::Invite); - EXPECT_EQ(content.displayName(), "Username"); + content.deserialize(data); + EXPECT_EQ(content.membershipState(), Membership::Invite); + EXPECT_EQ(content.displayName(), "Username"); - data = QJsonObject{{"membership", "leave"}, {"avatar_url", "https://matrix.org"}}; + data = QJsonObject{ { "membership", "leave" }, { "avatar_url", "https://matrix.org" } }; - content.deserialize(data); - EXPECT_EQ(content.membershipState(), Membership::Leave); - EXPECT_EQ(content.avatarUrl().toString(), "https://matrix.org"); + content.deserialize(data); + EXPECT_EQ(content.membershipState(), Membership::Leave); + EXPECT_EQ(content.avatarUrl().toString(), "https://matrix.org"); - data = QJsonObject{{"membership", "ban"}}; + data = QJsonObject{ { "membership", "ban" } }; - content.deserialize(data); - EXPECT_EQ(content.membershipState(), Membership::Ban); + content.deserialize(data); + EXPECT_EQ(content.membershipState(), Membership::Ban); - data = QJsonObject{{"membership", "knock"}}; + data = QJsonObject{ { "membership", "knock" } }; - content.deserialize(data); - EXPECT_EQ(content.membershipState(), Membership::Knock); + content.deserialize(data); + EXPECT_EQ(content.membershipState(), Membership::Knock); } TEST(MemberEventContent, InvalidMembership) { - auto data = QJsonObject{{"membership", "wrong"}}; + auto data = QJsonObject{ { "membership", "wrong" } }; - MemberEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + MemberEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("Unknown membership value: wrong", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("Unknown membership value: wrong", e.what()); + } } TEST(MemberEventContent, NotAnObject) { - auto data = QJsonArray{"name", "join"}; + auto data = QJsonArray{ "name", "join" }; - MemberEventContent content; + MemberEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(MemberEventContent, MissingName) { - auto data = QJsonObject{{"key", "random"}}; + auto data = QJsonObject{ { "key", "random" } }; - MemberEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + MemberEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("membership key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("membership key is missing", e.what()); + } } TEST(NameEventContent, Deserialization) { - auto data = QJsonObject{{"name", "Room Name"}}; + auto data = QJsonObject{ { "name", "Room Name" } }; - NameEventContent content; - content.deserialize(data); + NameEventContent content; + content.deserialize(data); - EXPECT_EQ(content.name(), "Room Name"); - EXPECT_EQ(content.serialize(), data); + EXPECT_EQ(content.name(), "Room Name"); + EXPECT_EQ(content.serialize(), data); } TEST(NameEventContent, NotAnObject) { - auto data = QJsonArray{"name", "Room Name"}; + auto data = QJsonArray{ "name", "Room Name" }; - NameEventContent content; + NameEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(NameEventContent, MissingName) { - auto data = QJsonObject{{"key", "Room Name"}}; + auto data = QJsonObject{ { "key", "Room Name" } }; - NameEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + NameEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("name key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("name key is missing", e.what()); + } } TEST(PowerLevelsEventContent, DefaultValues) { - PowerLevelsEventContent power_levels; + PowerLevelsEventContent power_levels; - EXPECT_EQ(power_levels.banLevel(), static_cast(PowerLevels::Moderator)); - EXPECT_EQ(power_levels.inviteLevel(), static_cast(PowerLevels::Moderator)); - EXPECT_EQ(power_levels.kickLevel(), static_cast(PowerLevels::Moderator)); - EXPECT_EQ(power_levels.redactLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.banLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.inviteLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.kickLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.redactLevel(), static_cast(PowerLevels::Moderator)); - EXPECT_EQ(power_levels.eventsDefaultLevel(), static_cast(PowerLevels::User)); - EXPECT_EQ(power_levels.usersDefaultLevel(), static_cast(PowerLevels::User)); - EXPECT_EQ(power_levels.stateDefaultLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.eventsDefaultLevel(), static_cast(PowerLevels::User)); + EXPECT_EQ(power_levels.usersDefaultLevel(), static_cast(PowerLevels::User)); + EXPECT_EQ(power_levels.stateDefaultLevel(), static_cast(PowerLevels::Moderator)); - // Default levels. - EXPECT_EQ(power_levels.userLevel("@joe:matrix.org"), static_cast(PowerLevels::User)); - EXPECT_EQ(power_levels.eventLevel("m.room.message"), static_cast(PowerLevels::User)); + // Default levels. + EXPECT_EQ(power_levels.userLevel("@joe:matrix.org"), static_cast(PowerLevels::User)); + EXPECT_EQ(power_levels.eventLevel("m.room.message"), static_cast(PowerLevels::User)); } TEST(PowerLevelsEventContent, FullDeserialization) { - auto data = QJsonObject{ - {"ban", 1}, - {"invite", 2}, - {"kick", 3}, - {"redact", 4}, + auto data = QJsonObject{ + { "ban", 1 }, + { "invite", 2 }, + { "kick", 3 }, + { "redact", 4 }, - {"events_default", 5}, - {"state_default", 6}, - {"users_default", 7}, + { "events_default", 5 }, + { "state_default", 6 }, + { "users_default", 7 }, - {"events", QJsonObject{{"m.message.text", 8}, {"m.message.image", 9}}}, - {"users", QJsonObject{{"@alice:matrix.org", 10}, {"@bob:matrix.org", 11}}}, - }; + { "events", QJsonObject{ { "m.message.text", 8 }, { "m.message.image", 9 } } }, + { "users", QJsonObject{ { "@alice:matrix.org", 10 }, { "@bob:matrix.org", 11 } } }, + }; - PowerLevelsEventContent power_levels; - power_levels.deserialize(data); + PowerLevelsEventContent power_levels; + power_levels.deserialize(data); - EXPECT_EQ(power_levels.banLevel(), 1); - EXPECT_EQ(power_levels.inviteLevel(), 2); - EXPECT_EQ(power_levels.kickLevel(), 3); - EXPECT_EQ(power_levels.redactLevel(), 4); + EXPECT_EQ(power_levels.banLevel(), 1); + EXPECT_EQ(power_levels.inviteLevel(), 2); + EXPECT_EQ(power_levels.kickLevel(), 3); + EXPECT_EQ(power_levels.redactLevel(), 4); - EXPECT_EQ(power_levels.eventsDefaultLevel(), 5); - EXPECT_EQ(power_levels.stateDefaultLevel(), 6); - EXPECT_EQ(power_levels.usersDefaultLevel(), 7); + EXPECT_EQ(power_levels.eventsDefaultLevel(), 5); + EXPECT_EQ(power_levels.stateDefaultLevel(), 6); + EXPECT_EQ(power_levels.usersDefaultLevel(), 7); - EXPECT_EQ(power_levels.userLevel("@alice:matrix.org"), 10); - EXPECT_EQ(power_levels.userLevel("@bob:matrix.org"), 11); - EXPECT_EQ(power_levels.userLevel("@carl:matrix.org"), 7); + EXPECT_EQ(power_levels.userLevel("@alice:matrix.org"), 10); + EXPECT_EQ(power_levels.userLevel("@bob:matrix.org"), 11); + EXPECT_EQ(power_levels.userLevel("@carl:matrix.org"), 7); - EXPECT_EQ(power_levels.eventLevel("m.message.text"), 8); - EXPECT_EQ(power_levels.eventLevel("m.message.image"), 9); - EXPECT_EQ(power_levels.eventLevel("m.message.gif"), 5); + EXPECT_EQ(power_levels.eventLevel("m.message.text"), 8); + EXPECT_EQ(power_levels.eventLevel("m.message.image"), 9); + EXPECT_EQ(power_levels.eventLevel("m.message.gif"), 5); - EXPECT_EQ(power_levels.serialize(), data); + EXPECT_EQ(power_levels.serialize(), data); } TEST(PowerLevelsEventContent, PartialDeserialization) { - auto data = QJsonObject{ - {"ban", 1}, - {"invite", 2}, + auto data = QJsonObject{ + { "ban", 1 }, + { "invite", 2 }, - {"events_default", 5}, - {"users_default", 7}, + { "events_default", 5 }, + { "users_default", 7 }, - {"users", QJsonObject{{"@alice:matrix.org", 10}, {"@bob:matrix.org", 11}}}, - }; + { "users", QJsonObject{ { "@alice:matrix.org", 10 }, { "@bob:matrix.org", 11 } } }, + }; - PowerLevelsEventContent power_levels; - power_levels.deserialize(data); + PowerLevelsEventContent power_levels; + power_levels.deserialize(data); - EXPECT_EQ(power_levels.banLevel(), 1); - EXPECT_EQ(power_levels.inviteLevel(), 2); - EXPECT_EQ(power_levels.kickLevel(), static_cast(PowerLevels::Moderator)); - EXPECT_EQ(power_levels.redactLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.banLevel(), 1); + EXPECT_EQ(power_levels.inviteLevel(), 2); + EXPECT_EQ(power_levels.kickLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.redactLevel(), static_cast(PowerLevels::Moderator)); - EXPECT_EQ(power_levels.eventsDefaultLevel(), 5); - EXPECT_EQ(power_levels.stateDefaultLevel(), static_cast(PowerLevels::Moderator)); - EXPECT_EQ(power_levels.usersDefaultLevel(), 7); + EXPECT_EQ(power_levels.eventsDefaultLevel(), 5); + EXPECT_EQ(power_levels.stateDefaultLevel(), static_cast(PowerLevels::Moderator)); + EXPECT_EQ(power_levels.usersDefaultLevel(), 7); - EXPECT_EQ(power_levels.userLevel("@alice:matrix.org"), 10); - EXPECT_EQ(power_levels.userLevel("@bob:matrix.org"), 11); - EXPECT_EQ(power_levels.userLevel("@carl:matrix.org"), 7); + EXPECT_EQ(power_levels.userLevel("@alice:matrix.org"), 10); + EXPECT_EQ(power_levels.userLevel("@bob:matrix.org"), 11); + EXPECT_EQ(power_levels.userLevel("@carl:matrix.org"), 7); - EXPECT_EQ(power_levels.eventLevel("m.message.text"), 5); - EXPECT_EQ(power_levels.eventLevel("m.message.image"), 5); - EXPECT_EQ(power_levels.eventLevel("m.message.gif"), 5); + EXPECT_EQ(power_levels.eventLevel("m.message.text"), 5); + EXPECT_EQ(power_levels.eventLevel("m.message.image"), 5); + EXPECT_EQ(power_levels.eventLevel("m.message.gif"), 5); } TEST(PowerLevelsEventContent, NotAnObject) { - auto data = QJsonArray{"test", "test2"}; + auto data = QJsonArray{ "test", "test2" }; - PowerLevelsEventContent power_levels; + PowerLevelsEventContent power_levels; - ASSERT_THROW(power_levels.deserialize(data), DeserializationException); + ASSERT_THROW(power_levels.deserialize(data), DeserializationException); } TEST(TopicEventContent, Deserialization) { - auto data = QJsonObject{{"topic", "Room Topic"}}; + auto data = QJsonObject{ { "topic", "Room Topic" } }; - TopicEventContent content; - content.deserialize(data); + TopicEventContent content; + content.deserialize(data); - EXPECT_EQ(content.topic(), "Room Topic"); - EXPECT_EQ(content.serialize(), data); + EXPECT_EQ(content.topic(), "Room Topic"); + EXPECT_EQ(content.serialize(), data); } TEST(TopicEventContent, NotAnObject) { - auto data = QJsonArray{"topic", "Room Topic"}; + auto data = QJsonArray{ "topic", "Room Topic" }; - TopicEventContent content; + TopicEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + ASSERT_THROW(content.deserialize(data), DeserializationException); } TEST(TopicEventContent, MissingName) { - auto data = QJsonObject{{"key", "Room Name"}}; + auto data = QJsonObject{ { "key", "Room Name" } }; - TopicEventContent content; - ASSERT_THROW(content.deserialize(data), DeserializationException); + TopicEventContent content; + ASSERT_THROW(content.deserialize(data), DeserializationException); - try { - content.deserialize(data); - } catch (const DeserializationException &e) { - ASSERT_STREQ("topic key is missing", e.what()); - } + try { + content.deserialize(data); + } catch (const DeserializationException &e) { + ASSERT_STREQ("topic key is missing", e.what()); + } } diff --git a/tests/message_events.cc b/tests/message_events.cc index cece67db..dfff50ab 100644 --- a/tests/message_events.cc +++ b/tests/message_events.cc @@ -19,293 +19,269 @@ using namespace matrix::events; TEST(MessageEvent, Audio) { - auto info = QJsonObject{ - {"duration", 2140786}, - {"mimetype", "audio/mpeg"}, - {"size", 1563688}}; + auto info = + QJsonObject{ { "duration", 2140786 }, { "mimetype", "audio/mpeg" }, { "size", 1563688 } }; - auto content = QJsonObject{ - {"body", "Bee Gees - Stayin' Alive"}, - {"msgtype", "m.audio"}, - {"url", "mxc://localhost/2sdfj23f33r3faad"}, - {"info", info}}; + auto content = QJsonObject{ { "body", "Bee Gees - Stayin' Alive" }, + { "msgtype", "m.audio" }, + { "url", "mxc://localhost/2sdfj23f33r3faad" }, + { "info", info } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent audio; - audio.deserialize(event); + MessageEvent audio; + audio.deserialize(event); - EXPECT_EQ(audio.msgContent().info().duration, 2140786); - EXPECT_EQ(audio.msgContent().info().size, 1563688); - EXPECT_EQ(audio.msgContent().info().mimetype, "audio/mpeg"); - EXPECT_EQ(audio.content().body(), "Bee Gees - Stayin' Alive"); + EXPECT_EQ(audio.msgContent().info().duration, 2140786); + EXPECT_EQ(audio.msgContent().info().size, 1563688); + EXPECT_EQ(audio.msgContent().info().mimetype, "audio/mpeg"); + EXPECT_EQ(audio.content().body(), "Bee Gees - Stayin' Alive"); } TEST(MessageEvent, Emote) { - auto content = QJsonObject{ - {"body", "emote message"}, - {"msgtype", "m.emote"}}; + auto content = QJsonObject{ { "body", "emote message" }, { "msgtype", "m.emote" } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent emote; - emote.deserialize(event); + MessageEvent emote; + emote.deserialize(event); - EXPECT_EQ(emote.content().body(), "emote message"); + EXPECT_EQ(emote.content().body(), "emote message"); } TEST(MessageEvent, File) { - auto thumbnail_info = QJsonObject{ - {"h", 300}, - {"w", 400}, - {"size", 3432434}, - {"mimetype", "image/jpeg"}}; + auto thumbnail_info = QJsonObject{ + { "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" } + }; - auto file_info = QJsonObject{ - {"size", 24242424}, - {"mimetype", "application/msword"}, - {"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, - {"thumbnail_info", thumbnail_info}}; + auto file_info = QJsonObject{ { "size", 24242424 }, + { "mimetype", "application/msword" }, + { "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" }, + { "thumbnail_info", thumbnail_info } }; - auto content = QJsonObject{ - {"body", "something-important.doc"}, - {"filename", "something-important.doc"}, - {"url", "mxc://localhost/23d233d32r3r2r"}, - {"info", file_info}, - {"msgtype", "m.file"}}; + auto content = QJsonObject{ { "body", "something-important.doc" }, + { "filename", "something-important.doc" }, + { "url", "mxc://localhost/23d233d32r3r2r" }, + { "info", file_info }, + { "msgtype", "m.file" } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent file; - file.deserialize(event); + MessageEvent file; + file.deserialize(event); - EXPECT_EQ(file.content().body(), "something-important.doc"); - EXPECT_EQ(file.msgContent().info().thumbnail_info.h, 300); - EXPECT_EQ(file.msgContent().info().thumbnail_info.w, 400); - EXPECT_EQ(file.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); - EXPECT_EQ(file.msgContent().info().mimetype, "application/msword"); - EXPECT_EQ(file.msgContent().info().size, 24242424); - EXPECT_EQ(file.content().body(), "something-important.doc"); + EXPECT_EQ(file.content().body(), "something-important.doc"); + EXPECT_EQ(file.msgContent().info().thumbnail_info.h, 300); + EXPECT_EQ(file.msgContent().info().thumbnail_info.w, 400); + EXPECT_EQ(file.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); + EXPECT_EQ(file.msgContent().info().mimetype, "application/msword"); + EXPECT_EQ(file.msgContent().info().size, 24242424); + EXPECT_EQ(file.content().body(), "something-important.doc"); } TEST(MessageEvent, Image) { - auto thumbinfo = QJsonObject{ - {"h", 11}, - {"w", 22}, - {"size", 212}, - {"mimetype", "img/jpeg"}, - }; + auto thumbinfo = QJsonObject{ + { "h", 11 }, { "w", 22 }, { "size", 212 }, { "mimetype", "img/jpeg" }, + }; - auto imginfo = QJsonObject{ - {"h", 110}, - {"w", 220}, - {"size", 2120}, - {"mimetype", "img/jpeg"}, - {"thumbnail_url", "https://images.com/image-thumb.jpg"}, - {"thumbnail_info", thumbinfo}, - }; + auto imginfo = QJsonObject{ + { "h", 110 }, + { "w", 220 }, + { "size", 2120 }, + { "mimetype", "img/jpeg" }, + { "thumbnail_url", "https://images.com/image-thumb.jpg" }, + { "thumbnail_info", thumbinfo }, + }; - auto content = QJsonObject{ - {"body", "Image title"}, - {"msgtype", "m.image"}, - {"url", "https://images.com/image.jpg"}, - {"info", imginfo}}; + auto content = QJsonObject{ { "body", "Image title" }, + { "msgtype", "m.image" }, + { "url", "https://images.com/image.jpg" }, + { "info", imginfo } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent img; - img.deserialize(event); + MessageEvent img; + img.deserialize(event); - EXPECT_EQ(img.content().body(), "Image title"); - EXPECT_EQ(img.msgContent().info().h, 110); - EXPECT_EQ(img.msgContent().info().w, 220); - EXPECT_EQ(img.msgContent().info().thumbnail_info.w, 22); - EXPECT_EQ(img.msgContent().info().mimetype, "img/jpeg"); - EXPECT_EQ(img.msgContent().info().thumbnail_url, "https://images.com/image-thumb.jpg"); + EXPECT_EQ(img.content().body(), "Image title"); + EXPECT_EQ(img.msgContent().info().h, 110); + EXPECT_EQ(img.msgContent().info().w, 220); + EXPECT_EQ(img.msgContent().info().thumbnail_info.w, 22); + EXPECT_EQ(img.msgContent().info().mimetype, "img/jpeg"); + EXPECT_EQ(img.msgContent().info().thumbnail_url, "https://images.com/image-thumb.jpg"); } TEST(MessageEvent, Location) { - auto thumbnail_info = QJsonObject{ - {"h", 300}, - {"w", 400}, - {"size", 3432434}, - {"mimetype", "image/jpeg"}}; + auto thumbnail_info = QJsonObject{ + { "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" } + }; - auto info = QJsonObject{ - {"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, - {"thumbnail_info", thumbnail_info}}; + auto info = QJsonObject{ { "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" }, + { "thumbnail_info", thumbnail_info } }; - auto content = QJsonObject{ - {"body", "Big Ben, London, UK"}, - {"geo_uri", "geo:51.5008,0.1247"}, - {"info", info}, - {"msgtype", "m.location"}}; + auto content = QJsonObject{ { "body", "Big Ben, London, UK" }, + { "geo_uri", "geo:51.5008,0.1247" }, + { "info", info }, + { "msgtype", "m.location" } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent location; - location.deserialize(event); + MessageEvent location; + location.deserialize(event); - EXPECT_EQ(location.msgContent().info().thumbnail_info.h, 300); - EXPECT_EQ(location.msgContent().info().thumbnail_info.w, 400); - EXPECT_EQ(location.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); - EXPECT_EQ(location.msgContent().info().thumbnail_url, "mxc://localhost/adfaefaFAFSDFF3"); - EXPECT_EQ(location.content().body(), "Big Ben, London, UK"); + EXPECT_EQ(location.msgContent().info().thumbnail_info.h, 300); + EXPECT_EQ(location.msgContent().info().thumbnail_info.w, 400); + EXPECT_EQ(location.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); + EXPECT_EQ(location.msgContent().info().thumbnail_url, "mxc://localhost/adfaefaFAFSDFF3"); + EXPECT_EQ(location.content().body(), "Big Ben, London, UK"); } TEST(MessageEvent, Notice) { - auto content = QJsonObject{ - {"body", "notice message"}, - {"msgtype", "m.notice"}}; + auto content = QJsonObject{ { "body", "notice message" }, { "msgtype", "m.notice" } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent notice; - notice.deserialize(event); + MessageEvent notice; + notice.deserialize(event); - EXPECT_EQ(notice.content().body(), "notice message"); + EXPECT_EQ(notice.content().body(), "notice message"); } TEST(MessageEvent, Text) { - auto content = QJsonObject{ - {"body", "text message"}, - {"msgtype", "m.text"}}; + auto content = QJsonObject{ { "body", "text message" }, { "msgtype", "m.text" } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent text; - text.deserialize(event); + MessageEvent text; + text.deserialize(event); - EXPECT_EQ(text.content().body(), "text message"); + EXPECT_EQ(text.content().body(), "text message"); } TEST(MessageEvent, Video) { - auto thumbnail_info = QJsonObject{ - {"h", 300}, - {"w", 400}, - {"size", 3432434}, - {"mimetype", "image/jpeg"}}; + auto thumbnail_info = QJsonObject{ + { "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" } + }; - auto video_info = QJsonObject{ - {"h", 222}, - {"w", 333}, - {"duration", 232323}, - {"size", 24242424}, - {"mimetype", "video/mp4"}, - {"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, - {"thumbnail_info", thumbnail_info}}; + auto video_info = QJsonObject{ { "h", 222 }, + { "w", 333 }, + { "duration", 232323 }, + { "size", 24242424 }, + { "mimetype", "video/mp4" }, + { "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" }, + { "thumbnail_info", thumbnail_info } }; - auto content = QJsonObject{ - {"body", "Gangnam Style"}, - {"url", "mxc://localhost/23d233d32r3r2r"}, - {"info", video_info}, - {"msgtype", "m.video"}}; + auto content = QJsonObject{ { "body", "Gangnam Style" }, + { "url", "mxc://localhost/23d233d32r3r2r" }, + { "info", video_info }, + { "msgtype", "m.video" } }; - auto event = QJsonObject{ - {"content", content}, - {"event_id", "$asdfafdf8af:matrix.org"}, - {"room_id", "!aasdfaeae23r9:matrix.org"}, - {"sender", "@alice:matrix.org"}, - {"origin_server_ts", 1323238293289323LL}, - {"type", "m.room.message"}}; + auto event = QJsonObject{ { "content", content }, + { "event_id", "$asdfafdf8af:matrix.org" }, + { "room_id", "!aasdfaeae23r9:matrix.org" }, + { "sender", "@alice:matrix.org" }, + { "origin_server_ts", 1323238293289323LL }, + { "type", "m.room.message" } }; - MessageEvent video; - video.deserialize(event); + MessageEvent video; + video.deserialize(event); - EXPECT_EQ(video.msgContent().info().thumbnail_info.h, 300); - EXPECT_EQ(video.msgContent().info().thumbnail_info.w, 400); - EXPECT_EQ(video.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); - EXPECT_EQ(video.msgContent().info().duration, 232323); - EXPECT_EQ(video.msgContent().info().size, 24242424); - EXPECT_EQ(video.msgContent().info().mimetype, "video/mp4"); - EXPECT_EQ(video.content().body(), "Gangnam Style"); + EXPECT_EQ(video.msgContent().info().thumbnail_info.h, 300); + EXPECT_EQ(video.msgContent().info().thumbnail_info.w, 400); + EXPECT_EQ(video.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); + EXPECT_EQ(video.msgContent().info().duration, 232323); + EXPECT_EQ(video.msgContent().info().size, 24242424); + EXPECT_EQ(video.msgContent().info().mimetype, "video/mp4"); + EXPECT_EQ(video.content().body(), "Gangnam Style"); } TEST(MessageEvent, Types) { - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.audio"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Audio); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.emote"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Emote); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.file"}}}, {"type", "m.room.message"}, - }), - MessageEventType::File); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.image"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Image); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.location"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Location); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.notice"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Notice); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.text"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Text); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.video"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Video); - EXPECT_EQ(extractMessageEventType(QJsonObject{ - {"content", QJsonObject{{"msgtype", "m.random"}}}, {"type", "m.room.message"}, - }), - MessageEventType::Unknown); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.audio" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Audio); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.emote" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Emote); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.file" } } }, { "type", "m.room.message" }, + }), + MessageEventType::File); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.image" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Image); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.location" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Location); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.notice" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Notice); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.text" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Text); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.video" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Video); + EXPECT_EQ( + extractMessageEventType(QJsonObject{ + { "content", QJsonObject{ { "msgtype", "m.random" } } }, { "type", "m.room.message" }, + }), + MessageEventType::Unknown); }