Changeset View
Changeset View
Standalone View
Standalone View
src/tests/matrix-room-state-test.cpp
- This file was added.
| /* | |||||
| * This file is part of kazv. | |||||
| * SPDX-FileCopyrightText: 2025 tusooa <tusooa@kazv.moe> | |||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | |||||
| */ | |||||
| #include <kazv-defs.hpp> | |||||
| #include <matrix-room-state.hpp> | |||||
| #include <memory> | |||||
| #include <QtTest> | |||||
| #include <factory.hpp> | |||||
| #include <matrix-sdk.hpp> | |||||
| #include <matrix-room-list.hpp> | |||||
| #include <matrix-room.hpp> | |||||
| #include <matrix-event-list.hpp> | |||||
| #include "test-model.hpp" | |||||
| #include "test-utils.hpp" | |||||
| using namespace Qt::Literals::StringLiterals; | |||||
| using namespace Kazv; | |||||
| using namespace Kazv::Factory; | |||||
| class MatrixRoomStateTest : public QObject | |||||
| { | |||||
| Q_OBJECT | |||||
| private Q_SLOTS: | |||||
| void testSimple(); | |||||
| }; | |||||
| void MatrixRoomStateTest::testSimple() | |||||
| { | |||||
| auto state = EventList{ | |||||
| makeMemberEvent(), | |||||
| makeMemberEvent(), | |||||
| makeEvent(withEventType("m.room.name") | withStateKey("")), | |||||
| makeEvent(withEventType("moe.kazv.mxc.foo") | withStateKey("a")), | |||||
| }; | |||||
| auto r = makeRoom(withRoomState(state)); | |||||
| auto c = makeClient(withRoom(r)); | |||||
| std::unique_ptr<MatrixSdk> sdk{makeTestSdk(SdkModel{c})}; | |||||
| auto roomList = toUniquePtr(sdk->roomList()); | |||||
| auto room = toUniquePtr(roomList->room(QString::fromStdString(r.roomId))); | |||||
| auto allState = toUniquePtr(room->allState()); | |||||
| QCOMPARE(allState->count(), 3); | |||||
| auto members = toUniquePtr(allState->eventsForType(u"m.room.member"_s)); | |||||
| QCOMPARE(members->count(), 2); | |||||
| auto names = toUniquePtr(allState->eventsForType(u"m.room.name"_s)); | |||||
| QCOMPARE(names->count(), 1); | |||||
| } | |||||
| QTEST_MAIN(MatrixRoomStateTest) | |||||
| #include "matrix-room-state-test.moc" | |||||