File indexing completed on 2024-05-12 16:25:27

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "otrtest.h"
0008 #include "otr/otr.h"
0009 #include "ruqola_autotest_helper.h"
0010 #include <QJsonDocument>
0011 #include <QJsonObject>
0012 
0013 QTEST_GUILESS_MAIN(OtrTest)
0014 
0015 OtrTest::OtrTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 void OtrTest::shouldHaveDefaultValue()
0021 {
0022     Otr t;
0023     QVERIFY(t.roomId().isEmpty());
0024     QVERIFY(t.userId().isEmpty());
0025     QCOMPARE(t.type(), Otr::OtrType::Unknown);
0026     QVERIFY(!t.isValid());
0027 }
0028 
0029 void OtrTest::shouldParseOtr_data()
0030 {
0031     QTest::addColumn<QString>("fileName");
0032     QTest::addColumn<Otr::OtrType>("otrtype");
0033     QTest::newRow("otrend") << QStringLiteral("otrend") << Otr::End;
0034     QTest::newRow("otrbegin") << QStringLiteral("otrbegin") << Otr::Handshake;
0035 }
0036 
0037 void OtrTest::shouldParseOtr()
0038 {
0039     QFETCH(QString, fileName);
0040     QFETCH(Otr::OtrType, otrtype);
0041     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/json/") + fileName + QLatin1String(".json");
0042     QFile f(originalJsonFile);
0043     QVERIFY(f.open(QIODevice::ReadOnly));
0044     const QByteArray content = f.readAll();
0045     f.close();
0046     const QJsonDocument doc = QJsonDocument::fromJson(content);
0047     const QJsonObject fields = doc.object().value(QLatin1String("fields")).toObject();
0048     const QJsonArray contents = fields.value(QLatin1String("args")).toArray();
0049 
0050     Otr otr;
0051     otr.parseOtr(contents);
0052     QVERIFY(otr.isValid());
0053     QCOMPARE(otr.type(), otrtype);
0054     // TODO
0055 }
0056 
0057 #include "moc_otrtest.cpp"