diff --git a/core/playlist.c b/core/playlist.c index a2c5be58..ece18c67 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -92,6 +92,13 @@ struct playlist *playlist_lookup(enum playlist_type_t type, const gchar *name) return playlist_types[type]->pl_lookup(name); } +struct playlist *playlist_get(enum playlist_type_t type, unsigned int id) +{ + if (type >= PL_MAX_TYPE) + return NULL; + return playlist_types[type]->pl_get(id); +} + bool playlist_add(struct playlist *playlist, struct track *track) { bool ret; @@ -164,15 +171,14 @@ struct track *playlist_next(void) { enum playlist_type_t type = settings_get(SETTINGS_CUR_TYPE); unsigned int id = settings_get(SETTINGS_CUR_ID); - gchar *name = playlist_get_name(type, id); - struct track *track = playlist_types[type]->pl_next(name); + struct playlist *playlist = playlist_get(type, id); + struct track *track = playlist_types[type]->pl_next(playlist->pl_name); - if (playlist_size(playlist_lookup(type, name)) == 0) { + if (playlist_size(playlist) == 0) { settings_set(SETTINGS_CUR_ID, settings_get(SETTINGS_PREV_ID)); settings_set(SETTINGS_CUR_TYPE, settings_get(SETTINGS_PREV_TYPE)); } - g_free(name); return track; } @@ -185,11 +191,7 @@ struct playlist *playlist_cur(void) { enum playlist_type_t type = settings_get(SETTINGS_CUR_TYPE); unsigned int id = settings_get(SETTINGS_CUR_ID); - gchar *name = playlist_get_name(type, id); - struct playlist *ret = playlist_lookup(type, name); - - g_free(name); - return ret; + return playlist_get(type, id); } struct queue *playlist_get_queue(enum playlist_type_t type, const gchar *name) @@ -202,8 +204,3 @@ unsigned int playlist_get_id(enum playlist_type_t type, const gchar *name) { return playlist_types[type]->pl_get_id(name); } - -gchar *playlist_get_name(enum playlist_type_t type, unsigned int id) -{ - return playlist_types[type]->pl_get_name(id); -} diff --git a/core/playlists/artist.c b/core/playlists/artist.c index aa879593..87d04f5d 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -105,6 +105,12 @@ static struct playlist *pl_artist_lookup(const gchar *name) return __artist_pl_lookup(name); } +static struct playlist *pl_artist_get(unsigned int id) +{ + struct artist *artist = artist_get(id); + return artist ? artist->ar_playlist : NULL; +} + static unsigned int pl_artist_get_id(const gchar *name) { struct artist *artist = artist_lookup(name); @@ -117,12 +123,6 @@ static bool pl_artist_can_select(const gchar *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)); - return artist ? g_strdup(artist->ar_name) : NULL; -} - static void pl_artist_update(const gchar *name) { } @@ -139,8 +139,8 @@ static struct track *pl_artist_next(const gchar *name) struct playlist_type pl_artist = { .pl_save = pl_artist_save, .pl_lookup = pl_artist_lookup, + .pl_get = pl_artist_get, .pl_get_id = pl_artist_get_id, - .pl_get_name = pl_artist_get_name, .pl_can_select = pl_artist_can_select, .pl_update = pl_artist_update, .pl_next = pl_artist_next, diff --git a/core/playlists/library.c b/core/playlists/library.c index 882aca18..96a0aea9 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -222,18 +222,18 @@ static struct playlist *pl_library_lookup(const gchar *name) return __lib_pl_lookup(name); } +static struct playlist *pl_library_get(unsigned int id) +{ + struct library *library = LIBRARY(db_at(library_db_get(), id)); + return library ? library->li_playlist : NULL; +} + static unsigned int pl_library_get_id(const gchar *name) { struct library *library = library_find(name); return library ? library->li_dbe.dbe_index : -1; } -static gchar *pl_library_get_name(unsigned int id) -{ - struct library *library = LIBRARY(db_at(library_db_get(), 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); @@ -273,8 +273,8 @@ static struct track *pl_library_next(const gchar *name) struct playlist_type pl_library = { .pl_save = pl_library_save, .pl_lookup = pl_library_lookup, + .pl_get = pl_library_get, .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_update = pl_library_update, diff --git a/core/playlists/system.c b/core/playlists/system.c index f19382d4..1d166f13 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -6,8 +6,8 @@ #include static struct playlist *pl_system_lookup(const gchar *); +static struct playlist *pl_system_get(unsigned int); static void pl_system_update(const gchar *); -static inline struct queue *__sys_pl_queue(enum sys_playlist_t); static void __sys_pl_save(); static bool __sys_pl_load(); @@ -15,7 +15,6 @@ static struct file sys_file = FILE_INIT("playlist.db", 0); static struct file sys_deck_f = FILE_INIT("deck", 1); static struct file sys_collection_f = FILE_INIT("library.q", 0); static struct file sys_pl_file = FILE_INIT("playlist.system", 0); -static struct sys_playlist *sys_playlists[SYS_PL_NUM_PLAYLISTS]; /* @@ -67,7 +66,7 @@ static void sys_pl_load_full(struct playlist *playlist, struct file *file) static bool sys_pl_generic_add_front(struct playlist *playlist, struct track *track) { - if (queue_has(__sys_pl_queue(SYS_PL_HIDDEN), track)) + if (queue_has(&pl_system_get(SYS_PL_HIDDEN)->pl_queue, track)) return false; return playlist_generic_add_track_front(playlist, track); } @@ -100,28 +99,25 @@ static struct sys_playlist sys_favorites = { */ static bool sys_pl_hidden_add(struct playlist *playlist, struct track *track) { - bool ret = playlist_generic_add_track(pl_system_lookup("Hidden"), track); - playlist_generic_remove_track(pl_system_lookup("Collection"), track); - playlist_generic_remove_track(pl_system_lookup("Unplayed"), track); - playlist_generic_remove_track(pl_system_lookup("Most Played"), track); - playlist_generic_remove_track(pl_system_lookup("Least Played") , track); + bool ret = playlist_generic_add_track(pl_system_get(SYS_PL_HIDDEN), track); + playlist_generic_remove_track(pl_system_get(SYS_PL_COLLECTION), track); + playlist_generic_remove_track(pl_system_get(SYS_PL_UNPLAYED), track); + playlist_generic_remove_track(pl_system_get(SYS_PL_MOST_PLAYED), track); + playlist_generic_remove_track(pl_system_get(SYS_PL_LEAST_PLAYED), track); return ret; } static bool sys_pl_hidden_remove(struct playlist *playlist, struct track *track) { bool ret = playlist_generic_remove_track(playlist, track); - struct playlist *add; + unsigned int average = track_db_average_plays(); + unsigned int add_id = SYS_PL_LEAST_PLAYED; - if (track->tr_count == 0) - add = pl_system_lookup("Unplayed"); - else if (track->tr_count > track_db_average_plays()) - add = pl_system_lookup("Most Played"); - else - add = pl_system_lookup("Least Played"); + add_id = (track->tr_count == 0) ? SYS_PL_UNPLAYED : add_id; + add_id = (track->tr_count > average) ? SYS_PL_MOST_PLAYED : add_id; - playlist_generic_add_track(pl_system_lookup("Collection"), track); - playlist_generic_add_track(add, track); + playlist_generic_add_track(pl_system_get(SYS_PL_COLLECTION), track); + playlist_generic_add_track(pl_system_get(add_id), track); return ret; } @@ -161,8 +157,7 @@ static struct sys_playlist sys_hidden = { */ static bool sys_pl_queued_load() { - struct playlist *playlist = &sys_playlists[SYS_PL_QUEUED]->spl_playlist; - struct queue *queue = &playlist->pl_queue; + struct queue *queue = &pl_system_get(SYS_PL_QUEUED)->pl_queue; unsigned int num, i, flags = 0; if (!file_open(&sys_deck_f, OPEN_READ)) @@ -211,7 +206,7 @@ static struct sys_playlist sys_queued = { */ static bool sys_pl_collection_load() { - struct playlist *playlist = &sys_playlists[SYS_PL_COLLECTION]->spl_playlist; + struct playlist *playlist = pl_system_get(SYS_PL_COLLECTION); if (file_open(&sys_collection_f, OPEN_READ)) { queue_load_flags(&playlist->pl_queue, &sys_collection_f, false); @@ -389,11 +384,6 @@ static struct sys_playlist * __sys_pl_lookup(const gchar *name) return NULL; } -static inline struct queue *__sys_pl_queue(enum sys_playlist_t plist) -{ - return &sys_playlists[plist]->spl_playlist.pl_queue; -} - static void __sys_pl_save() { struct sys_playlist *sys_pl; @@ -484,24 +474,22 @@ static struct playlist *pl_system_lookup(const gchar *name) return sys_pl ? &sys_pl->spl_playlist : NULL; } +static struct playlist *pl_system_get(unsigned int id) +{ + return (id < SYS_PL_NUM_PLAYLISTS) ? &sys_playlists[id]->spl_playlist : NULL; +} + static unsigned int pl_system_get_id(const gchar *name) { unsigned int i; for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { - if (string_match(name, sys_playlists[i]->spl_playlist.pl_name)) + if (string_match(name, pl_system_get(i)->pl_name)) return i; } return SYS_PL_NUM_PLAYLISTS; } -static gchar *pl_system_get_name(unsigned int id) -{ - if (id < SYS_PL_NUM_PLAYLISTS) - return g_strdup(sys_playlists[id]->spl_playlist.pl_name); - return NULL; -} - static bool pl_system_can_select(const gchar *name) { struct sys_playlist *sys_pl = __sys_pl_lookup(name); @@ -530,8 +518,8 @@ static struct track *pl_system_next(const gchar *name) struct playlist_type pl_system = { .pl_save = pl_system_save, .pl_lookup = pl_system_lookup, + .pl_get = pl_system_get, .pl_get_id = pl_system_get_id, - .pl_get_name = pl_system_get_name, .pl_can_select = pl_system_can_select, .pl_update = pl_system_update, .pl_next = pl_system_next, @@ -553,10 +541,8 @@ void pl_system_init(struct queue_ops *ops) void pl_system_deinit() { - unsigned int i; - - for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) - queue_deinit(__sys_pl_queue(i)); + for (unsigned int i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) + queue_deinit(&pl_system_get(i)->pl_queue); } void pl_system_new_track(struct track *track) diff --git a/core/playlists/user.c b/core/playlists/user.c index 18b6b787..188a49a3 100644 --- a/core/playlists/user.c +++ b/core/playlists/user.c @@ -101,18 +101,18 @@ static struct playlist *pl_user_lookup(const gchar *name) return dbe ? &USER_PLAYLIST(dbe)->pl_playlist : NULL; } +static struct playlist *pl_user_get(unsigned int id) +{ + struct db_entry *dbe = db_at(&user_db, id); + return dbe ? &USER_PLAYLIST(dbe)->pl_playlist : NULL; +} + static unsigned int pl_user_get_id(const gchar *name) { struct db_entry *dbe = db_get(&user_db, name); return dbe ? dbe->dbe_index : -1; } -static gchar *pl_user_get_name(unsigned int id) -{ - struct db_entry *dbe = db_at(&user_db, id); - return dbe ? g_strdup(USER_PLAYLIST(dbe)->pl_playlist.pl_name) : NULL; -} - static bool pl_user_can_select(const gchar *name) { return db_get(&user_db, name) != NULL; @@ -144,8 +144,8 @@ static struct track *pl_user_next(const gchar *name) struct playlist_type pl_user = { .pl_save = pl_user_save, .pl_lookup = pl_user_lookup, + .pl_get = pl_user_get, .pl_get_id = pl_user_get_id, - .pl_get_name = pl_user_get_name, .pl_can_select = pl_user_can_select, .pl_new = pl_user_new, .pl_update = pl_user_update, diff --git a/include/core/playlist.h b/include/core/playlist.h index 440a9235..f39fbc33 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -35,8 +35,9 @@ struct playlist *playlist_new(enum playlist_type_t, const gchar *); bool playlist_delete(struct playlist *); -/* Called to look up playlists. */ +/* Called to look up playlists either by name or id. */ struct playlist *playlist_lookup(enum playlist_type_t, const gchar *); +struct playlist *playlist_get(enum playlist_type_t, unsigned int); /* Called to add a track to a playlist. */ @@ -82,7 +83,4 @@ struct queue *playlist_get_queue(enum playlist_type_t, const gchar *); /* Called to convert a playlist name to an integer id. */ unsigned int playlist_get_id(enum playlist_type_t, const gchar *); -/* Called to convert a playlist id to a name. */ -gchar *playlist_get_name(enum playlist_type_t, unsigned int); - #endif /* OCARINA_CORE_PLAYLIST_H */ diff --git a/include/core/playlists/type.h b/include/core/playlists/type.h index c7a15d72..11102ca5 100644 --- a/include/core/playlists/type.h +++ b/include/core/playlists/type.h @@ -61,13 +61,11 @@ struct playlist_type { /* Called to look up playlists. */ struct playlist *(*pl_lookup)(const gchar *); + struct playlist *(*pl_get)(unsigned int); /* Called to convert a playlist name to an integer id. */ unsigned int (*pl_get_id)(const gchar *); - /* 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 *); diff --git a/tests/core/playlist.c b/tests/core/playlist.c index ca6f85e6..b6f14871 100644 --- a/tests/core/playlist.c +++ b/tests/core/playlist.c @@ -12,7 +12,9 @@ static void test_null() g_assert_null(playlist_new(PL_MAX_TYPE, NULL)); g_assert_false(playlist_delete(NULL)); + g_assert_null(playlist_lookup(PL_MAX_TYPE, "NULL")); g_assert_null(playlist_lookup(PL_MAX_TYPE, NULL)); + g_assert_null(playlist_get(PL_MAX_TYPE, 0)); g_assert_false(playlist_add(NULL, NULL)); g_assert_false(playlist_add(NULL, track_get(0))); diff --git a/tests/core/playlists/artist.c b/tests/core/playlists/artist.c index 50ae266f..157d1eed 100644 --- a/tests/core/playlists/artist.c +++ b/tests/core/playlists/artist.c @@ -28,7 +28,6 @@ void test_artist() 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()) {}; playlist = playlist_lookup(PL_ARTIST, "Koji Kondo"); diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index b3761578..e9d6b90b 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -24,7 +24,6 @@ void test_library() 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); diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index c3eef1a1..ce9be8f0 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -10,7 +10,6 @@ #define __test_playlist_id(name, id) \ g_assert_cmpuint(playlist_get_id(PL_SYSTEM, name), ==, id); \ - g_assert_cmpstr_free(playlist_get_name(PL_SYSTEM, id), ==, name) #define __test_playlist_has(name, track, expected) \ if (expected) \ @@ -104,6 +103,8 @@ static inline struct playlist *__test_pl_least_played(void) static void test_init() { struct library *library = library_find("tests/Music"); + struct playlist *playlist; + unsigned int i; /* Add tracks to the collection. */ track_add(library, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg"); @@ -112,14 +113,16 @@ static void test_init() pl_system_new_track(track_get(1)); g_assert_null(playlist_new(PL_SYSTEM, "New Playlist")); - g_assert_cmpuint(playlist_size(__test_pl_favorites()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_hidden()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 2); - g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_unplayed()), ==, 2); - g_assert_cmpuint(playlist_size(__test_pl_most_played()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_least_played()), ==, 0); + for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { + playlist = playlist_get(PL_SYSTEM, i); + g_assert_nonnull(playlist); + g_assert(playlist_lookup(PL_SYSTEM, playlist->pl_name) == playlist); + + if (i == SYS_PL_COLLECTION || i == SYS_PL_UNPLAYED) + g_assert_cmpuint(playlist_size(playlist), ==, 2); + else + g_assert_cmpuint(playlist_size(playlist), ==, 0); + } } static void test_invalid() @@ -131,7 +134,6 @@ static void test_invalid() SYS_PL_NUM_PLAYLISTS); g_assert_cmpuint(playlist_get_id(PL_SYSTEM, "Invalid"), ==, SYS_PL_NUM_PLAYLISTS); - g_assert_null(playlist_get_name(PL_SYSTEM, SYS_PL_NUM_PLAYLISTS)); __test_playlist_noselect(NULL); __test_playlist_noselect("Invalid"); @@ -353,89 +355,44 @@ static void test_least_played() static void test_random() { - g_assert_false(playlist_get_random(__test_pl_favorites())); - g_assert_false(playlist_get_random(__test_pl_hidden())); - g_assert_false(playlist_get_random(__test_pl_queued())); - g_assert_false(playlist_get_random(__test_pl_collection())); - g_assert_false(playlist_get_random(__test_pl_history())); - g_assert_false(playlist_get_random(__test_pl_unplayed())); - g_assert_false(playlist_get_random(__test_pl_most_played())); - g_assert_false(playlist_get_random(__test_pl_least_played())); + struct playlist *playlist; + unsigned int i; - playlist_set_random(__test_pl_favorites(), true); - playlist_set_random(__test_pl_hidden(), true); - playlist_set_random(__test_pl_queued(), true); - playlist_set_random(__test_pl_collection(), true); - playlist_set_random(__test_pl_history(), true); - playlist_set_random(__test_pl_unplayed(), true); - playlist_set_random(__test_pl_most_played(), true); - playlist_set_random(__test_pl_least_played(), true); + for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { + playlist = playlist_get(PL_SYSTEM, i); - g_assert_true( playlist_get_random(__test_pl_favorites())); - g_assert_true( playlist_get_random(__test_pl_hidden())); - g_assert_true( playlist_get_random(__test_pl_queued())); - g_assert_true( playlist_get_random(__test_pl_collection())); - g_assert_false(playlist_get_random(__test_pl_history())); - g_assert_true( playlist_get_random(__test_pl_unplayed())); - g_assert_true( playlist_get_random(__test_pl_most_played())); - g_assert_true( playlist_get_random(__test_pl_least_played())); + g_assert_false(playlist_get_random(playlist_get(PL_SYSTEM, i))); + playlist_set_random(playlist, true); + if (i == SYS_PL_HISTORY) + g_assert_false(playlist_get_random(playlist)); + else + g_assert_true(playlist_get_random(playlist)); - playlist_set_random(__test_pl_favorites(), false); - playlist_set_random(__test_pl_hidden(), false); - playlist_set_random(__test_pl_queued(), false); - playlist_set_random(__test_pl_collection(), false); - playlist_set_random(__test_pl_history(), false); - playlist_set_random(__test_pl_unplayed(), false); - playlist_set_random(__test_pl_most_played(), false); - playlist_set_random(__test_pl_least_played(), false); - - g_assert_false(playlist_get_random(__test_pl_favorites())); - g_assert_false(playlist_get_random(__test_pl_hidden())); - g_assert_false(playlist_get_random(__test_pl_queued())); - g_assert_false(playlist_get_random(__test_pl_collection())); - g_assert_false(playlist_get_random(__test_pl_history())); - g_assert_false(playlist_get_random(__test_pl_unplayed())); - g_assert_false(playlist_get_random(__test_pl_most_played())); - g_assert_false(playlist_get_random(__test_pl_least_played())); + playlist_set_random(playlist, false); + g_assert_false(playlist_get_random(playlist)); + } } static void test_sort() { - g_assert_true( playlist_sort(__test_pl_favorites(), COMPARE_TRACK, true)); - g_assert_true( playlist_sort(__test_pl_hidden(), COMPARE_TRACK, true)); - g_assert_true( playlist_sort(__test_pl_queued(), COMPARE_TRACK, true)); - g_assert_true( playlist_sort(__test_pl_collection(), COMPARE_TRACK, true)); - g_assert_false(playlist_sort(__test_pl_history(), COMPARE_TRACK, true)); - g_assert_true( playlist_sort(__test_pl_unplayed(), COMPARE_TRACK, true)); - g_assert_true( playlist_sort(__test_pl_most_played(), COMPARE_TRACK, true)); - g_assert_true( playlist_sort(__test_pl_least_played(), COMPARE_TRACK, true)); + struct playlist *playlist; + unsigned int i; - g_assert_cmpuint(g_slist_length(__test_pl_favorites()->pl_queue.q_sort), ==, 1); - g_assert_cmpuint(g_slist_length(__test_pl_hidden()->pl_queue.q_sort), ==, 1); - g_assert_cmpuint(g_slist_length(__test_pl_queued()->pl_queue.q_sort), ==, 1); - g_assert_cmpuint(g_slist_length(__test_pl_collection()->pl_queue.q_sort), ==, 1); - g_assert_cmpuint(g_slist_length(__test_pl_history()->pl_queue.q_sort), ==, 0); - g_assert_cmpuint(g_slist_length(__test_pl_unplayed()->pl_queue.q_sort), ==, 1); - g_assert_cmpuint(g_slist_length(__test_pl_most_played()->pl_queue.q_sort), ==, 1); - g_assert_cmpuint(g_slist_length(__test_pl_least_played()->pl_queue.q_sort), ==, 1); + for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { + playlist = playlist_get(PL_SYSTEM, i); - g_assert_true( playlist_sort(__test_pl_favorites(), COMPARE_YEAR, false)); - g_assert_true( playlist_sort(__test_pl_hidden(), COMPARE_YEAR, false)); - g_assert_true( playlist_sort(__test_pl_queued(), COMPARE_YEAR, false)); - g_assert_true( playlist_sort(__test_pl_collection(), COMPARE_YEAR, false)); - g_assert_false(playlist_sort(__test_pl_history(), COMPARE_YEAR, false)); - g_assert_true( playlist_sort(__test_pl_unplayed(), COMPARE_YEAR, false)); - g_assert_true( playlist_sort(__test_pl_most_played(), COMPARE_YEAR, false)); - g_assert_true( playlist_sort(__test_pl_least_played(), COMPARE_YEAR, false)); - - g_assert_cmpuint(g_slist_length(__test_pl_favorites()->pl_queue.q_sort), ==, 2); - g_assert_cmpuint(g_slist_length(__test_pl_hidden()->pl_queue.q_sort), ==, 2); - g_assert_cmpuint(g_slist_length(__test_pl_queued()->pl_queue.q_sort), ==, 2); - g_assert_cmpuint(g_slist_length(__test_pl_collection()->pl_queue.q_sort), ==, 2); - g_assert_cmpuint(g_slist_length(__test_pl_history()->pl_queue.q_sort), ==, 0); - g_assert_cmpuint(g_slist_length(__test_pl_unplayed()->pl_queue.q_sort), ==, 2); - g_assert_cmpuint(g_slist_length(__test_pl_most_played()->pl_queue.q_sort), ==, 2); - g_assert_cmpuint(g_slist_length(__test_pl_least_played()->pl_queue.q_sort), ==, 2); + if (i == SYS_PL_HISTORY) { + g_assert_false(playlist_sort(playlist, COMPARE_TRACK, true)); + g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 0); + g_assert_false(playlist_sort(playlist, COMPARE_YEAR, false)); + g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 0); + } else { + g_assert_true(playlist_sort(playlist, COMPARE_TRACK, true)); + g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 1); + g_assert_true(playlist_sort(playlist, COMPARE_YEAR, false)); + g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 2); + } + } } static void test_add() @@ -534,20 +491,16 @@ static void test_remove() static void test_delete() { + unsigned int i; + playlist_add(__test_pl_favorites(), track_get(0)); playlist_add(__test_pl_hidden(), track_get(1)); playlist_add(__test_pl_hidden(), track_get(2)); playlist_add(__test_pl_queued(), track_get(0)); playlist_add(__test_pl_history(), track_get(0)); - g_assert_false(playlist_delete(__test_pl_favorites())); - g_assert_false(playlist_delete(__test_pl_hidden())); - g_assert_false(playlist_delete(__test_pl_queued())); - g_assert_false(playlist_delete(__test_pl_collection())); - g_assert_false(playlist_delete(__test_pl_history())); - g_assert_false(playlist_delete(__test_pl_unplayed())); - g_assert_false(playlist_delete(__test_pl_most_played())); - g_assert_false(playlist_delete(__test_pl_least_played())); + for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) + g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, i))); g_assert_cmpuint(playlist_size(__test_pl_favorites()), ==, 0); g_assert_cmpuint(playlist_size(__test_pl_hidden()), ==, 0); @@ -561,6 +514,8 @@ static void test_delete() static void test_delete_tracks() { + unsigned int i; + g_assert_true(playlist_add(__test_pl_favorites(), track_get(0))); g_assert_true(playlist_add(__test_pl_hidden(), track_get(1))); g_assert_true(playlist_add(__test_pl_queued(), track_get(0))); @@ -569,14 +524,8 @@ static void test_delete_tracks() pl_system_delete_track(track_get(1)); pl_system_delete_track(track_get(2)); - g_assert_cmpuint(playlist_size(__test_pl_favorites()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_hidden()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_unplayed()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_most_played()), ==, 0); - g_assert_cmpuint(playlist_size(__test_pl_least_played()), ==, 0); + for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) + g_assert_cmpuint(playlist_size(playlist_get(PL_SYSTEM, i)), ==, 0); } diff --git a/tests/core/playlists/user.c b/tests/core/playlists/user.c index 14f51413..e312c6f9 100644 --- a/tests/core/playlists/user.c +++ b/tests/core/playlists/user.c @@ -30,9 +30,6 @@ void test_user() g_assert_cmpuint(playlist_get_id(PL_USER, "No Playlist"), ==, (unsigned int)-1); - g_assert_cmpstr_free(playlist_get_name(PL_USER, 0), ==, "Test Playlist"); - g_assert_null(playlist_get_name(PL_USER, 1)); - g_assert(playlist_cur() != playlist_lookup(PL_USER, "Test Playlist")); g_assert_true( playlist_select(PL_USER, "Test Playlist")); g_assert(playlist_cur() == playlist_lookup(PL_USER, "Test Playlist"));