/* This file is part of Clementine.
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 .
*/
#include "albumcoverfetcher.h"
#include
#include
#include
#include
#include "mock_networkaccessmanager.h"
#include "gtest/gtest.h"
namespace {
class AlbumCoverFetcherTest : public ::testing::Test {
protected:
static void SetUpTestCase() {
lastfm::ws::ApiKey = "foobar";
}
void SetUp() {
// Lastfm takes ownership of this.
network_ = new MockNetworkAccessManager;
lastfm::setNetworkAccessManager(network_);
}
MockNetworkAccessManager* network_;
};
TEST_F(AlbumCoverFetcherTest, FetchesAlbumCover) {
QByteArray data("BarFoo"
"http://example.com/image.jpg");
QMap params;
params["artist"] = "Foo";
params["album"] = "Bar";
params["api_key"] = "foobar";
params["method"] = "album.getInfo";
MockNetworkReply* get_info_reply = network_->ExpectGet("audioscrobbler", params, 200, data);
params.clear();
MockNetworkReply* album_reply = network_->ExpectGet("http://example.com/image.jpg", params, 200, "");
AlbumCoverFetcher fetcher(network_, NULL);
QSignalSpy spy(&fetcher, SIGNAL(AlbumCoverFetched(quint64, const QImage&)));
ASSERT_TRUE(spy.isValid());
fetcher.FetchAlbumCover("Foo", "Bar");
get_info_reply->Done();
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
album_reply->Done();
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
EXPECT_EQ(1, spy.count());
}
} // namespace