More playlist tests
This commit is contained in:
parent
921eb94a21
commit
747ae61620
|
@ -33,6 +33,7 @@ set(TESTUTILS-SOURCES
|
|||
test_utils.cpp
|
||||
mock_networkaccessmanager.cpp
|
||||
mock_taglib.cpp
|
||||
mock_playlistitem.cpp
|
||||
)
|
||||
|
||||
set(TESTUTILS-MOC-HEADERS
|
||||
|
|
|
@ -26,10 +26,6 @@
|
|||
#include <QSignalSpy>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
void PrintTo(const ::QString& str, std::ostream& os) {
|
||||
os << str.toStdString();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class LibraryTest : public ::testing::Test {
|
||||
|
|
|
@ -32,10 +32,6 @@ using ::testing::AtMost;
|
|||
using ::testing::Invoke;
|
||||
using ::testing::Return;
|
||||
|
||||
void PrintTo(const ::QString& str, std::ostream& os) {
|
||||
os << str.toStdString();
|
||||
}
|
||||
|
||||
class LibraryBackendTest : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOCK_PLAYLISTITEM_H
|
||||
#define MOCK_PLAYLISTITEM_H
|
||||
|
||||
#include "playlistitem.h"
|
||||
#include "song.h"
|
||||
#include "settingsprovider.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
class MockPlaylistItem : public PlaylistItem {
|
||||
public:
|
||||
MockPlaylistItem();
|
||||
|
||||
MOCK_CONST_METHOD0(type,
|
||||
Type());
|
||||
MOCK_CONST_METHOD0(options,
|
||||
Options());
|
||||
MOCK_CONST_METHOD1(Save,
|
||||
void(SettingsProvider& settings));
|
||||
MOCK_METHOD1(Restore,
|
||||
void(const SettingsProvider& settings));
|
||||
MOCK_METHOD0(Reload,
|
||||
void());
|
||||
MOCK_CONST_METHOD0(Metadata,
|
||||
Song());
|
||||
MOCK_METHOD0(StartLoading,
|
||||
void());
|
||||
MOCK_CONST_METHOD0(Url,
|
||||
QUrl());
|
||||
MOCK_METHOD0(LoadNext,
|
||||
void());
|
||||
MOCK_METHOD1(SetTemporaryMetadata,
|
||||
void(const Song& metadata));
|
||||
MOCK_METHOD0(ClearTemporaryMetadata,
|
||||
void());
|
||||
};
|
||||
|
||||
#endif // MOCK_PLAYLISTITEM_H
|
|
@ -19,11 +19,14 @@
|
|||
|
||||
#include "playlist.h"
|
||||
#include "mock_settingsprovider.h"
|
||||
#include "mock_playlistitem.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
using ::testing::Return;
|
||||
|
||||
namespace {
|
||||
|
||||
class PlaylistTest : public ::testing::Test {
|
||||
|
@ -38,6 +41,22 @@ class PlaylistTest : public ::testing::Test {
|
|||
playlist_->set_sequence(sequence_.get());
|
||||
}
|
||||
|
||||
MockPlaylistItem* MakeMockItem(const QString& title,
|
||||
const QString& artist = QString(),
|
||||
const QString& album = QString(),
|
||||
int length = 123) const {
|
||||
Song metadata;
|
||||
metadata.Init(title, artist, album, length);
|
||||
|
||||
MockPlaylistItem* ret = new MockPlaylistItem;
|
||||
EXPECT_CALL(*ret, type())
|
||||
.WillRepeatedly(Return(PlaylistItem::Type_Song));
|
||||
EXPECT_CALL(*ret, Metadata())
|
||||
.WillRepeatedly(Return(metadata));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
boost::scoped_ptr<Playlist> playlist_;
|
||||
boost::scoped_ptr<PlaylistSequence> sequence_;
|
||||
};
|
||||
|
@ -46,5 +65,99 @@ TEST_F(PlaylistTest, Basic) {
|
|||
EXPECT_EQ(0, playlist_->rowCount(QModelIndex()));
|
||||
}
|
||||
|
||||
TEST_F(PlaylistTest, InsertItems) {
|
||||
MockPlaylistItem* item = MakeMockItem("Title", "Artist", "Album", 123);
|
||||
|
||||
// Insert the item
|
||||
EXPECT_EQ(0, playlist_->rowCount(QModelIndex()));
|
||||
playlist_->InsertItems(QList<PlaylistItem*>() << item, -1);
|
||||
ASSERT_EQ(1, playlist_->rowCount(QModelIndex()));
|
||||
|
||||
// Get the metadata
|
||||
EXPECT_EQ("Title", playlist_->data(playlist_->index(0, Playlist::Column_Title)));
|
||||
EXPECT_EQ("Artist", playlist_->data(playlist_->index(0, Playlist::Column_Artist)));
|
||||
EXPECT_EQ("Album", playlist_->data(playlist_->index(0, Playlist::Column_Album)));
|
||||
EXPECT_EQ(123, playlist_->data(playlist_->index(0, Playlist::Column_Length)));
|
||||
}
|
||||
|
||||
TEST_F(PlaylistTest, Indexes) {
|
||||
playlist_->InsertItems(QList<PlaylistItem*>()
|
||||
<< MakeMockItem("One") << MakeMockItem("Two") << MakeMockItem("Three"));
|
||||
ASSERT_EQ(3, playlist_->rowCount(QModelIndex()));
|
||||
|
||||
// Start "playing" track 1
|
||||
playlist_->set_current_index(0);
|
||||
EXPECT_EQ(0, playlist_->current_index());
|
||||
EXPECT_EQ("One", playlist_->current_item()->Metadata().title());
|
||||
EXPECT_EQ(-1, playlist_->previous_index());
|
||||
EXPECT_EQ(1, playlist_->next_index());
|
||||
|
||||
// Stop playing
|
||||
EXPECT_EQ(0, playlist_->last_played_index());
|
||||
playlist_->set_current_index(-1);
|
||||
EXPECT_EQ(0, playlist_->last_played_index());
|
||||
EXPECT_EQ(-1, playlist_->current_index());
|
||||
|
||||
// Play track 2
|
||||
playlist_->set_current_index(1);
|
||||
EXPECT_EQ(1, playlist_->current_index());
|
||||
EXPECT_EQ("Two", playlist_->current_item()->Metadata().title());
|
||||
EXPECT_EQ(0, playlist_->previous_index());
|
||||
EXPECT_EQ(2, playlist_->next_index());
|
||||
|
||||
// Play track 3
|
||||
playlist_->set_current_index(2);
|
||||
EXPECT_EQ(2, playlist_->current_index());
|
||||
EXPECT_EQ("Three", playlist_->current_item()->Metadata().title());
|
||||
EXPECT_EQ(1, playlist_->previous_index());
|
||||
EXPECT_EQ(-1, playlist_->next_index());
|
||||
}
|
||||
|
||||
TEST_F(PlaylistTest, RepeatPlaylist) {
|
||||
playlist_->InsertItems(QList<PlaylistItem*>()
|
||||
<< MakeMockItem("One") << MakeMockItem("Two") << MakeMockItem("Three"));
|
||||
ASSERT_EQ(3, playlist_->rowCount(QModelIndex()));
|
||||
|
||||
playlist_->sequence()->SetRepeatMode(PlaylistSequence::Repeat_Playlist);
|
||||
|
||||
playlist_->set_current_index(0);
|
||||
EXPECT_EQ(1, playlist_->next_index());
|
||||
|
||||
playlist_->set_current_index(1);
|
||||
EXPECT_EQ(2, playlist_->next_index());
|
||||
|
||||
playlist_->set_current_index(2);
|
||||
EXPECT_EQ(0, playlist_->next_index());
|
||||
}
|
||||
|
||||
TEST_F(PlaylistTest, RepeatTrack) {
|
||||
playlist_->InsertItems(QList<PlaylistItem*>()
|
||||
<< MakeMockItem("One") << MakeMockItem("Two") << MakeMockItem("Three"));
|
||||
ASSERT_EQ(3, playlist_->rowCount(QModelIndex()));
|
||||
|
||||
playlist_->sequence()->SetRepeatMode(PlaylistSequence::Repeat_Track);
|
||||
|
||||
playlist_->set_current_index(0);
|
||||
EXPECT_EQ(0, playlist_->next_index());
|
||||
}
|
||||
|
||||
TEST_F(PlaylistTest, RepeatAlbum) {
|
||||
playlist_->InsertItems(QList<PlaylistItem*>()
|
||||
<< MakeMockItem("One", "Album one")
|
||||
<< MakeMockItem("Two", "Album two")
|
||||
<< MakeMockItem("Three", "Album one"));
|
||||
ASSERT_EQ(3, playlist_->rowCount(QModelIndex()));
|
||||
|
||||
playlist_->sequence()->SetRepeatMode(PlaylistSequence::Repeat_Album);
|
||||
|
||||
playlist_->set_current_index(0);
|
||||
EXPECT_EQ(2, playlist_->next_index());
|
||||
|
||||
playlist_->set_current_index(2);
|
||||
EXPECT_EQ(0, playlist_->next_index());
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -34,3 +34,16 @@ std::ostream& operator <<(std::ostream& stream, const QNetworkRequest& req) {
|
|||
stream << req.url().toString().toStdString();
|
||||
return stream;
|
||||
}
|
||||
|
||||
std::ostream& operator <<(std::ostream& stream, const QVariant& var) {
|
||||
stream << var.toString().toStdString();
|
||||
return stream;
|
||||
}
|
||||
|
||||
void PrintTo(const ::QString& str, std::ostream& os) {
|
||||
os << str.toStdString();
|
||||
}
|
||||
|
||||
void PrintTo(const ::QVariant& var, std::ostream& os) {
|
||||
os << var.toString().toStdString();
|
||||
}
|
||||
|
|
|
@ -22,11 +22,16 @@
|
|||
class QNetworkRequest;
|
||||
class QString;
|
||||
class QUrl;
|
||||
class QVariant;
|
||||
|
||||
std::ostream& operator <<(std::ostream& stream, const QString& str);
|
||||
std::ostream& operator <<(std::ostream& stream, const QVariant& var);
|
||||
std::ostream& operator <<(std::ostream& stream, const QUrl& url);
|
||||
std::ostream& operator <<(std::ostream& stream, const QNetworkRequest& req);
|
||||
|
||||
void PrintTo(const ::QString& str, std::ostream& os);
|
||||
void PrintTo(const ::QVariant& var, std::ostream& os);
|
||||
|
||||
#define EXPOSE_SIGNAL0(n) \
|
||||
void Emit##n() { emit n(); }
|
||||
#define EXPOSE_SIGNAL1(n, t1) \
|
||||
|
|
Loading…
Reference in New Issue