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 Qt::Literals::StringLiterals;
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() == u"device1"_s);
QVERIFY(dev->trustLevel() == u"unseen"_s);
}
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() == u"device1"_s);
QTRY_VERIFY(dev->trustLevel() == u"verified"_s); // 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
Sun, Nov 24, 3:47 PM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39446
Default Alt Text
matrix-sdk-test.cpp (1 KB)

Event Timeline