From 8985e7043958813392ede7f128208c052f1f7c5b Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 1 Aug 2016 09:41:10 -0400 Subject: [PATCH] core/playlists: Add a playlist_select() function I query the underlying playlist to see if it is selectable, and then update the settings file if it is. Implements #10: Select default playlist Signed-off-by: Anna Schumaker --- core/playlist.c | 17 ++++ core/playlists/artist.c | 7 ++ core/playlists/generic.c | 10 ++ core/playlists/library.c | 7 ++ core/playlists/system.c | 156 ++++++++++++++++++-------------- include/core/playlist.h | 3 + include/core/playlists/system.h | 1 + include/core/playlists/type.h | 9 ++ tests/core/playlists/artist.c | 13 +++ tests/core/playlists/library.c | 9 ++ tests/core/playlists/system.c | 36 +++++++- 11 files changed, 198 insertions(+), 70 deletions(-) diff --git a/core/playlist.c b/core/playlist.c index 9d6cbb14..fc3e175d 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -2,7 +2,10 @@ * Copyright 2013 (c) Anna Schumaker. */ #include +#include +static const gchar *SETTINGS_CUR_TYPE = "core.playlist.cur.type"; +static const gchar *SETTINGS_CUR_ID = "core.playlist.cur.id"; struct playlist_type *playlist_types[] = { [PL_SYSTEM] = &pl_system, @@ -16,6 +19,10 @@ void playlist_init(struct queue_ops *ops) pl_system_init(ops); pl_artist_init(ops); pl_library_init(ops); + + if (!settings_has(SETTINGS_CUR_TYPE) || + !settings_has(SETTINGS_CUR_ID)) + playlist_select(PL_SYSTEM, "Collection"); } void playlist_deinit() @@ -25,6 +32,16 @@ void playlist_deinit() pl_library_deinit(); } +bool playlist_select(enum playlist_type_t type, const gchar *name) +{ + if (!playlist_types[type]->pl_can_select(name)) + return false; + + settings_set(SETTINGS_CUR_TYPE, type); + settings_set(SETTINGS_CUR_ID, playlist_get_id(type, name)); + return true; +} + bool playlist_new(enum playlist_type_t type, const gchar *name) { return playlist_types[type]->pl_new(name); diff --git a/core/playlists/artist.c b/core/playlists/artist.c index e37d5938..51f97094 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -61,6 +61,12 @@ static unsigned int pl_artist_get_id(const gchar *name) return artist ? artist->ar_dbe.dbe_index : -1; } +static bool pl_artist_can_select(const gchar *name) +{ + struct playlist *playlist = __artist_pl_lookup(name); + return playlist ? playlist_generic_can_select(playlist) : false; +} + static gchar *pl_artist_get_name(unsigned int id) { struct artist *artist = ARTIST(db_at(artist_db_get(), id)); @@ -105,6 +111,7 @@ struct playlist_type pl_artist = { .pl_get_queue = pl_artist_get_queue, .pl_get_id = pl_artist_get_id, .pl_get_name = pl_artist_get_name, + .pl_can_select = pl_artist_can_select, .pl_new = pl_artist_new_delete, .pl_delete = pl_artist_new_delete, .pl_add_track = pl_artist_add_rm, diff --git a/core/playlists/generic.c b/core/playlists/generic.c index f9b0f7c4..c0b1ec15 100644 --- a/core/playlists/generic.c +++ b/core/playlists/generic.c @@ -8,6 +8,11 @@ /* * Noop playlist operations. */ +bool playlist_noop_can_select(struct playlist *playlist) +{ + return false; +} + void playlist_noop_clear(struct playlist *playlist) { } @@ -35,6 +40,11 @@ void playlist_generic_init(struct playlist *playlist, unsigned int flags, queue_sort(&playlist->pl_queue, COMPARE_TRACK, false); } +bool playlist_generic_can_select(struct playlist *playlist) +{ + return queue_size(&playlist->pl_queue) > 0; +} + void playlist_generic_clear(struct playlist *playlist) { queue_clear(&playlist->pl_queue); diff --git a/core/playlists/library.c b/core/playlists/library.c index 84ef361c..dafe848e 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -157,6 +157,12 @@ static gchar *pl_library_get_name(unsigned int id) return library ? g_strdup(library->li_path) : NULL; } +static bool pl_library_can_select(const gchar *name) +{ + struct playlist *playlist = __lib_pl_lookup(name); + return playlist ? playlist_generic_can_select(playlist) : false; +} + static bool pl_library_new(const gchar *name) { struct library *library; @@ -227,6 +233,7 @@ struct playlist_type pl_library = { .pl_get_queue = pl_library_get_queue, .pl_get_id = pl_library_get_id, .pl_get_name = pl_library_get_name, + .pl_can_select = pl_library_can_select, .pl_new = pl_library_new, .pl_delete = pl_library_delete, .pl_add_track = pl_library_add_rm, diff --git a/core/playlists/system.c b/core/playlists/system.c index df82e415..b78c710d 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -66,14 +66,15 @@ static void sys_pl_favorites_clear(struct playlist *playlist) } static struct sys_playlist sys_favorites = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"), - .spl_init = playlist_generic_init, - .spl_add = sys_pl_favorites_add, - .spl_remove = sys_pl_favorites_remove, - .spl_clear = sys_pl_favorites_clear, - .spl_set_flag = playlist_generic_set_flag, - .spl_sort = playlist_generic_sort, - .spl_next = playlist_generic_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"), + .spl_init = playlist_generic_init, + .spl_can_select = playlist_generic_can_select, + .spl_add = sys_pl_favorites_add, + .spl_remove = sys_pl_favorites_remove, + .spl_clear = sys_pl_favorites_clear, + .spl_set_flag = playlist_generic_set_flag, + .spl_sort = playlist_generic_sort, + .spl_next = playlist_generic_next, }; @@ -121,14 +122,15 @@ static void sys_pl_hidden_clear(struct playlist *playlist) } static struct sys_playlist sys_hidden = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"), - .spl_init = playlist_generic_init, - .spl_add = sys_pl_hidden_add, - .spl_remove = sys_pl_hidden_remove, - .spl_clear = sys_pl_hidden_clear, - .spl_set_flag = playlist_generic_set_flag, - .spl_sort = playlist_generic_sort, - .spl_next = playlist_generic_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"), + .spl_init = playlist_generic_init, + .spl_can_select = playlist_generic_can_select, + .spl_add = sys_pl_hidden_add, + .spl_remove = sys_pl_hidden_remove, + .spl_clear = sys_pl_hidden_clear, + .spl_set_flag = playlist_generic_set_flag, + .spl_sort = playlist_generic_sort, + .spl_next = playlist_generic_next, }; @@ -215,14 +217,15 @@ static struct track *sys_pl_queued_next(struct playlist *playlist) } static struct sys_playlist sys_queued = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Queued Tracks"), - .spl_init = sys_pl_queued_init, - .spl_add = sys_pl_queued_add, - .spl_remove = sys_pl_queued_remove, - .spl_clear = sys_pl_queued_clear, - .spl_set_flag = sys_pl_queued_set_flag, - .spl_sort = playlist_generic_sort, - .spl_next = sys_pl_queued_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Queued Tracks"), + .spl_init = sys_pl_queued_init, + .spl_can_select = playlist_noop_can_select, + .spl_add = sys_pl_queued_add, + .spl_remove = sys_pl_queued_remove, + .spl_clear = sys_pl_queued_clear, + .spl_set_flag = sys_pl_queued_set_flag, + .spl_sort = playlist_generic_sort, + .spl_next = sys_pl_queued_next, }; @@ -251,6 +254,11 @@ static bool sys_pl_collection_load() return true; } +static bool sys_pl_collection_can_select(struct playlist *playlist) +{ + return true; +} + static bool sys_pl_collection_add(struct playlist *playlist, struct track *track) { if (track->tr_library->li_enabled != true) @@ -281,15 +289,16 @@ static void sys_pl_collection_sort(struct playlist *playlist, } static struct sys_playlist sys_collection = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"), - .spl_init = sys_pl_update_init, - .spl_add = sys_pl_collection_add, - .spl_remove = playlist_generic_remove_track, - .spl_clear = playlist_noop_clear, - .spl_update = sys_pl_collection_update, - .spl_set_flag = sys_pl_collection_set_flag, - .spl_sort = sys_pl_collection_sort, - .spl_next = playlist_generic_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"), + .spl_init = sys_pl_update_init, + .spl_can_select = sys_pl_collection_can_select, + .spl_add = sys_pl_collection_add, + .spl_remove = playlist_generic_remove_track, + .spl_clear = playlist_noop_clear, + .spl_update = sys_pl_collection_update, + .spl_set_flag = sys_pl_collection_set_flag, + .spl_sort = sys_pl_collection_sort, + .spl_next = playlist_generic_next, }; @@ -312,14 +321,15 @@ static bool sys_pl_history_add(struct playlist *playlist, struct track *track) } static struct sys_playlist sys_history = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"), - .spl_init = sys_pl_history_init, - .spl_add = sys_pl_history_add, - .spl_remove = playlist_generic_remove_track, - .spl_clear = playlist_noop_clear, - .spl_set_flag = playlist_noop_set_flag, - .spl_sort = playlist_noop_sort, - .spl_next = playlist_generic_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"), + .spl_init = sys_pl_history_init, + .spl_can_select = playlist_noop_can_select, + .spl_add = sys_pl_history_add, + .spl_remove = playlist_generic_remove_track, + .spl_clear = playlist_noop_clear, + .spl_set_flag = playlist_noop_set_flag, + .spl_sort = playlist_noop_sort, + .spl_next = playlist_generic_next, }; @@ -342,15 +352,16 @@ static bool sys_pl_unplayed_update(struct playlist *playlist, } static struct sys_playlist sys_unplayed = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"), - .spl_init = sys_pl_update_init, - .spl_add = sys_pl_unplayed_add, - .spl_remove = playlist_generic_remove_track, - .spl_clear = playlist_noop_clear, - .spl_update = sys_pl_unplayed_update, - .spl_set_flag = playlist_generic_set_flag, - .spl_sort = playlist_generic_sort, - .spl_next = playlist_generic_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"), + .spl_init = sys_pl_update_init, + .spl_can_select = playlist_generic_can_select, + .spl_add = sys_pl_unplayed_add, + .spl_remove = playlist_generic_remove_track, + .spl_clear = playlist_noop_clear, + .spl_update = sys_pl_unplayed_update, + .spl_set_flag = playlist_generic_set_flag, + .spl_sort = playlist_generic_sort, + .spl_next = playlist_generic_next, }; @@ -375,15 +386,16 @@ static bool sys_pl_most_played_update(struct playlist *playlist, } static struct sys_playlist sys_most_played = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"), - .spl_init = sys_pl_update_init, - .spl_add = sys_pl_most_played_add, - .spl_remove = playlist_generic_remove_track, - .spl_update = sys_pl_most_played_update, - .spl_clear = playlist_noop_clear, - .spl_set_flag = playlist_generic_set_flag, - .spl_sort = playlist_generic_sort, - .spl_next = playlist_generic_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"), + .spl_init = sys_pl_update_init, + .spl_can_select = playlist_generic_can_select, + .spl_add = sys_pl_most_played_add, + .spl_remove = playlist_generic_remove_track, + .spl_update = sys_pl_most_played_update, + .spl_clear = playlist_noop_clear, + .spl_set_flag = playlist_generic_set_flag, + .spl_sort = playlist_generic_sort, + .spl_next = playlist_generic_next, }; @@ -408,15 +420,16 @@ static bool sys_pl_least_played_update(struct playlist *playlist, } static struct sys_playlist sys_least_played = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"), - .spl_init = sys_pl_update_init, - .spl_clear = playlist_noop_clear, - .spl_add = sys_pl_least_played_add, - .spl_remove = playlist_generic_remove_track, - .spl_update = sys_pl_least_played_update, - .spl_set_flag = playlist_generic_set_flag, - .spl_sort = playlist_generic_sort, - .spl_next = playlist_generic_next, + .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"), + .spl_init = sys_pl_update_init, + .spl_can_select = playlist_generic_can_select, + .spl_clear = playlist_noop_clear, + .spl_add = sys_pl_least_played_add, + .spl_remove = playlist_generic_remove_track, + .spl_update = sys_pl_least_played_update, + .spl_set_flag = playlist_generic_set_flag, + .spl_sort = playlist_generic_sort, + .spl_next = playlist_generic_next, }; @@ -513,6 +526,12 @@ static gchar *pl_system_get_name(unsigned int id) return NULL; } +static bool pl_system_can_select(const gchar *name) +{ + struct sys_playlist *sys_pl = __sys_pl_lookup(name); + return sys_pl ? sys_pl->spl_can_select(&sys_pl->spl_playlist) : false; +} + static bool pl_system_new(const gchar *name) { return false; @@ -573,6 +592,7 @@ struct playlist_type pl_system = { .pl_get_queue = pl_system_get_queue, .pl_get_id = pl_system_get_id, .pl_get_name = pl_system_get_name, + .pl_can_select = pl_system_can_select, .pl_new = pl_system_new, .pl_delete = pl_system_delete, .pl_add_track = pl_system_add_track, diff --git a/include/core/playlist.h b/include/core/playlist.h index afda8b68..97a48532 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -20,6 +20,9 @@ void playlist_init(struct queue_ops *); /* Called to deinitialize the playlist manager. */ void playlist_deinit(); +/* Called to select the current playlist. */ +bool playlist_select(enum playlist_type_t, const gchar *); + /* Called to create a new playlist. */ bool playlist_new(enum playlist_type_t, const gchar *); diff --git a/include/core/playlists/system.h b/include/core/playlists/system.h index f75196bd..50281a74 100644 --- a/include/core/playlists/system.h +++ b/include/core/playlists/system.h @@ -22,6 +22,7 @@ struct sys_playlist { struct playlist spl_playlist; void (*spl_init)(struct playlist *, unsigned int, struct queue_ops *); + bool (*spl_can_select)(struct playlist *); bool (*spl_add)(struct playlist *, struct track *); bool (*spl_remove)(struct playlist *, struct track *); void (*spl_clear)(struct playlist *); diff --git a/include/core/playlists/type.h b/include/core/playlists/type.h index af113042..537290df 100644 --- a/include/core/playlists/type.h +++ b/include/core/playlists/type.h @@ -37,6 +37,9 @@ struct playlist_type { /* Called to convert a playlist id to a name. */ gchar *(*pl_get_name)(unsigned int); + /* Called to check if a playlist can be selected. */ + bool (*pl_can_select)(const gchar *); + /* Called to create a new playlist. */ bool (*pl_new)(const gchar *); @@ -63,6 +66,9 @@ struct playlist_type { }; +/* Noop playlist can-select operation. */ +bool playlist_noop_can_select(struct playlist *); + /* Noop playlist clear operation. */ void playlist_noop_clear(struct playlist *); @@ -76,6 +82,9 @@ void playlist_noop_sort(struct playlist *, enum compare_t, bool); /* Generic playlist init function. */ void playlist_generic_init(struct playlist *, unsigned int, struct queue_ops *); +/* Generic playlist can-select function. */ +bool playlist_generic_can_select(struct playlist *); + /* Generic playlist clear operation. */ void playlist_generic_clear(struct playlist *); diff --git a/tests/core/playlists/artist.c b/tests/core/playlists/artist.c index 88cc1a4e..bd1cc109 100644 --- a/tests/core/playlists/artist.c +++ b/tests/core/playlists/artist.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include #include @@ -19,8 +20,12 @@ void test_artist() artist = artist_find("Koji Kondo"); g_assert_null(artist->ar_playlist); g_assert_false(playlist_add(PL_ARTIST, "Koji Kondo", track_get(0))); + g_assert_false(playlist_select(PL_ARTIST, "Koji Kondo")); + g_assert_false(playlist_select(PL_ARTIST, "Hajime Wakai")); + pl_artist_deinit(); pl_artist_init(NULL); + g_assert_cmpuint(playlist_get_id(PL_ARTIST, "Koji Kondo"), ==, 0); g_assert_cmpstr_free(playlist_get_name(PL_ARTIST, 0), ==, "Koji Kondo"); while (idle_run_task()) {}; @@ -30,6 +35,10 @@ void test_artist() g_assert_false(playlist_remove(PL_ARTIST, "Koji Kondo", track_get(0))); g_assert_cmpuint(playlist_size(PL_ARTIST, "Koji Kondo"), ==, 2); + g_assert_true(playlist_select(PL_ARTIST, "Koji Kondo")); + g_assert_cmpuint(settings_get("core.playlist.cur.type"), ==, PL_ARTIST); + g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, 0); + g_assert_false(playlist_delete(PL_ARTIST, "Koji Kondo")); pl_artist_deinit(); g_assert_null(artist->ar_playlist); @@ -41,7 +50,9 @@ int main(int argc, char **argv) int ret; idle_init_sync(); + settings_init(); tags_init(); + playlist_init(NULL); while (idle_run_task()) {}; /* Add tracks to the collection. */ @@ -53,7 +64,9 @@ int main(int argc, char **argv) g_test_add_func("/Core/Playlists/Artist", test_artist); ret = g_test_run(); + playlist_deinit(); tags_deinit(); + settings_deinit(); idle_deinit(); return ret; } diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index 065a0b2c..60fc2071 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include #include @@ -15,12 +16,14 @@ void test_library() g_assert_false(playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg")); g_assert_null(playlist_get_queue(PL_LIBRARY, "tests/Music")); + g_assert_false(playlist_select(PL_LIBRARY, "tests/Music")); g_assert_true(playlist_new(PL_LIBRARY, "tests/Music")); g_assert_false(playlist_new(PL_LIBRARY, "tests/Music")); g_assert_nonnull(playlist_get_queue(PL_LIBRARY, "tests/Music")); g_assert_cmpuint(playlist_get_id(PL_LIBRARY, "tests/Music"), ==, 0); g_assert_cmpstr_free(playlist_get_name(PL_LIBRARY, 0), ==, "tests/Music"); + g_assert_false(playlist_select(PL_LIBRARY, "tests/Music")); library = library_get(0); g_assert_nonnull(library); @@ -32,6 +35,10 @@ void test_library() g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 48); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 48); + g_assert_true(playlist_select(PL_LIBRARY, "tests/Music")); + g_assert_cmpuint(settings_get("core.playlist.cur.type"), ==, PL_LIBRARY); + g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, 0); + g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(0))); g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(1))); g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(0))); @@ -96,6 +103,7 @@ int main(int argc, char **argv) int ret; idle_init_sync(); + settings_init(); tags_init(); playlist_init(NULL); while (idle_run_task()) {}; @@ -106,6 +114,7 @@ int main(int argc, char **argv) playlist_deinit(); tags_deinit(); + settings_deinit(); idle_deinit(); return ret; } diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index e24f0404..009b11ff 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #include @@ -66,6 +67,17 @@ __test_playlist_clear("Hidden", 0, false, false); \ __test_playlist_state(name, ex_size, ex_track0, ex_track1); +#define __test_playlist_select(name, id) \ + g_assert_true(playlist_select(PL_SYSTEM, name)); \ + g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, id) + +#define __test_playlist_noselect(name) \ +do { \ + unsigned int id = settings_get("core.playlist.cur.id"); \ + g_assert_false(playlist_select(PL_SYSTEM, name)); \ + g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, id); \ +} while (0) + #define __test_playlist_reinit(name, ex_size, ex_track0, ex_track1) \ do { \ struct queue *queue; \ @@ -94,6 +106,9 @@ static void test_invalid() g_assert_false(playlist_new(PL_SYSTEM, "New Playlist")); g_assert_false(playlist_delete(PL_SYSTEM, "Favorites")); + __test_playlist_noselect(NULL); + __test_playlist_noselect("Invalid"); + playlist_update(PL_SYSTEM, NULL); g_assert_false(playlist_add(PL_SYSTEM, NULL, track_get(0))); g_assert_false(playlist_remove(PL_SYSTEM, NULL, track_get(0))); @@ -114,8 +129,10 @@ static void test_favorites() g_assert_false(queue_has_flag(queue, Q_ADD_FRONT)); __test_playlist_id("Favorites", SYS_PL_FAVORITES); + __test_playlist_noselect("Favorites"); __test_playlist_random("Favorites"); __test_playlist_add("Favorites"); + __test_playlist_select("Favorites", SYS_PL_FAVORITES); __test_playlist_reinit("Favorites", 2, true, true); __test_playlist_update("Favorites", 2, true, true); __test_playlist_clear("Favorites", 0, false, false); @@ -133,8 +150,10 @@ static void test_hidden() g_assert_false(queue_has_flag(queue, Q_ADD_FRONT)); __test_playlist_id("Hidden", SYS_PL_HIDDEN); + __test_playlist_noselect("Hidden"); __test_playlist_random("Hidden"); __test_playlist_add("Hidden"); + __test_playlist_select("Hidden", SYS_PL_HIDDEN); __test_playlist_reinit("Hidden", 2, true, true); __test_playlist_update("Hidden", 2, true, true); __test_playlist_clear("Hidden", 0, false, false); @@ -153,8 +172,10 @@ static void test_queued() g_assert_cmpuint(g_slist_length(queue->q_sort), ==, 0); __test_playlist_id("Queued Tracks", SYS_PL_QUEUED); + __test_playlist_noselect("Queued Tracks"); __test_playlist_random("Queued Tracks"); __test_playlist_add("Queued Tracks"); + __test_playlist_noselect("Queued Tracks"); __test_playlist_reinit("Queued Tracks", 2, true, true); g_assert(playlist_next() == track_get(0)); @@ -182,6 +203,7 @@ static void test_collection() g_assert_true(queue_has_flag(queue, Q_ADD_FRONT)); __test_playlist_id("Collection", SYS_PL_COLLECTION); + __test_playlist_select("Collection", SYS_PL_COLLECTION); __test_playlist_random("Collection"); __test_playlist_add("Collection"); __test_playlist_hide_track("Collection", 1, false, true); @@ -201,6 +223,7 @@ static void test_history() g_assert_true(queue_has_flag(queue, Q_ADD_FRONT)); g_assert_true(queue_has_flag(queue, Q_NO_SORT)); __test_playlist_id("History", SYS_PL_HISTORY); + __test_playlist_noselect("History"); g_assert_cmpuint(g_slist_length(queue->q_sort), ==, 0); playlist_sort(PL_SYSTEM, "History", COMPARE_TRACK, true); @@ -216,6 +239,7 @@ static void test_history() g_assert_true(playlist_add(PL_SYSTEM, "History", track_get(1))); g_assert_true(playlist_add(PL_SYSTEM, "History", track_get(1))); __test_playlist_state("History", 4, true, true); + __test_playlist_noselect("History"); g_assert(playlist_prev() == track_get(1)); g_assert(playlist_prev() == track_get(0)); @@ -240,6 +264,7 @@ static void test_unplayed() g_assert_true(queue_has_flag(queue, Q_ADD_FRONT)); __test_playlist_id("Unplayed", SYS_PL_UNPLAYED); + __test_playlist_noselect("Unplayed"); __test_playlist_random("Unplayed"); __test_playlist_reinit("Unplayed", 2, true, true); __test_playlist_remove("Unplayed"); @@ -248,6 +273,7 @@ static void test_unplayed() g_assert_true( playlist_add(PL_SYSTEM, "Unplayed", track_get(0))); g_assert_false(playlist_add(PL_SYSTEM, "Unplayed", track_get(1))); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 1); + __test_playlist_select("Unplayed", SYS_PL_UNPLAYED); track_get(0)->tr_count = 1; track_get(1)->tr_count = 0; @@ -282,6 +308,7 @@ static void test_most_played() g_assert_true(queue_has_flag(most, Q_ADD_FRONT)); __test_playlist_id("Most Played", SYS_PL_MOST_PLAYED); + __test_playlist_noselect("Most Played"); __test_playlist_random("Most Played"); __test_playlist_reinit("Most Played", 1, false, true); @@ -294,6 +321,7 @@ static void test_most_played() g_assert_true( playlist_add(PL_SYSTEM, "Most Played", track_get(1))); g_assert_false(playlist_add(PL_SYSTEM, "Most Played", track_get(1))); __test_playlist_state("Most Played", 1, false, true); + __test_playlist_select("Most Played", SYS_PL_MOST_PLAYED); track_get(0)->tr_count = 3; track_get(1)->tr_count = 1; @@ -323,6 +351,7 @@ static void test_least_played() g_assert_true(queue_has_flag(least, Q_ADD_FRONT)); __test_playlist_id("Least Played", SYS_PL_LEAST_PLAYED); + __test_playlist_noselect("Least Played"); __test_playlist_random("Least Played"); __test_playlist_reinit("Least Played", 1, false, true); @@ -335,6 +364,7 @@ static void test_least_played() g_assert_true( playlist_add(PL_SYSTEM, "Least Played", track_get(1))); g_assert_false(playlist_add(PL_SYSTEM, "Least Played", track_get(1))); __test_playlist_state("Least Played", 1, false, true); + __test_playlist_select("Least Played", SYS_PL_LEAST_PLAYED); track_get(0)->tr_count = 1; track_get(1)->tr_count = 3; @@ -356,8 +386,9 @@ int main(int argc, char **argv) int ret; idle_init_sync(); + settings_init(); tags_init(); - pl_system_init(NULL); + playlist_init(NULL); while (idle_run_task()) {}; /* Add tracks to the collection. */ @@ -377,8 +408,9 @@ int main(int argc, char **argv) g_test_add_func("/Core/Playlists/System/Least Played Tracks", test_least_played); ret = g_test_run(); - pl_system_deinit(); + playlist_deinit(); tags_deinit(); + settings_deinit(); idle_deinit(); return ret; }