-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#include "test/musicbrainzrecordingstasktest.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <QNetworkAccessManager> | ||
#include <QTest> | ||
|
||
#include "musicbrainz/web/musicbrainzrecordingstask.h" | ||
#include "test/mixxxtest.h" | ||
#include "test/mock_networkaccessmanager.h" | ||
#include "util/compatibility.h" | ||
|
||
class MusicBrainzRecordingsTaskTest : public MixxxTest { | ||
protected: | ||
MusicBrainzRecordingsTaskTest() { | ||
m_pReceiver.reset(new MockMusicBrainzReceiver()); | ||
m_recordingIds = { | ||
"416a273e-51b8-4b1c-8873-4c9b4ed54a0f", | ||
"5e0aa7e4-01cb-441c-9fc2-d89e890cb981", | ||
"5f6340ae-9cab-4f00-83d5-7ad00ac35f5b"}; | ||
m_expectedParams = { | ||
{"inc", "artists+artist-credits+releases+release-groups+media"}}; | ||
|
||
m_pMusicBrainzTask.reset(new mixxx::MusicBrainzRecordingsTask( | ||
&m_network, | ||
m_recordingIds, | ||
m_pReceiver.data())); | ||
QObject::connect(m_pMusicBrainzTask.data(), | ||
&mixxx::MusicBrainzRecordingsTask::succeeded, | ||
m_pReceiver.data(), | ||
&MockMusicBrainzReceiver::slotMusicBrainzTaskSucceeded); | ||
QObject::connect(m_pMusicBrainzTask.data(), | ||
&mixxx::MusicBrainzRecordingsTask::failed, | ||
m_pReceiver.data(), | ||
&MockMusicBrainzReceiver::slotMusicBrainzTaskFailed); | ||
QObject::connect(m_pMusicBrainzTask.data(), | ||
&mixxx::MusicBrainzRecordingsTask::aborted, | ||
m_pReceiver.data(), | ||
&MockMusicBrainzReceiver::slotMusicBrainzTaskAborted); | ||
QObject::connect(m_pMusicBrainzTask.data(), | ||
&mixxx::MusicBrainzRecordingsTask::networkError, | ||
m_pReceiver.data(), | ||
&MockMusicBrainzReceiver::slotMusicBrainzTaskNetworkError); | ||
}; | ||
|
||
QScopedPointer<MockMusicBrainzReceiver> m_pReceiver; | ||
QScopedPointer<mixxx::MusicBrainzRecordingsTask> m_pMusicBrainzTask; | ||
QList<QUuid> m_recordingIds; | ||
QMap<QString, QString> m_expectedParams; | ||
MockNetworkAccessManager m_network; | ||
}; | ||
|
||
void MockMusicBrainzReceiver::slotMusicBrainzTaskSucceeded( | ||
const QList<mixxx::musicbrainz::TrackRelease>& guessedTrackReleases) { | ||
Q_UNUSED(guessedTrackReleases); | ||
qDebug() << "MockMusicBrainzReceiver::slotMusicBrainzTaskSucceeded"; | ||
MocSucceeded(); | ||
} | ||
|
||
void MockMusicBrainzReceiver::slotMusicBrainzTaskFailed( | ||
const mixxx::network::WebResponse& response, | ||
int errorCode, | ||
const QString& errorMessage) { | ||
Q_UNUSED(response); | ||
Q_UNUSED(errorCode); | ||
Q_UNUSED(errorMessage); | ||
qDebug() << "MockMusicBrainzReceiver::slotMusicBrainzTaskFailed"; | ||
MocFailed(); | ||
} | ||
|
||
void MockMusicBrainzReceiver::slotMusicBrainzTaskAborted() { | ||
qDebug() << "MockMusicBrainzReceiver::slotMusicBrainzTaskAborted"; | ||
MocAborted(); | ||
} | ||
|
||
void MockMusicBrainzReceiver::slotMusicBrainzTaskNetworkError( | ||
QNetworkReply::NetworkError errorCode, | ||
const QString& errorString, | ||
const mixxx::network::WebResponseWithContent& responseWithContent) { | ||
Q_UNUSED(errorCode); | ||
Q_UNUSED(errorString); | ||
Q_UNUSED(responseWithContent); | ||
qDebug() << "MockMusicBrainzReceiver::slotMusicBrainzTaskNetworkError"; | ||
MocNetworkError(); | ||
} | ||
|
||
TEST_F(MusicBrainzRecordingsTaskTest, ClinetSideTimeout) { | ||
EXPECT_CALL(*m_pReceiver.data(), MocNetworkError()).Times(1); | ||
m_network.ExpectGet( | ||
uuidToStringWithoutBraces(m_recordingIds[0]), | ||
m_expectedParams, | ||
404, | ||
QByteArray()); | ||
m_pMusicBrainzTask->invokeStart(100); | ||
|
||
// Wait until the timeout happens | ||
while (m_pMusicBrainzTask->isBusy()) { | ||
application()->processEvents(); | ||
} | ||
} | ||
|
||
TEST_F(MusicBrainzRecordingsTaskTest, RespodsEmpty) { | ||
EXPECT_CALL(*m_pReceiver.data(), MocFailed()).Times(1); | ||
MockNetworkReply* pReply0 = m_network.ExpectGet( | ||
uuidToStringWithoutBraces(m_recordingIds[0]), | ||
m_expectedParams, | ||
200, | ||
QByteArray()); | ||
m_pMusicBrainzTask->invokeStart(10000); | ||
|
||
application()->processEvents(); | ||
qDebug() << "pReply0->Done()" << pReply0; | ||
pReply0->Done(); | ||
MockNetworkReply* pReply1 = m_network.ExpectGet( | ||
uuidToStringWithoutBraces(m_recordingIds[1]), | ||
m_expectedParams, | ||
200, | ||
QByteArray()); | ||
|
||
QTest::qSleep(1000); // millis | ||
application()->processEvents(); | ||
|
||
qDebug() << "pReply1->Done()" << pReply1; | ||
pReply1->Done(); | ||
MockNetworkReply* pReply2 = m_network.ExpectGet( | ||
uuidToStringWithoutBraces(m_recordingIds[2]), | ||
m_expectedParams, | ||
200, | ||
QByteArray()); | ||
|
||
QTest::qSleep(1000); // millis | ||
application()->processEvents(); | ||
|
||
qDebug() << "pReply2->Done()" << pReply2; | ||
pReply2->Done(); | ||
|
||
while (m_pMusicBrainzTask->isBusy()) { | ||
application()->processEvents(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <QObject> | ||
|
||
#include "gmock/gmock.h" | ||
#include "musicbrainz/musicbrainz.h" | ||
#include "network/webtask.h" | ||
|
||
class MockMusicBrainzReceiver : public QObject { | ||
Q_OBJECT | ||
public: | ||
MockMusicBrainzReceiver() = default; | ||
~MockMusicBrainzReceiver() override = default; | ||
|
||
MOCK_METHOD(void, MocSucceeded, ()); | ||
MOCK_METHOD(void, MocFailed, ()); | ||
MOCK_METHOD(void, MocAborted, ()); | ||
MOCK_METHOD(void, MocNetworkError, ()); | ||
|
||
public slots: | ||
void slotMusicBrainzTaskSucceeded( | ||
const QList<mixxx::musicbrainz::TrackRelease>& guessedTrackReleases); | ||
void slotMusicBrainzTaskFailed( | ||
const mixxx::network::WebResponse& response, | ||
int errorCode, | ||
const QString& errorMessage); | ||
void slotMusicBrainzTaskAborted(); | ||
void slotMusicBrainzTaskNetworkError( | ||
QNetworkReply::NetworkError errorCode, | ||
const QString& errorString, | ||
const mixxx::network::WebResponseWithContent& responseWithContent); | ||
}; |