CollectionModelTest: Remove unused test
This commit is contained in:
parent
89990624ec
commit
ec21a55271
|
@ -318,386 +318,4 @@ TEST_F(CollectionModelTest, RemoveEmptyArtists) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test to check that the container nodes are created identical and unique all through the model with all possible collection groupings.
|
|
||||||
// model1 - Nodes are created from a complete reset done through lazy-loading.
|
|
||||||
// model2 - Initial container nodes are created in SongsAdded.
|
|
||||||
// model3 - All container nodes are created in SongsAdded.
|
|
||||||
|
|
||||||
// WARNING: This test can take up to 30 minutes to complete.
|
|
||||||
#if 0
|
|
||||||
TEST_F(CollectionModelTest, TestContainerNodes) {
|
|
||||||
|
|
||||||
SongList songs;
|
|
||||||
int year = 1960;
|
|
||||||
// Add some normal albums.
|
|
||||||
for (int artist_number = 1; artist_number <= 3 ; ++artist_number) {
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_artist(QStringLiteral("Artist %1").arg(artist_number));
|
|
||||||
song.set_composer(QStringLiteral("Composer %1").arg(artist_number));
|
|
||||||
song.set_performer(QStringLiteral("Performer %1").arg(artist_number));
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
for (int album_number = 1; album_number <= 3 ; ++album_number) {
|
|
||||||
if (year > 2020) year = 1960;
|
|
||||||
song.set_album(QStringLiteral("Artist %1 - Album %2").arg(artist_number).arg(album_number));
|
|
||||||
song.set_album_id(QString::number(album_number));
|
|
||||||
song.set_year(year++);
|
|
||||||
song.set_genre(QStringLiteral("Rock"));
|
|
||||||
for (int song_number = 1; song_number <= 5 ; ++song_number) {
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///mnt/music/Artist %1/Album %2/%3 - artist song-n-%3").arg(artist_number).arg(album_number).arg(song_number)));
|
|
||||||
song.set_title(QStringLiteral("Title %1").arg(song_number));
|
|
||||||
song.set_track(song_number);
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add some albums with 'album artist'.
|
|
||||||
for (int album_artist_number = 1; album_artist_number <= 3 ; ++album_artist_number) {
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_albumartist(QStringLiteral("Album Artist %1").arg(album_artist_number));
|
|
||||||
song.set_composer(QStringLiteral("Composer %1").arg(album_artist_number));
|
|
||||||
song.set_performer(QStringLiteral("Performer %1").arg(album_artist_number));
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
for (int album_number = 1; album_number <= 3 ; ++album_number) {
|
|
||||||
if (year > 2020) year = 1960;
|
|
||||||
song.set_album(QStringLiteral("Album Artist %1 - Album %2").arg(album_artist_number).arg(album_number));
|
|
||||||
song.set_album_id(QString::number(album_number));
|
|
||||||
song.set_year(year++);
|
|
||||||
song.set_genre(QStringLiteral("Rock"));
|
|
||||||
int artist_number = 1;
|
|
||||||
for (int song_number = 1; song_number <= 5 ; ++song_number) {
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///mnt/music/Album Artist %1/Album %2/%3 - album artist song-n-%3").arg(album_artist_number).arg(album_number).arg(QString::number(song_number))));
|
|
||||||
song.set_title(QStringLiteral("Title ") + QString::number(song_number));
|
|
||||||
song.set_track(song_number);
|
|
||||||
song.set_artist(QStringLiteral("Artist ") + QString::number(artist_number));
|
|
||||||
songs << song;
|
|
||||||
++artist_number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add some compilation albums.
|
|
||||||
for (int album_number = 1; album_number <= 3 ; ++album_number) {
|
|
||||||
if (year > 2020) year = 1960;
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
song.set_album(QStringLiteral("Compilation Album %1").arg(album_number));
|
|
||||||
song.set_album_id(QString::number(album_number));
|
|
||||||
song.set_year(year++);
|
|
||||||
song.set_genre(QStringLiteral("Pop"));
|
|
||||||
song.set_compilation(true);
|
|
||||||
int artist_number = 1;
|
|
||||||
for (int song_number = 1; song_number <= 4 ; ++song_number) {
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///mnt/music/Compilation Artist %1/Compilation Album %2/%3 - compilation song-n-%3").arg(artist_number).arg(album_number).arg(QString::number(song_number))));
|
|
||||||
song.set_artist(QStringLiteral("Compilation Artist %1").arg(artist_number));
|
|
||||||
song.set_composer(QStringLiteral("Composer %1").arg(artist_number));
|
|
||||||
song.set_performer(QStringLiteral("Performer %1").arg(artist_number));
|
|
||||||
song.set_title(QStringLiteral("Title %1").arg(song_number));
|
|
||||||
song.set_track(song_number);
|
|
||||||
songs << song;
|
|
||||||
++artist_number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Songs with only title
|
|
||||||
{
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///mnt/music/no album song 1/song-only-1")));
|
|
||||||
song.set_title(QStringLiteral("Only Title 1"));
|
|
||||||
songs << song;
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///mnt/music/no album song 2/song-only-2")));
|
|
||||||
song.set_title(QStringLiteral("Only Title 2"));
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Song with only artist, album and title.
|
|
||||||
{
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///tmp/artist-album-title-song")));
|
|
||||||
song.set_artist(QStringLiteral("Not Only Artist"));
|
|
||||||
song.set_album(QStringLiteral("Not Only Album"));
|
|
||||||
song.set_title(QStringLiteral("Not Only Title"));
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
song.set_year(1970);
|
|
||||||
song.set_track(1);
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add possible Various artists conflicting songs.
|
|
||||||
{
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///tmp/song-va-conflicting-1")));
|
|
||||||
song.set_artist(QStringLiteral("Various artists"));
|
|
||||||
song.set_album(QStringLiteral("VA Album"));
|
|
||||||
song.set_title(QStringLiteral("VA Title"));
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
song.set_year(1970);
|
|
||||||
song.set_track(1);
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///tmp/song-va-conflicting-2")));
|
|
||||||
song.set_artist(QStringLiteral("Various artists"));
|
|
||||||
song.set_albumartist(QStringLiteral("Various artists"));
|
|
||||||
song.set_album(QStringLiteral("VA Album"));
|
|
||||||
song.set_title(QStringLiteral("VA Title"));
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
song.set_year(1970);
|
|
||||||
song.set_track(1);
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///tmp/song-va-conflicting-3")));
|
|
||||||
song.set_albumartist(QStringLiteral("Various artists"));
|
|
||||||
song.set_album(QStringLiteral("VA Album"));
|
|
||||||
song.set_title(QStringLiteral("VA Title"));
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
song.set_year(1970);
|
|
||||||
song.set_track(1);
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Albums with Album ID.
|
|
||||||
for (int album_id = 0; album_id <= 2 ; ++album_id) {
|
|
||||||
Song song(Song::Source::Collection);
|
|
||||||
song.set_url(QUrl(QStringLiteral("file:///tmp/song-with-album-id-1")));
|
|
||||||
song.set_artist(QStringLiteral("Artist with Album ID"));
|
|
||||||
song.set_album(QStringLiteral("Album %1 with Album ID").arg(album_id));
|
|
||||||
song.set_album_id(QStringLiteral("Album ID %1").arg(album_id));
|
|
||||||
song.set_mtime(1);
|
|
||||||
song.set_ctime(1);
|
|
||||||
song.set_directory_id(1);
|
|
||||||
song.set_filetype(Song::FileType::FLAC);
|
|
||||||
song.set_filesize(1);
|
|
||||||
song.set_year(1970);
|
|
||||||
for (int i = 0; i <= 3 ; ++i) {
|
|
||||||
song.set_title(QStringLiteral("Title %1 %2").arg(album_id).arg(i));
|
|
||||||
song.set_track(i);
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int f = static_cast<int>(CollectionModel::GroupBy::None) + 1 ; f < static_cast<int>(CollectionModel::GroupBy::GroupByCount) ; ++f) {
|
|
||||||
for (int s = static_cast<int>(CollectionModel::GroupBy::None) ; s < static_cast<int>(CollectionModel::GroupBy::GroupByCount) ; ++s) {
|
|
||||||
for (int t = static_cast<int>(CollectionModel::GroupBy::None) ; t < static_cast<int>(CollectionModel::GroupBy::GroupByCount) ; ++t) {
|
|
||||||
|
|
||||||
qLog(Debug) << "Testing collection model grouping: " << f << s << t;
|
|
||||||
|
|
||||||
SharedPtr<Database> database1;
|
|
||||||
SharedPtr<Database> database2;
|
|
||||||
SharedPtr<Database> database3;
|
|
||||||
SharedPtr<CollectionBackend> backend1;
|
|
||||||
SharedPtr<CollectionBackend> backend2;
|
|
||||||
SharedPtr<CollectionBackend> backend3;
|
|
||||||
ScopedPtr<CollectionModel> model1;
|
|
||||||
ScopedPtr<CollectionModel> model2;
|
|
||||||
ScopedPtr<CollectionModel> model3;
|
|
||||||
|
|
||||||
database1 = make_unique<MemoryDatabase>(nullptr);
|
|
||||||
database2 = make_unique<MemoryDatabase>(nullptr);
|
|
||||||
database3 = make_unique<MemoryDatabase>(nullptr);
|
|
||||||
backend1 = make_shared<CollectionBackend>();
|
|
||||||
backend2= make_shared<CollectionBackend>();
|
|
||||||
backend3 = make_shared<CollectionBackend>();
|
|
||||||
backend1->Init(database1, nullptr, Song::Source::Collection, QLatin1String(SCollection::kSongsTable), QLatin1String(SCollection::kDirsTable), QLatin1String(SCollection::kSubdirsTable));
|
|
||||||
backend2->Init(database2, nullptr, Song::Source::Collection, QLatin1String(SCollection::kSongsTable), QLatin1String(SCollection::kDirsTable), QLatin1String(SCollection::kSubdirsTable));
|
|
||||||
backend3->Init(database3, nullptr, Song::Source::Collection, QLatin1String(SCollection::kSongsTable), QLatin1String(SCollection::kDirsTable), QLatin1String(SCollection::kSubdirsTable));
|
|
||||||
model1 = make_unique<CollectionModel>(backend1, nullptr);
|
|
||||||
model2 = make_unique<CollectionModel>(backend2, nullptr);
|
|
||||||
model3 = make_unique<CollectionModel>(backend3, nullptr);
|
|
||||||
|
|
||||||
backend1->AddDirectory(QStringLiteral("/mnt/music"));
|
|
||||||
backend2->AddDirectory(QStringLiteral("/mnt/music"));
|
|
||||||
backend3->AddDirectory(QStringLiteral("/mut/music"));
|
|
||||||
|
|
||||||
model1->SetGroupBy(CollectionModel::Grouping(CollectionModel::GroupBy(f), CollectionModel::GroupBy(s), CollectionModel::GroupBy(t)));
|
|
||||||
model2->SetGroupBy(CollectionModel::Grouping(CollectionModel::GroupBy(f), CollectionModel::GroupBy(s), CollectionModel::GroupBy(t)));
|
|
||||||
model3->SetGroupBy(CollectionModel::Grouping(CollectionModel::GroupBy(f), CollectionModel::GroupBy(s), CollectionModel::GroupBy(t)));
|
|
||||||
|
|
||||||
QSignalSpy model1_update(&*model1, &CollectionModel::SongsAdded);
|
|
||||||
QSignalSpy model2_update(&*model2, &CollectionModel::SongsAdded);
|
|
||||||
QSignalSpy model3_update(&*model3, &CollectionModel::SongsAdded);
|
|
||||||
|
|
||||||
{
|
|
||||||
QEventLoop event_loop;
|
|
||||||
QObject::connect(&*model1, &CollectionModel::rowsInserted, &event_loop, &QEventLoop::quit);
|
|
||||||
backend1->AddOrUpdateSongs(songs);
|
|
||||||
event_loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
QEventLoop event_loop;
|
|
||||||
QObject::connect(&*model2, &CollectionModel::rowsInserted, &event_loop, &QEventLoop::quit);
|
|
||||||
backend2->AddOrUpdateSongs(songs);
|
|
||||||
event_loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
QEventLoop event_loop;
|
|
||||||
QObject::connect(&*model3, &CollectionModel::rowsInserted, &event_loop, &QEventLoop::quit);
|
|
||||||
backend3->AddOrUpdateSongs(songs);
|
|
||||||
event_loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT_EQ(model1->song_nodes().count(), songs.count());
|
|
||||||
ASSERT_EQ(model2->song_nodes().count(), songs.count());
|
|
||||||
ASSERT_EQ(model3->song_nodes().count(), songs.count());
|
|
||||||
|
|
||||||
model1->Init();
|
|
||||||
|
|
||||||
model1->ExpandAll();
|
|
||||||
model2->ExpandAll();
|
|
||||||
// All nodes in model3 should be created already.
|
|
||||||
|
|
||||||
ASSERT_EQ(model1->song_nodes().count(), songs.count());
|
|
||||||
ASSERT_EQ(model2->song_nodes().count(), songs.count());
|
|
||||||
ASSERT_EQ(model3->song_nodes().count(), songs.count());
|
|
||||||
|
|
||||||
// Container nodes for all models should now be identical.
|
|
||||||
for (int i = 0 ; i < 3 ; ++i) {
|
|
||||||
for (CollectionItem *node : model1->container_nodes(i).values()) {
|
|
||||||
ASSERT_TRUE(model2->container_nodes(i).keys().contains(node->key));
|
|
||||||
CollectionItem *node2 = model2->container_nodes(i)[node->key];
|
|
||||||
ASSERT_EQ(node->key, node2->key);
|
|
||||||
ASSERT_EQ(node->display_text, node2->display_text);
|
|
||||||
ASSERT_EQ(node->sort_text, node2->sort_text);
|
|
||||||
}
|
|
||||||
for (CollectionItem *node : model1->container_nodes(i).values()) {
|
|
||||||
ASSERT_TRUE(model3->container_nodes(i).keys().contains(node->key));
|
|
||||||
CollectionItem *node2 = model2->container_nodes(i)[node->key];
|
|
||||||
ASSERT_EQ(node->key, node2->key);
|
|
||||||
ASSERT_EQ(node->display_text, node2->display_text);
|
|
||||||
ASSERT_EQ(node->sort_text, node2->sort_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CollectionItem *node : model2->container_nodes(i).values()) {
|
|
||||||
ASSERT_TRUE(model1->container_nodes(i).keys().contains(node->key));
|
|
||||||
CollectionItem *node2 = model2->container_nodes(i)[node->key];
|
|
||||||
ASSERT_EQ(node->key, node2->key);
|
|
||||||
ASSERT_EQ(node->display_text, node2->display_text);
|
|
||||||
ASSERT_EQ(node->sort_text, node2->sort_text);
|
|
||||||
}
|
|
||||||
for (CollectionItem *node : model2->container_nodes(i).values()) {
|
|
||||||
ASSERT_TRUE(model3->container_nodes(i).keys().contains(node->key));
|
|
||||||
CollectionItem *node2 = model2->container_nodes(i)[node->key];
|
|
||||||
ASSERT_EQ(node->key, node2->key);
|
|
||||||
ASSERT_EQ(node->display_text, node2->display_text);
|
|
||||||
ASSERT_EQ(node->sort_text, node2->sort_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CollectionItem *node : model3->container_nodes(i).values()) {
|
|
||||||
ASSERT_TRUE(model1->container_nodes(i).keys().contains(node->key));
|
|
||||||
CollectionItem *node2 = model2->container_nodes(i)[node->key];
|
|
||||||
ASSERT_EQ(node->key, node2->key);
|
|
||||||
ASSERT_EQ(node->display_text, node2->display_text);
|
|
||||||
ASSERT_EQ(node->sort_text, node2->sort_text);
|
|
||||||
}
|
|
||||||
for (CollectionItem *node : model3->container_nodes(i).values()) {
|
|
||||||
ASSERT_TRUE(model2->container_nodes(i).keys().contains(node->key));
|
|
||||||
CollectionItem *node2 = model2->container_nodes(i)[node->key];
|
|
||||||
ASSERT_EQ(node->key, node2->key);
|
|
||||||
ASSERT_EQ(node->display_text, node2->display_text);
|
|
||||||
ASSERT_EQ(node->sort_text, node2->sort_text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QSignalSpy database_reset_1(&*backend1, &CollectionBackend::DatabaseReset);
|
|
||||||
QSignalSpy database_reset_2(&*backend2, &CollectionBackend::DatabaseReset);
|
|
||||||
QSignalSpy database_reset_3(&*backend3, &CollectionBackend::DatabaseReset);
|
|
||||||
|
|
||||||
{
|
|
||||||
QEventLoop event_loop;
|
|
||||||
QObject::connect(&*model1, &CollectionModel::modelReset, &event_loop, &QEventLoop::quit);
|
|
||||||
backend1->DeleteAll();
|
|
||||||
event_loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
QEventLoop event_loop;
|
|
||||||
QObject::connect(&*model2, &CollectionModel::modelReset, &event_loop, &QEventLoop::quit);
|
|
||||||
backend2->DeleteAll();
|
|
||||||
event_loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
QEventLoop event_loop;
|
|
||||||
QObject::connect(&*model3, &CollectionModel::modelReset, &event_loop, &QEventLoop::quit);
|
|
||||||
backend3->DeleteAll();
|
|
||||||
event_loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT_EQ(database_reset_1.count(), 1);
|
|
||||||
ASSERT_EQ(database_reset_2.count(), 1);
|
|
||||||
ASSERT_EQ(database_reset_3.count(), 1);
|
|
||||||
|
|
||||||
// Make sure all nodes are deleted.
|
|
||||||
|
|
||||||
ASSERT_EQ(model1->container_nodes(0).count(), 0);
|
|
||||||
ASSERT_EQ(model1->container_nodes(1).count(), 0);
|
|
||||||
ASSERT_EQ(model1->container_nodes(2).count(), 0);
|
|
||||||
|
|
||||||
ASSERT_EQ(model2->container_nodes(0).count(), 0);
|
|
||||||
ASSERT_EQ(model2->container_nodes(1).count(), 0);
|
|
||||||
ASSERT_EQ(model2->container_nodes(2).count(), 0);
|
|
||||||
|
|
||||||
ASSERT_EQ(model3->container_nodes(0).count(), 0);
|
|
||||||
ASSERT_EQ(model3->container_nodes(1).count(), 0);
|
|
||||||
ASSERT_EQ(model3->container_nodes(2).count(), 0);
|
|
||||||
|
|
||||||
ASSERT_EQ(model1->song_nodes().count(), 0);
|
|
||||||
ASSERT_EQ(model2->song_nodes().count(), 0);
|
|
||||||
ASSERT_EQ(model3->song_nodes().count(), 0);
|
|
||||||
|
|
||||||
ASSERT_EQ(model1->divider_nodes_count(), 0);
|
|
||||||
ASSERT_EQ(model2->divider_nodes_count(), 0);
|
|
||||||
ASSERT_EQ(model3->divider_nodes_count(), 0);
|
|
||||||
|
|
||||||
backend1->Close();
|
|
||||||
backend2->Close();
|
|
||||||
backend3->Close();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue