diff --git a/core/playlist.c b/core/playlist.c index 1b152eb0..a81865b2 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -100,12 +100,17 @@ bool playlist_add(struct playlist *playlist, struct track *track) return ret; } -bool playlist_remove(enum playlist_type_t type, const gchar *name, - struct track *track) +bool playlist_remove(struct playlist *playlist, struct track *track) { - if (!track) + bool ret; + + if (!track || !playlist || !playlist->pl_ops->pl_remove) return false; - return playlist_types[type]->pl_remove_track(name, track); + + ret = playlist->pl_ops->pl_remove(playlist, track); + if (ret) + playlist_types[playlist->pl_type]->pl_save(); + return ret; } void playlist_update(enum playlist_type_t type, const gchar *name) diff --git a/core/playlists/artist.c b/core/playlists/artist.c index fbe158b2..886e497f 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -120,11 +120,6 @@ static gchar *pl_artist_get_name(unsigned int id) return artist ? g_strdup(artist->ar_name) : NULL; } -static bool pl_artist_rm(const gchar *name, struct track *track) -{ - return false; -} - static void pl_artist_update(const gchar *name) { } @@ -159,7 +154,6 @@ struct playlist_type pl_artist = { .pl_get_id = pl_artist_get_id, .pl_get_name = pl_artist_get_name, .pl_can_select = pl_artist_can_select, - .pl_remove_track = pl_artist_rm, .pl_update = pl_artist_update, .pl_set_flag = pl_artist_set_flag, .pl_sort = pl_artist_sort, diff --git a/core/playlists/library.c b/core/playlists/library.c index 9bb08569..c597aae3 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -252,11 +252,6 @@ static struct playlist *pl_library_new(const gchar *name) return library->li_playlist; } -static bool pl_library_rm(const gchar *name, struct track *track) -{ - return false; -} - static void pl_library_update(const gchar *name) { struct playlist *playlist = __lib_pl_lookup(name); @@ -295,7 +290,6 @@ struct playlist_type pl_library = { .pl_get_name = pl_library_get_name, .pl_can_select = pl_library_can_select, .pl_new = pl_library_new, - .pl_remove_track = pl_library_rm, .pl_update = pl_library_update, .pl_set_flag = pl_library_set_flag, .pl_sort = pl_library_sort, diff --git a/core/playlists/system.c b/core/playlists/system.c index 78505650..e564ad5b 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -6,7 +6,6 @@ #include static struct playlist *pl_system_get_playlist(const gchar *); -static bool pl_system_remove_track(const gchar *, struct track *); static void pl_system_update(const gchar *); static inline struct queue *__sys_pl_queue(enum sys_playlist_t); static void __sys_pl_save(); @@ -81,6 +80,7 @@ static bool sys_pl_generic_add_front(struct playlist *playlist, static struct playlist_ops favorites_ops = { .pl_add = playlist_generic_add_track, .pl_delete = sys_pl_delete_clear, + .pl_remove = playlist_generic_remove_track, }; static struct sys_playlist sys_favorites = { @@ -89,7 +89,6 @@ static struct sys_playlist sys_favorites = { .spl_save = sys_pl_save_full, .spl_load = sys_pl_load_full, .spl_can_select = playlist_generic_can_select, - .spl_remove = playlist_generic_remove_track, .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, .spl_next = playlist_generic_next, @@ -101,11 +100,11 @@ static struct sys_playlist sys_favorites = { */ static bool sys_pl_hidden_add(struct playlist *playlist, struct track *track) { - bool ret = playlist_generic_add_track(playlist, track); - pl_system_remove_track("Collection", track); - pl_system_remove_track("Unplayed", track); - pl_system_remove_track("Most Played", track); - pl_system_remove_track("Least Played", track); + bool ret = playlist_generic_add_track(pl_system_get_playlist("Hidden"), track); + playlist_generic_remove_track(pl_system_get_playlist("Collection"), track); + playlist_generic_remove_track(pl_system_get_playlist("Unplayed"), track); + playlist_generic_remove_track(pl_system_get_playlist("Most Played"), track); + playlist_generic_remove_track(pl_system_get_playlist("Least Played"), track); return ret; } @@ -142,6 +141,7 @@ static bool sys_pl_hidden_clear(struct playlist *playlist) static struct playlist_ops hidden_ops = { .pl_add = sys_pl_hidden_add, .pl_delete = sys_pl_hidden_clear, + .pl_remove = sys_pl_hidden_remove, }; static struct sys_playlist sys_hidden = { @@ -150,7 +150,6 @@ static struct sys_playlist sys_hidden = { .spl_save = sys_pl_save_full, .spl_load = sys_pl_load_full, .spl_can_select = playlist_generic_can_select, - .spl_remove = sys_pl_hidden_remove, .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, .spl_next = playlist_generic_next, @@ -192,6 +191,7 @@ static void sys_pl_queued_init(struct playlist *playlist, static struct playlist_ops queued_ops = { .pl_add = playlist_generic_add_track, .pl_delete = sys_pl_delete_clear, + .pl_remove = playlist_generic_remove_track, }; static struct sys_playlist sys_queued = { @@ -200,7 +200,6 @@ static struct sys_playlist sys_queued = { .spl_save = sys_pl_save_full, .spl_load = sys_pl_load_full, .spl_can_select = playlist_generic_can_select, - .spl_remove = playlist_generic_remove_track, .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, .spl_next = playlist_generic_next, @@ -234,7 +233,9 @@ static bool sys_pl_collection_update(struct playlist *playlist, return sys_pl_generic_add_front(playlist, track) || true; } -static struct playlist_ops collection_ops; +static struct playlist_ops collection_ops = { + .pl_remove = sys_pl_hidden_add, +}; static struct sys_playlist sys_collection = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection", @@ -243,7 +244,6 @@ static struct sys_playlist sys_collection = { .spl_save = sys_pl_save_partial, .spl_load = sys_pl_load_partial, .spl_can_select = sys_pl_collection_can_select, - .spl_remove = playlist_generic_remove_track, .spl_update = sys_pl_collection_update, .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, @@ -277,7 +277,6 @@ static struct sys_playlist sys_history = { .spl_save = sys_pl_save_partial, .spl_load = sys_pl_load_partial, .spl_can_select = playlist_noop_can_select, - .spl_remove = playlist_generic_remove_track, .spl_set_flag = playlist_noop_set_flag, .spl_sort = playlist_noop_sort, .spl_next = playlist_generic_next, @@ -303,7 +302,6 @@ static struct sys_playlist sys_unplayed = { .spl_save = sys_pl_save_partial, .spl_load = sys_pl_load_partial, .spl_can_select = playlist_generic_can_select, - .spl_remove = playlist_generic_remove_track, .spl_update = sys_pl_unplayed_update, .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, @@ -332,7 +330,6 @@ static struct sys_playlist sys_most_played = { .spl_save = sys_pl_save_partial, .spl_load = sys_pl_load_partial, .spl_can_select = playlist_generic_can_select, - .spl_remove = playlist_generic_remove_track, .spl_update = sys_pl_most_played_update, .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, @@ -361,7 +358,6 @@ static struct sys_playlist sys_least_played = { .spl_save = sys_pl_save_partial, .spl_load = sys_pl_load_partial, .spl_can_select = playlist_generic_can_select, - .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, @@ -511,19 +507,6 @@ static bool pl_system_can_select(const gchar *name) return sys_pl ? sys_pl->spl_can_select(&sys_pl->spl_playlist) : false; } -static bool pl_system_remove_track(const gchar *name, struct track *track) -{ - struct sys_playlist *sys_pl = __sys_pl_lookup(name); - bool ret = false; - - if (sys_pl) { - ret = sys_pl->spl_remove(&sys_pl->spl_playlist, track); - if (ret) - __sys_pl_save(); - } - return ret; -} - static void pl_system_update(const gchar *name) { struct sys_playlist *sys_pl = __sys_pl_lookup(name); @@ -568,7 +551,6 @@ struct playlist_type pl_system = { .pl_get_id = pl_system_get_id, .pl_get_name = pl_system_get_name, .pl_can_select = pl_system_can_select, - .pl_remove_track = pl_system_remove_track, .pl_update = pl_system_update, .pl_set_flag = pl_system_set_flag, .pl_sort = pl_system_sort, diff --git a/core/playlists/user.c b/core/playlists/user.c index 77a214ff..663d9ec8 100644 --- a/core/playlists/user.c +++ b/core/playlists/user.c @@ -83,6 +83,7 @@ static bool pl_user_delete(struct playlist *playlist) static struct playlist_ops user_ops = { .pl_add = playlist_generic_add_track, + .pl_remove = playlist_generic_remove_track, .pl_delete = pl_user_delete, }; @@ -130,20 +131,6 @@ static struct playlist *pl_user_new(const gchar *name) return dbe ? &USER_PLAYLIST(dbe)->pl_playlist : NULL; } -static bool pl_user_remove(const gchar *name, struct track *track) -{ - struct playlist *playlist = __user_pl_lookup(name); - bool ret = false; - - if (playlist) { - ret = playlist_generic_remove_track(playlist, track); - if (ret) - pl_user_save(); - } - - return ret; -} - static void pl_user_update(const gchar *name) { } @@ -179,7 +166,6 @@ struct playlist_type pl_user = { .pl_get_name = pl_user_get_name, .pl_can_select = pl_user_can_select, .pl_new = pl_user_new, - .pl_remove_track = pl_user_remove, .pl_update = pl_user_update, .pl_set_flag = pl_user_set_flag, .pl_sort = pl_user_sort, diff --git a/gui/playlist.c b/gui/playlist.c index 81bc5068..396c4f72 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -67,25 +67,6 @@ static void __gui_playlist_updated(struct queue *queue, unsigned int n) static bool __gui_playlist_erase(struct queue *queue, struct track *track) { - struct playlist *playlist = queue->q_private; - enum playlist_type_t type = playlist->pl_type; - const gchar *name = playlist->pl_name; - - switch (type) { - case PL_SYSTEM: - if (string_match(name, "Collection")) { - playlist_add(playlist_get(PL_SYSTEM, "Hidden"), track); - break; - } else if (!string_match(name, "Favorites") && - !string_match(name, "Hidden") && - !string_match(name, "Queued Tracks")) - break; - case PL_USER: - playlist_remove(type, name, track); - default: - break; - }; - return false; } @@ -157,7 +138,7 @@ void __gui_playlist_delete(GtkMenuItem *item, gpointer data) cur = g_list_first(list); while (cur) { track = (struct track *)cur->data; - queue_erase_track(&playlist->pl_queue, track); + playlist_remove(playlist, track); cur = g_list_next(cur); } g_list_free(list); diff --git a/gui/playlists/system.c b/gui/playlists/system.c index e06c08a4..f1977f56 100644 --- a/gui/playlists/system.c +++ b/gui/playlists/system.c @@ -39,7 +39,7 @@ void __gui_pl_system_favorite_toggled(GtkToggleButton *toggle, gpointer data) if (gtk_toggle_button_get_active(toggle)) playlist_add(favorites, audio_cur_track()); else - playlist_remove(PL_SYSTEM, "Favorites", audio_cur_track()); + playlist_remove(favorites, audio_cur_track()); } void __gui_pl_system_hide_toggled(GtkToggleButton *toggle, gpointer data) @@ -49,7 +49,7 @@ void __gui_pl_system_hide_toggled(GtkToggleButton *toggle, gpointer data) if (playlist_add(hidden, audio_cur_track())) audio_next(); } else - playlist_remove(PL_SYSTEM, "Hidden", audio_cur_track()); + playlist_remove(hidden, audio_cur_track()); } static bool __gui_pl_system_init_idle() diff --git a/include/core/playlist.h b/include/core/playlist.h index 8966eccc..e68d1302 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -39,7 +39,7 @@ bool playlist_delete(struct playlist *); bool playlist_add(struct playlist *, struct track *); /* Called to remove a track from a playlist. */ -bool playlist_remove(enum playlist_type_t, const gchar *, struct track *); +bool playlist_remove(struct playlist *, struct track *); /* Called to update tracks on a playlist. */ void playlist_update(enum playlist_type_t, const gchar *); diff --git a/include/core/playlists/system.h b/include/core/playlists/system.h index 0b8a8e62..3c13be52 100644 --- a/include/core/playlists/system.h +++ b/include/core/playlists/system.h @@ -25,7 +25,6 @@ struct sys_playlist { void (*spl_save)(struct playlist *, struct file *); void (*spl_load)(struct playlist *, struct file *); bool (*spl_can_select)(struct playlist *); - bool (*spl_remove)(struct playlist *, struct track *); bool (*spl_update)(struct playlist *, struct track *); void (*spl_set_flag)(struct playlist *, enum queue_flags, bool); void (*spl_sort)(struct playlist *, enum compare_t, bool); diff --git a/include/core/playlists/type.h b/include/core/playlists/type.h index ce7e7327..76c1e51e 100644 --- a/include/core/playlists/type.h +++ b/include/core/playlists/type.h @@ -26,6 +26,9 @@ struct playlist_ops { /* Called to delete a playlist. */ bool (*pl_delete)(struct playlist *); + + /* Called to remove a track from the playlist. */ + bool (*pl_remove)(struct playlist *, struct track *); }; @@ -65,9 +68,6 @@ struct playlist_type { /* Called to create a new playlist. */ struct playlist *(*pl_new)(const gchar *); - /* Called to remove a track from the playlist. */ - bool (*pl_remove_track)(const gchar *, struct track *); - /* Called to update a playlist. */ void (*pl_update)(const gchar *); diff --git a/tests/core/playlist.c b/tests/core/playlist.c index 572bd81f..8a5abab8 100644 --- a/tests/core/playlist.c +++ b/tests/core/playlist.c @@ -14,6 +14,8 @@ static void test_null() g_assert_false(playlist_add(NULL, NULL)); g_assert_false(playlist_add(NULL, track_get(0))); + g_assert_false(playlist_remove(NULL, NULL)); + g_assert_false(playlist_remove(NULL, track_get(0))); } int main(int argc, char **argv) diff --git a/tests/core/playlists/artist.c b/tests/core/playlists/artist.c index ec1cc3bc..0c937aad 100644 --- a/tests/core/playlists/artist.c +++ b/tests/core/playlists/artist.c @@ -36,7 +36,7 @@ void test_artist() g_assert_cmpuint(playlist_size(PL_ARTIST, "Koji Kondo"), ==, 2); g_assert_nonnull(artist->ar_playlist); - g_assert_false(playlist_remove(PL_ARTIST, "Koji Kondo", track_get(0))); + g_assert_false(playlist_remove(playlist, track_get(0))); g_assert_cmpuint(playlist_size(PL_ARTIST, "Koji Kondo"), ==, 2); g_assert(playlist_cur() != playlist_get(PL_ARTIST, "Koji Kondo")); diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index bc6e6922..e8bd1a09 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -46,8 +46,8 @@ void test_library() g_assert_false(playlist_add(playlist, track_get(0))); g_assert_false(playlist_add(playlist, track_get(1))); - g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(0))); - g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(1))); + g_assert_false(playlist_remove(playlist, track_get(0))); + g_assert_false(playlist_remove(playlist, track_get(1))); pl_library_deinit(); g_assert_null(playlist_get_queue(PL_LIBRARY, "tests/Music")); @@ -63,8 +63,8 @@ void test_library() playlist = library->li_playlist; g_assert_false(playlist_add(playlist, track_get(0))); g_assert_false(playlist_add(playlist, track_get(1))); - g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(0))); - g_assert_false(playlist_remove(PL_LIBRARY, "tests/Music", track_get(1))); + g_assert_false(playlist_remove(playlist, track_get(0))); + g_assert_false(playlist_remove(playlist, track_get(1))); g_assert_cmpuint(playlist_size(PL_LIBRARY, "tests/Music"), ==, 48); g_assert_false(playlist_get_random(PL_LIBRARY, "tests/Music")); diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index f72db8e3..427bf3ff 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -39,10 +39,10 @@ __test_playlist_state(name, 2, true, true) #define __test_playlist_remove(name) \ - g_assert_true( playlist_remove(PL_SYSTEM, name, track_get(0))); \ - g_assert_false(playlist_remove(PL_SYSTEM, name, track_get(0))); \ - g_assert_true( playlist_remove(PL_SYSTEM, name, track_get(1))); \ - g_assert_false(playlist_remove(PL_SYSTEM, name, track_get(1))); \ + g_assert_true( playlist_remove(playlist_get(PL_SYSTEM, name), track_get(0))); \ + g_assert_false(playlist_remove(playlist_get(PL_SYSTEM, name), track_get(0))); \ + g_assert_true( playlist_remove(playlist_get(PL_SYSTEM, name), track_get(1))); \ + g_assert_false(playlist_remove(playlist_get(PL_SYSTEM, name), track_get(1))); \ __test_playlist_state(name, 0, false, false) #define __test_playlist_update(name, ex_size, ex_track0, ex_track1) \ @@ -56,7 +56,7 @@ g_assert_false(playlist_add(playlist_get(PL_SYSTEM, name), track_get(0))) #define __test_playlist_unhide_track(name, ex_size, ex_track0, ex_track1) \ - g_assert_true(playlist_remove(PL_SYSTEM, "Hidden", track_get(0))); \ + g_assert_true(playlist_remove(playlist_get(PL_SYSTEM, "Hidden"), track_get(0))); \ __test_playlist_state(name, ex_size, ex_track0, ex_track1) #define __test_playlist_clear_hidden(name, ex_size, ex_track0, ex_track1) \ @@ -144,7 +144,6 @@ static void test_invalid() __test_playlist_noselect("Invalid"); playlist_update(PL_SYSTEM, NULL); - g_assert_false(playlist_remove(PL_SYSTEM, NULL, track_get(0))); g_assert_false(playlist_has(PL_SYSTEM, NULL, track_get(0))); g_assert_cmpuint(playlist_size(PL_SYSTEM, NULL), ==, 0); @@ -272,8 +271,7 @@ static void test_history() g_assert_cmpuint(playlist_size(PL_SYSTEM, "History"), ==, 5); g_assert(playlist_prev() == track_get(1)); - __test_playlist_remove("History"); - __test_playlist_update("History", 0, false, false); + __test_playlist_update("History", 5, true, true); } static void test_unplayed() @@ -290,7 +288,6 @@ static void test_unplayed() __test_playlist_noselect("Unplayed"); __test_playlist_random("Unplayed"); __test_playlist_reinit("Unplayed", 2, true, true); - __test_playlist_remove("Unplayed"); track_get(1)->tr_count = 1; __test_playlist_update("Unplayed", 1, true, false); @@ -331,13 +328,6 @@ static void test_most_played() __test_playlist_noselect("Most Played"); __test_playlist_random("Most Played"); __test_playlist_reinit("Most Played", 1, false, true); - - g_assert_false(playlist_remove(PL_SYSTEM, "Most Played", track_get(0))); - g_assert_true( playlist_remove(PL_SYSTEM, "Most Played", track_get(1))); - g_assert_false(playlist_remove(PL_SYSTEM, "Most Played", track_get(1))); - __test_playlist_state("Most Played", 0, false, false); - - __test_playlist_update("Most Played", 1, false, true); __test_playlist_select("Most Played", SYS_PL_MOST_PLAYED); track_get(0)->tr_count = 3; @@ -370,13 +360,6 @@ static void test_least_played() __test_playlist_noselect("Least Played"); __test_playlist_random("Least Played"); __test_playlist_reinit("Least Played", 1, false, true); - - g_assert_false(playlist_remove(PL_SYSTEM, "Least Played", track_get(0))); - g_assert_true( playlist_remove(PL_SYSTEM, "Least Played", track_get(1))); - g_assert_false(playlist_remove(PL_SYSTEM, "Least Played", track_get(1))); - __test_playlist_state("Least Played", 0, false, false); - - __test_playlist_update("Least Played", 1, false, true); __test_playlist_select("Least Played", SYS_PL_LEAST_PLAYED); track_get(0)->tr_count = 1; @@ -444,6 +427,52 @@ static void test_add() g_assert_false(playlist_has(PL_SYSTEM, "Unplayed", track_get(2))); } +static void test_remove() +{ + g_assert_true( playlist_remove(__test_pl_favorites(), track_get(0))); + g_assert_false(playlist_remove(__test_pl_favorites(), track_get(0))); + g_assert_true( playlist_remove(__test_pl_queued(), track_get(0))); + g_assert_false(playlist_remove(__test_pl_queued(), track_get(0))); + g_assert_false(playlist_remove(__test_pl_history(), track_get(0))); + + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Favorites"), ==, 0); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 0); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "History"), ==, 2); + + g_assert_false(playlist_has(PL_SYSTEM, "Favorites", track_get(0))); + g_assert_false(playlist_has(PL_SYSTEM, "Queued Tracks", track_get(0))); + g_assert_true( playlist_has(PL_SYSTEM, "History", track_get(0))); + + g_assert_true( playlist_remove(__test_pl_hidden(), track_get(0))); + g_assert_true( playlist_remove(__test_pl_hidden(), track_get(1))); + g_assert_true( playlist_remove(__test_pl_hidden(), track_get(2))); + g_assert_false(playlist_remove(__test_pl_most_played(), track_get(0))); + g_assert_false(playlist_remove(__test_pl_least_played(), track_get(1))); + g_assert_false(playlist_remove(__test_pl_unplayed(), track_get(2))); + + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Hidden"), ==, 0); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 3); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Most Played"), ==, 1); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Least Played"), ==, 1); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 1); + + g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(0))); + g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(1))); + g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(2))); + g_assert_true( playlist_has(PL_SYSTEM, "Collection", track_get(0))); + g_assert_true( playlist_has(PL_SYSTEM, "Collection", track_get(1))); + g_assert_true( playlist_has(PL_SYSTEM, "Collection", track_get(2))); + g_assert_true( playlist_has(PL_SYSTEM, "Most Played", track_get(0))); + g_assert_true( playlist_has(PL_SYSTEM, "Least Played", track_get(1))); + g_assert_true( playlist_has(PL_SYSTEM, "Unplayed", track_get(2))); + + g_assert_true(playlist_remove(__test_pl_collection(), track_get(0))); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Hidden"), ==, 1); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 2); + g_assert_true (playlist_has(PL_SYSTEM, "Hidden", track_get(0))); + g_assert_false(playlist_has(PL_SYSTEM, "Collection", track_get(0))); +} + static void test_delete() { playlist_add(__test_pl_favorites(), track_get(0)); @@ -514,6 +543,7 @@ int main(int argc, char **argv) g_test_add_func("/Core/Playlists/System/Most Played Tracks", test_most_played); g_test_add_func("/Core/Playlists/System/Least Played Tracks", test_least_played); g_test_add_func("/Core/Playlists/System/Add Tracks", test_add); + g_test_add_func("/Core/Playlists/System/Remove Tracks", test_remove); g_test_add_func("/Core/Playlists/System/Delete", test_delete); g_test_add_func("/Core/PLaylists/System/Delete Tracks", test_delete_tracks); ret = g_test_run(); diff --git a/tests/core/playlists/user.c b/tests/core/playlists/user.c index 4fae53b6..4f1c1a0d 100644 --- a/tests/core/playlists/user.c +++ b/tests/core/playlists/user.c @@ -57,8 +57,8 @@ void test_user() g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 1); g_assert_true( playlist_has( PL_USER, "Test Playlist", track_get(0))); - g_assert_true( playlist_remove(PL_USER, "Test Playlist", track_get(0))); - g_assert_false(playlist_remove(PL_USER, "Test Playlist", track_get(0))); + g_assert_true( playlist_remove(playlist, track_get(0))); + g_assert_false(playlist_remove(playlist, track_get(0))); g_assert_false(playlist_has( PL_USER, "Test Playlist", track_get(0))); g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 0); diff --git a/tests/gui/model.c b/tests/gui/model.c index 0b837b85..911bc64a 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -163,7 +163,6 @@ static void test_empty() static void test_model() { GtkTreeModel *model = GTK_TREE_MODEL(gui_model_get()); - struct db_entry *dbe, *next; struct track *track; GtkTreePath *path; GtkTreeIter iter; @@ -180,6 +179,8 @@ static void test_model() /* Okay, now scan a directory ... */ playlist_get_queue(PL_SYSTEM, "Collection")->q_private = playlist_get(PL_SYSTEM, "Collection"); + playlist_get_queue(PL_SYSTEM, "Favorites")->q_private = + playlist_get(PL_SYSTEM, "Favorites"); playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task() == true) {} g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 13); @@ -280,9 +281,13 @@ static void test_model() g_assert_false(gtk_tree_model_iter_parent(model, &iter, &iter)); - db_for_each(dbe, next, track_db_get()) - playlist_remove(PL_SYSTEM, "Collection", TRACK(dbe)); + gui_model_set_playlist(playlist_get(PL_SYSTEM, "Favorites")); g_assert_cmpuint(count_delete, ==, 29); + g_assert_cmpuint(count_insert, ==, 16); + playlist_remove(playlist_get(PL_SYSTEM, "Favorites"), track_get(0)); + playlist_remove(playlist_get(PL_SYSTEM, "Favorites"), track_get(1)); + playlist_remove(playlist_get(PL_SYSTEM, "Favorites"), track_get(2)); + g_assert_cmpuint(count_delete, ==, 32); } int main(int argc, char **argv)