Page MenuHomePhorge

matrix-sdk-test.cpp
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

matrix-sdk-test.cpp

/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <kazv-defs.hpp>
#include <memory>
#include <QtTest>
#include <QSignalSpy>
#include <matrix-sdk.hpp>
#include <matrix-device-list.hpp>
#include <matrix-device.hpp>
#include <matrix-promise.hpp>
#include "test-model.hpp"
#include "test-utils.hpp"
using namespace Kazv;
class MatrixSdkTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testDevicesOfUser();
void testSetDeviceTrustLevel();
};
void MatrixSdkTest::testDevicesOfUser()
{
auto model = makeTestModel();
std::unique_ptr<MatrixSdk> sdk{new MatrixSdk(model, /* testing = */ true)};
auto devices = toUniquePtr(sdk->devicesOfUser(QStringLiteral("@test1:test1.org")));
QVERIFY(devices->count() == 2);
auto dev = toUniquePtr(devices->at(0));
QVERIFY(dev->deviceId() == "device1");
QVERIFY(dev->trustLevel() == "unseen");
}
void MatrixSdkTest::testSetDeviceTrustLevel()
{
auto model = makeTestModel();
std::unique_ptr<MatrixSdk> sdk{new MatrixSdk(model, /* testing = */ true)};
sdk->startThread();
auto promise = toUniquePtr(
sdk->setDeviceTrustLevel(
QStringLiteral("@test1:test1.org"),
QStringLiteral("device1"),
QStringLiteral("verified")
)
);
auto spy = QSignalSpy(promise.get(), &MatrixPromise::succeeded);
spy.wait();
auto devices = toUniquePtr(sdk->devicesOfUser(QStringLiteral("@test1:test1.org")));
QVERIFY(devices->count() == 2);
auto dev = toUniquePtr(devices->at(0));
QVERIFY(dev->deviceId() == "device1");
QTRY_VERIFY(dev->trustLevel() == "verified"); // wait for the change to propagate to this thread
}
QTEST_MAIN(MatrixSdkTest)
#include "matrix-sdk-test.moc"

File Metadata

Mime Type
text/x-c
Expires
Fri, Nov 22, 10:17 PM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38730
Default Alt Text
matrix-sdk-test.cpp (1 KB)

Event Timeline