diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-05-03 03:42:43 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-05-04 17:11:04 +0300 |
commit | 02ef7411e648e5738bd5a8c97fbda5c00496f337 (patch) | |
tree | 464e34e3d4ca43576f36fd71dfc406f5dea0ccf7 /tests/events.cc | |
parent | Add RoomEvent (diff) | |
download | nheko-02ef7411e648e5738bd5a8c97fbda5c00496f337.tar.xz |
Add StateEvent
Diffstat (limited to '')
-rw-r--r-- | tests/events.cc | 45 |
1 files changed, 45 insertions, 0 deletions
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<NameEventContent> 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<NameEventContent> 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); |