Exemplo n.º 1
0
SearchProvider::ResultList IcecastSearchProvider::Search(int id, const QString& query) {
  IcecastBackend::StationList stations = backend_->GetStations(query);
  ResultList ret;

  const QStringList tokens = TokenizeQuery(query);

  foreach (const IcecastBackend::Station& station, stations) {
    if (ret.count() > 3)
      break;

    Result result(this);
    result.type_ = globalsearch::Type_Stream;
    result.metadata_ = station.ToSong();
    result.match_quality_ = MatchQuality(tokens, station.name);
    ret << result;
  }

  return ret;
}
Exemplo n.º 2
0
// 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_.get());

  // 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());
}
Exemplo n.º 3
0
// 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_.get());

  // 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, QStringList() << "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());
}
Exemplo n.º 4
0
// 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_.get());

  // 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_);
}