File indexing completed on 2024-12-01 04:35:23
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 "deviceinfotest.h" 0008 #include "managedevices/deviceinfo.h" 0009 #include "ruqola_autotest_helper.h" 0010 0011 QTEST_GUILESS_MAIN(DeviceInfoTest) 0012 DeviceInfoTest::DeviceInfoTest(QObject *parent) 0013 : QObject{parent} 0014 { 0015 } 0016 0017 void DeviceInfoTest::shouldHaveDefaultValues() 0018 { 0019 DeviceInfo w; 0020 QVERIFY(w.identifier().isEmpty()); 0021 QVERIFY(w.host().isEmpty()); 0022 QVERIFY(w.sessionId().isEmpty()); 0023 QVERIFY(w.ip().isEmpty()); 0024 QVERIFY(w.userId().isEmpty()); 0025 QCOMPARE(w.loginAt(), -1); 0026 QVERIFY(w.os().isEmpty()); 0027 QVERIFY(w.client().isEmpty()); 0028 } 0029 0030 void DeviceInfoTest::shouldDeviceInfo() 0031 { 0032 QFETCH(QString, name); 0033 QFETCH(DeviceInfo, deviceInfo); 0034 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/deviceinfo/") + name + QLatin1String(".json"); 0035 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0036 0037 DeviceInfo result; 0038 result.parseDeviceInfo(obj); 0039 const bool equal = result == deviceInfo; 0040 if (!equal) { 0041 qDebug() << " result " << result; 0042 qDebug() << " deviceInfo " << deviceInfo; 0043 } 0044 QVERIFY(equal); 0045 } 0046 0047 void DeviceInfoTest::shouldDeviceInfo_data() 0048 { 0049 QTest::addColumn<QString>("name"); 0050 QTest::addColumn<DeviceInfo>("deviceInfo"); 0051 QTest::addRow("deviceinfoempty") << QStringLiteral("deviceinfoempty") << DeviceInfo(); 0052 { 0053 DeviceInfo info; 0054 info.setHost(QStringLiteral("chat.kde.org")); 0055 info.setIdentifier(QStringLiteral("iy78NiKzd")); 0056 info.setIp(QStringLiteral("179.4.8.1")); 0057 info.setSessionId(QStringLiteral("iKzd")); 0058 info.setUserId(QStringLiteral("acidH")); 0059 info.setLoginAt(1660405994979); 0060 QTest::addRow("deviceinfo1") << QStringLiteral("deviceinfo1") << info; 0061 } 0062 { 0063 DeviceInfo info; 0064 info.setHost(QStringLiteral("chat.kde.org")); 0065 info.setIdentifier(QStringLiteral("87pMW")); 0066 info.setIp(QStringLiteral("1.7.6.11")); 0067 info.setSessionId(QStringLiteral("87pMW")); 0068 info.setUserId(QStringLiteral("dacidH")); 0069 info.setClient(QStringLiteral("Firefox")); 0070 info.setOs(QStringLiteral("Linux x86_64")); 0071 info.setLoginAt(1660404361954); 0072 QTest::addRow("deviceinfo2") << QStringLiteral("deviceinfo2") << info; 0073 } 0074 } 0075 0076 #include "moc_deviceinfotest.cpp"