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 #include "deviceinfostest.h" 0007 #include "managedevices/deviceinfos.h" 0008 #include "ruqola_autotest_helper.h" 0009 #include <QJsonObject> 0010 0011 QTEST_GUILESS_MAIN(DeviceInfosTest) 0012 0013 DeviceInfosTest::DeviceInfosTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void DeviceInfosTest::shouldHaveDefaultValues() 0019 { 0020 DeviceInfos w; 0021 QVERIFY(w.isEmpty()); 0022 QCOMPARE(w.offset(), 0); 0023 QCOMPARE(w.total(), 0); 0024 QCOMPARE(w.deviceInfosCount(), 0); 0025 } 0026 0027 void DeviceInfosTest::shouldLoadDeviceInfos_data() 0028 { 0029 QTest::addColumn<QString>("name"); 0030 QTest::addColumn<int>("deviceInfosCount"); 0031 QTest::addColumn<int>("total"); 0032 QTest::addColumn<int>("offset"); 0033 0034 QTest::addRow("empty") << QStringLiteral("deviceinfos-empty") << 0 << 0 << 0; 0035 QTest::addRow("1-element") << QStringLiteral("deviceinfos-1-element") << 50 << 2 << 0; 0036 } 0037 0038 void DeviceInfosTest::shouldLoadDeviceInfos() 0039 { 0040 QFETCH(QString, name); 0041 QFETCH(int, deviceInfosCount); 0042 QFETCH(int, total); 0043 QFETCH(int, offset); 0044 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/deviceinfos/") + name + QLatin1String(".json"); 0045 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0046 DeviceInfos m; 0047 m.parseDeviceInfos(obj); 0048 QCOMPARE(m.deviceInfosCount(), deviceInfosCount); 0049 QCOMPARE(m.total(), total); 0050 QCOMPARE(m.offset(), offset); 0051 } 0052 0053 #include "moc_deviceinfostest.cpp"