diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -6,11 +6,13 @@
TEST_NAME "extractortest"
LINK_LIBRARIES Qt5::Test
)
-ecm_add_test(filemetadatawidgettest.cpp
- TEST_NAME "filemetadatawidgettest"
+ecm_add_tests(
+ filemetadatawidgettest.cpp
+ filemetadataitemcounttest.cpp
LINK_LIBRARIES KF5::KIOCore
KF5::KIOWidgets
KF5::KIOFileWidgets
+ KF5::ConfigCore
KF5::BalooWidgets
KF5::FileMetaData
Qt5::Test
diff --git a/autotests/filemetadatawidgettest.h b/autotests/filemetadataitemcounttest.h
copy from autotests/filemetadatawidgettest.h
copy to autotests/filemetadataitemcounttest.h
--- a/autotests/filemetadatawidgettest.h
+++ b/autotests/filemetadataitemcounttest.h
@@ -19,26 +19,23 @@
* along with this program. If not, see .
*/
-#ifndef FILEMETADATAWIDGETTEST_H
-#define FILEMETADATAWIDGETTEST_H
+#ifndef FILEMETADATAITEMCOUNTTEST_H
+#define FILEMETADATAITEMCOUNTTEST_H
#include
-class FileMetadataWidgetTest : public QObject
+class FileMetadataItemCountTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
- void shouldSignalOnceWithoutFile();
- void shouldSignalOnceWithEmptyFile();
- void shouldSignalOnceFile();
- void shouldSignalOnceFiles();
-
+ void testItemCount();
+
private:
- Baloo::FileMetaDataWidget* m_widget;
+ Baloo::FileMetaDataWidget* m_widget;
};
-#endif // FILEMETADATAWIDGETTEST_H
+#endif // FILEMETADATAITEMCOUNTTEST_H
diff --git a/autotests/filemetadataitemcounttest.cpp b/autotests/filemetadataitemcounttest.cpp
new file mode 100644
--- /dev/null
+++ b/autotests/filemetadataitemcounttest.cpp
@@ -0,0 +1,88 @@
+/*
+ * 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 "filemetadataitemcounttest.h"
+#include "config.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+
+QTEST_MAIN(FileMetadataItemCountTest)
+
+void FileMetadataItemCountTest::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);
+ }
+}
+
+void FileMetadataItemCountTest::init()
+{
+ m_widget = new Baloo::FileMetaDataWidget;
+}
+
+void FileMetadataItemCountTest::cleanup()
+{
+ delete m_widget;
+}
+
+void FileMetadataItemCountTest::testItemCount()
+{
+ const int expectedItems = 19;
+ const int widgetsPerItem = 2;
+ const auto propCheck = [this, expectedItems, widgetsPerItem](){
+ QList items = m_widget->findChildren(QString(), Qt::FindDirectChildrenOnly);
+ QCOMPARE(items.count(), expectedItems * widgetsPerItem);
+ };
+
+ connect(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished, propCheck);
+ QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished);
+ m_widget->setItems(KFileItemList()
+ << QUrl::fromLocalFile(QFINDTESTDATA("testtagged.mp3"))
+ );
+ QVERIFY(spy.wait());
+}
diff --git a/autotests/filemetadatawidgettest.h b/autotests/filemetadatawidgettest.h
--- a/autotests/filemetadatawidgettest.h
+++ b/autotests/filemetadatawidgettest.h
@@ -36,9 +36,12 @@
void shouldSignalOnceWithEmptyFile();
void shouldSignalOnceFile();
void shouldSignalOnceFiles();
+ void shouldShowProperties();
+ void shouldShowCommonProperties();
private:
Baloo::FileMetaDataWidget* m_widget;
+ bool m_mayTestRating = false;
};
#endif // FILEMETADATAWIDGETTEST_H
diff --git a/autotests/filemetadatawidgettest.cpp b/autotests/filemetadatawidgettest.cpp
--- a/autotests/filemetadatawidgettest.cpp
+++ b/autotests/filemetadatawidgettest.cpp
@@ -23,16 +23,66 @@
#include "filemetadatawidgettest.h"
#include
-#include
#include
+#include
+#include
#include
#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
QTEST_MAIN(FileMetadataWidgetTest)
void FileMetadataWidgetTest::initTestCase()
{
qRegisterMetaType("KFileItemList");
+
+ qputenv("LC_ALL", "en_US.UTF-8");
+
+ 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("testtagged.mp3")
+ , QFINDTESTDATA("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()
@@ -65,7 +115,7 @@
{
QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished);
m_widget->setItems(KFileItemList()
- << QUrl::fromLocalFile(QStringLiteral("%1/testtagged.m4a").arg(TESTS_SAMPLE_FILES_PATH))
+ << QUrl::fromLocalFile(QFINDTESTDATA("testtagged.m4a"))
);
QVERIFY(spy.wait());
QCOMPARE(spy.count(), 1);
@@ -77,12 +127,76 @@
{
QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished);
m_widget->setItems(KFileItemList()
- << QUrl::fromLocalFile(QStringLiteral("%1/test.mp3").arg(TESTS_SAMPLE_FILES_PATH))
- << QUrl::fromLocalFile(QStringLiteral("%1/testtagged.mp3").arg(TESTS_SAMPLE_FILES_PATH))
- << QUrl::fromLocalFile(QStringLiteral("%1/testtagged.m4a").arg(TESTS_SAMPLE_FILES_PATH))
+ << QUrl::fromLocalFile(QFINDTESTDATA("test.mp3"))
+ << QUrl::fromLocalFile(QFINDTESTDATA("testtagged.mp3"))
+ << QUrl::fromLocalFile(QFINDTESTDATA("testtagged.m4a"))
);
QVERIFY(spy.wait());
QCOMPARE(spy.count(), 1);
QCOMPARE(m_widget->items().count(), 3);
+}
+
+void FileMetadataWidgetTest::shouldShowProperties()
+{
+ auto propCheck = [this](){
+ // simple property
+ QLabel* value;
+ value = m_widget->findChild("kfileitem#type");
+ QVERIFY2(value, "Type data missing");
+ QCOMPARE(value->text(), QLatin1String("MP3 audio"));
+
+ if (m_mayTestRating) {
+ // editable property
+ KRatingWidget* rating = m_widget->findChild("rating");
+ QVERIFY2(rating, "Rating data missing");
+ QCOMPARE(rating->rating(), 5);
+ } else {
+ qDebug() << "Skipped 'Rating' test";
+ }
+ // async property
+ value = m_widget->findChild("albumArtist");
+ QVERIFY2(value, "albumArtist data was not found");
+ QCOMPARE(value->text(), QLatin1String("Bill Laswell"));
+ };
+ connect(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished, propCheck);
+ QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished);
+ m_widget->setItems(KFileItemList()
+ << QUrl::fromLocalFile(QFINDTESTDATA("testtagged.mp3"))
+ );
+ QVERIFY(spy.wait());
+}
+
+void FileMetadataWidgetTest::shouldShowCommonProperties()
+{
+ auto propCheck = [this](){
+ // simple property
+ QLabel* value = m_widget->findChild("kfileitem#type");
+ QVERIFY(!value);
+
+ value = m_widget->findChild("kfileitem#totalSize");
+ // circumvent i18n formatting
+ QCOMPARE(value->text().left(3), QLatin1String("153"));
+
+ // editable property
+ if (m_mayTestRating) {
+ KRatingWidget* rating = m_widget->findChild("rating");
+ QCOMPARE(rating->rating(), 5);
+ } else {
+ qDebug() << "Skipped 'Rating' test";
+ }
+ // async property
+ // FIXME: Make this pass
+ // QCOMPARE( map->value("Album Artist:"), QLatin1String("Bill Laswell"));
+ };
+
+ connect(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished, propCheck);
+ QSignalSpy spy(m_widget, &Baloo::FileMetaDataWidget::metaDataRequestFinished);
+ m_widget->setItems(KFileItemList()
+ << QUrl::fromLocalFile(QFINDTESTDATA("testtagged.mp3"))
+ << QUrl::fromLocalFile(QFINDTESTDATA("testtagged.m4a"))
+ );
+ QVERIFY(spy.wait());
+ QCOMPARE(spy.count(), 1);
}
+