diff --git a/autotests/ffmpegextractortest.cpp b/autotests/ffmpegextractortest.cpp index 54638ec..693dc02 100644 --- a/autotests/ffmpegextractortest.cpp +++ b/autotests/ffmpegextractortest.cpp @@ -1,115 +1,113 @@ /* * Copyright (C) 2019 Alexander Stippich * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "ffmpegextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" #include "extractors/ffmpegextractor.h" +#include "mimeutils.h" #include using namespace KFileMetaData; namespace { QString testFilePath(const QString& baseName, const QString& extension) { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + baseName + QLatin1Char('.') + extension; } } // namespace void ffmpegExtractorTest::testVideoProperties_data() { QTest::addColumn("fileType"); - QTest::addColumn("mimeType"); QTest::addRow("WebM") - << QStringLiteral("webm") - << QStringLiteral("video/webm"); + << QStringLiteral("webm"); QTest::addRow("Matroska Video") - << QStringLiteral("mkv") - << QStringLiteral("video/x-matroska"); + << QStringLiteral("mkv"); QTest::addRow("Vorbis Video") - << QStringLiteral("ogv") - << QStringLiteral("video/ogg"); + << QStringLiteral("ogv"); QTest::addRow("MPEG Transport") - << QStringLiteral("ts") - << QStringLiteral("video/mp2t"); + << QStringLiteral("ts"); } // only for testing of intrinsic video properties void ffmpegExtractorTest::testVideoProperties() { QFETCH(QString, fileType); - QFETCH(QString, mimeType); + + QString fileName = testFilePath(QStringLiteral("test"), fileType); + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); FFmpegExtractor plugin{this}; - SimpleExtractionResult result(testFilePath(QLatin1String("test"), fileType), mimeType); + QVERIFY(plugin.mimetypes().contains(plugin.getSupportedMimeType(mimeType))); + + SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), Type::Video); QCOMPARE(result.properties().value(Property::Width).toInt(), 1280); QCOMPARE(result.properties().value(Property::Height).toInt(), 720); QCOMPARE(result.properties().value(Property::FrameRate).toDouble(), 24.0/1.001); QCOMPARE(result.properties().value(Property::AspectRatio).toDouble(), 16.0/9); } void ffmpegExtractorTest::testMetaData_data() { QTest::addColumn("fileType"); - QTest::addColumn("mimeType"); QTest::addRow("WebM") - << QStringLiteral("webm") - << QStringLiteral("video/webm"); + << QStringLiteral("webm"); QTest::addRow("Matroska Video") - << QStringLiteral("mkv") - << QStringLiteral("video/x-matroska"); + << QStringLiteral("mkv"); QTest::addRow("Vorbis Video") - << QStringLiteral("ogv") - << QStringLiteral("video/ogg"); + << QStringLiteral("ogv"); } void ffmpegExtractorTest::testMetaData() { QFETCH(QString, fileType); - QFETCH(QString, mimeType); + + QString fileName = testFilePath(QStringLiteral("test"), fileType); + QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); FFmpegExtractor plugin{this}; - SimpleExtractionResult result(testFilePath(QLatin1String("test"), fileType), mimeType); + SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QEXPECT_FAIL("Vorbis Video", "Not yet supported", Abort); QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("Title")); QCOMPARE(result.properties().value(Property::Copyright).toString(), QStringLiteral("Copyright")); QCOMPARE(result.properties().value(Property::Author).toString(), QStringLiteral("Author")); QCOMPARE(result.properties().value(Property::ReleaseYear).toInt(), 2019); } QTEST_GUILESS_MAIN(ffmpegExtractorTest) diff --git a/autotests/ffmpegextractortest.h b/autotests/ffmpegextractortest.h index c7d5856..f2b676f 100644 --- a/autotests/ffmpegextractortest.h +++ b/autotests/ffmpegextractortest.h @@ -1,36 +1,43 @@ /* * Copyright (C) 2019 Alexander Stippich * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef FFMPEGEXTRACTORTEST_H #define FFMPEGEXTRACTORTEST_H #include +#include + +namespace KFileMetaData { class ffmpegExtractorTest : public QObject { Q_OBJECT private Q_SLOTS: void testVideoProperties(); void testVideoProperties_data(); void testMetaData(); void testMetaData_data(); + +private: + QMimeDatabase mimeDb; }; +} // namespace KFileMetaData #endif // FFMPEGEXTRACTORTEST_H diff --git a/src/extractors/ffmpegextractor.h b/src/extractors/ffmpegextractor.h index 268a460..fc2b449 100644 --- a/src/extractors/ffmpegextractor.h +++ b/src/extractors/ffmpegextractor.h @@ -1,43 +1,45 @@ /* Copyright (C) 2012 Vishesh Handa This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef FFMPEGEXTRACTOR_H #define FFMPEGEXTRACTOR_H #include "extractorplugin.h" namespace KFileMetaData { class FFmpegExtractor : public ExtractorPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.kde.kf5.kfilemetadata.ExtractorPlugin" FILE "ffmpegextractor.json") Q_INTERFACES(KFileMetaData::ExtractorPlugin) public: explicit FFmpegExtractor(QObject* parent = nullptr); void extract(ExtractionResult* result) override; QStringList mimetypes() const override; + + friend class ffmpegExtractorTest; }; } #endif // FFMPEGEXTRACTOR_H