From 9df2b7ffa4fd99c39e73263c0ee07c203053096b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 12 Oct 2023 14:10:49 -0700 Subject: [PATCH] tst_QStorageInfo: make storageList() test table-driven Otherwise we have no way of knowing which QStorageInfo entry was being tested. Previous: FAIL! : tst_QStorageInfo::storageList() 'other.isValid()' returned FALSE. () Now: FAIL! : tst_QStorageInfo::storageList(/run/user/0/gvfs) 'other.isValid()' returned FALSE. () Change-Id: I8f3ce163ccc5408cac39fffd178d786e596ece81 Reviewed-by: Volker Hilsheimer --- .../io/qstorageinfo/tst_qstorageinfo.cpp | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp index 59143738dd..6acc4fbcdc 100644 --- a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp +++ b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include +#include #include #include #include @@ -24,6 +25,7 @@ private slots: void operatorNotEqual(); void root(); void currentStorage(); + void storageList_data(); void storageList(); void tempFile(); void caching(); @@ -144,7 +146,7 @@ void tst_QStorageInfo::currentStorage() QCOMPARE_GE(storage.bytesAvailable(), 0); } -void tst_QStorageInfo::storageList() +void tst_QStorageInfo::storageList_data() { QStorageInfo root = QStorageInfo::root(); @@ -155,9 +157,26 @@ void tst_QStorageInfo::storageList() volumes.removeOne(root); QVERIFY(!volumes.contains(root)); + if (volumes.isEmpty()) + QSKIP("Only the root volume was mounted on this system"); + + QTest::addColumn("storage"); + QSet seenRoots; for (const QStorageInfo &storage : std::as_const(volumes)) { if (!storage.isReady()) continue; + QString rootPath = storage.rootPath(); + if (seenRoots.contains(rootPath)) + qInfo() << rootPath << "is mounted over; QStorageInfo may be unpredictable"; + else + QTest::newRow(qUtf8Printable(rootPath)) << storage; + seenRoots.insert(rootPath); + } +} + +void tst_QStorageInfo::storageList() +{ + QFETCH(QStorageInfo, storage); QVERIFY(storage.isValid()); QVERIFY(!storage.isRoot()); @@ -165,7 +184,6 @@ void tst_QStorageInfo::storageList() QVERIFY(!storage.device().isEmpty()); QVERIFY(!storage.fileSystemType().isEmpty()); #endif - } } static bool checkFilesystemGoodForWriting(QTemporaryFile &file, QStorageInfo &storage)