Changeset View
Changeset View
Standalone View
Standalone View
src/tests/matrix-sticker-pack-test.cpp
| Show All 34 Lines | |||||
| { | { | ||||
| Q_OBJECT | Q_OBJECT | ||||
| private Q_SLOTS: | private Q_SLOTS: | ||||
| void testStickerPack(); | void testStickerPack(); | ||||
| void testStickerPackList(); | void testStickerPackList(); | ||||
| void testStickerPackListInRoom(); | void testStickerPackListInRoom(); | ||||
| void testAddToPack(); | void testAddToPack(); | ||||
| void testRemoveFromPack(); | |||||
| }; | }; | ||||
| // https://github.com/Sorunome/matrix-doc/blob/soru/emotes/proposals/2545-emotes.md | // https://github.com/Sorunome/matrix-doc/blob/soru/emotes/proposals/2545-emotes.md | ||||
| static auto stickerPackEvent = Event{R"({ | static auto stickerPackEvent = Event{R"({ | ||||
| "content": { | "content": { | ||||
| "images": { | "images": { | ||||
| "myemote": { | "myemote": { | ||||
| "url": "mxc://example.org/blah" | "url": "mxc://example.org/blah" | ||||
| ▲ Show 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | void MatrixStickerPackTest::testAddToPack() | ||||
| auto event = toUniquePtr(new MatrixEvent(eventCursor)); | auto event = toUniquePtr(new MatrixEvent(eventCursor)); | ||||
| auto newSource = stickerPack->addSticker(u"someotheremote"_s, event.get()).template value<MatrixStickerPackSource>(); | auto newSource = stickerPack->addSticker(u"someotheremote"_s, event.get()).template value<MatrixStickerPackSource>(); | ||||
| auto expected = sourceCursor.get().event.content().get(); | auto expected = sourceCursor.get().event.content().get(); | ||||
| expected["images"]["someotheremote"] = contentJson; | expected["images"]["someotheremote"] = contentJson; | ||||
| QVERIFY(newSource.event.content().get() == expected); | QVERIFY(newSource.event.content().get() == expected); | ||||
| } | |||||
| void MatrixStickerPackTest::testRemoveFromPack() | |||||
| { | |||||
| auto sourceCursor = lager::make_state(MatrixStickerPackSource{ | |||||
| MatrixStickerPackSource::AccountData, | |||||
| "im.ponies.user_emotes", | |||||
| stickerPackEvent, | |||||
| "", | |||||
| "", | |||||
| }, lager::automatic_tag{}); | |||||
| auto stickerPack = toUniquePtr(new MatrixStickerPack(sourceCursor)); | |||||
| auto newSource = stickerPack->removeSticker(u"myemote"_s).template value<MatrixStickerPackSource>(); | |||||
| auto expected = sourceCursor.get().event.content().get(); | |||||
| expected["images"].erase("myemote"); | |||||
| QVERIFY(newSource.event.content().get() == expected); | |||||
| QVERIFY(!newSource.event.content().get()["images"].contains("myemote")); | |||||
| // Removing a non-existent sticker should leave the pack unchanged. | |||||
| auto unchangedSource = stickerPack->removeSticker(u"doesnotexist"_s).template value<MatrixStickerPackSource>(); | |||||
| QVERIFY(unchangedSource.event.content().get() == sourceCursor.get().event.content().get()); | |||||
| } | } | ||||
| QTEST_MAIN(MatrixStickerPackTest) | QTEST_MAIN(MatrixStickerPackTest) | ||||
| #include "matrix-sticker-pack-test.moc" | #include "matrix-sticker-pack-test.moc" | ||||