File indexing completed on 2024-04-28 15:22:17

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