File indexing completed on 2025-02-16 13:03:36
0001 /* 0002 SPDX-FileCopyrightText: 2019 Alexander Stippich <a.stippich@gmx.net> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "ffmpegextractortest.h" 0008 #include "simpleextractionresult.h" 0009 #include "indexerextractortestsconfig.h" 0010 #include "extractors/ffmpegextractor.h" 0011 #include "mimeutils.h" 0012 0013 #include <QTest> 0014 0015 using namespace KFileMetaData; 0016 0017 namespace { 0018 0019 QString testFilePath(const QString& baseName, const QString& extension) 0020 { 0021 return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) 0022 + QLatin1Char('/') + baseName + QLatin1Char('.') + extension; 0023 } 0024 0025 } // namespace 0026 0027 void ffmpegExtractorTest::testNoExtraction() 0028 { 0029 QString fileName = testFilePath(QStringLiteral("test"), QStringLiteral("webm")); 0030 QMimeDatabase mimeDb; 0031 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0032 0033 FFmpegExtractor plugin{this}; 0034 QVERIFY(plugin.mimetypes().contains(plugin.getSupportedMimeType(mimeType))); 0035 0036 SimpleExtractionResult result(fileName, mimeType, ExtractionResult::ExtractNothing); 0037 plugin.extract(&result); 0038 0039 QCOMPARE(result.types().size(), 1); 0040 QCOMPARE(result.types().constFirst(), Type::Video); 0041 QCOMPARE(result.properties().size(), 0); 0042 } 0043 0044 0045 void ffmpegExtractorTest::testVideoProperties_data() 0046 { 0047 QTest::addColumn<QString>("fileType"); 0048 0049 QTest::addRow("WebM") 0050 << QStringLiteral("webm"); 0051 0052 QTest::addRow("Matroska Video") 0053 << QStringLiteral("mkv"); 0054 0055 QTest::addRow("Vorbis Video") 0056 << QStringLiteral("ogv"); 0057 0058 QTest::addRow("MPEG Transport") 0059 << QStringLiteral("ts"); 0060 0061 QTest::addRow("MS AVI") 0062 << QStringLiteral("avi"); 0063 } 0064 0065 // only for testing of intrinsic video properties 0066 void ffmpegExtractorTest::testVideoProperties() 0067 { 0068 QFETCH(QString, fileType); 0069 0070 QString fileName = testFilePath(QStringLiteral("test"), fileType); 0071 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0072 0073 FFmpegExtractor plugin{this}; 0074 0075 QVERIFY(plugin.mimetypes().contains(plugin.getSupportedMimeType(mimeType))); 0076 0077 SimpleExtractionResult result(fileName, mimeType); 0078 plugin.extract(&result); 0079 0080 QCOMPARE(result.types().size(), 1); 0081 QCOMPARE(result.types().constFirst(), Type::Video); 0082 0083 QCOMPARE(result.properties().value(Property::Width).toInt(), 1280); 0084 QCOMPARE(result.properties().value(Property::Height).toInt(), 720); 0085 QCOMPARE(result.properties().value(Property::FrameRate).toDouble(), 24.0/1.001); 0086 QCOMPARE(result.properties().value(Property::AspectRatio).toDouble(), 16.0/9); 0087 } 0088 0089 void ffmpegExtractorTest::testMetaData_data() 0090 { 0091 QTest::addColumn<QString>("fileType"); 0092 0093 QTest::addRow("WebM") 0094 << QStringLiteral("webm"); 0095 0096 QTest::addRow("Matroska Video") 0097 << QStringLiteral("mkv"); 0098 0099 QTest::addRow("Vorbis Video") 0100 << QStringLiteral("ogv"); 0101 } 0102 0103 void ffmpegExtractorTest::testMetaData() 0104 { 0105 QFETCH(QString, fileType); 0106 0107 QString fileName = testFilePath(QStringLiteral("test"), fileType); 0108 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0109 0110 FFmpegExtractor plugin{this}; 0111 0112 SimpleExtractionResult result(fileName, mimeType); 0113 plugin.extract(&result); 0114 0115 QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("Title")); 0116 QCOMPARE(result.properties().value(Property::Copyright).toString(), QStringLiteral("Copyright")); 0117 QCOMPARE(result.properties().value(Property::Author).toString(), QStringLiteral("Author")); 0118 QCOMPARE(result.properties().value(Property::ReleaseYear).toInt(), 2019); 0119 } 0120 QTEST_GUILESS_MAIN(ffmpegExtractorTest) 0121 0122 #include "moc_ffmpegextractortest.cpp"