2010-04-14 16:48:10 +02:00
|
|
|
/* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test_utils.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2010-06-18 16:26:46 +02:00
|
|
|
#include "library/libraryplaylistitem.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "playlist/playlist.h"
|
2010-04-14 16:48:10 +02:00
|
|
|
#include "mock_settingsprovider.h"
|
2010-04-14 17:39:24 +02:00
|
|
|
#include "mock_playlistitem.h"
|
2010-04-14 16:48:10 +02:00
|
|
|
|
|
|
|
#include <QtDebug>
|
2010-04-20 20:41:12 +02:00
|
|
|
#include <QUndoStack>
|
2010-04-14 16:48:10 +02:00
|
|
|
|
2010-04-15 00:36:28 +02:00
|
|
|
using boost::shared_ptr;
|
2010-04-14 17:39:24 +02:00
|
|
|
using ::testing::Return;
|
|
|
|
|
2010-04-14 16:48:10 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class PlaylistTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
PlaylistTest()
|
2010-06-23 17:16:44 +02:00
|
|
|
: playlist_(NULL, NULL, NULL),
|
2010-04-14 18:00:45 +02:00
|
|
|
sequence_(NULL, new DummySettingsProvider)
|
2010-04-14 16:48:10 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUp() {
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_sequence(&sequence_);
|
2010-04-14 16:48:10 +02:00
|
|
|
}
|
|
|
|
|
2010-04-14 17:39:24 +02:00
|
|
|
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, Metadata())
|
|
|
|
.WillRepeatedly(Return(metadata));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-15 00:36:28 +02:00
|
|
|
shared_ptr<PlaylistItem> MakeMockItemP(
|
2010-04-15 00:11:59 +02:00
|
|
|
const QString& title, const QString& artist = QString(),
|
|
|
|
const QString& album = QString(), int length = 123) const {
|
2010-04-15 00:36:28 +02:00
|
|
|
return shared_ptr<PlaylistItem>(MakeMockItem(title, artist, album, length));
|
2010-04-15 00:11:59 +02:00
|
|
|
}
|
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
Playlist playlist_;
|
|
|
|
PlaylistSequence sequence_;
|
2010-04-14 16:48:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, Basic) {
|
2010-04-14 18:00:45 +02:00
|
|
|
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
2010-04-14 16:48:10 +02:00
|
|
|
}
|
|
|
|
|
2010-04-14 17:39:24 +02:00
|
|
|
TEST_F(PlaylistTest, InsertItems) {
|
|
|
|
MockPlaylistItem* item = MakeMockItem("Title", "Artist", "Album", 123);
|
2010-04-15 00:36:28 +02:00
|
|
|
shared_ptr<PlaylistItem> item_ptr(item);
|
2010-04-14 17:39:24 +02:00
|
|
|
|
|
|
|
// Insert the item
|
2010-04-14 18:00:45 +02:00
|
|
|
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList() << item_ptr, -1);
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(1, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:39:24 +02:00
|
|
|
|
|
|
|
// Get the metadata
|
2010-04-14 18:00:45 +02:00
|
|
|
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)));
|
2010-04-14 17:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, Indexes) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:39:24 +02:00
|
|
|
|
|
|
|
// Start "playing" track 1
|
2010-04-14 18:00:45 +02:00
|
|
|
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());
|
2010-04-14 17:39:24 +02:00
|
|
|
|
|
|
|
// Stop playing
|
2010-04-14 18:00:45 +02:00
|
|
|
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());
|
2010-04-14 17:39:24 +02:00
|
|
|
|
|
|
|
// Play track 2
|
2010-04-14 18:00:45 +02:00
|
|
|
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());
|
2010-04-14 17:39:24 +02:00
|
|
|
|
|
|
|
// Play track 3
|
2010-04-14 18:00:45 +02:00
|
|
|
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());
|
2010-04-14 17:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, RepeatPlaylist) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.sequence()->SetRepeatMode(PlaylistSequence::Repeat_Playlist);
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(0);
|
|
|
|
EXPECT_EQ(1, playlist_.next_index());
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(1);
|
|
|
|
EXPECT_EQ(2, playlist_.next_index());
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(2);
|
|
|
|
EXPECT_EQ(0, playlist_.next_index());
|
2010-04-14 17:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, RepeatTrack) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.sequence()->SetRepeatMode(PlaylistSequence::Repeat_Track);
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(0);
|
|
|
|
EXPECT_EQ(0, playlist_.next_index());
|
2010-04-14 16:48:10 +02:00
|
|
|
}
|
|
|
|
|
2010-04-14 17:39:24 +02:00
|
|
|
TEST_F(PlaylistTest, RepeatAlbum) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One", "Album one")
|
|
|
|
<< MakeMockItemP("Two", "Album two")
|
|
|
|
<< MakeMockItemP("Three", "Album one"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.sequence()->SetRepeatMode(PlaylistSequence::Repeat_Album);
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(0);
|
|
|
|
EXPECT_EQ(2, playlist_.next_index());
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(2);
|
|
|
|
EXPECT_EQ(0, playlist_.next_index());
|
2010-04-14 17:39:24 +02:00
|
|
|
}
|
|
|
|
|
2010-04-14 17:57:58 +02:00
|
|
|
TEST_F(PlaylistTest, RemoveBeforeCurrent) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
|
|
|
// Remove a row before the currently playing track
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(2);
|
|
|
|
EXPECT_EQ(2, playlist_.current_index());
|
|
|
|
playlist_.removeRow(1, QModelIndex());
|
|
|
|
EXPECT_EQ(1, playlist_.current_index());
|
|
|
|
EXPECT_EQ(1, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(0, playlist_.previous_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.next_index());
|
2010-04-14 17:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, RemoveAfterCurrent) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
|
|
|
// Remove a row after the currently playing track
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(0);
|
|
|
|
EXPECT_EQ(0, playlist_.current_index());
|
|
|
|
playlist_.removeRow(1, QModelIndex());
|
|
|
|
EXPECT_EQ(0, playlist_.current_index());
|
|
|
|
EXPECT_EQ(0, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.previous_index());
|
|
|
|
EXPECT_EQ(1, playlist_.next_index());
|
|
|
|
|
|
|
|
playlist_.set_current_index(1);
|
|
|
|
EXPECT_EQ(-1, playlist_.next_index());
|
2010-04-14 17:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, RemoveCurrent) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
|
|
|
// Remove the currently playing track's row
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(1);
|
|
|
|
EXPECT_EQ(1, playlist_.current_index());
|
|
|
|
playlist_.removeRow(1, QModelIndex());
|
|
|
|
EXPECT_EQ(-1, playlist_.current_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.previous_index());
|
|
|
|
EXPECT_EQ(0, playlist_.next_index());
|
2010-04-14 17:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, InsertBeforeCurrent) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(1);
|
|
|
|
EXPECT_EQ(1, playlist_.current_index());
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("Four"), 0);
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(4, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
EXPECT_EQ(2, playlist_.current_index());
|
|
|
|
EXPECT_EQ(2, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(1, playlist_.previous_index());
|
|
|
|
EXPECT_EQ(3, playlist_.next_index());
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
EXPECT_EQ("Four", playlist_.data(playlist_.index(0, Playlist::Column_Title)));
|
|
|
|
EXPECT_EQ("One", playlist_.data(playlist_.index(1, Playlist::Column_Title)));
|
2010-04-14 17:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, InsertAfterCurrent) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(1);
|
|
|
|
EXPECT_EQ(1, playlist_.current_index());
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("Four"), 2);
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(4, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
EXPECT_EQ(1, playlist_.current_index());
|
|
|
|
EXPECT_EQ(1, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(0, playlist_.previous_index());
|
|
|
|
EXPECT_EQ(2, playlist_.next_index());
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
EXPECT_EQ("Two", playlist_.data(playlist_.index(1, Playlist::Column_Title)));
|
|
|
|
EXPECT_EQ("Four", playlist_.data(playlist_.index(2, Playlist::Column_Title)));
|
|
|
|
EXPECT_EQ("Three", playlist_.data(playlist_.index(3, Playlist::Column_Title)));
|
2010-04-14 17:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, Clear) {
|
2010-04-15 00:11:59 +02:00
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
2010-04-14 18:00:45 +02:00
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
playlist_.set_current_index(1);
|
|
|
|
EXPECT_EQ(1, playlist_.current_index());
|
|
|
|
playlist_.Clear();
|
2010-04-14 17:57:58 +02:00
|
|
|
|
2010-04-14 18:00:45 +02:00
|
|
|
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
|
|
|
EXPECT_EQ(-1, playlist_.current_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.previous_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.next_index());
|
2010-04-14 17:57:58 +02:00
|
|
|
}
|
2010-04-14 17:39:24 +02:00
|
|
|
|
2010-04-20 20:41:12 +02:00
|
|
|
TEST_F(PlaylistTest, UndoAdd) {
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canUndo());
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canRedo());
|
|
|
|
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("Title"));
|
|
|
|
EXPECT_EQ(1, playlist_.rowCount(QModelIndex()));
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canRedo());
|
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canUndo());
|
|
|
|
|
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canUndo());
|
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canRedo());
|
|
|
|
|
|
|
|
playlist_.undo_stack()->redo();
|
|
|
|
EXPECT_EQ(1, playlist_.rowCount(QModelIndex()));
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canRedo());
|
|
|
|
EXPECT_TRUE(playlist_.undo_stack()->canUndo());
|
|
|
|
|
|
|
|
EXPECT_EQ("Title", playlist_.data(playlist_.index(0, Playlist::Column_Title)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, UndoMultiAdd) {
|
|
|
|
// Add 1 item
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("One"));
|
|
|
|
|
|
|
|
// Add 2 items
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
|
|
|
|
|
|
|
// Undo adding 2 items
|
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canUndo());
|
|
|
|
EXPECT_EQ("add 2 songs", playlist_.undo_stack()->undoText());
|
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
|
|
|
|
// Undo adding 1 item
|
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canUndo());
|
|
|
|
EXPECT_EQ("add 1 songs", playlist_.undo_stack()->undoText());
|
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canUndo());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, UndoRemove) {
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canUndo());
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canRedo());
|
|
|
|
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("Title"));
|
|
|
|
playlist_.removeRow(0);
|
|
|
|
|
|
|
|
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canRedo());
|
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canUndo());
|
|
|
|
|
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
EXPECT_EQ(1, playlist_.rowCount(QModelIndex()));
|
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canRedo());
|
|
|
|
|
|
|
|
EXPECT_EQ("Title", playlist_.data(playlist_.index(0, Playlist::Column_Title)));
|
|
|
|
|
|
|
|
playlist_.undo_stack()->redo();
|
|
|
|
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
|
|
|
EXPECT_FALSE(playlist_.undo_stack()->canRedo());
|
|
|
|
EXPECT_TRUE(playlist_.undo_stack()->canUndo());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, UndoMultiRemove) {
|
|
|
|
// Add 3 items
|
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
|
|
|
|
|
|
|
// Remove 1 item
|
|
|
|
playlist_.removeRow(1); // Item "Two"
|
|
|
|
|
|
|
|
// Remove 2 items
|
|
|
|
playlist_.removeRows(0, 2); // "One" and "Three"
|
|
|
|
|
|
|
|
ASSERT_EQ(0, playlist_.rowCount(QModelIndex()));
|
|
|
|
|
2010-04-30 01:58:31 +02:00
|
|
|
// Undo removing all 3 items
|
2010-04-20 20:41:12 +02:00
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canUndo());
|
2010-04-30 01:58:31 +02:00
|
|
|
EXPECT_EQ("remove 3 songs", playlist_.undo_stack()->undoText());
|
2010-04-20 20:41:12 +02:00
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, UndoClear) {
|
|
|
|
playlist_.InsertItems(PlaylistItemList()
|
|
|
|
<< MakeMockItemP("One") << MakeMockItemP("Two") << MakeMockItemP("Three"));
|
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
|
|
|
|
|
|
|
playlist_.Clear();
|
|
|
|
ASSERT_EQ(0, playlist_.rowCount(QModelIndex()));
|
|
|
|
ASSERT_TRUE(playlist_.undo_stack()->canUndo());
|
|
|
|
EXPECT_EQ("remove 3 songs", playlist_.undo_stack()->undoText());
|
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
|
|
|
|
ASSERT_EQ(3, playlist_.rowCount(QModelIndex()));
|
|
|
|
}
|
|
|
|
|
2010-04-20 21:08:12 +02:00
|
|
|
TEST_F(PlaylistTest, UndoRemoveCurrent) {
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("Title"));
|
|
|
|
playlist_.set_current_index(0);
|
|
|
|
EXPECT_EQ(0, playlist_.current_index());
|
|
|
|
EXPECT_EQ(0, playlist_.last_played_index());
|
|
|
|
|
|
|
|
playlist_.removeRow(0);
|
|
|
|
EXPECT_EQ(-1, playlist_.current_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.last_played_index());
|
|
|
|
|
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
EXPECT_EQ(0, playlist_.current_index());
|
|
|
|
EXPECT_EQ(0, playlist_.last_played_index());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, UndoRemoveOldCurrent) {
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << MakeMockItemP("Title"));
|
|
|
|
playlist_.set_current_index(0);
|
|
|
|
EXPECT_EQ(0, playlist_.current_index());
|
|
|
|
EXPECT_EQ(0, playlist_.last_played_index());
|
|
|
|
|
|
|
|
playlist_.removeRow(0);
|
|
|
|
EXPECT_EQ(-1, playlist_.current_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.last_played_index());
|
|
|
|
|
|
|
|
playlist_.set_current_index(-1);
|
|
|
|
|
|
|
|
playlist_.undo_stack()->undo();
|
|
|
|
EXPECT_EQ(-1, playlist_.current_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.last_played_index());
|
|
|
|
}
|
|
|
|
|
2010-04-26 13:36:10 +02:00
|
|
|
TEST_F(PlaylistTest, ShuffleThenNext) {
|
|
|
|
// Add 100 items
|
|
|
|
PlaylistItemList items;
|
|
|
|
for (int i=0 ; i<100 ; ++i)
|
|
|
|
items << MakeMockItemP("Item " + QString::number(i));
|
|
|
|
playlist_.InsertItems(items);
|
|
|
|
|
|
|
|
playlist_.set_current_index(0);
|
|
|
|
|
|
|
|
// Shuffle until the current index is not at the end
|
|
|
|
forever {
|
|
|
|
playlist_.Shuffle();
|
|
|
|
if (playlist_.current_index() != items.count()-1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = playlist_.current_index();
|
|
|
|
EXPECT_EQ("Item 0", playlist_.current_item()->Metadata().title());
|
|
|
|
EXPECT_EQ("Item 0", playlist_.data(playlist_.index(index, Playlist::Column_Title)));
|
|
|
|
EXPECT_EQ(index, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(index + 1, playlist_.next_index());
|
|
|
|
|
|
|
|
// Shuffle until the current index *is* at the end
|
|
|
|
forever {
|
|
|
|
playlist_.Shuffle();
|
|
|
|
if (playlist_.current_index() == items.count()-1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = playlist_.current_index();
|
|
|
|
EXPECT_EQ("Item 0", playlist_.current_item()->Metadata().title());
|
|
|
|
EXPECT_EQ("Item 0", playlist_.data(playlist_.index(index, Playlist::Column_Title)));
|
|
|
|
EXPECT_EQ(index, playlist_.last_played_index());
|
|
|
|
EXPECT_EQ(-1, playlist_.next_index());
|
|
|
|
EXPECT_EQ(index-1, playlist_.previous_index());
|
|
|
|
}
|
|
|
|
|
2010-06-18 16:26:46 +02:00
|
|
|
TEST_F(PlaylistTest, LibraryIdMapSingle) {
|
|
|
|
Song song;
|
|
|
|
song.Init("title", "artist", "album", 123);
|
|
|
|
song.set_id(1);
|
|
|
|
|
|
|
|
boost::shared_ptr<PlaylistItem> item(new LibraryPlaylistItem(song));
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << item);
|
|
|
|
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(-1).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(0).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(2).count());
|
|
|
|
ASSERT_EQ(1, playlist_.library_items_by_id(1).count());
|
|
|
|
EXPECT_EQ(song.title(), playlist_.library_items_by_id(1)[0]->Metadata().title());
|
|
|
|
|
|
|
|
playlist_.Clear();
|
|
|
|
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(1).count());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, LibraryIdMapInvalid) {
|
|
|
|
Song invalid;
|
|
|
|
invalid.Init("title", "artist", "album", 123);
|
|
|
|
ASSERT_EQ(-1, invalid.id());
|
|
|
|
|
|
|
|
boost::shared_ptr<PlaylistItem> item(new LibraryPlaylistItem(invalid));
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << item);
|
|
|
|
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(-1).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(0).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(1).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(2).count());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PlaylistTest, LibraryIdMapMulti) {
|
|
|
|
Song one;
|
|
|
|
one.Init("title", "artist", "album", 123);
|
|
|
|
one.set_id(1);
|
|
|
|
|
|
|
|
Song two;
|
|
|
|
two.Init("title 2", "artist 2", "album 2", 123);
|
|
|
|
two.set_id(2);
|
|
|
|
|
|
|
|
boost::shared_ptr<PlaylistItem> item_one(new LibraryPlaylistItem(one));
|
|
|
|
boost::shared_ptr<PlaylistItem> item_two(new LibraryPlaylistItem(two));
|
|
|
|
boost::shared_ptr<PlaylistItem> item_three(new LibraryPlaylistItem(one));
|
|
|
|
playlist_.InsertItems(PlaylistItemList() << item_one << item_two << item_three);
|
|
|
|
|
|
|
|
EXPECT_EQ(2, playlist_.library_items_by_id(1).count());
|
|
|
|
EXPECT_EQ(1, playlist_.library_items_by_id(2).count());
|
|
|
|
|
|
|
|
playlist_.removeRow(1); // item_two
|
|
|
|
EXPECT_EQ(2, playlist_.library_items_by_id(1).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(2).count());
|
|
|
|
|
|
|
|
playlist_.removeRow(1); // item_three
|
|
|
|
EXPECT_EQ(1, playlist_.library_items_by_id(1).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(2).count());
|
|
|
|
|
|
|
|
playlist_.removeRow(0); // item_one
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(1).count());
|
|
|
|
EXPECT_EQ(0, playlist_.library_items_by_id(2).count());
|
|
|
|
}
|
|
|
|
|
2010-04-14 17:39:24 +02:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|