1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

Fix LibraryModel tests.

This commit is contained in:
John Maguire 2010-05-11 19:03:29 +00:00
parent ae233ada44
commit 6794b67a2f
2 changed files with 13 additions and 1 deletions

View File

@ -29,7 +29,7 @@ class SimpleTreeModel : public QAbstractItemModel {
// QAbstractItemModel // QAbstractItemModel
int columnCount(const QModelIndex& parent) const; int columnCount(const QModelIndex& parent) const;
QModelIndex index(int row, int, const QModelIndex& parent) const; QModelIndex index(int row, int, const QModelIndex& parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex& index) const; QModelIndex parent(const QModelIndex& index) const;
int rowCount(const QModelIndex& parent) const; int rowCount(const QModelIndex& parent) const;
bool hasChildren(const QModelIndex& parent) const; bool hasChildren(const QModelIndex& parent) const;

View File

@ -101,6 +101,7 @@ TEST_F(LibraryModelTest, CompilationAlbums) {
AddSong(song); AddSong(song);
model_->Init(); model_->Init();
model_->fetchMore(model_->index(0, 0));
ASSERT_EQ(1, model_->rowCount(QModelIndex())); ASSERT_EQ(1, model_->rowCount(QModelIndex()));
@ -144,6 +145,7 @@ TEST_F(LibraryModelTest, MixedCaseHeaders) {
TEST_F(LibraryModelTest, UnknownArtists) { TEST_F(LibraryModelTest, UnknownArtists) {
AddSong("Title", "", "Album", 123); AddSong("Title", "", "Album", 123);
model_->Init(); model_->Init();
model_->fetchMore(model_->index(0, 0));
ASSERT_EQ(1, model_->rowCount(QModelIndex())); ASSERT_EQ(1, model_->rowCount(QModelIndex()));
QModelIndex unknown_index = model_->index(0, 0, QModelIndex()); QModelIndex unknown_index = model_->index(0, 0, QModelIndex());
@ -157,6 +159,7 @@ TEST_F(LibraryModelTest, UnknownAlbums) {
AddSong("Title", "Artist", "", 123); AddSong("Title", "Artist", "", 123);
AddSong("Title", "Artist", "Album", 123); AddSong("Title", "Artist", "Album", 123);
model_->Init(); model_->Init();
model_->fetchMore(model_->index(0, 0));
QModelIndex artist_index = model_->index(0, 0, QModelIndex()); QModelIndex artist_index = model_->index(0, 0, QModelIndex());
ASSERT_EQ(2, model_->rowCount(artist_index)); ASSERT_EQ(2, model_->rowCount(artist_index));
@ -188,9 +191,11 @@ TEST_F(LibraryModelTest, VariousArtistSongs) {
model_->Init(); model_->Init();
QModelIndex artist_index = model_->index(0, 0, QModelIndex()); QModelIndex artist_index = model_->index(0, 0, QModelIndex());
model_->fetchMore(artist_index);
ASSERT_EQ(1, model_->rowCount(artist_index)); ASSERT_EQ(1, model_->rowCount(artist_index));
QModelIndex album_index = model_->index(0, 0, artist_index); QModelIndex album_index = model_->index(0, 0, artist_index);
model_->fetchMore(album_index);
ASSERT_EQ(4, model_->rowCount(album_index)); ASSERT_EQ(4, model_->rowCount(album_index));
EXPECT_EQ("Artist 1 - Title 1", model_->index(0, 0, album_index).data().toString()); EXPECT_EQ("Artist 1 - Title 1", model_->index(0, 0, album_index).data().toString());
@ -207,8 +212,10 @@ TEST_F(LibraryModelTest, RemoveSongsLazyLoaded) {
// Lazy load the items // Lazy load the items
QModelIndex artist_index = model_->index(0, 0, QModelIndex()); QModelIndex artist_index = model_->index(0, 0, QModelIndex());
model_->fetchMore(artist_index);
ASSERT_EQ(1, model_->rowCount(artist_index)); ASSERT_EQ(1, model_->rowCount(artist_index));
QModelIndex album_index = model_->index(0, 0, artist_index); QModelIndex album_index = model_->index(0, 0, artist_index);
model_->fetchMore(album_index);
ASSERT_EQ(3, model_->rowCount(album_index)); ASSERT_EQ(3, model_->rowCount(album_index));
// Remove the first two songs // Remove the first two songs
@ -253,6 +260,7 @@ TEST_F(LibraryModelTest, RemoveEmptyAlbums) {
model_->Init(); model_->Init();
QModelIndex artist_index = model_->index(0, 0, QModelIndex()); QModelIndex artist_index = model_->index(0, 0, QModelIndex());
model_->fetchMore(artist_index);
ASSERT_EQ(2, model_->rowCount(artist_index)); ASSERT_EQ(2, model_->rowCount(artist_index));
// Remove one song from each album // Remove one song from each album
@ -260,8 +268,10 @@ TEST_F(LibraryModelTest, RemoveEmptyAlbums) {
// Check the model // Check the model
artist_index = model_->index(0, 0, QModelIndex()); artist_index = model_->index(0, 0, QModelIndex());
model_->fetchMore(artist_index);
ASSERT_EQ(1, model_->rowCount(artist_index)); ASSERT_EQ(1, model_->rowCount(artist_index));
QModelIndex album_index = model_->index(0, 0, artist_index); QModelIndex album_index = model_->index(0, 0, artist_index);
model_->fetchMore(album_index);
EXPECT_EQ("Album 2", album_index.data().toString()); EXPECT_EQ("Album 2", album_index.data().toString());
ASSERT_EQ(1, model_->rowCount(album_index)); ASSERT_EQ(1, model_->rowCount(album_index));
@ -274,8 +284,10 @@ TEST_F(LibraryModelTest, RemoveEmptyArtists) {
// Lazy load the items // Lazy load the items
QModelIndex artist_index = model_->index(0, 0, QModelIndex()); QModelIndex artist_index = model_->index(0, 0, QModelIndex());
model_->fetchMore(artist_index);
ASSERT_EQ(1, model_->rowCount(artist_index)); ASSERT_EQ(1, model_->rowCount(artist_index));
QModelIndex album_index = model_->index(0, 0, artist_index); QModelIndex album_index = model_->index(0, 0, artist_index);
model_->fetchMore(album_index);
ASSERT_EQ(1, model_->rowCount(album_index)); ASSERT_EQ(1, model_->rowCount(album_index));
// The artist header is there too right? // The artist header is there too right?