File indexing completed on 2024-12-08 10:14:50
0001 /* 0002 SPDX-FileCopyrightText: 2018 Michael Heidelbach <ottwolt@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "filemetadataitemcounttest.h" 0008 0009 #include <QSignalSpy> 0010 #include <QStandardPaths> 0011 #include <QTest> 0012 0013 #include <KConfig> 0014 #include <KConfigGroup> 0015 #include <KFileItem> 0016 0017 #include <memory> 0018 0019 QTEST_MAIN(FileMetadataItemCountTest) 0020 0021 void FileMetadataItemCountTest::initTestCase() 0022 { 0023 qRegisterMetaType<KFileItemList>("KFileItemList"); 0024 0025 QStandardPaths::setTestModeEnabled(true); 0026 0027 KConfig balooConfig(QStringLiteral("baloofilerc"), KConfig::NoGlobals); 0028 KConfigGroup balooSettings = balooConfig.group(QStringLiteral("General")); 0029 // If we use .writePathEntry here, the test will fail. 0030 balooSettings.writeEntry(QStringLiteral("folders"), QString()); 0031 0032 // Ensure show configuration 0033 KConfig config(QStringLiteral("baloofileinformationrc"), KConfig::NoGlobals); 0034 KConfigGroup settings = config.group(QStringLiteral("Show")); 0035 const auto keys = settings.keyList(); 0036 for (const auto &key : keys) { 0037 settings.writeEntry(key, true); 0038 } 0039 } 0040 0041 void FileMetadataItemCountTest::testItemCount() 0042 { 0043 auto widget = std::make_unique<Baloo::FileMetaDataWidget>(); 0044 0045 // the number of items will increase in the future adding the file creation time field 0046 // when the system has KIO 5.58, glibc 2.28, linux 4.11 and a filesystem storing file creation times (btrfs, ext4...) 0047 // The expectedItems count will need to be updated 0048 const int expectedItems = 20; 0049 const int widgetsPerItem = 2; 0050 0051 QSignalSpy spy(widget.get(), &Baloo::FileMetaDataWidget::metaDataRequestFinished); 0052 const auto fileUrl = QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")); 0053 widget->setItems({KFileItem{fileUrl}}); 0054 0055 QVERIFY(spy.wait()); 0056 QCOMPARE(spy.count(), 1); 0057 0058 QList<QWidget *> items = widget->findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly); 0059 QCOMPARE(items.count(), expectedItems * widgetsPerItem); 0060 } 0061 0062 #include "moc_filemetadataitemcounttest.cpp"