diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,10 +1,18 @@ -set(EXTRACTOR_TEST_SRCS - extractortest.cpp -) +include(ECMMarkAsTest) configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) -ecm_add_test(${EXTRACTOR_TEST_SRCS} +ecm_add_test(extractortest.cpp TEST_NAME "extractortest" LINK_LIBRARIES Qt5::Test ) +ecm_add_test(filemetadatawidgettest.cpp + TEST_NAME "filemetadatawidgettest" + LINK_LIBRARIES KF5::KIOCore + KF5::KIOWidgets + KF5::KIOFileWidgets + KF5::BalooWidgets + KF5::FileMetaData + Qt5::Test + Qt5::Widgets +) diff --git a/autotests/filemetadatawidgettest.h b/autotests/filemetadatawidgettest.h new file mode 100644 --- /dev/null +++ b/autotests/filemetadatawidgettest.h @@ -0,0 +1,44 @@ +/* + * 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 shouldSignalOnceWithEmptyFile(); + void shouldSignalOnceFile(); + void shouldSignalOnceFiles(); + +private: + Baloo::FileMetaDataWidget* m_widget; +}; + +#endif // FILEMETADATAWIDGETTEST_H diff --git a/autotests/filemetadatawidgettest.cpp b/autotests/filemetadatawidgettest.cpp new file mode 100644 --- /dev/null +++ b/autotests/filemetadatawidgettest.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 "config.h" +#include "filemetadatawidgettest.h" + +#include +#include +#include +#include +#include + +QTEST_MAIN(FileMetadataWidgetTest) + +void FileMetadataWidgetTest::initTestCase() +{ + qRegisterMetaType("KFileItemList"); +} + +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() << QUrl()); + QCOMPARE(spy.count(), 1); + QCOMPARE(m_widget->items().count(), 0); +} + +void FileMetadataWidgetTest::shouldSignalOnceWithEmptyFile() +{ + 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(QStringLiteral("%1/testtagged.m4a").arg(TESTS_SAMPLE_FILES_PATH)) + ); + 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(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)) + ); + QVERIFY(spy.wait()); + QCOMPARE(spy.count(), 1); + QCOMPARE(m_widget->items().count(), 3); + +} diff --git a/autotests/testtagged.m4a b/autotests/testtagged.m4a new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@