Add test for MusicBrainzClient.
This commit is contained in:
parent
f65c48ef9c
commit
e14c59948f
@ -34,9 +34,10 @@ const char* MusicBrainzClient::kDiscUrl =
|
||||
const char* MusicBrainzClient::kDateRegex = "^[12]\\d{3}";
|
||||
const int MusicBrainzClient::kDefaultTimeout = 5000; // msec
|
||||
|
||||
MusicBrainzClient::MusicBrainzClient(QObject* parent)
|
||||
MusicBrainzClient::MusicBrainzClient(QObject* parent,
|
||||
QNetworkAccessManager* network)
|
||||
: QObject(parent),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
network_(network ? network : new NetworkAccessManager(this)),
|
||||
timeouts_(new NetworkTimeouts(kDefaultTimeout, this)) {}
|
||||
|
||||
void MusicBrainzClient::Start(int id, const QString& mbid) {
|
||||
|
@ -38,7 +38,10 @@ class MusicBrainzClient : public QObject {
|
||||
// the Finished signal - they have no meaning to MusicBrainzClient.
|
||||
|
||||
public:
|
||||
MusicBrainzClient(QObject* parent = nullptr);
|
||||
// The second argument allows for specifying a custom network access
|
||||
// manager. It is used in tests.
|
||||
MusicBrainzClient(QObject* parent = nullptr,
|
||||
QNetworkAccessManager* network = nullptr);
|
||||
|
||||
struct Result {
|
||||
Result() : duration_msec_(0), track_(0), year_(-1) {}
|
||||
@ -133,5 +136,4 @@ inline uint qHash(const MusicBrainzClient::Result& result) {
|
||||
return qHash(result.album_) ^ qHash(result.artist_) ^ result.duration_msec_ ^
|
||||
qHash(result.title_) ^ result.track_ ^ result.year_;
|
||||
}
|
||||
|
||||
#endif // MUSICBRAINZCLIENT_H
|
||||
|
@ -131,6 +131,7 @@ add_test_file(fmpsparser_test.cpp false)
|
||||
#add_test_file(librarymodel_test.cpp true)
|
||||
#add_test_file(m3uparser_test.cpp false)
|
||||
add_test_file(mergedproxymodel_test.cpp false)
|
||||
add_test_file(musicbrainzclient_test.cpp false)
|
||||
add_test_file(organiseformat_test.cpp false)
|
||||
add_test_file(organisedialog_test.cpp false)
|
||||
#add_test_file(playlist_test.cpp true)
|
||||
|
399
tests/data/discid_2cd.xml
Normal file
399
tests/data/discid_2cd.xml
Normal file
@ -0,0 +1,399 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
|
||||
<disc id="lvcH9_vbw_rJAbXieTOo1CbyNmQ-">
|
||||
<sectors>267785</sectors>
|
||||
<release-list count="2">
|
||||
<release id="97af3cb5-31bf-40b5-ac1a-ce790bc95aae">
|
||||
<title>Live on the Edge of Forever</title>
|
||||
<status>Official</status>
|
||||
<quality>normal</quality>
|
||||
<text-representation>
|
||||
<language>eng</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<artist-credit>
|
||||
<name-credit>
|
||||
<artist id="b669c53e-5a1f-4adc-80be-755e64e8115e">
|
||||
<name>Symphony X</name>
|
||||
<sort-name>Symphony X</sort-name>
|
||||
</artist>
|
||||
</name-credit>
|
||||
</artist-credit>
|
||||
<date>2001-11-13</date>
|
||||
<country>US</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>2001-11-13</date>
|
||||
<area id="489ce91b-6658-3307-9877-795b68554c98">
|
||||
<name>United States</name>
|
||||
<sort-name>United States</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>US</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<cover-art-archive>
|
||||
<artwork>false</artwork>
|
||||
<count>0</count>
|
||||
<front>false</front>
|
||||
<back>false</back>
|
||||
</cover-art-archive>
|
||||
<medium-list count="2">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<disc-list count="1">
|
||||
<disc id="jsvwUD2Pw0qZEJNumbOoVKj7vbU-">
|
||||
<sectors>213610</sectors>
|
||||
</disc>
|
||||
</disc-list>
|
||||
<track-list count="9" offset="0">
|
||||
<track id="2fe8e651-3f9f-3f90-91c5-26195f8d27b7">
|
||||
<position>1</position>
|
||||
<number>1</number>
|
||||
<length>98266</length>
|
||||
<recording id="38041f24-5a49-4ffe-b41c-8eb67945ebfb">
|
||||
<title>Prelude</title>
|
||||
<length>98266</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="de1c5729-65c5-3c74-a131-35e67fbd5e71">
|
||||
<position>2</position>
|
||||
<number>2</number>
|
||||
<length>318400</length>
|
||||
<recording id="75e9cddb-5e27-4f30-91f1-a6fc4162caf6">
|
||||
<title>Evolution (The Grand Design)</title>
|
||||
<length>318400</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="f03c1c71-b49d-32e1-87de-f1666238a613">
|
||||
<position>3</position>
|
||||
<number>3</number>
|
||||
<length>390826</length>
|
||||
<recording id="54f964f0-f64a-49d6-acd4-2dea66d2eb07">
|
||||
<title>Fallen / Transcendence</title>
|
||||
<length>390826</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="7c992fb8-d0a3-3750-b70f-13d40c3f6b66">
|
||||
<position>4</position>
|
||||
<number>4</number>
|
||||
<length>459040</length>
|
||||
<recording id="73098f0f-526c-4920-9f6a-b4b4ae42fd15">
|
||||
<title>Communion and the Oracle</title>
|
||||
<length>459040</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="80885c22-2b9c-3aa0-95d9-888a1c91e037">
|
||||
<position>5</position>
|
||||
<number>5</number>
|
||||
<length>219760</length>
|
||||
<recording id="4f462d15-841d-417c-85dc-6698feffa35c">
|
||||
<title>The Bird-Serpent War</title>
|
||||
<length>219760</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="2e2b2a62-f634-30d6-85a7-2099c2d1e48a">
|
||||
<position>6</position>
|
||||
<number>6</number>
|
||||
<length>309573</length>
|
||||
<recording id="e0d3ef99-1100-4e55-be30-734d52b96e92">
|
||||
<title>On the Breath of Poseidon</title>
|
||||
<length>309573</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="4ce98e0a-9a52-336c-930b-b838fd1ad4c6">
|
||||
<position>7</position>
|
||||
<number>7</number>
|
||||
<length>425226</length>
|
||||
<recording id="71961c16-c3be-4f2b-9f3f-efb25daf1615">
|
||||
<title>Egypt</title>
|
||||
<length>425226</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="cf409e9a-bf72-3676-a74b-497d117bc975">
|
||||
<position>8</position>
|
||||
<number>8</number>
|
||||
<length>352666</length>
|
||||
<recording id="56cc2b94-725c-4473-908f-1806eafe7cd0">
|
||||
<title>The Death of Balance / Candlelight Fantasia</title>
|
||||
<length>352666</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="7babb3d9-f8bb-3eff-9385-dadaf186ff61">
|
||||
<position>9</position>
|
||||
<number>9</number>
|
||||
<length>272373</length>
|
||||
<recording id="fa2bc0cf-afbc-4eec-a757-a81ff73537c3">
|
||||
<title>The Eyes of Medusa</title>
|
||||
<length>272373</length>
|
||||
</recording>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
<medium>
|
||||
<position>2</position>
|
||||
<format>CD</format>
|
||||
<disc-list count="1">
|
||||
<disc id="lvcH9_vbw_rJAbXieTOo1CbyNmQ-">
|
||||
<sectors>267785</sectors>
|
||||
</disc>
|
||||
</disc-list>
|
||||
<track-list count="6" offset="0">
|
||||
<track id="bad44362-dc25-38a8-b9f3-612c68c10eb5">
|
||||
<position>1</position>
|
||||
<number>1</number>
|
||||
<length>394600</length>
|
||||
<recording id="257a5030-a862-41dc-b9c2-2b2c48f4e78f">
|
||||
<title>Smoke and Mirrors</title>
|
||||
<length>394600</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="b0470b63-caf2-3a2c-9bf6-4d01d63ed278">
|
||||
<position>2</position>
|
||||
<number>2</number>
|
||||
<length>441866</length>
|
||||
<recording id="a8c0cc29-07e9-4836-a6ec-780c85d54b01">
|
||||
<title>Church of the Machine</title>
|
||||
<length>441866</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="534e123c-06b0-3d3a-b96a-3fa2b8e5dba7">
|
||||
<position>3</position>
|
||||
<number>3</number>
|
||||
<length>849426</length>
|
||||
<recording id="b269f849-e6e3-44b6-8cd4-5f80927ea714">
|
||||
<title>Through the Looking Glass</title>
|
||||
<length>849426</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="2eebe76a-1b4f-30f4-a9bb-8795c45cd2ea">
|
||||
<position>4</position>
|
||||
<number>4</number>
|
||||
<length>442773</length>
|
||||
<recording id="c5cf4c79-d2a3-4aa0-abab-773a7a5c87ff">
|
||||
<title>Of Sins and Shadows</title>
|
||||
<length>442773</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="7e3defd7-4a61-3496-bfc2-27536d51fc1a">
|
||||
<position>5</position>
|
||||
<number>5</number>
|
||||
<length>245160</length>
|
||||
<recording id="1a5a0210-9b49-4c5b-883f-a52bc8e1c2d4">
|
||||
<title>Sea of Lies</title>
|
||||
<length>245160</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="5f31a762-0bf6-3fbb-9549-2b8bb92c9787">
|
||||
<position>6</position>
|
||||
<number>6</number>
|
||||
<length>1194640</length>
|
||||
<recording id="21d5e15f-5e35-4ad0-b058-5e1da0c1936e">
|
||||
<title>The Divine Wings of Tragedy</title>
|
||||
<length>1194640</length>
|
||||
</recording>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
<release id="e3857aef-2070-3736-952b-ff7fe081d963">
|
||||
<title>Live on the Edge of Forever</title>
|
||||
<status>Official</status>
|
||||
<quality>normal</quality>
|
||||
<text-representation>
|
||||
<language>eng</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<artist-credit>
|
||||
<name-credit>
|
||||
<artist id="b669c53e-5a1f-4adc-80be-755e64e8115e">
|
||||
<name>Symphony X</name>
|
||||
<sort-name>Symphony X</sort-name>
|
||||
</artist>
|
||||
</name-credit>
|
||||
</artist-credit>
|
||||
<date>2001-10-22</date>
|
||||
<country>DE</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>2001-10-22</date>
|
||||
<area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad">
|
||||
<name>Germany</name>
|
||||
<sort-name>Germany</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>DE</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<asin>B00005Q8VB</asin>
|
||||
<cover-art-archive>
|
||||
<artwork>false</artwork>
|
||||
<count>0</count>
|
||||
<front>false</front>
|
||||
<back>false</back>
|
||||
</cover-art-archive>
|
||||
<medium-list count="2">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<disc-list count="1">
|
||||
<disc id="jsvwUD2Pw0qZEJNumbOoVKj7vbU-">
|
||||
<sectors>213610</sectors>
|
||||
</disc>
|
||||
</disc-list>
|
||||
<track-list count="9" offset="0">
|
||||
<track id="ab709d6d-9c4c-3e95-816c-edcf4fdd5943">
|
||||
<position>1</position>
|
||||
<number>1</number>
|
||||
<length>98266</length>
|
||||
<recording id="38041f24-5a49-4ffe-b41c-8eb67945ebfb">
|
||||
<title>Prelude</title>
|
||||
<length>98266</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="b90e822f-6107-3c75-bae0-109334b27168">
|
||||
<position>2</position>
|
||||
<number>2</number>
|
||||
<length>318400</length>
|
||||
<recording id="75e9cddb-5e27-4f30-91f1-a6fc4162caf6">
|
||||
<title>Evolution (The Grand Design)</title>
|
||||
<length>318400</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="370868bc-fb45-356a-ae42-f1c80a8793f5">
|
||||
<position>3</position>
|
||||
<number>3</number>
|
||||
<length>390826</length>
|
||||
<recording id="54f964f0-f64a-49d6-acd4-2dea66d2eb07">
|
||||
<title>Fallen / Transcendence</title>
|
||||
<length>390826</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="cc864e8b-0094-38bb-b948-3388b416f463">
|
||||
<position>4</position>
|
||||
<number>4</number>
|
||||
<length>459040</length>
|
||||
<recording id="73098f0f-526c-4920-9f6a-b4b4ae42fd15">
|
||||
<title>Communion and the Oracle</title>
|
||||
<length>459040</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="76f62531-9627-3810-9d6f-3ee4cd617d6b">
|
||||
<position>5</position>
|
||||
<number>5</number>
|
||||
<length>219760</length>
|
||||
<recording id="4f462d15-841d-417c-85dc-6698feffa35c">
|
||||
<title>The Bird-Serpent War</title>
|
||||
<length>219760</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="3d29ee07-8815-3fc6-a6f2-af974a89e8fa">
|
||||
<position>6</position>
|
||||
<number>6</number>
|
||||
<length>309573</length>
|
||||
<recording id="e0d3ef99-1100-4e55-be30-734d52b96e92">
|
||||
<title>On the Breath of Poseidon</title>
|
||||
<length>309573</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="2540d8b5-3915-37a7-93c6-f4db9a25f153">
|
||||
<position>7</position>
|
||||
<number>7</number>
|
||||
<length>425226</length>
|
||||
<recording id="71961c16-c3be-4f2b-9f3f-efb25daf1615">
|
||||
<title>Egypt</title>
|
||||
<length>425226</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="6ee19436-5805-3841-a5c6-e3870166335c">
|
||||
<position>8</position>
|
||||
<number>8</number>
|
||||
<length>352666</length>
|
||||
<recording id="56cc2b94-725c-4473-908f-1806eafe7cd0">
|
||||
<title>The Death of Balance / Candlelight Fantasia</title>
|
||||
<length>352666</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="ac334353-0a64-3b18-92b2-7c5a55b792df">
|
||||
<position>9</position>
|
||||
<number>9</number>
|
||||
<length>272373</length>
|
||||
<recording id="fa2bc0cf-afbc-4eec-a757-a81ff73537c3">
|
||||
<title>The Eyes of Medusa</title>
|
||||
<length>272373</length>
|
||||
</recording>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
<medium>
|
||||
<position>2</position>
|
||||
<disc-list count="1">
|
||||
<disc id="lvcH9_vbw_rJAbXieTOo1CbyNmQ-">
|
||||
<sectors>267785</sectors>
|
||||
</disc>
|
||||
</disc-list>
|
||||
<track-list count="6" offset="0">
|
||||
<track id="3c7e7590-9b8b-3010-b645-311a6bd8cd03">
|
||||
<position>1</position>
|
||||
<number>1</number>
|
||||
<length>394600</length>
|
||||
<recording id="257a5030-a862-41dc-b9c2-2b2c48f4e78f">
|
||||
<title>Smoke and Mirrors</title>
|
||||
<length>394600</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="bff575f8-fb8f-33fb-abc4-e70882817adf">
|
||||
<position>2</position>
|
||||
<number>2</number>
|
||||
<length>441866</length>
|
||||
<recording id="a8c0cc29-07e9-4836-a6ec-780c85d54b01">
|
||||
<title>Church of the Machine</title>
|
||||
<length>441866</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="18e00695-2445-381f-84fa-5917141d796c">
|
||||
<position>3</position>
|
||||
<number>3</number>
|
||||
<length>849426</length>
|
||||
<recording id="b269f849-e6e3-44b6-8cd4-5f80927ea714">
|
||||
<title>Through the Looking Glass</title>
|
||||
<length>849426</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="0fa493f0-a5e5-325b-aa7a-5cda47800867">
|
||||
<position>4</position>
|
||||
<number>4</number>
|
||||
<length>442773</length>
|
||||
<recording id="c5cf4c79-d2a3-4aa0-abab-773a7a5c87ff">
|
||||
<title>Of Sins and Shadows</title>
|
||||
<length>442773</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="df6521dd-3e43-3813-a0a3-33e8872cf5f3">
|
||||
<position>5</position>
|
||||
<number>5</number>
|
||||
<length>245160</length>
|
||||
<recording id="1a5a0210-9b49-4c5b-883f-a52bc8e1c2d4">
|
||||
<title>Sea of Lies</title>
|
||||
<length>245160</length>
|
||||
</recording>
|
||||
</track>
|
||||
<track id="4d554d18-05c0-3dfc-8684-d14d932717d4">
|
||||
<position>6</position>
|
||||
<number>6</number>
|
||||
<length>1194640</length>
|
||||
<recording id="21d5e15f-5e35-4ad0-b058-5e1da0c1936e">
|
||||
<title>The Divine Wings of Tragedy</title>
|
||||
<length>1194640</length>
|
||||
</recording>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
</release-list>
|
||||
</disc>
|
||||
</metadata>
|
48
tests/data/recording.xml
Normal file
48
tests/data/recording.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
|
||||
<recording id="9225a9b4-3000-493e-a4d7-e7157ad32a4d">
|
||||
<title>Victoria und ihr Husar: Pardon Madame</title>
|
||||
<length>203906</length>
|
||||
<artist-credit>
|
||||
<name-credit>
|
||||
<artist id="ea4cad4e-137d-4fed-9b3e-7482064da2d8">
|
||||
<name>Paul Abraham</name>
|
||||
<sort-name>Abraham, Paul</sort-name>
|
||||
</artist>
|
||||
</name-credit>
|
||||
</artist-credit>
|
||||
<release-list count="1">
|
||||
<release id="60619d7f-4cec-40bb-8f94-d02b05e006c4">
|
||||
<title>An Evening at the Operetta</title>
|
||||
<status>Official</status>
|
||||
<quality>normal</quality>
|
||||
<packaging>Jewel Case</packaging>
|
||||
<text-representation>
|
||||
<language>deu</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<date>1992</date>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>1992</date>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<barcode>8712157906266</barcode>
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<track-list count="22" offset="5">
|
||||
<track id="2b67486a-bd0c-4678-a00b-9eacfac65c0a">
|
||||
<position>6</position>
|
||||
<number>6</number>
|
||||
<title>Victoria und ihr Husar: Pardon Madame</title>
|
||||
<length>203906</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
</release-list>
|
||||
</recording>
|
||||
</metadata>
|
285
tests/data/recording_with_multiple_releases.xml
Normal file
285
tests/data/recording_with_multiple_releases.xml
Normal file
@ -0,0 +1,285 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
|
||||
<recording id="d88ad1b4-73a7-4b3d-893a-9a6bfc8cf429">
|
||||
<title>Symphony no. 40 in G minor, K. 550 "Great": I. Allegro molto</title>
|
||||
<length>458386</length>
|
||||
<artist-credit>
|
||||
<name-credit joinphrase=", ">
|
||||
<artist id="b791b51c-03d0-427e-a96e-75090623d168">
|
||||
<name>Hans Graf</name>
|
||||
<sort-name>Graf, Hans</sort-name>
|
||||
</artist>
|
||||
</name-credit>
|
||||
<name-credit>
|
||||
<artist id="a027c92f-0fe9-4a6d-af45-6f5fd18ed544">
|
||||
<name>Mozarteum Orchester Salzburg</name>
|
||||
<sort-name>Mozarteum Orchester Salzburg</sort-name>
|
||||
</artist>
|
||||
</name-credit>
|
||||
</artist-credit>
|
||||
<release-list count="7">
|
||||
<release id="0c187ba2-6eea-49e1-a6d4-249cccccf4b6">
|
||||
<title>Masters of Classical Music, Volume 1</title>
|
||||
<status>Official</status>
|
||||
<quality>normal</quality>
|
||||
<packaging>Jewel Case</packaging>
|
||||
<text-representation>
|
||||
<language>eng</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<date>1988</date>
|
||||
<country>US</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>1988</date>
|
||||
<area id="489ce91b-6658-3307-9877-795b68554c98">
|
||||
<name>United States</name>
|
||||
<sort-name>United States</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>US</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<barcode>018111580120</barcode>
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<track-list count="11" offset="3">
|
||||
<track id="2a60c333-3b66-4853-a84a-798ec00fb71a">
|
||||
<position>4</position>
|
||||
<number>4</number>
|
||||
<title>Symphony no. 40 in G minor, K. 550 "Great": I. Allegro molto</title>
|
||||
<length>458960</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
<release id="10cd503c-2466-3ab3-8e5f-1d8632c0df88">
|
||||
<title>The Classic Composers, Volume 3: Musical Masterpieces</title>
|
||||
<status>Promotion</status>
|
||||
<quality>normal</quality>
|
||||
<text-representation>
|
||||
<language>eng</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<date>2005</date>
|
||||
<country>US</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>2005</date>
|
||||
<area id="489ce91b-6658-3307-9877-795b68554c98">
|
||||
<name>United States</name>
|
||||
<sort-name>United States</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>US</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<track-list count="11" offset="8">
|
||||
<track id="17dfd781-0780-3d08-b3e0-809dda9d171f">
|
||||
<position>9</position>
|
||||
<number>9</number>
|
||||
<title>Symphony No. 40 in G minor with clarinets, K. 550: I. Allegro molto</title>
|
||||
<length>458386</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
<release id="4ef96635-fd8f-4ea6-8b99-56de1be2d5d9">
|
||||
<title>Masters of Classical Music, Volume 1</title>
|
||||
<status>Official</status>
|
||||
<quality>normal</quality>
|
||||
<packaging>Jewel Case</packaging>
|
||||
<text-representation>
|
||||
<language>eng</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<date>2010-10-18</date>
|
||||
<country>DE</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>2010-10-18</date>
|
||||
<area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad">
|
||||
<name>Germany</name>
|
||||
<sort-name>Germany</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>DE</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<barcode>4006408158011</barcode>
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<track-list count="11" offset="3">
|
||||
<track id="d34d0770-c1f3-308c-a482-6abbcf0aac10">
|
||||
<position>4</position>
|
||||
<number>4</number>
|
||||
<title>Symphony no. 40 in G minor, K. 550 "Great": I. Allegro molto</title>
|
||||
<length>458960</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
<release id="5348c099-eb89-48b9-ba20-1df8d0cc80ac">
|
||||
<title>Les grands compositeurs : Mozart prodige musical</title>
|
||||
<status>Official</status>
|
||||
<quality>normal</quality>
|
||||
<packaging>Other</packaging>
|
||||
<text-representation>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<date>2003</date>
|
||||
<country>FR</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>2003</date>
|
||||
<area id="08310658-51eb-3801-80de-5a0739207115">
|
||||
<name>France</name>
|
||||
<sort-name>France</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>FR</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<barcode />
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<track-list count="11" offset="8">
|
||||
<track id="a798201b-0e1a-370a-ad08-da55d8cb069d">
|
||||
<position>9</position>
|
||||
<number>9</number>
|
||||
<title>Symphonie n° 40, K 550 : 1er mouvement</title>
|
||||
<length>456000</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
<release id="9ef15aa9-db32-44f5-8ce9-c312ab05df04">
|
||||
<title>The Classic Composers, Volume 3: Musical Masterpieces</title>
|
||||
<status>Promotion</status>
|
||||
<quality>normal</quality>
|
||||
<text-representation>
|
||||
<language>eng</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<date>2002</date>
|
||||
<country>GB</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<date>2002</date>
|
||||
<area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed">
|
||||
<name>United Kingdom</name>
|
||||
<sort-name>United Kingdom</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>GB</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<track-list count="11" offset="8">
|
||||
<track id="4393e6a8-d7f2-3098-920b-efbe25dcab92">
|
||||
<position>9</position>
|
||||
<number>9</number>
|
||||
<title>Symphony No. 40 in G minor with clarinets, K. 550: I. Allegro molto</title>
|
||||
<length>458386</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
<release id="ec96580f-7197-474c-b067-ead382994950">
|
||||
<title>Klassiset säveltäjät: Taitoa ja mielikuvitusta</title>
|
||||
<quality>normal</quality>
|
||||
<packaging>Other</packaging>
|
||||
<text-representation>
|
||||
<language>fin</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<country>FI</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<area id="6a264f94-6ff1-30b1-9a81-41f7bfabd616">
|
||||
<name>Finland</name>
|
||||
<sort-name>Finland</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>FI</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<barcode />
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<track-list count="11" offset="8">
|
||||
<track id="7d3bd619-e59a-3a80-b62f-13d5cfa4202a">
|
||||
<position>9</position>
|
||||
<number>9</number>
|
||||
<title>Sinfonia nro 40 G-molli, KV 550: 1. osa</title>
|
||||
<length>458386</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
<release id="ee1cf8e2-68c6-3a88-8cd2-d06eb80a1fea">
|
||||
<title>The Classic Composers, Volume 3: Musical Masterpieces</title>
|
||||
<status>Official</status>
|
||||
<quality>normal</quality>
|
||||
<packaging>Other</packaging>
|
||||
<text-representation>
|
||||
<language>eng</language>
|
||||
<script>Latn</script>
|
||||
</text-representation>
|
||||
<country>DE</country>
|
||||
<release-event-list count="1">
|
||||
<release-event>
|
||||
<area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad">
|
||||
<name>Germany</name>
|
||||
<sort-name>Germany</sort-name>
|
||||
<iso-3166-1-code-list>
|
||||
<iso-3166-1-code>DE</iso-3166-1-code>
|
||||
</iso-3166-1-code-list>
|
||||
</area>
|
||||
</release-event>
|
||||
</release-event-list>
|
||||
<barcode />
|
||||
<medium-list count="1">
|
||||
<medium>
|
||||
<position>1</position>
|
||||
<format>CD</format>
|
||||
<track-list count="11" offset="8">
|
||||
<track id="6517e872-c0f3-384e-a05e-26278576a149">
|
||||
<position>9</position>
|
||||
<number>9</number>
|
||||
<title>Symphony no. 40 in G minor, K. 550 "Great": I. Allegro molto</title>
|
||||
<length>458000</length>
|
||||
</track>
|
||||
</track-list>
|
||||
</medium>
|
||||
</medium-list>
|
||||
</release>
|
||||
</release-list>
|
||||
</recording>
|
||||
</metadata>
|
@ -8,6 +8,7 @@
|
||||
<file>beep.wma</file>
|
||||
<file>beep.m4a</file>
|
||||
<file>brokensong.cue</file>
|
||||
<file>discid_2cd.xml</file>
|
||||
<file>fmpsplaycount.mp3</file>
|
||||
<file>fmpsplaycountboth.mp3</file>
|
||||
<file>fmpsplaycountuser.mp3</file>
|
||||
@ -22,6 +23,8 @@
|
||||
<file>popmrating.mp3</file>
|
||||
<file>pls_one.pls</file>
|
||||
<file>pls_somafm.pls</file>
|
||||
<file>recording.xml</file>
|
||||
<file>recording_with_multiple_releases.xml</file>
|
||||
<file>secretagent.asx</file>
|
||||
<file>secretagent.pls</file>
|
||||
<file>test.m3u</file>
|
||||
|
248
tests/musicbrainzclient_test.cpp
Normal file
248
tests/musicbrainzclient_test.cpp
Normal file
@ -0,0 +1,248 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
|
||||
Clementine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Clementine 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "musicbrainz/musicbrainzclient.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QEventLoop>
|
||||
#include <QFile>
|
||||
#include <QMetaType>
|
||||
#include <QSignalSpy>
|
||||
#include <QString>
|
||||
|
||||
#include "mock_networkaccessmanager.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
namespace {
|
||||
typedef QList<MusicBrainzClient::Result> ResultList;
|
||||
Q_DECLARE_METATYPE(ResultList);
|
||||
};
|
||||
|
||||
class MusicBrainzClientTest : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestCase() {
|
||||
mock_network_ = new MockNetworkAccessManager;
|
||||
qRegisterMetaType<ResultList>("MusicBrainzClient::ResultList");
|
||||
}
|
||||
|
||||
static void TearDownTestCase() { delete mock_network_; }
|
||||
|
||||
// Reads the data from a file into a QByteArray and returns it.
|
||||
QByteArray ReadDataFromFile(const QString& filename) {
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
return data;
|
||||
}
|
||||
|
||||
static MockNetworkAccessManager* mock_network_;
|
||||
};
|
||||
|
||||
MockNetworkAccessManager* MusicBrainzClientTest::mock_network_;
|
||||
|
||||
// Test if a discid that do not exist in the musicbrainz database
|
||||
// generates an empty result.
|
||||
TEST_F(MusicBrainzClientTest, DiscIdNotFound) {
|
||||
QByteArray data =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><error><text>Not "
|
||||
"Found</text><text>For usage, please see: "
|
||||
"http://musicbrainz.org/development/mmd</text></error>";
|
||||
|
||||
// Create a MusicBrainzClient instance with mock_network_.
|
||||
MusicBrainzClient musicbrainz_client(nullptr, mock_network_);
|
||||
|
||||
// Hook the data as the response to a query of a given type.
|
||||
QMap<QString, QString> params;
|
||||
params["inc"] = "artists+recordings";
|
||||
MockNetworkReply* discid_reply =
|
||||
mock_network_->ExpectGet("discid", params, 200, data);
|
||||
|
||||
// Set up a QSignalSpy which stores the result.
|
||||
QSignalSpy spy(&musicbrainz_client,
|
||||
SIGNAL(Finished(const QString&, const QString,
|
||||
const MusicBrainzClient::ResultList&)));
|
||||
ASSERT_TRUE(spy.isValid());
|
||||
EXPECT_EQ(0, spy.count());
|
||||
|
||||
// Start the request and get a result. The argument doesn't matter
|
||||
// in the test.
|
||||
musicbrainz_client.StartDiscIdRequest("fooDiscid");
|
||||
discid_reply->Done();
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
EXPECT_EQ(1, spy.count());
|
||||
|
||||
QList<QVariant> result = spy.takeFirst();
|
||||
QString artist = result.takeFirst().toString();
|
||||
QString album = result.takeFirst().toString();
|
||||
ResultList tracks = result.takeFirst().value<ResultList>();
|
||||
|
||||
// Check that title and artist are empty, and that there are zero tracks.
|
||||
EXPECT_TRUE(artist.isEmpty());
|
||||
EXPECT_TRUE(album.isEmpty());
|
||||
EXPECT_EQ(0, tracks.count());
|
||||
}
|
||||
|
||||
// Test if MusicBrainzClient::StartDiscIdRequest() parses a discid
|
||||
// correctly.
|
||||
TEST_F(MusicBrainzClientTest, ParseDiscID) {
|
||||
QByteArray data = ReadDataFromFile(":testdata/discid_2cd.xml");
|
||||
ASSERT_FALSE(data.isEmpty());
|
||||
|
||||
// The following are the expected values given for the test file
|
||||
// discid_2cd.xml. The discid corresponds to the 2nd disc in the
|
||||
// set. The test file contains two releases but we only parse the first.
|
||||
const QString expected_artist = "Symphony X";
|
||||
const QString expected_title = "Live on the Edge of Forever";
|
||||
const int expected_number_of_tracks = 6;
|
||||
|
||||
// Create a MusicBrainzClient instance with mock_network_.
|
||||
MusicBrainzClient musicbrainz_client(nullptr, mock_network_);
|
||||
|
||||
// Hook the data as the response to a query of a given type.
|
||||
QMap<QString, QString> params;
|
||||
params["inc"] = "artists+recordings";
|
||||
MockNetworkReply* discid_reply =
|
||||
mock_network_->ExpectGet("discid", params, 200, data);
|
||||
|
||||
// Set up a QSignalSpy which stores the result.
|
||||
QSignalSpy spy(&musicbrainz_client,
|
||||
SIGNAL(Finished(const QString&, const QString,
|
||||
const MusicBrainzClient::ResultList&)));
|
||||
ASSERT_TRUE(spy.isValid());
|
||||
EXPECT_EQ(0, spy.count());
|
||||
|
||||
// Start the request and get a result. The argument doesn't matter
|
||||
// in the test. It is here set to the discid of the requested disc.
|
||||
musicbrainz_client.StartDiscIdRequest("lvcH9_vbw_rJAbXieTOo1CbyNmQ-");
|
||||
discid_reply->Done();
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
EXPECT_EQ(1, spy.count());
|
||||
|
||||
QList<QVariant> result = spy.takeFirst();
|
||||
QString artist = result.takeFirst().toString();
|
||||
QString album = result.takeFirst().toString();
|
||||
ResultList tracks = result.takeFirst().value<ResultList>();
|
||||
|
||||
// Check that title and artist are correct.
|
||||
EXPECT_EQ(expected_artist, artist);
|
||||
EXPECT_EQ(expected_title, album);
|
||||
|
||||
// Check that we get the correct number of tracks, i.e. that the
|
||||
// correct disc is chosen in a multi-disc release.
|
||||
EXPECT_EQ(expected_number_of_tracks, tracks.count());
|
||||
|
||||
// Check that the tracks is ordered by track number in ascending
|
||||
// order.
|
||||
for (int i = 0; i < tracks.count(); ++i) {
|
||||
EXPECT_EQ(i + 1, tracks[i].track_);
|
||||
}
|
||||
|
||||
// Check some track information.
|
||||
EXPECT_EQ("Smoke and Mirrors", tracks[0].title_);
|
||||
EXPECT_EQ(1, tracks[0].track_);
|
||||
EXPECT_EQ(394600, tracks[0].duration_msec_);
|
||||
|
||||
EXPECT_EQ("Church of the Machine", tracks[1].title_);
|
||||
EXPECT_EQ(2, tracks[1].track_);
|
||||
EXPECT_EQ(441866, tracks[1].duration_msec_);
|
||||
}
|
||||
|
||||
// Test if MusicBrainzClient::Start() parses a track correctly.
|
||||
TEST_F(MusicBrainzClientTest, ParseTrack) {
|
||||
QByteArray data = ReadDataFromFile(":testdata/recording.xml");
|
||||
ASSERT_FALSE(data.isEmpty());
|
||||
|
||||
// Expected results from the test file recording.xml:
|
||||
const int expected_track_number = 6;
|
||||
const QString expected_title = "Victoria und ihr Husar: Pardon Madame";
|
||||
const QString expected_artist = "Paul Abraham";
|
||||
const QString expected_album = "An Evening at the Operetta";
|
||||
|
||||
// Create a MusicBrainzClient instance with mock_network_.
|
||||
MusicBrainzClient musicbrainz_client(nullptr, mock_network_);
|
||||
|
||||
// Hook the data as the response to a query of a given type.
|
||||
QMap<QString, QString> params;
|
||||
params["inc"] = "artists+releases+media";
|
||||
MockNetworkReply* discid_reply =
|
||||
mock_network_->ExpectGet("recording", params, 200, data);
|
||||
|
||||
QSignalSpy spy(&musicbrainz_client,
|
||||
SIGNAL(Finished(int, const MusicBrainzClient::ResultList&)));
|
||||
ASSERT_TRUE(spy.isValid());
|
||||
EXPECT_EQ(0, spy.count());
|
||||
|
||||
// Start the request and get a result.
|
||||
// The mbid argument doesn't matter in the test.
|
||||
const int sent_id = 0;
|
||||
musicbrainz_client.Start(sent_id, "fooMbid");
|
||||
discid_reply->Done();
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
EXPECT_EQ(1, spy.count());
|
||||
|
||||
QList<QVariant> result = spy.takeFirst();
|
||||
int id = result.takeFirst().toInt();
|
||||
EXPECT_EQ(sent_id, id);
|
||||
|
||||
ResultList tracks = result.takeFirst().value<ResultList>();
|
||||
for (const MusicBrainzClient::Result& track : tracks) {
|
||||
EXPECT_EQ(expected_track_number, track.track_);
|
||||
EXPECT_EQ(expected_title, track.title_);
|
||||
EXPECT_EQ(expected_artist, track.artist_);
|
||||
EXPECT_EQ(expected_album, track.album_);
|
||||
}
|
||||
}
|
||||
|
||||
// For a recording with multiple releases, we should get them all.
|
||||
TEST_F(MusicBrainzClientTest, ParseTrackWithMultipleReleases) {
|
||||
QByteArray data =
|
||||
ReadDataFromFile(":testdata/recording_with_multiple_releases.xml");
|
||||
ASSERT_FALSE(data.isEmpty());
|
||||
|
||||
const int expected_number_of_releases = 7;
|
||||
|
||||
// Create a MusicBrainzClient instance with mock_network_.
|
||||
MusicBrainzClient musicbrainz_client(nullptr, mock_network_);
|
||||
|
||||
// Hook the data as the response to a query of a given type.
|
||||
QMap<QString, QString> params;
|
||||
params["inc"] = "artists+releases+media";
|
||||
MockNetworkReply* discid_reply =
|
||||
mock_network_->ExpectGet("recording", params, 200, data);
|
||||
|
||||
QSignalSpy spy(&musicbrainz_client,
|
||||
SIGNAL(Finished(int, const MusicBrainzClient::ResultList&)));
|
||||
ASSERT_TRUE(spy.isValid());
|
||||
EXPECT_EQ(0, spy.count());
|
||||
|
||||
// Start the request and get a result.
|
||||
// The mbid argument doesn't matter in the test.
|
||||
const int sent_id = 0;
|
||||
musicbrainz_client.Start(sent_id, "fooMbid");
|
||||
discid_reply->Done();
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
EXPECT_EQ(1, spy.count());
|
||||
|
||||
QList<QVariant> result = spy.takeFirst();
|
||||
int id = result.takeFirst().toInt();
|
||||
EXPECT_EQ(sent_id, id);
|
||||
|
||||
ResultList tracks = result.takeFirst().value<ResultList>();
|
||||
EXPECT_EQ(expected_number_of_releases, tracks.count());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user