diff --git a/autotests/filemetadatawidgettest.cpp b/autotests/filemetadatawidgettest.cpp index 52efa2b..9202081 100644 --- a/autotests/filemetadatawidgettest.cpp +++ b/autotests/filemetadatawidgettest.cpp @@ -1,194 +1,209 @@ /* * This file is part of the KDE Baloo Project * Copyright 2018 Michael Heidelbach * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "filemetadatawidgettest.h" #include #include #include #include #include #include #include #include #include #include #include #include #include void initLocale() { QLocale::setDefault(QLocale("en_US")); } Q_CONSTRUCTOR_FUNCTION(initLocale) QTEST_MAIN(FileMetadataWidgetTest) void FileMetadataWidgetTest::initTestCase() { qRegisterMetaType("KFileItemList"); QStandardPaths::setTestModeEnabled(true); KConfig balooConfig("baloofilerc", KConfig::NoGlobals); KConfigGroup balooSettings = balooConfig.group("General"); // If we use .writePathEntry here, the test will fail. balooSettings.writeEntry(QStringLiteral("folders"), QString()); // Ensure show configuration KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup settings = config.group("Show"); const auto keys = settings.keyList(); for (const auto &key: keys) { settings.writeEntry(key, true); } const QString exe = QStandardPaths::findExecutable(QStringLiteral("setfattr")); if (exe.isEmpty()) { return; } const QStringList args = {QStringLiteral("--name=user.baloo.rating"), QStringLiteral("--value=5") , QFINDTESTDATA("samplefiles/testtagged.mp3"), QFINDTESTDATA("samplefiles/testtagged.m4a")}; QProcess process; process.start(exe, args); if (!process.waitForFinished(10000)) { qDebug() << "setfattr timed out"; return; } if (process.exitStatus() == QProcess::NormalExit) { m_mayTestRating = true; } else { qDebug() << "setfattr err:" << process.readAllStandardError(); } } void FileMetadataWidgetTest::init() { m_widget = new Baloo::FileMetaDataWidget; } void FileMetadataWidgetTest::cleanup() { delete m_widget; } void FileMetadataWidgetTest::shouldSignalOnceWithoutFile() { QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); m_widget->setItems(KFileItemList()); QCOMPARE(spy.count(), 1); QCOMPARE(m_widget->items().count(), 0); } void FileMetadataWidgetTest::shouldSignalOnceFile() { QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); m_widget->setItems(KFileItemList() << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.m4a")) ); QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); QCOMPARE(m_widget->items().count(), 1); } void FileMetadataWidgetTest::shouldSignalOnceFiles() { QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); m_widget->setItems(KFileItemList() << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/test.mp3")) << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")) << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.m4a")) ); QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); QCOMPARE(m_widget->items().count(), 3); } void FileMetadataWidgetTest::shouldShowProperties() { QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); m_widget->setItems(KFileItemList() << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")) ); QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); // simple property QLabel* valueWidget = m_widget->findChild("kfileitem#type"); QVERIFY2(valueWidget, "Type data missing"); QCOMPARE(valueWidget->text(), QLatin1String("MP3 audio")); if (m_mayTestRating) { // editable property KRatingWidget* ratingWidget = m_widget->findChild("rating"); QVERIFY2(ratingWidget, "Rating data missing"); QCOMPARE(ratingWidget->rating(), 5u); } else { qDebug() << "Skipped 'Rating' test"; } // async property valueWidget = m_widget->findChild("albumArtist"); QVERIFY2(valueWidget, "albumArtist data was not found"); QCOMPARE(valueWidget->text(), QLatin1String("Bill Laswell")); } void FileMetadataWidgetTest::shouldShowCommonProperties() { QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); m_widget->setItems(KFileItemList() << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.mp3")) << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/testtagged.m4a")) ); QVERIFY(spy.wait()); QCOMPARE(spy.count(), 1); // simple property QLabel* valueWidget = m_widget->findChild("kfileitem#type"); QVERIFY(!valueWidget); valueWidget = m_widget->findChild("kfileitem#totalSize"); // circumvent i18n formatting QCOMPARE(valueWidget->text().left(3), QLatin1String("153")); // editable property if (m_mayTestRating) { KRatingWidget* ratingWidget = m_widget->findChild("rating"); QVERIFY2(ratingWidget, "Rating data missing"); QCOMPARE(ratingWidget->rating(), 5u); } else { qDebug() << "Skipped 'Rating' test"; } // async property // FIXME: Make this pass // QCOMPARE( map->value("Album Artist:"), QLatin1String("Bill Laswell")); } +void FileMetadataWidgetTest::shouldShowMultiValueProperties() +{ + QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished); + m_widget->setItems(KFileItemList() + << QUrl::fromLocalFile(QFINDTESTDATA("samplefiles/test_multivalue.ogg")) + ); + QVERIFY(spy.wait()); + QCOMPARE(spy.count(), 1); + auto artistWidget = m_widget->findChild(QStringLiteral("artist")); + QVERIFY2(artistWidget, "artist not found"); + QCOMPARE(artistWidget->text(), "Artist1 and Artist2"); + auto genreWidget = m_widget->findChild(QStringLiteral("genre")); + QVERIFY2(genreWidget, "genre not found"); + QCOMPARE(genreWidget->text(), "Genre1, Genre2, and Genre3"); +} diff --git a/autotests/filemetadatawidgettest.h b/autotests/filemetadatawidgettest.h index 6268bb7..91eeb86 100644 --- a/autotests/filemetadatawidgettest.h +++ b/autotests/filemetadatawidgettest.h @@ -1,46 +1,47 @@ /* * This file is part of the KDE Baloo Project * Copyright 2018 Michael Heidelbach * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef FILEMETADATAWIDGETTEST_H #define FILEMETADATAWIDGETTEST_H #include class FileMetadataWidgetTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void init(); void cleanup(); void shouldSignalOnceWithoutFile(); void shouldSignalOnceFile(); void shouldSignalOnceFiles(); void shouldShowProperties(); void shouldShowCommonProperties(); + void shouldShowMultiValueProperties(); private: Baloo::FileMetaDataWidget* m_widget; bool m_mayTestRating = false; }; #endif // FILEMETADATAWIDGETTEST_H diff --git a/autotests/samplefiles/test_multivalue.ogg b/autotests/samplefiles/test_multivalue.ogg new file mode 100644 index 0000000..71eba6c Binary files /dev/null and b/autotests/samplefiles/test_multivalue.ogg differ