File indexing completed on 2025-04-13 06:43:45
0001 /* 0002 TagLibExtractor tests. 0003 0004 SPDX-FileCopyrightText: 2015 Juan Palacios <jpalaciosdev@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #include "simpleextractionresult.h" 0010 #include "propertyinfo.h" 0011 //TODO: use QTESTFINDDATA and remove this 0012 #include "indexerextractortestsconfig.h" 0013 #include "extractors/taglibextractor.h" 0014 #include "mimeutils.h" 0015 #include "properties.h" 0016 0017 #include <QMimeDatabase> 0018 #include <QObject> 0019 #include <QSet> 0020 #include <QTest> 0021 0022 class TagLibExtractorTest : public QObject 0023 { 0024 Q_OBJECT 0025 private: 0026 QString testFilePath(const QString& fileName) const; 0027 0028 private Q_SLOTS: 0029 void initTestCase(); 0030 void testNoExtraction(); 0031 void testPropertyTypes(); 0032 void testCommonData(); 0033 void testCommonData_data(); 0034 void testVorbisComment(); 0035 void testVorbisComment_data(); 0036 void testVorbisCommentMultivalue(); 0037 void testVorbisCommentMultivalue_data(); 0038 void testId3(); 0039 void testId3_data(); 0040 void testApe(); 0041 void testApe_data(); 0042 void testMp4(); 0043 void testMp4_data(); 0044 void testAax(); 0045 void testAax_data(); 0046 void testAsf(); 0047 void testAsf_data(); 0048 void testId3Rating_data(); 0049 void testId3Rating(); 0050 void testWmaRating_data(); 0051 void testWmaRating(); 0052 void testNoMetadata(); 0053 void testNoMetadata_data(); 0054 void testRobustness(); 0055 void testRobustness_data(); 0056 void testImageData(); 0057 void testImageData_data(); 0058 0059 private: 0060 // Convenience function 0061 const QStringList propertyEnumNames(const QList<KFileMetaData::Property::Property>& key) const; 0062 QMimeDatabase mimeDb; 0063 QByteArray m_coverImage; 0064 }; 0065 0066 using namespace KFileMetaData; 0067 0068 QString TagLibExtractorTest::testFilePath(const QString& fileName) const 0069 { 0070 return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; 0071 } 0072 0073 void TagLibExtractorTest::initTestCase() 0074 { 0075 QFile imgFile(testFilePath("cover.jpg")); 0076 imgFile.open(QIODevice::ReadOnly); 0077 m_coverImage = imgFile.readAll(); 0078 } 0079 0080 const QStringList TagLibExtractorTest::propertyEnumNames(const QList<KFileMetaData::Property::Property>& keys) const 0081 { 0082 QStringList result; 0083 for (auto key : keys) { 0084 result.append(PropertyInfo(key).name()); 0085 } 0086 return result; 0087 } 0088 0089 void TagLibExtractorTest::testNoExtraction() 0090 { 0091 TagLibExtractor plugin{this}; 0092 0093 SimpleExtractionResult result(testFilePath("test.opus"), QStringLiteral("audio/opus"), ExtractionResult::ExtractNothing); 0094 plugin.extract(&result); 0095 0096 QCOMPARE(result.types().size(), 1); 0097 QCOMPARE(result.types().constFirst(), Type::Audio); 0098 QCOMPARE(result.properties().size(), 0); 0099 } 0100 0101 void TagLibExtractorTest::testPropertyTypes() 0102 { 0103 TagLibExtractor plugin{this}; 0104 0105 SimpleExtractionResult resultOpus(testFilePath("test.opus"), "audio/opus"); 0106 plugin.extract(&resultOpus); 0107 0108 auto testForType = [](SimpleExtractionResult &result, Property::Property prop) { 0109 QCOMPARE(result.properties().value(prop).userType(), PropertyInfo(prop).valueType()); 0110 }; 0111 0112 QCOMPARE(resultOpus.types().size(), 1); 0113 QCOMPARE(resultOpus.types().constFirst(), Type::Audio); 0114 testForType(resultOpus, Property::Title); 0115 testForType(resultOpus, Property::Artist); 0116 testForType(resultOpus, Property::Album); 0117 testForType(resultOpus, Property::AlbumArtist); 0118 testForType(resultOpus, Property::Genre); 0119 testForType(resultOpus, Property::Comment); 0120 testForType(resultOpus, Property::Composer); 0121 testForType(resultOpus, Property::Lyricist); 0122 testForType(resultOpus, Property::Conductor); 0123 testForType(resultOpus, Property::Arranger); 0124 testForType(resultOpus, Property::Ensemble); 0125 testForType(resultOpus, Property::Location); 0126 testForType(resultOpus, Property::Performer); 0127 testForType(resultOpus, Property::Language); 0128 testForType(resultOpus, Property::Publisher); 0129 testForType(resultOpus, Property::Label); 0130 testForType(resultOpus, Property::Author); 0131 testForType(resultOpus, Property::Copyright); 0132 testForType(resultOpus, Property::Compilation); 0133 testForType(resultOpus, Property::License); 0134 testForType(resultOpus, Property::Opus); 0135 testForType(resultOpus, Property::TrackNumber); 0136 testForType(resultOpus, Property::ReleaseYear); 0137 testForType(resultOpus, Property::Channels); 0138 testForType(resultOpus, Property::DiscNumber); 0139 testForType(resultOpus, Property::Rating); 0140 testForType(resultOpus, Property::ReplayGainAlbumGain); 0141 testForType(resultOpus, Property::ReplayGainAlbumPeak); 0142 testForType(resultOpus, Property::ReplayGainTrackGain); 0143 testForType(resultOpus, Property::ReplayGainTrackPeak); 0144 } 0145 0146 void TagLibExtractorTest::testCommonData() 0147 { 0148 QFETCH(QString, fileType); 0149 0150 QString fileName = testFilePath(QStringLiteral("test.") + fileType); 0151 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0152 TagLibExtractor plugin{this}; 0153 0154 QVERIFY(plugin.mimetypes().contains(mimeType)); 0155 0156 SimpleExtractionResult result(fileName, mimeType); 0157 plugin.extract(&result); 0158 0159 QCOMPARE(result.types().size(), 1); 0160 QCOMPARE(result.types().constFirst(), Type::Audio); 0161 0162 QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); 0163 QCOMPARE(result.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); 0164 QCOMPARE(result.properties().value(Property::Album), QVariant(QStringLiteral("Album"))); 0165 // ID3v1 only supports a limited set of Genres, not the ID3v2 freeform string "Genre" 0166 if (qstrcmp(QTest::currentDataTag(), "mp3 id3v1") == 0) { 0167 QCOMPARE(result.properties().value(Property::Genre), QVariant(QStringLiteral("Soul"))); 0168 } else { 0169 QCOMPARE(result.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); 0170 } 0171 QCOMPARE(result.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); 0172 QCOMPARE(result.properties().value(Property::TrackNumber).toInt(), 1); 0173 QCOMPARE(result.properties().value(Property::ReleaseYear).toInt(), 2015); 0174 } 0175 0176 void TagLibExtractorTest::testCommonData_data() 0177 { 0178 QTest::addColumn<QString>("fileType"); 0179 0180 QTest::addRow("aiff") 0181 << QStringLiteral("aif") 0182 ; 0183 0184 QTest::addRow("ape") 0185 << QStringLiteral("ape") 0186 ; 0187 0188 QTest::addRow("flac") 0189 << QStringLiteral("flac") 0190 ; 0191 0192 QTest::addRow("flac+ogg") 0193 << QStringLiteral("flac.ogg") 0194 ; 0195 0196 QTest::addRow("m4a") 0197 << QStringLiteral("m4a") 0198 ; 0199 0200 QTest::addRow("mp3 id3v2") << QStringLiteral("mp3") ; 0201 QTest::addRow("mp3 id3v1") << QStringLiteral("id3v1.mp3"); 0202 0203 QTest::addRow("mpc") 0204 << QStringLiteral("mpc") 0205 ; 0206 0207 QTest::addRow("ogg") 0208 << QStringLiteral("ogg") 0209 ; 0210 0211 QTest::addRow("opus") 0212 << QStringLiteral("opus") 0213 ; 0214 0215 QTest::addRow("speex") 0216 << QStringLiteral("spx") 0217 ; 0218 0219 QTest::addRow("wav") 0220 << QStringLiteral("wav") 0221 ; 0222 0223 QTest::addRow("wavpack") 0224 << QStringLiteral("wv") 0225 ; 0226 0227 QTest::addRow("wma") 0228 << QStringLiteral("wma") 0229 ; 0230 } 0231 0232 void TagLibExtractorTest::testVorbisComment() 0233 { 0234 QFETCH(QString, fileType); 0235 0236 QString fileName = testFilePath(QStringLiteral("test.") + fileType); 0237 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0238 0239 TagLibExtractor plugin{this}; 0240 SimpleExtractionResult result(fileName, mimeType); 0241 plugin.extract(&result); 0242 0243 QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); 0244 QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); 0245 QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); 0246 QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); 0247 QCOMPARE(result.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); 0248 QCOMPARE(result.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); 0249 QCOMPARE(result.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); 0250 QCOMPARE(result.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); 0251 QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); 0252 QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); 0253 QCOMPARE(result.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); 0254 QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); 0255 QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); 0256 QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); 0257 QCOMPARE(result.properties().value(Property::License), QVariant(QStringLiteral("License"))); 0258 QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); 0259 QCOMPARE(result.properties().value(Property::Opus).toInt(), 1); 0260 QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); 0261 QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); 0262 QCOMPARE(result.properties().value(Property::Rating).toInt(), 5); 0263 QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-9.90)); 0264 QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.512)); 0265 QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(-10.44)); 0266 QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.301)); 0267 } 0268 0269 void TagLibExtractorTest::testVorbisComment_data() 0270 { 0271 QTest::addColumn<QString>("fileType"); 0272 0273 QTest::addRow("flac") 0274 << QStringLiteral("flac") 0275 ; 0276 0277 QTest::addRow("flac+ogg") 0278 << QStringLiteral("flac.ogg") 0279 ; 0280 0281 QTest::addRow("ogg") 0282 << QStringLiteral("ogg") 0283 ; 0284 0285 QTest::addRow("opus") 0286 << QStringLiteral("opus") 0287 ; 0288 0289 QTest::addRow("speex") 0290 << QStringLiteral("spx") 0291 ; 0292 } 0293 0294 void TagLibExtractorTest::testVorbisCommentMultivalue() 0295 { 0296 QFETCH(QString, fileName); 0297 QFETCH(QString, mimeType); 0298 0299 TagLibExtractor plugin{this}; 0300 SimpleExtractionResult result(testFilePath(fileName), mimeType); 0301 plugin.extract(&result); 0302 0303 QCOMPARE(result.properties().values(Property::Artist), QVariantList({QStringLiteral("Artist1"), QStringLiteral("Artist2")})); 0304 QCOMPARE(result.properties().values(Property::Genre), QVariantList({QStringLiteral("Genre1"), QStringLiteral("Genre2")})); 0305 } 0306 0307 void TagLibExtractorTest::testVorbisCommentMultivalue_data() 0308 { 0309 QTest::addColumn<QString>("fileName"); 0310 QTest::addColumn<QString>("mimeType"); 0311 0312 QTest::addRow("ogg multivalue") 0313 << QStringLiteral("test_multivalue.ogg") 0314 << QStringLiteral("audio/ogg") 0315 ; 0316 } 0317 0318 void TagLibExtractorTest::testId3() 0319 { 0320 QFETCH(QString, fileType); 0321 0322 QString fileName = testFilePath(QStringLiteral("test.") + fileType); 0323 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0324 0325 TagLibExtractor plugin{this}; 0326 SimpleExtractionResult result(fileName, mimeType); 0327 plugin.extract(&result); 0328 0329 QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); 0330 QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); 0331 QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); 0332 QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); 0333 QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); 0334 QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); 0335 QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); 0336 QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); 0337 QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); 0338 QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); 0339 QCOMPARE(result.properties().value(Property::Rating).toInt(), 10); 0340 QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-3.33)); 0341 QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.333)); 0342 QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(3.33)); 0343 QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.369)); 0344 } 0345 0346 void TagLibExtractorTest::testId3_data() 0347 { 0348 QTest::addColumn<QString>("fileType"); 0349 0350 QTest::addRow("aiff") 0351 << QStringLiteral("aif") 0352 ; 0353 0354 QTest::addRow("mp3") 0355 << QStringLiteral("mp3") 0356 ; 0357 0358 QTest::addRow("wav") 0359 << QStringLiteral("wav") 0360 ; 0361 } 0362 0363 void TagLibExtractorTest::testApe() 0364 { 0365 QFETCH(QString, fileType); 0366 0367 QString fileName = testFilePath(QStringLiteral("test.") + fileType); 0368 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0369 0370 TagLibExtractor plugin{this}; 0371 SimpleExtractionResult result(fileName, mimeType); 0372 plugin.extract(&result); 0373 0374 QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); 0375 QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); 0376 QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); 0377 QCOMPARE(result.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); 0378 QCOMPARE(result.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); 0379 QCOMPARE(result.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); 0380 QCOMPARE(result.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); 0381 QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); 0382 QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); 0383 QCOMPARE(result.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); 0384 QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); 0385 QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); 0386 QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); 0387 QCOMPARE(result.properties().value(Property::License), QVariant(QStringLiteral("License"))); 0388 QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); 0389 QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); 0390 QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); 0391 QCOMPARE(result.properties().value(Property::Rating).toInt(), 4); 0392 QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-9.44)); 0393 QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.099)); 0394 QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(-5.23)); 0395 QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.234)); 0396 } 0397 0398 void TagLibExtractorTest::testApe_data() 0399 { 0400 QTest::addColumn<QString>("fileType"); 0401 0402 QTest::addRow("ape") 0403 << QStringLiteral("ape") 0404 ; 0405 0406 QTest::addRow("musepack") 0407 << QStringLiteral("mpc") 0408 ; 0409 0410 QTest::addRow("wavpack") 0411 << QStringLiteral("wv") 0412 ; 0413 } 0414 0415 void TagLibExtractorTest::testMp4() 0416 { 0417 QFETCH(QString, fileType); 0418 0419 QString fileName = testFilePath(QStringLiteral("test.") + fileType); 0420 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0421 0422 TagLibExtractor plugin{this}; 0423 SimpleExtractionResult resultMp4(fileName, mimeType); 0424 plugin.extract(&resultMp4); 0425 0426 QCOMPARE(resultMp4.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); 0427 QCOMPARE(resultMp4.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); 0428 QCOMPARE(resultMp4.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); 0429 QCOMPARE(resultMp4.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); 0430 QCOMPARE(resultMp4.properties().value(Property::Channels).toInt(), 2); 0431 QCOMPARE(resultMp4.properties().value(Property::DiscNumber).toInt(), 1); 0432 QCOMPARE(resultMp4.properties().value(Property::Rating).toInt(), 8); 0433 } 0434 0435 void TagLibExtractorTest::testMp4_data() 0436 { 0437 QTest::addColumn<QString>("fileType"); 0438 0439 QTest::addRow("mp4") 0440 << QStringLiteral("m4a") 0441 ; 0442 } 0443 0444 void TagLibExtractorTest::testAax() 0445 { 0446 QFETCH(QString, fileType); 0447 0448 QString fileName = testFilePath(QStringLiteral("nocoverage_test.") + fileType); 0449 QString mimeType = QStringLiteral("audio/vnd.audible.aax"); 0450 0451 TagLibExtractor plugin{this}; 0452 SimpleExtractionResult resultAax(fileName, mimeType); 0453 plugin.extract(&resultAax); 0454 0455 QCOMPARE(resultAax.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); 0456 QCOMPARE(resultAax.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); 0457 QCOMPARE(resultAax.properties().value(Property::Genre), QVariant(QStringLiteral("Hörbuch"))); 0458 QCOMPARE(resultAax.properties().value(Property::Copyright), QVariant(QStringLiteral("CopyrightHolder"))); 0459 QCOMPARE(resultAax.properties().value(Property::Title), QVariant(QStringLiteral("TrackTitle"))); 0460 QCOMPARE(resultAax.properties().value(Property::Channels).toInt(), 2); 0461 } 0462 0463 void TagLibExtractorTest::testAax_data() 0464 { 0465 QTest::addColumn<QString>("fileType"); 0466 0467 QTest::addRow("aax") 0468 << QStringLiteral("aax") 0469 ; 0470 } 0471 0472 void TagLibExtractorTest::testAsf() 0473 { 0474 QFETCH(QString, fileType); 0475 0476 QString fileName = testFilePath(QStringLiteral("test.") + fileType); 0477 QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); 0478 0479 TagLibExtractor plugin{this}; 0480 SimpleExtractionResult result(fileName, mimeType); 0481 plugin.extract(&result); 0482 0483 QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); 0484 QCOMPARE(result.properties().value(Property::Rating).toInt(), 6); 0485 QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); 0486 QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); 0487 QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); 0488 QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); 0489 QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); 0490 QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); 0491 QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); 0492 } 0493 0494 void TagLibExtractorTest::testAsf_data() 0495 { 0496 QTest::addColumn<QString>("fileType"); 0497 0498 // ASF container format, used by WMA 0499 QTest::addRow("wma") << QStringLiteral("wma"); 0500 } 0501 0502 void TagLibExtractorTest::testId3Rating_data() 0503 { 0504 QTest::addColumn<QString>("path"); 0505 QTest::addColumn<int>("expectedRating"); 0506 0507 QTest::addRow("WMP") 0508 << QFINDTESTDATA("samplefiles/mp3_rating/testWMP.mp3") 0509 << 0 ; 0510 QTest::addRow("WMP1") 0511 << QFINDTESTDATA("samplefiles/mp3_rating/testWMP1.mp3") 0512 << 2 ; 0513 QTest::addRow("WMP2") 0514 << QFINDTESTDATA("samplefiles/mp3_rating/testWMP2.mp3") 0515 << 4 ; 0516 QTest::addRow("WMP3") 0517 << QFINDTESTDATA("samplefiles/mp3_rating/testWMP3.mp3") 0518 << 6 ; 0519 QTest::addRow("WMP4") 0520 << QFINDTESTDATA("samplefiles/mp3_rating/testWMP4.mp3") 0521 << 8 ; 0522 QTest::addRow("WMP5") 0523 << QFINDTESTDATA("samplefiles/mp3_rating/testWMP5.mp3") 0524 << 10 ; 0525 QTest::addRow("MM") 0526 << QFINDTESTDATA("samplefiles/mp3_rating/testMM.mp3") 0527 << 0 ; 0528 QTest::addRow("MM1") 0529 << QFINDTESTDATA("samplefiles/mp3_rating/testMM1.mp3") 0530 << 1 ; 0531 QTest::addRow("MM2") 0532 << QFINDTESTDATA("samplefiles/mp3_rating/testMM2.mp3") 0533 << 2 ; 0534 QTest::addRow("MM3") 0535 << QFINDTESTDATA("samplefiles/mp3_rating/testMM3.mp3") 0536 << 3 ; 0537 QTest::addRow("MM4") 0538 << QFINDTESTDATA("samplefiles/mp3_rating/testMM4.mp3") 0539 << 4 ; 0540 QTest::addRow("MM5") 0541 << QFINDTESTDATA("samplefiles/mp3_rating/testMM5.mp3") 0542 << 5 ; 0543 QTest::addRow("MM6") 0544 << QFINDTESTDATA("samplefiles/mp3_rating/testMM6.mp3") 0545 << 6 ; 0546 QTest::addRow("MM7") 0547 << QFINDTESTDATA("samplefiles/mp3_rating/testMM7.mp3") 0548 << 7 ; 0549 QTest::addRow("MM8") 0550 << QFINDTESTDATA("samplefiles/mp3_rating/testMM8.mp3") 0551 << 8 ; 0552 QTest::addRow("MM9") 0553 << QFINDTESTDATA("samplefiles/mp3_rating/testMM9.mp3") 0554 << 9 ; 0555 QTest::addRow("MM10") 0556 << QFINDTESTDATA("samplefiles/mp3_rating/testMM10.mp3") 0557 << 10 ; 0558 } 0559 0560 void TagLibExtractorTest::testId3Rating() 0561 { 0562 QFETCH(QString, path); 0563 QFETCH(int, expectedRating); 0564 0565 TagLibExtractor plugin{this}; 0566 SimpleExtractionResult result(path, "audio/mpeg"); 0567 plugin.extract(&result); 0568 0569 QCOMPARE(result.properties().value(Property::Rating).toInt(), expectedRating); 0570 } 0571 0572 void TagLibExtractorTest::testWmaRating() 0573 { 0574 QFETCH(QString, path); 0575 QFETCH(int, expectedRating); 0576 0577 TagLibExtractor plugin{this}; 0578 SimpleExtractionResult result(path, "audio/x-ms-wma"); 0579 plugin.extract(&result); 0580 0581 QCOMPARE(result.properties().value(Property::Rating).toInt(), expectedRating); 0582 } 0583 0584 void TagLibExtractorTest::testWmaRating_data() 0585 { 0586 QTest::addColumn<QString>("path"); 0587 QTest::addColumn<int>("expectedRating"); 0588 0589 QTest::addRow("WMP0") 0590 << QFINDTESTDATA("samplefiles/wma_rating/test0.wma") 0591 << 0 ; 0592 QTest::addRow("WMP1") 0593 << QFINDTESTDATA("samplefiles/wma_rating/test1.wma") 0594 << 2 ; 0595 QTest::addRow("WMP2") 0596 << QFINDTESTDATA("samplefiles/wma_rating/test2.wma") 0597 << 4 ; 0598 QTest::addRow("WMP3") 0599 << QFINDTESTDATA("samplefiles/wma_rating/test3.wma") 0600 << 6 ; 0601 QTest::addRow("WMP4") 0602 << QFINDTESTDATA("samplefiles/wma_rating/test4.wma") 0603 << 8 ; 0604 QTest::addRow("WMP5") 0605 << QFINDTESTDATA("samplefiles/wma_rating/test5.wma") 0606 << 10 ; 0607 } 0608 0609 void TagLibExtractorTest::testNoMetadata_data() 0610 { 0611 const auto expectedKeys = QList<Property::Property>{ 0612 Property::BitRate, 0613 Property::Channels, 0614 Property::Duration, 0615 Property::SampleRate, 0616 }; 0617 0618 QTest::addColumn<QString>("path"); 0619 QTest::addColumn<QString>("mimeType"); 0620 QTest::addColumn<QList<Property::Property>>("expectedKeys"); 0621 QTest::addColumn<QString>("failMessage"); 0622 0623 QTest::addRow("mp3") 0624 << QFINDTESTDATA("samplefiles/no-meta/test.mp3") 0625 << QStringLiteral("audio/mpeg") 0626 << expectedKeys << QString() 0627 ; 0628 0629 QTest::addRow("m4a") 0630 << QFINDTESTDATA("samplefiles/no-meta/test.m4a") 0631 << QStringLiteral("audio/mp4") 0632 << expectedKeys << QString() 0633 ; 0634 0635 QTest::addRow("flac") 0636 << QFINDTESTDATA("samplefiles/no-meta/test.flac") 0637 << QStringLiteral("audio/flac") 0638 << expectedKeys << QString() 0639 ; 0640 0641 QTest::addRow("opus") 0642 << QFINDTESTDATA("samplefiles/no-meta/test.opus") 0643 << QStringLiteral("audio/opus") 0644 << expectedKeys << QString() 0645 ; 0646 0647 QTest::addRow("ogg") 0648 << QFINDTESTDATA("samplefiles/no-meta/test.ogg") 0649 << QStringLiteral("audio/ogg") 0650 << expectedKeys << QString() 0651 ; 0652 0653 QTest::addRow("mpc") 0654 << QFINDTESTDATA("samplefiles/no-meta/test.mpc") 0655 << QStringLiteral("audio/x-musepack") 0656 << expectedKeys << QString() 0657 ; 0658 0659 QTest::addRow("aax") 0660 << QFINDTESTDATA("samplefiles/no-meta/test.aax") 0661 << QStringLiteral("audio/vnd.audible.aax") 0662 << expectedKeys << QString() 0663 ; 0664 0665 } 0666 0667 void TagLibExtractorTest::testNoMetadata() 0668 { 0669 QFETCH(QString, path); 0670 QFETCH(QString, mimeType); 0671 QFETCH(QList<Property::Property>, expectedKeys); 0672 QFETCH(QString, failMessage); 0673 0674 TagLibExtractor plugin{this}; 0675 SimpleExtractionResult extracted(path, mimeType); 0676 plugin.extract(&extracted); 0677 0678 const auto resultList = extracted.properties(); 0679 const auto resultKeys = resultList.uniqueKeys(); 0680 0681 const QSet<KFileMetaData::Property::Property> resultKeySet(resultKeys.begin(), resultKeys.end()); 0682 const QSet<KFileMetaData::Property::Property> expectedKeySet(expectedKeys.begin(), expectedKeys.end()); 0683 0684 const auto excessKeys = resultKeySet - expectedKeySet; 0685 const auto missingKeys = expectedKeySet - resultKeySet; 0686 0687 if (!excessKeys.isEmpty()) { 0688 const auto propNames = propertyEnumNames(excessKeys.values()).join(QLatin1String(", ")); 0689 if (failMessage.isEmpty()) { 0690 const auto message = QStringLiteral("Excess properties: %1").arg(propNames); 0691 qWarning() << message; 0692 } else { 0693 QEXPECT_FAIL("", qPrintable(QStringLiteral("%1: %2").arg(failMessage).arg(propNames)), Continue); 0694 } 0695 } else if (!missingKeys.isEmpty()) { 0696 const auto message = QStringLiteral("Missing properties: %1") 0697 .arg(propertyEnumNames(missingKeys.values()).join(QLatin1String(", "))); 0698 qWarning() << message; 0699 } 0700 QCOMPARE(resultKeys, expectedKeys); 0701 if (!failMessage.isEmpty()) { 0702 const auto message = QStringLiteral("%1: %2") 0703 .arg(failMessage) 0704 .arg(propertyEnumNames(excessKeys.values()).join(QLatin1String(", "))); 0705 QEXPECT_FAIL("", qPrintable(message), Continue); 0706 } 0707 QCOMPARE(resultKeys, expectedKeys); 0708 } 0709 0710 void TagLibExtractorTest::testRobustness_data() 0711 { 0712 QTest::addColumn<QString>("path"); 0713 QTest::addColumn<QString>("mimeType"); 0714 0715 QTest::addRow("ArcGIS GeoData spx") 0716 << QFINDTESTDATA("samplefiles/misdetected/test_arcgis_geodata.spx") 0717 << QStringLiteral("audio/x-speex+ogg"); 0718 } 0719 0720 void TagLibExtractorTest::testRobustness() 0721 { 0722 QFETCH(QString, path); 0723 QFETCH(QString, mimeType); 0724 0725 TagLibExtractor plugin{this}; 0726 SimpleExtractionResult extracted(path, mimeType); 0727 plugin.extract(&extracted); 0728 } 0729 0730 void TagLibExtractorTest::testImageData() 0731 { 0732 QFETCH(QString, fileName); 0733 QString testAudioFile; 0734 TagLibExtractor plugin{this};; 0735 0736 testAudioFile = testFilePath(fileName); 0737 const QString mimeType = mimeDb.mimeTypeForFile(testAudioFile).name(); 0738 0739 QVERIFY2(!mimeType.isEmpty(), "Failed to determine mimetype"); 0740 QVERIFY2(plugin.mimetypes().contains(mimeType), qPrintable(mimeType + " not supported by taglib")); 0741 0742 SimpleExtractionResult result(testAudioFile, mimeType, ExtractionResult::ExtractImageData); 0743 plugin.extract(&result); 0744 0745 QCOMPARE(result.imageData().value(EmbeddedImageData::FrontCover), m_coverImage); 0746 } 0747 0748 void TagLibExtractorTest::testImageData_data() 0749 { 0750 QTest::addColumn<QString>("fileName"); 0751 0752 QTest::addRow("aiff") 0753 << QStringLiteral("test.aif") 0754 ; 0755 0756 QTest::addRow("ape") 0757 << QStringLiteral("test.ape") 0758 ; 0759 0760 QTest::addRow("opus") 0761 << QStringLiteral("test.opus") 0762 ; 0763 0764 QTest::addRow("ogg") 0765 << QStringLiteral("test.ogg") 0766 ; 0767 0768 QTest::addRow("flac") 0769 << QStringLiteral("test.flac") 0770 ; 0771 0772 QTest::addRow("flac+ogg") 0773 << QStringLiteral("test.flac.ogg") 0774 ; 0775 0776 QTest::addRow("mp3") 0777 << QStringLiteral("test.mp3") 0778 ; 0779 0780 QTest::addRow("m4a") 0781 << QStringLiteral("test.m4a") 0782 ; 0783 0784 QTest::addRow("mpc") 0785 << QStringLiteral("test.mpc") 0786 ; 0787 0788 QTest::addRow("speex") 0789 << QStringLiteral("test.spx") 0790 ; 0791 0792 QTest::addRow("wav") 0793 << QStringLiteral("test.wav") 0794 ; 0795 0796 QTest::addRow("wavpack") 0797 << QStringLiteral("test.wv") 0798 ; 0799 0800 QTest::addRow("wma") 0801 << QStringLiteral("test.wma") 0802 ; 0803 } 0804 0805 QTEST_GUILESS_MAIN(TagLibExtractorTest) 0806 0807 #include "taglibextractortest.moc"