This commit is contained in:
Konstantinos Sideris 2017-09-24 17:39:06 +03:00
parent 37ff1398b7
commit 9def76aa08
4 changed files with 669 additions and 696 deletions

View file

@ -18,12 +18,12 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "Config.h" #include "Config.h"
#include <QApplication>
#include <QLayout> #include <QLayout>
#include <QNetworkReply> #include <QNetworkReply>
#include <QSettings> #include <QSettings>
#include <QSystemTrayIcon>
#include <QShortcut> #include <QShortcut>
#include <QApplication> #include <QSystemTrayIcon>
MainWindow *MainWindow::instance_ = nullptr; MainWindow *MainWindow::instance_ = nullptr;

View file

@ -23,24 +23,22 @@ using namespace matrix::events;
TEST(EventCollection, Deserialize) TEST(EventCollection, Deserialize)
{ {
auto events = QJsonArray{ auto events = QJsonArray{
QJsonObject{ QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } },
{"content", QJsonObject{{"name", "Name"}}}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "prev_content", QJsonObject{ { "name", "Previous Name" } } },
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "state_key", "" },
{"state_key", ""}, { "type", "m.room.name" } },
{"type", "m.room.name"}}, QJsonObject{ { "content", QJsonObject{ { "topic", "Topic" } } },
QJsonObject{ { "event_id", "$asdfafdf8af:matrix.org" },
{"content", QJsonObject{{"topic", "Topic"}}}, { "prev_content", QJsonObject{ { "topic", "Previous Topic" } } },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"prev_content", QJsonObject{{"topic", "Previous Topic"}}}, { "state_key", "" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"state_key", ""}, { "origin_server_ts", 1323238293289323LL },
{"sender", "@alice:matrix.org"}, { "type", "m.room.topic" } },
{"origin_server_ts", 1323238293289323LL},
{"type", "m.room.topic"}},
}; };
for (const auto &event : events) { for (const auto &event : events) {
@ -68,24 +66,22 @@ TEST(EventCollection, DeserializationException)
{ {
// Using wrong event types. // Using wrong event types.
auto events = QJsonArray{ auto events = QJsonArray{
QJsonObject{ QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } },
{"content", QJsonObject{{"name", "Name"}}}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "prev_content", QJsonObject{ { "name", "Previous Name" } } },
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "state_key", "" },
{"state_key", ""}, { "type", "m.room.topic" } },
{"type", "m.room.topic"}}, QJsonObject{ { "content", QJsonObject{ { "topic", "Topic" } } },
QJsonObject{ { "event_id", "$asdfafdf8af:matrix.org" },
{"content", QJsonObject{{"topic", "Topic"}}}, { "prev_content", QJsonObject{ { "topic", "Previous Topic" } } },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"prev_content", QJsonObject{{"topic", "Previous Topic"}}}, { "state_key", "" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"state_key", ""}, { "origin_server_ts", 1323238293289323LL },
{"sender", "@alice:matrix.org"}, { "type", "m.room.name" } },
{"origin_server_ts", 1323238293289323LL},
{"type", "m.room.name"}},
}; };
for (const auto &event : events) { for (const auto &event : events) {

View file

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <QDebug> #include <QDebug>
#include <QJsonArray> #include <QJsonArray>
#include <gtest/gtest.h>
#include "Event.h" #include "Event.h"
#include "RoomEvent.h" #include "RoomEvent.h"
@ -22,9 +22,8 @@ using namespace matrix::events;
TEST(BaseEvent, Deserialization) TEST(BaseEvent, Deserialization)
{ {
// NameEventContent // NameEventContent
auto data = QJsonObject{ auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Room Name" } } },
{"content", QJsonObject{{"name", "Room Name"}}}, { "type", "m.room.name" } };
{"type", "m.room.name"}};
Event<NameEventContent> name_event; Event<NameEventContent> name_event;
name_event.deserialize(data); name_event.deserialize(data);
@ -32,9 +31,8 @@ TEST(BaseEvent, Deserialization)
EXPECT_EQ(name_event.serialize(), data); EXPECT_EQ(name_event.serialize(), data);
// TopicEventContent // TopicEventContent
data = QJsonObject{ data = QJsonObject{ { "content", QJsonObject{ { "topic", "Room Topic" } } },
{"content", QJsonObject{{"topic", "Room Topic"}}}, { "type", "m.room.topic" } };
{"type", "m.room.topic"}};
Event<TopicEventContent> topic_event; Event<TopicEventContent> topic_event;
topic_event.deserialize(data); topic_event.deserialize(data);
@ -42,9 +40,8 @@ TEST(BaseEvent, Deserialization)
EXPECT_EQ(topic_event.serialize(), data); EXPECT_EQ(topic_event.serialize(), data);
// AvatarEventContent // AvatarEventContent
data = QJsonObject{ data = QJsonObject{ { "content", QJsonObject{ { "url", "https://matrix.org" } } },
{"content", QJsonObject{{"url", "https://matrix.org"}}}, { "type", "m.room.avatar" } };
{"type", "m.room.avatar"}};
Event<AvatarEventContent> avatar_event; Event<AvatarEventContent> avatar_event;
avatar_event.deserialize(data); avatar_event.deserialize(data);
@ -52,9 +49,11 @@ TEST(BaseEvent, Deserialization)
EXPECT_EQ(avatar_event.serialize(), data); EXPECT_EQ(avatar_event.serialize(), data);
// AliasesEventContent // AliasesEventContent
data = QJsonObject{ data =
{"content", QJsonObject{{"aliases", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}}, QJsonObject{ { "content",
{"type", "m.room.aliases"}}; QJsonObject{
{ "aliases", QJsonArray{ "#test:matrix.org", "#test2:matrix.org" } } } },
{ "type", "m.room.aliases" } };
Event<AliasesEventContent> aliases_event; Event<AliasesEventContent> aliases_event;
aliases_event.deserialize(data); aliases_event.deserialize(data);
@ -62,9 +61,8 @@ TEST(BaseEvent, Deserialization)
EXPECT_EQ(aliases_event.serialize(), data); EXPECT_EQ(aliases_event.serialize(), data);
// CreateEventContent // CreateEventContent
data = QJsonObject{ data = QJsonObject{ { "content", QJsonObject{ { "creator", "@alice:matrix.org" } } },
{"content", QJsonObject{{"creator", "@alice:matrix.org"}}}, { "type", "m.room.create" } };
{"type", "m.room.create"}};
Event<CreateEventContent> create_event; Event<CreateEventContent> create_event;
create_event.deserialize(data); create_event.deserialize(data);
@ -72,9 +70,8 @@ TEST(BaseEvent, Deserialization)
EXPECT_EQ(create_event.serialize(), data); EXPECT_EQ(create_event.serialize(), data);
// JoinRulesEventContent // JoinRulesEventContent
data = QJsonObject{ data = QJsonObject{ { "content", QJsonObject{ { "join_rule", "private" } } },
{"content", QJsonObject{{"join_rule", "private"}}}, { "type", "m.room.join_rules" } };
{"type", "m.room.join_rules"}};
Event<JoinRulesEventContent> join_rules_event; Event<JoinRulesEventContent> join_rules_event;
join_rules_event.deserialize(data); join_rules_event.deserialize(data);
@ -84,16 +81,14 @@ TEST(BaseEvent, Deserialization)
TEST(BaseEvent, DeserializationException) TEST(BaseEvent, DeserializationException)
{ {
auto data = QJsonObject{ auto data = QJsonObject{ { "content", QJsonObject{ { "rule", "private" } } },
{"content", QJsonObject{{"rule", "private"}}}, { "type", "m.room.join_rules" } };
{"type", "m.room.join_rules"}};
Event<JoinRulesEventContent> event1; Event<JoinRulesEventContent> event1;
ASSERT_THROW(event1.deserialize(data), DeserializationException); ASSERT_THROW(event1.deserialize(data), DeserializationException);
data = QJsonObject{ data = QJsonObject{ { "contents", QJsonObject{ { "join_rule", "private" } } },
{"contents", QJsonObject{{"join_rule", "private"}}}, { "type", "m.room.join_rules" } };
{"type", "m.room.join_rules"}};
Event<JoinRulesEventContent> event2; Event<JoinRulesEventContent> event2;
ASSERT_THROW(event2.deserialize(data), DeserializationException); ASSERT_THROW(event2.deserialize(data), DeserializationException);
@ -101,13 +96,12 @@ TEST(BaseEvent, DeserializationException)
TEST(RoomEvent, Deserialization) TEST(RoomEvent, Deserialization)
{ {
auto data = QJsonObject{ auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } },
{"content", QJsonObject{{"name", "Name"}}}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.name" } };
{"type", "m.room.name"}};
RoomEvent<NameEventContent> event; RoomEvent<NameEventContent> event;
event.deserialize(data); event.deserialize(data);
@ -122,12 +116,11 @@ TEST(RoomEvent, Deserialization)
TEST(RoomEvent, DeserializationException) TEST(RoomEvent, DeserializationException)
{ {
auto data = QJsonObject{ auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } },
{"content", QJsonObject{{"name", "Name"}}}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.name" } };
{"type", "m.room.name"}};
RoomEvent<NameEventContent> event; RoomEvent<NameEventContent> event;
@ -140,15 +133,14 @@ TEST(RoomEvent, DeserializationException)
TEST(StateEvent, Deserialization) TEST(StateEvent, Deserialization)
{ {
auto data = QJsonObject{ auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } },
{"content", QJsonObject{{"name", "Name"}}}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "state_key", "some_state_key" },
{"state_key", "some_state_key"}, { "prev_content", QJsonObject{ { "name", "Previous Name" } } },
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.name" } };
{"type", "m.room.name"}};
StateEvent<NameEventContent> event; StateEvent<NameEventContent> event;
event.deserialize(data); event.deserialize(data);
@ -165,14 +157,13 @@ TEST(StateEvent, Deserialization)
TEST(StateEvent, DeserializationException) TEST(StateEvent, DeserializationException)
{ {
auto data = QJsonObject{ auto data = QJsonObject{ { "content", QJsonObject{ { "name", "Name" } } },
{"content", QJsonObject{{"name", "Name"}}}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "prev_content", QJsonObject{ { "name", "Previous Name" } } },
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.name" } };
{"type", "m.room.name"}};
StateEvent<NameEventContent> event; StateEvent<NameEventContent> event;
@ -185,24 +176,35 @@ TEST(StateEvent, DeserializationException)
TEST(EventType, Mapping) TEST(EventType, Mapping)
{ {
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.aliases"}}), EventType::RoomAliases); EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.aliases" } }),
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.avatar"}}), EventType::RoomAvatar); EventType::RoomAliases);
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.canonical_alias"}}), EventType::RoomCanonicalAlias); EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.avatar" } }),
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.create"}}), EventType::RoomCreate); EventType::RoomAvatar);
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.history_visibility"}}), EventType::RoomHistoryVisibility); EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.canonical_alias" } }),
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.join_rules"}}), EventType::RoomJoinRules); EventType::RoomCanonicalAlias);
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.member"}}), EventType::RoomMember); EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.create" } }),
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.message"}}), EventType::RoomMessage); EventType::RoomCreate);
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.name"}}), EventType::RoomName); EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.history_visibility" } }),
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.power_levels"}}), EventType::RoomPowerLevels); EventType::RoomHistoryVisibility);
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.topic"}}), EventType::RoomTopic); EXPECT_EQ(extractEventType(QJsonObject{ { "type", "m.room.join_rules" } }),
EXPECT_EQ(extractEventType(QJsonObject{{"type", "m.room.unknown"}}), EventType::Unsupported); 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) TEST(AliasesEventContent, Deserialization)
{ {
auto data = QJsonObject{ auto data =
{"aliases", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}}; QJsonObject{ { "aliases", QJsonArray{ "#test:matrix.org", "#test2:matrix.org" } } };
AliasesEventContent content; AliasesEventContent content;
content.deserialize(data); content.deserialize(data);
@ -213,7 +215,7 @@ TEST(AliasesEventContent, Deserialization)
TEST(AliasesEventContent, NotAnObject) TEST(AliasesEventContent, NotAnObject)
{ {
auto data = QJsonArray{"#test:matrix.org", "#test2:matrix.org"}; auto data = QJsonArray{ "#test:matrix.org", "#test2:matrix.org" };
AliasesEventContent content; AliasesEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -221,8 +223,7 @@ TEST(AliasesEventContent, NotAnObject)
TEST(AliasesEventContent, MissingKey) TEST(AliasesEventContent, MissingKey)
{ {
auto data = QJsonObject{ auto data = QJsonObject{ { "key", QJsonArray{ "#test:matrix.org", "#test2:matrix.org" } } };
{"key", QJsonArray{"#test:matrix.org", "#test2:matrix.org"}}};
AliasesEventContent content; AliasesEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -236,7 +237,7 @@ TEST(AliasesEventContent, MissingKey)
TEST(AvatarEventContent, Deserialization) TEST(AvatarEventContent, Deserialization)
{ {
auto data = QJsonObject{{"url", "https://matrix.org/avatar.png"}}; auto data = QJsonObject{ { "url", "https://matrix.org/avatar.png" } };
AvatarEventContent content; AvatarEventContent content;
content.deserialize(data); content.deserialize(data);
@ -247,7 +248,7 @@ TEST(AvatarEventContent, Deserialization)
TEST(AvatarEventContent, NotAnObject) TEST(AvatarEventContent, NotAnObject)
{ {
auto data = QJsonArray{"key", "url"}; auto data = QJsonArray{ "key", "url" };
AvatarEventContent content; AvatarEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -255,7 +256,7 @@ TEST(AvatarEventContent, NotAnObject)
TEST(AvatarEventContent, MissingKey) TEST(AvatarEventContent, MissingKey)
{ {
auto data = QJsonObject{{"key", "https://matrix.org"}}; auto data = QJsonObject{ { "key", "https://matrix.org" } };
AvatarEventContent content; AvatarEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -269,7 +270,7 @@ TEST(AvatarEventContent, MissingKey)
TEST(CreateEventContent, Deserialization) TEST(CreateEventContent, Deserialization)
{ {
auto data = QJsonObject{{"creator", "@alice:matrix.org"}}; auto data = QJsonObject{ { "creator", "@alice:matrix.org" } };
CreateEventContent content; CreateEventContent content;
content.deserialize(data); content.deserialize(data);
@ -280,7 +281,7 @@ TEST(CreateEventContent, Deserialization)
TEST(CreateEventContent, NotAnObject) TEST(CreateEventContent, NotAnObject)
{ {
auto data = QJsonArray{"creator", "alice"}; auto data = QJsonArray{ "creator", "alice" };
CreateEventContent content; CreateEventContent content;
@ -289,7 +290,7 @@ TEST(CreateEventContent, NotAnObject)
TEST(CreateEventContent, MissingKey) TEST(CreateEventContent, MissingKey)
{ {
auto data = QJsonObject{{"key", "@alice:matrix.org"}}; auto data = QJsonObject{ { "key", "@alice:matrix.org" } };
CreateEventContent content; CreateEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -303,23 +304,23 @@ TEST(CreateEventContent, MissingKey)
TEST(HistoryVisibilityEventContent, Deserialization) TEST(HistoryVisibilityEventContent, Deserialization)
{ {
auto data = QJsonObject{{"history_visibility", "invited"}}; auto data = QJsonObject{ { "history_visibility", "invited" } };
HistoryVisibilityEventContent content; HistoryVisibilityEventContent content;
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Invited); EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Invited);
data = QJsonObject{{"history_visibility", "joined"}}; data = QJsonObject{ { "history_visibility", "joined" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Joined); EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Joined);
data = QJsonObject{{"history_visibility", "shared"}}; data = QJsonObject{ { "history_visibility", "shared" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Shared); EXPECT_EQ(content.historyVisibility(), HistoryVisibility::Shared);
data = QJsonObject{{"history_visibility", "world_readable"}}; data = QJsonObject{ { "history_visibility", "world_readable" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.historyVisibility(), HistoryVisibility::WorldReadable); EXPECT_EQ(content.historyVisibility(), HistoryVisibility::WorldReadable);
@ -327,7 +328,7 @@ TEST(HistoryVisibilityEventContent, Deserialization)
TEST(HistoryVisibilityEventContent, NotAnObject) TEST(HistoryVisibilityEventContent, NotAnObject)
{ {
auto data = QJsonArray{"history_visibility", "alice"}; auto data = QJsonArray{ "history_visibility", "alice" };
HistoryVisibilityEventContent content; HistoryVisibilityEventContent content;
@ -336,7 +337,7 @@ TEST(HistoryVisibilityEventContent, NotAnObject)
TEST(HistoryVisibilityEventContent, InvalidHistoryVisibility) TEST(HistoryVisibilityEventContent, InvalidHistoryVisibility)
{ {
auto data = QJsonObject{{"history_visibility", "wrong"}}; auto data = QJsonObject{ { "history_visibility", "wrong" } };
HistoryVisibilityEventContent content; HistoryVisibilityEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -350,7 +351,7 @@ TEST(HistoryVisibilityEventContent, InvalidHistoryVisibility)
TEST(HistoryVisibilityEventContent, MissingKey) TEST(HistoryVisibilityEventContent, MissingKey)
{ {
auto data = QJsonObject{{"key", "joined"}}; auto data = QJsonObject{ { "key", "joined" } };
HistoryVisibilityEventContent content; HistoryVisibilityEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -364,23 +365,23 @@ TEST(HistoryVisibilityEventContent, MissingKey)
TEST(JoinRulesEventContent, Deserialization) TEST(JoinRulesEventContent, Deserialization)
{ {
auto data = QJsonObject{{"join_rule", "invite"}}; auto data = QJsonObject{ { "join_rule", "invite" } };
JoinRulesEventContent content; JoinRulesEventContent content;
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.joinRule(), JoinRule::Invite); EXPECT_EQ(content.joinRule(), JoinRule::Invite);
data = QJsonObject{{"join_rule", "knock"}}; data = QJsonObject{ { "join_rule", "knock" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.joinRule(), JoinRule::Knock); EXPECT_EQ(content.joinRule(), JoinRule::Knock);
data = QJsonObject{{"join_rule", "private"}}; data = QJsonObject{ { "join_rule", "private" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.joinRule(), JoinRule::Private); EXPECT_EQ(content.joinRule(), JoinRule::Private);
data = QJsonObject{{"join_rule", "public"}}; data = QJsonObject{ { "join_rule", "public" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.joinRule(), JoinRule::Public); EXPECT_EQ(content.joinRule(), JoinRule::Public);
@ -388,7 +389,7 @@ TEST(JoinRulesEventContent, Deserialization)
TEST(JoinRulesEventContent, NotAnObject) TEST(JoinRulesEventContent, NotAnObject)
{ {
auto data = QJsonArray{"rule", "alice"}; auto data = QJsonArray{ "rule", "alice" };
JoinRulesEventContent content; JoinRulesEventContent content;
@ -397,7 +398,7 @@ TEST(JoinRulesEventContent, NotAnObject)
TEST(JoinRulesEventContent, InvalidHistoryVisibility) TEST(JoinRulesEventContent, InvalidHistoryVisibility)
{ {
auto data = QJsonObject{{"join_rule", "wrong"}}; auto data = QJsonObject{ { "join_rule", "wrong" } };
JoinRulesEventContent content; JoinRulesEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -411,7 +412,7 @@ TEST(JoinRulesEventContent, InvalidHistoryVisibility)
TEST(JoinRulesEventContent, MissingKey) TEST(JoinRulesEventContent, MissingKey)
{ {
auto data = QJsonObject{{"key", "invite"}}; auto data = QJsonObject{ { "key", "invite" } };
JoinRulesEventContent content; JoinRulesEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -425,7 +426,7 @@ TEST(JoinRulesEventContent, MissingKey)
TEST(CanonicalAliasEventContent, Deserialization) TEST(CanonicalAliasEventContent, Deserialization)
{ {
auto data = QJsonObject{{"alias", "Room Alias"}}; auto data = QJsonObject{ { "alias", "Room Alias" } };
CanonicalAliasEventContent content; CanonicalAliasEventContent content;
content.deserialize(data); content.deserialize(data);
@ -436,7 +437,7 @@ TEST(CanonicalAliasEventContent, Deserialization)
TEST(CanonicalAliasEventContent, NotAnObject) TEST(CanonicalAliasEventContent, NotAnObject)
{ {
auto data = QJsonArray{"alias", "Room Alias"}; auto data = QJsonArray{ "alias", "Room Alias" };
CanonicalAliasEventContent content; CanonicalAliasEventContent content;
@ -445,7 +446,7 @@ TEST(CanonicalAliasEventContent, NotAnObject)
TEST(CanonicalAliasEventContent, MissingKey) TEST(CanonicalAliasEventContent, MissingKey)
{ {
auto data = QJsonObject{{"key", "alias"}}; auto data = QJsonObject{ { "key", "alias" } };
CanonicalAliasEventContent content; CanonicalAliasEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -461,29 +462,29 @@ TEST(MemberEventContent, Deserialization)
{ {
MemberEventContent content; MemberEventContent content;
auto data = QJsonObject{{"membership", "join"}}; auto data = QJsonObject{ { "membership", "join" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.membershipState(), Membership::Join); EXPECT_EQ(content.membershipState(), Membership::Join);
data = QJsonObject{{"membership", "invite"}, {"displayname", "Username"}}; data = QJsonObject{ { "membership", "invite" }, { "displayname", "Username" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.membershipState(), Membership::Invite); EXPECT_EQ(content.membershipState(), Membership::Invite);
EXPECT_EQ(content.displayName(), "Username"); 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); content.deserialize(data);
EXPECT_EQ(content.membershipState(), Membership::Leave); EXPECT_EQ(content.membershipState(), Membership::Leave);
EXPECT_EQ(content.avatarUrl().toString(), "https://matrix.org"); EXPECT_EQ(content.avatarUrl().toString(), "https://matrix.org");
data = QJsonObject{{"membership", "ban"}}; data = QJsonObject{ { "membership", "ban" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.membershipState(), Membership::Ban); EXPECT_EQ(content.membershipState(), Membership::Ban);
data = QJsonObject{{"membership", "knock"}}; data = QJsonObject{ { "membership", "knock" } };
content.deserialize(data); content.deserialize(data);
EXPECT_EQ(content.membershipState(), Membership::Knock); EXPECT_EQ(content.membershipState(), Membership::Knock);
@ -491,7 +492,7 @@ TEST(MemberEventContent, Deserialization)
TEST(MemberEventContent, InvalidMembership) TEST(MemberEventContent, InvalidMembership)
{ {
auto data = QJsonObject{{"membership", "wrong"}}; auto data = QJsonObject{ { "membership", "wrong" } };
MemberEventContent content; MemberEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -505,7 +506,7 @@ TEST(MemberEventContent, InvalidMembership)
TEST(MemberEventContent, NotAnObject) TEST(MemberEventContent, NotAnObject)
{ {
auto data = QJsonArray{"name", "join"}; auto data = QJsonArray{ "name", "join" };
MemberEventContent content; MemberEventContent content;
@ -514,7 +515,7 @@ TEST(MemberEventContent, NotAnObject)
TEST(MemberEventContent, MissingName) TEST(MemberEventContent, MissingName)
{ {
auto data = QJsonObject{{"key", "random"}}; auto data = QJsonObject{ { "key", "random" } };
MemberEventContent content; MemberEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -528,7 +529,7 @@ TEST(MemberEventContent, MissingName)
TEST(NameEventContent, Deserialization) TEST(NameEventContent, Deserialization)
{ {
auto data = QJsonObject{{"name", "Room Name"}}; auto data = QJsonObject{ { "name", "Room Name" } };
NameEventContent content; NameEventContent content;
content.deserialize(data); content.deserialize(data);
@ -539,7 +540,7 @@ TEST(NameEventContent, Deserialization)
TEST(NameEventContent, NotAnObject) TEST(NameEventContent, NotAnObject)
{ {
auto data = QJsonArray{"name", "Room Name"}; auto data = QJsonArray{ "name", "Room Name" };
NameEventContent content; NameEventContent content;
@ -548,7 +549,7 @@ TEST(NameEventContent, NotAnObject)
TEST(NameEventContent, MissingName) TEST(NameEventContent, MissingName)
{ {
auto data = QJsonObject{{"key", "Room Name"}}; auto data = QJsonObject{ { "key", "Room Name" } };
NameEventContent content; NameEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);
@ -581,17 +582,17 @@ TEST(PowerLevelsEventContent, DefaultValues)
TEST(PowerLevelsEventContent, FullDeserialization) TEST(PowerLevelsEventContent, FullDeserialization)
{ {
auto data = QJsonObject{ auto data = QJsonObject{
{"ban", 1}, { "ban", 1 },
{"invite", 2}, { "invite", 2 },
{"kick", 3}, { "kick", 3 },
{"redact", 4}, { "redact", 4 },
{"events_default", 5}, { "events_default", 5 },
{"state_default", 6}, { "state_default", 6 },
{"users_default", 7}, { "users_default", 7 },
{"events", QJsonObject{{"m.message.text", 8}, {"m.message.image", 9}}}, { "events", QJsonObject{ { "m.message.text", 8 }, { "m.message.image", 9 } } },
{"users", QJsonObject{{"@alice:matrix.org", 10}, {"@bob:matrix.org", 11}}}, { "users", QJsonObject{ { "@alice:matrix.org", 10 }, { "@bob:matrix.org", 11 } } },
}; };
PowerLevelsEventContent power_levels; PowerLevelsEventContent power_levels;
@ -620,13 +621,13 @@ TEST(PowerLevelsEventContent, FullDeserialization)
TEST(PowerLevelsEventContent, PartialDeserialization) TEST(PowerLevelsEventContent, PartialDeserialization)
{ {
auto data = QJsonObject{ auto data = QJsonObject{
{"ban", 1}, { "ban", 1 },
{"invite", 2}, { "invite", 2 },
{"events_default", 5}, { "events_default", 5 },
{"users_default", 7}, { "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; PowerLevelsEventContent power_levels;
@ -652,7 +653,7 @@ TEST(PowerLevelsEventContent, PartialDeserialization)
TEST(PowerLevelsEventContent, NotAnObject) TEST(PowerLevelsEventContent, NotAnObject)
{ {
auto data = QJsonArray{"test", "test2"}; auto data = QJsonArray{ "test", "test2" };
PowerLevelsEventContent power_levels; PowerLevelsEventContent power_levels;
@ -661,7 +662,7 @@ TEST(PowerLevelsEventContent, NotAnObject)
TEST(TopicEventContent, Deserialization) TEST(TopicEventContent, Deserialization)
{ {
auto data = QJsonObject{{"topic", "Room Topic"}}; auto data = QJsonObject{ { "topic", "Room Topic" } };
TopicEventContent content; TopicEventContent content;
content.deserialize(data); content.deserialize(data);
@ -672,7 +673,7 @@ TEST(TopicEventContent, Deserialization)
TEST(TopicEventContent, NotAnObject) TEST(TopicEventContent, NotAnObject)
{ {
auto data = QJsonArray{"topic", "Room Topic"}; auto data = QJsonArray{ "topic", "Room Topic" };
TopicEventContent content; TopicEventContent content;
@ -681,7 +682,7 @@ TEST(TopicEventContent, NotAnObject)
TEST(TopicEventContent, MissingName) TEST(TopicEventContent, MissingName)
{ {
auto data = QJsonObject{{"key", "Room Name"}}; auto data = QJsonObject{ { "key", "Room Name" } };
TopicEventContent content; TopicEventContent content;
ASSERT_THROW(content.deserialize(data), DeserializationException); ASSERT_THROW(content.deserialize(data), DeserializationException);

View file

@ -19,24 +19,20 @@ using namespace matrix::events;
TEST(MessageEvent, Audio) TEST(MessageEvent, Audio)
{ {
auto info = QJsonObject{ auto info =
{"duration", 2140786}, QJsonObject{ { "duration", 2140786 }, { "mimetype", "audio/mpeg" }, { "size", 1563688 } };
{"mimetype", "audio/mpeg"},
{"size", 1563688}};
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "Bee Gees - Stayin' Alive" },
{"body", "Bee Gees - Stayin' Alive"}, { "msgtype", "m.audio" },
{"msgtype", "m.audio"}, { "url", "mxc://localhost/2sdfj23f33r3faad" },
{"url", "mxc://localhost/2sdfj23f33r3faad"}, { "info", info } };
{"info", info}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::Audio> audio; MessageEvent<messages::Audio> audio;
audio.deserialize(event); audio.deserialize(event);
@ -49,17 +45,14 @@ TEST(MessageEvent, Audio)
TEST(MessageEvent, Emote) TEST(MessageEvent, Emote)
{ {
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "emote message" }, { "msgtype", "m.emote" } };
{"body", "emote message"},
{"msgtype", "m.emote"}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::Emote> emote; MessageEvent<messages::Emote> emote;
emote.deserialize(event); emote.deserialize(event);
@ -70,31 +63,26 @@ TEST(MessageEvent, Emote)
TEST(MessageEvent, File) TEST(MessageEvent, File)
{ {
auto thumbnail_info = QJsonObject{ auto thumbnail_info = QJsonObject{
{"h", 300}, { "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" }
{"w", 400}, };
{"size", 3432434},
{"mimetype", "image/jpeg"}};
auto file_info = QJsonObject{ auto file_info = QJsonObject{ { "size", 24242424 },
{"size", 24242424}, { "mimetype", "application/msword" },
{"mimetype", "application/msword"}, { "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" },
{"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, { "thumbnail_info", thumbnail_info } };
{"thumbnail_info", thumbnail_info}};
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "something-important.doc" },
{"body", "something-important.doc"}, { "filename", "something-important.doc" },
{"filename", "something-important.doc"}, { "url", "mxc://localhost/23d233d32r3r2r" },
{"url", "mxc://localhost/23d233d32r3r2r"}, { "info", file_info },
{"info", file_info}, { "msgtype", "m.file" } };
{"msgtype", "m.file"}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::File> file; MessageEvent<messages::File> file;
file.deserialize(event); file.deserialize(event);
@ -111,34 +99,29 @@ TEST(MessageEvent, File)
TEST(MessageEvent, Image) TEST(MessageEvent, Image)
{ {
auto thumbinfo = QJsonObject{ auto thumbinfo = QJsonObject{
{"h", 11}, { "h", 11 }, { "w", 22 }, { "size", 212 }, { "mimetype", "img/jpeg" },
{"w", 22},
{"size", 212},
{"mimetype", "img/jpeg"},
}; };
auto imginfo = QJsonObject{ auto imginfo = QJsonObject{
{"h", 110}, { "h", 110 },
{"w", 220}, { "w", 220 },
{"size", 2120}, { "size", 2120 },
{"mimetype", "img/jpeg"}, { "mimetype", "img/jpeg" },
{"thumbnail_url", "https://images.com/image-thumb.jpg"}, { "thumbnail_url", "https://images.com/image-thumb.jpg" },
{"thumbnail_info", thumbinfo}, { "thumbnail_info", thumbinfo },
}; };
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "Image title" },
{"body", "Image title"}, { "msgtype", "m.image" },
{"msgtype", "m.image"}, { "url", "https://images.com/image.jpg" },
{"url", "https://images.com/image.jpg"}, { "info", imginfo } };
{"info", imginfo}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::Image> img; MessageEvent<messages::Image> img;
img.deserialize(event); img.deserialize(event);
@ -154,28 +137,23 @@ TEST(MessageEvent, Image)
TEST(MessageEvent, Location) TEST(MessageEvent, Location)
{ {
auto thumbnail_info = QJsonObject{ auto thumbnail_info = QJsonObject{
{"h", 300}, { "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" }
{"w", 400}, };
{"size", 3432434},
{"mimetype", "image/jpeg"}};
auto info = QJsonObject{ auto info = QJsonObject{ { "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" },
{"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, { "thumbnail_info", thumbnail_info } };
{"thumbnail_info", thumbnail_info}};
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "Big Ben, London, UK" },
{"body", "Big Ben, London, UK"}, { "geo_uri", "geo:51.5008,0.1247" },
{"geo_uri", "geo:51.5008,0.1247"}, { "info", info },
{"info", info}, { "msgtype", "m.location" } };
{"msgtype", "m.location"}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::Location> location; MessageEvent<messages::Location> location;
location.deserialize(event); location.deserialize(event);
@ -189,17 +167,14 @@ TEST(MessageEvent, Location)
TEST(MessageEvent, Notice) TEST(MessageEvent, Notice)
{ {
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "notice message" }, { "msgtype", "m.notice" } };
{"body", "notice message"},
{"msgtype", "m.notice"}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::Notice> notice; MessageEvent<messages::Notice> notice;
notice.deserialize(event); notice.deserialize(event);
@ -209,17 +184,14 @@ TEST(MessageEvent, Notice)
TEST(MessageEvent, Text) TEST(MessageEvent, Text)
{ {
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "text message" }, { "msgtype", "m.text" } };
{"body", "text message"},
{"msgtype", "m.text"}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::Text> text; MessageEvent<messages::Text> text;
text.deserialize(event); text.deserialize(event);
@ -230,33 +202,28 @@ TEST(MessageEvent, Text)
TEST(MessageEvent, Video) TEST(MessageEvent, Video)
{ {
auto thumbnail_info = QJsonObject{ auto thumbnail_info = QJsonObject{
{"h", 300}, { "h", 300 }, { "w", 400 }, { "size", 3432434 }, { "mimetype", "image/jpeg" }
{"w", 400}, };
{"size", 3432434},
{"mimetype", "image/jpeg"}};
auto video_info = QJsonObject{ auto video_info = QJsonObject{ { "h", 222 },
{"h", 222}, { "w", 333 },
{"w", 333}, { "duration", 232323 },
{"duration", 232323}, { "size", 24242424 },
{"size", 24242424}, { "mimetype", "video/mp4" },
{"mimetype", "video/mp4"}, { "thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3" },
{"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, { "thumbnail_info", thumbnail_info } };
{"thumbnail_info", thumbnail_info}};
auto content = QJsonObject{ auto content = QJsonObject{ { "body", "Gangnam Style" },
{"body", "Gangnam Style"}, { "url", "mxc://localhost/23d233d32r3r2r" },
{"url", "mxc://localhost/23d233d32r3r2r"}, { "info", video_info },
{"info", video_info}, { "msgtype", "m.video" } };
{"msgtype", "m.video"}};
auto event = QJsonObject{ auto event = QJsonObject{ { "content", content },
{"content", content}, { "event_id", "$asdfafdf8af:matrix.org" },
{"event_id", "$asdfafdf8af:matrix.org"}, { "room_id", "!aasdfaeae23r9:matrix.org" },
{"room_id", "!aasdfaeae23r9:matrix.org"}, { "sender", "@alice:matrix.org" },
{"sender", "@alice:matrix.org"}, { "origin_server_ts", 1323238293289323LL },
{"origin_server_ts", 1323238293289323LL}, { "type", "m.room.message" } };
{"type", "m.room.message"}};
MessageEvent<messages::Video> video; MessageEvent<messages::Video> video;
video.deserialize(event); video.deserialize(event);
@ -272,40 +239,49 @@ TEST(MessageEvent, Video)
TEST(MessageEvent, Types) TEST(MessageEvent, Types)
{ {
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.audio"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.audio" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Audio); MessageEventType::Audio);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.emote"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.emote" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Emote); MessageEventType::Emote);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.file"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.file" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::File); MessageEventType::File);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.image"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.image" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Image); MessageEventType::Image);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.location"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.location" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Location); MessageEventType::Location);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.notice"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.notice" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Notice); MessageEventType::Notice);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.text"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.text" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Text); MessageEventType::Text);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.video"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.video" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Video); MessageEventType::Video);
EXPECT_EQ(extractMessageEventType(QJsonObject{ EXPECT_EQ(
{"content", QJsonObject{{"msgtype", "m.random"}}}, {"type", "m.room.message"}, extractMessageEventType(QJsonObject{
{ "content", QJsonObject{ { "msgtype", "m.random" } } }, { "type", "m.room.message" },
}), }),
MessageEventType::Unknown); MessageEventType::Unknown);
} }