From 02ef7411e648e5738bd5a8c97fbda5c00496f337 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Wed, 3 May 2017 03:42:43 +0300 Subject: Add StateEvent --- tests/events.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/events.cc') diff --git a/tests/events.cc b/tests/events.cc index a6a3c30c..cb6abd88 100644 --- a/tests/events.cc +++ b/tests/events.cc @@ -3,6 +3,7 @@ #include "Event.h" #include "RoomEvent.h" +#include "StateEvent.h" #include "AliasesEventContent.h" #include "AvatarEventContent.h" @@ -127,6 +128,50 @@ TEST(RoomEvent, DeserializationException) } } +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"}}; + + 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"); +} + +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"}}; + + StateEvent event; + + 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); -- cgit 1.4.1