File indexing completed on 2024-05-19 05:02:21

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "blocktest.h"
0008 #include "messages/block.h"
0009 #include "ruqola_autotest_helper.h"
0010 #include <QJsonObject>
0011 
0012 QTEST_GUILESS_MAIN(BlockTest)
0013 BlockTest::BlockTest(QObject *parent)
0014     : QObject{parent}
0015 {
0016 }
0017 
0018 void BlockTest::shouldHaveDefaultValues()
0019 {
0020     Block b;
0021     QVERIFY(b.callId().isEmpty());
0022     QVERIFY(b.blockId().isEmpty());
0023     QVERIFY(b.appId().isEmpty());
0024     QVERIFY(b.blockTypeStr().isEmpty());
0025     QCOMPARE(b.blockType(), Block::Unknown);
0026 
0027     QVERIFY(!b.videoConferenceInfo().isValid());
0028     QVERIFY(!b.isValid());
0029 }
0030 
0031 void BlockTest::shouldLoadBlock_data()
0032 {
0033     QTest::addColumn<QString>("name");
0034     QTest::addColumn<Block>("blockInfo");
0035     Block info;
0036     info.setBlockId(QStringLiteral("63936e304ef3f3baa9658bd7"));
0037     info.setAppId(QStringLiteral("videoconf-core"));
0038     info.setCallId(QStringLiteral("63936e304ef"));
0039     info.setBlockTypeStr(QStringLiteral("video_conf"));
0040     QTest::addRow("blocks1") << QStringLiteral("blocks1") << info;
0041 }
0042 
0043 void BlockTest::shouldLoadBlock()
0044 {
0045     QFETCH(QString, name);
0046     QFETCH(Block, blockInfo);
0047     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/blocks/") + name + QLatin1String(".json");
0048     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0049 
0050     Block r;
0051     r.parseBlock(obj);
0052     const bool equalOwner = (r == blockInfo);
0053     if (!equalOwner) {
0054         qDebug() << "ACTUAL " << r;
0055         qDebug() << "EXPECTED " << blockInfo;
0056     }
0057     QVERIFY(equalOwner);
0058 }
0059 
0060 void BlockTest::shouldSerializeData()
0061 {
0062     Block input;
0063     input.setBlockId(QStringLiteral("63936e304ef3f3baa9658bd7"));
0064     input.setAppId(QStringLiteral("videoconf-core"));
0065     input.setCallId(QStringLiteral("63936e304ef"));
0066     input.setBlockTypeStr(QStringLiteral("video_conf"));
0067 
0068     const QJsonObject ba = Block::serialize(input);
0069     const Block output = Block::deserialize(ba);
0070     QCOMPARE(input, output);
0071 }
0072 
0073 #include "moc_blocktest.cpp"