From 6b8b782aa0ea1fdff81c07a413b4b95a0c9c41ab Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 27 Apr 2024 22:43:44 +0200 Subject: [PATCH] Extend tests of models --- syncthingmodel/CMakeLists.txt | 2 +- syncthingmodel/tests/models.cpp | 44 ++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/syncthingmodel/CMakeLists.txt b/syncthingmodel/CMakeLists.txt index b966bac..4fdbe52 100644 --- a/syncthingmodel/CMakeLists.txt +++ b/syncthingmodel/CMakeLists.txt @@ -39,7 +39,7 @@ set(TS_FILES translations/${META_PROJECT_NAME}_zh_CN.ts translations/${META_PROJ translations/${META_PROJECT_NAME}_de_DE.ts translations/${META_PROJECT_NAME}_en_US.ts) set(QT_TESTS models) -set(QT_TEST_SRC_FILES_models syncthingicons.cpp syncthingmodel.cpp syncthingdirectorymodel.cpp) +set(QT_TEST_SRC_FILES_models syncthingicons.cpp syncthingmodel.cpp syncthingdirectorymodel.cpp syncthingdevicemodel.cpp) # find c++utilities find_package(${PACKAGE_NAMESPACE_PREFIX}c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED) diff --git a/syncthingmodel/tests/models.cpp b/syncthingmodel/tests/models.cpp index faa9958..55bcb53 100644 --- a/syncthingmodel/tests/models.cpp +++ b/syncthingmodel/tests/models.cpp @@ -1,4 +1,5 @@ #include "../syncthingdirectorymodel.h" +#include "../syncthingdevicemodel.h" #include @@ -6,6 +7,7 @@ #include #include +#include #include @@ -17,6 +19,7 @@ private Q_SLOTS: void cleanupTestCase(); void testDirectoryModel(); + void testDevicesModel(); private: QTimer m_timeout; @@ -26,6 +29,9 @@ private: void ModelTests::initTestCase() { + // ensure all text is English + QLocale::setDefault(QLocale(QLocale::English)); + // setup timeout m_timeout.setSingleShot(true); m_timeout.setInterval(5000); @@ -48,11 +54,47 @@ void ModelTests::cleanupTestCase() void ModelTests::testDirectoryModel() { - auto model = Data::SyncthingDirectoryModel(m_connection); + const auto model = Data::SyncthingDirectoryModel(m_connection); QCOMPARE(model.rowCount(QModelIndex()), 3); QCOMPARE(model.index(0, 0).data(), QStringLiteral("A folder")); QCOMPARE(model.index(1, 0).data(), QStringLiteral("Yet another folder")); QCOMPARE(model.index(2, 0).data(), QStringLiteral("A folder which is not shared")); + const auto folder1Idx = model.index(0, 0); + QCOMPARE(model.rowCount(folder1Idx), 10); + QCOMPARE(model.index(0, 0, folder1Idx).data(), QStringLiteral("ID")); + QCOMPARE(model.index(0, 1, folder1Idx).data(), QStringLiteral("GXWxf-3zgnU")); + QCOMPARE(model.index(1, 0, folder1Idx).data(), QStringLiteral("Path")); + QCOMPARE(model.index(1, 1, folder1Idx).data(), QStringLiteral("...")); + const auto folder2Idx = model.index(1, 0); + QCOMPARE(model.rowCount(folder2Idx), 10); + QCOMPARE(model.index(0, 1, folder2Idx).data(), QStringLiteral("zX8xfl3ygn-")); + QCOMPARE(model.index(1, 1, folder2Idx).data(), QStringLiteral("...")); + const auto folder3Idx = model.index(2, 0); + QCOMPARE(model.rowCount(folder2Idx), 10); + QCOMPARE(model.index(0, 1, folder3Idx).data(), QStringLiteral("forever-alone")); + QCOMPARE(model.index(1, 1, folder3Idx).data(), QStringLiteral("...")); +} + +void ModelTests::testDevicesModel() +{ + const auto model = Data::SyncthingDeviceModel(m_connection); + QCOMPARE(model.rowCount(QModelIndex()), 2); + QCOMPARE(model.index(0, 0).data(), QStringLiteral("Myself")); + QCOMPARE(model.index(0, 1).data(), QStringLiteral("This device")); + QCOMPARE(model.index(1, 0).data(), QStringLiteral("Other instance")); + QCOMPARE(model.index(1, 1).data(), QStringLiteral("Unknown status")); + const auto dev1Idx = model.index(0, 0); + QCOMPARE(model.rowCount(dev1Idx), 5); + QCOMPARE(model.index(0, 0, dev1Idx).data(), QStringLiteral("ID")); + QCOMPARE(model.index(0, 1, dev1Idx).data(), QStringLiteral("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2")); + QCOMPARE(model.index(1, 0, dev1Idx).data(), QStringLiteral("Address")); + QCOMPARE(model.index(1, 1, dev1Idx).data(), QStringLiteral("dynamic, tcp://192.168.1.2:22000")); + QCOMPARE(model.index(4, 0, dev1Idx).data(), QStringLiteral("Introducer")); + QCOMPARE(model.index(4, 1, dev1Idx).data(), QStringLiteral("no")); + const auto dev2Idx = model.index(1, 0); + QCOMPARE(model.rowCount(dev2Idx), 5); + QCOMPARE(model.index(0, 1, dev2Idx).data(), QStringLiteral("53STGR7-YBM6FCX-PAZ2RHM-YPY6OEJ-WYHVZO7-PCKQRCK-PZLTP7T")); + QCOMPARE(model.index(1, 1, dev2Idx).data(), QStringLiteral("dynamic, tcp://192.168.1.3:22000")); } QTEST_MAIN(ModelTests)