File indexing completed on 2024-05-05 04:55:40

0001 /**
0002  * \file testmusicbrainzreleaseimporter.cpp
0003  * Test import from MusicBrainz server.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 07 Oct 2012
0008  *
0009  * Copyright (C) 2012-2018  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #include "testmusicbrainzreleaseimporter.h"
0028 #include <QTest>
0029 #include "serverimporter.h"
0030 #include "trackdatamodel.h"
0031 
0032 void TestMusicBrainzReleaseImporter::initTestCase()
0033 {
0034   setServerImporter(QLatin1String("MusicBrainzImport"));
0035 }
0036 
0037 void TestMusicBrainzReleaseImporter::testQueryAlbums()
0038 {
0039   queryAlbums(QLatin1String("Wizard"), QLatin1String("Odin"));
0040   AlbumListModel* albumModel = m_importer->getAlbumListModel();
0041   QCOMPARE(albumModel->rowCount(), 4);
0042   QString text, category, id;
0043   albumModel->getItem(0, text, category, id);
0044   QCOMPARE(text, QString(QLatin1String("Wizard - Odin")));
0045   QCOMPARE(category, QString(QLatin1String("release")));
0046   QVERIFY(!id.isEmpty());
0047 }
0048 
0049 void TestMusicBrainzReleaseImporter::testQueryTracks()
0050 {
0051   queryTracks(QLatin1String("release"), QLatin1String("978c7ed1-a854-4ef2-bd4e-e7c1317be854"));
0052 
0053   QStringList titles;
0054   titles << QLatin1String("The Prophecy") << QLatin1String("Betrayer")
0055          << QLatin1String("Dead Hope") << QLatin1String("Dark God")
0056          << QLatin1String("Loki") + QChar(0x2019) + QLatin1String("s Punishment")
0057          << QLatin1String("Beginning of the End")
0058          << QLatin1String("Thor") + QChar(0x2019) + QLatin1String("s Hammer")
0059          << QLatin1String("Hall of Odin") << QLatin1String("The Powergod")
0060          << QLatin1String("March of the Einheriers")
0061          << QLatin1String("End of All");
0062   QStringList lengths;
0063   lengths << QLatin1String("5:19") << QLatin1String("4:53")
0064           << QLatin1String("6:02") << QLatin1String("5:42")
0065           << QLatin1String("5:08") << QLatin1String("4:01")
0066           << QLatin1String("5:01") << QLatin1String("5:06")
0067           << QLatin1String("5:21") << QLatin1String("5:40")
0068           << QLatin1String("3:55");
0069   QCOMPARE(m_trackDataModel->rowCount(), 11);
0070   for (int row = 0; row < 11; ++row) {
0071     QCOMPARE(m_trackDataModel->index(row, 0).data().toString(),
0072              lengths.at(row));
0073     QCOMPARE(m_trackDataModel->index(row, 3).data().toInt(), row + 1);
0074     QCOMPARE(m_trackDataModel->index(row, 4).data().toString(), titles.at(row));
0075     QCOMPARE(m_trackDataModel->index(row, 5).data().toString(),
0076              QString(QLatin1String("Wizard")));
0077     QCOMPARE(m_trackDataModel->index(row, 6).data().toString(),
0078              QString(QLatin1String("Odin")));
0079     QCOMPARE(m_trackDataModel->index(row, 7).data().toInt(), 2003);
0080     QCOMPARE(m_trackDataModel->index(row, 10).data().toString(),
0081              QString(QLatin1String("Wizard")));
0082     QCOMPARE(m_trackDataModel->index(row, 11).data().toString(),
0083              QString(QLatin1String("LMP 0303-054 CD")));
0084     QCOMPARE(m_trackDataModel->index(row, 12).data().toString(),
0085              QString(QLatin1String("Limb Music Products")));
0086     QCOMPARE(m_trackDataModel->index(row, 13).data().toString(),
0087              QString(QLatin1String("DE")));
0088   }
0089 }