core/playlist: playlist_{get,set}_random() take a playlist pointer

Additionally, playlist_set_random() uses a playlist-level function
pointer to decide what to do.  In most cases this will simply toggle the
flag, but the history playlist does not support random playback.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-09-12 08:17:41 -04:00
parent 0c1147513e
commit 61e3137131
15 changed files with 120 additions and 133 deletions

View File

@ -130,16 +130,17 @@ unsigned int playlist_size(struct playlist *playlist)
return playlist ? queue_size(&playlist->pl_queue) : 0;
}
void playlist_set_random(enum playlist_type_t type, const gchar *name,
bool enabled)
void playlist_set_random(struct playlist *playlist, bool enabled)
{
playlist_types[type]->pl_set_flag(name, Q_RANDOM, enabled);
if (playlist && playlist->pl_ops->pl_set_flag) {
playlist->pl_ops->pl_set_flag(playlist, Q_RANDOM, enabled);
playlist_types[playlist->pl_type]->pl_save();
}
}
bool playlist_get_random(enum playlist_type_t type, const gchar *name)
bool playlist_get_random(struct playlist *playlist)
{
struct queue *queue = playlist_get_queue(type, name);
return queue ? queue_has_flag(queue, Q_RANDOM) : false;
return playlist ? queue_has_flag(&playlist->pl_queue, Q_RANDOM) : false;
}
void playlist_sort(enum playlist_type_t type, const gchar *name,

View File

@ -8,7 +8,9 @@
static struct queue_ops *artist_ops = NULL;
static struct file artist_file = FILE_INIT("playlist.artist", 0);
static struct playlist_ops pl_artist_ops;
static struct playlist_ops pl_artist_ops = {
.pl_set_flag = playlist_generic_set_flag,
};
static struct playlist *__artist_pl_alloc(gchar *name)
@ -124,14 +126,6 @@ static void pl_artist_update(const gchar *name)
{
}
static void pl_artist_set_flag(const gchar *name, enum queue_flags flag,
bool enabled)
{
struct playlist *playlist = __artist_pl_lookup(name);
playlist_generic_set_flag(playlist, flag, enabled);
pl_artist_save();
}
static void pl_artist_sort(const gchar *name, enum compare_t sort, bool reset)
{
struct playlist *playlist = __artist_pl_lookup(name);
@ -155,7 +149,6 @@ struct playlist_type pl_artist = {
.pl_get_name = pl_artist_get_name,
.pl_can_select = pl_artist_can_select,
.pl_update = pl_artist_update,
.pl_set_flag = pl_artist_set_flag,
.pl_sort = pl_artist_sort,
.pl_next = pl_artist_next,
};

View File

@ -13,11 +13,6 @@ bool playlist_noop_can_select(struct playlist *playlist)
return false;
}
void playlist_noop_set_flag(struct playlist *playlist,
enum queue_flags flag, bool enabled)
{
}
void playlist_noop_sort(struct playlist *playlist,
enum compare_t sort, bool reset)
{

View File

@ -193,7 +193,8 @@ static bool pl_library_delete(struct playlist *playlist)
static struct playlist_ops pl_library_ops = {
.pl_delete = pl_library_delete,
.pl_delete = pl_library_delete,
.pl_set_flag = playlist_generic_set_flag,
};
@ -259,14 +260,6 @@ static void pl_library_update(const gchar *name)
idle_schedule(IDLE_SYNC, __lib_pl_update, playlist);
}
static void pl_library_set_flag(const gchar *name, enum queue_flags flag,
bool enabled)
{
struct playlist *playlist = __lib_pl_lookup(name);
playlist_generic_set_flag(playlist, flag, enabled);
pl_library_save();
}
static void pl_library_sort(const gchar *name, enum compare_t sort, bool reset)
{
struct playlist *playlist = __lib_pl_lookup(name);
@ -291,7 +284,6 @@ struct playlist_type pl_library = {
.pl_can_select = pl_library_can_select,
.pl_new = pl_library_new,
.pl_update = pl_library_update,
.pl_set_flag = pl_library_set_flag,
.pl_sort = pl_library_sort,
.pl_next = pl_library_next,
};

View File

@ -78,9 +78,10 @@ static bool sys_pl_generic_add_front(struct playlist *playlist,
* Favorite tracks playlist operations.
*/
static struct playlist_ops favorites_ops = {
.pl_add = playlist_generic_add_track,
.pl_delete = sys_pl_delete_clear,
.pl_remove = playlist_generic_remove_track,
.pl_add = playlist_generic_add_track,
.pl_delete = sys_pl_delete_clear,
.pl_remove = playlist_generic_remove_track,
.pl_set_flag = playlist_generic_set_flag,
};
static struct sys_playlist sys_favorites = {
@ -89,7 +90,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_set_flag = playlist_generic_set_flag,
.spl_sort = playlist_generic_sort,
.spl_next = playlist_generic_next,
};
@ -139,9 +139,10 @@ 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,
.pl_add = sys_pl_hidden_add,
.pl_delete = sys_pl_hidden_clear,
.pl_remove = sys_pl_hidden_remove,
.pl_set_flag = playlist_generic_set_flag,
};
static struct sys_playlist sys_hidden = {
@ -150,7 +151,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_set_flag = playlist_generic_set_flag,
.spl_sort = playlist_generic_sort,
.spl_next = playlist_generic_next,
};
@ -189,9 +189,10 @@ 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,
.pl_add = playlist_generic_add_track,
.pl_delete = sys_pl_delete_clear,
.pl_remove = playlist_generic_remove_track,
.pl_set_flag = playlist_generic_set_flag,
};
static struct sys_playlist sys_queued = {
@ -200,7 +201,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_set_flag = playlist_generic_set_flag,
.spl_sort = playlist_generic_sort,
.spl_next = playlist_generic_next,
};
@ -234,7 +234,8 @@ static bool sys_pl_collection_update(struct playlist *playlist,
}
static struct playlist_ops collection_ops = {
.pl_remove = sys_pl_hidden_add,
.pl_remove = sys_pl_hidden_add,
.pl_set_flag = playlist_generic_set_flag,
};
static struct sys_playlist sys_collection = {
@ -245,7 +246,6 @@ static struct sys_playlist sys_collection = {
.spl_load = sys_pl_load_partial,
.spl_can_select = sys_pl_collection_can_select,
.spl_update = sys_pl_collection_update,
.spl_set_flag = playlist_generic_set_flag,
.spl_sort = playlist_generic_sort,
.spl_next = playlist_generic_next,
};
@ -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_set_flag = playlist_noop_set_flag,
.spl_sort = playlist_noop_sort,
.spl_next = playlist_generic_next,
};
@ -294,7 +293,9 @@ static bool sys_pl_unplayed_update(struct playlist *playlist,
return sys_pl_generic_add_front(playlist, track) || true;
}
static struct playlist_ops unplayed_ops;
static struct playlist_ops unplayed_ops = {
.pl_set_flag = playlist_generic_set_flag,
};
static struct sys_playlist sys_unplayed = {
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed", &unplayed_ops),
@ -303,7 +304,6 @@ static struct sys_playlist sys_unplayed = {
.spl_load = sys_pl_load_partial,
.spl_can_select = playlist_generic_can_select,
.spl_update = sys_pl_unplayed_update,
.spl_set_flag = playlist_generic_set_flag,
.spl_sort = playlist_generic_sort,
.spl_next = playlist_generic_next,
};
@ -321,7 +321,9 @@ static bool sys_pl_most_played_update(struct playlist *playlist,
return sys_pl_generic_add_front(playlist, track) || true;
}
static struct playlist_ops most_played_ops;
static struct playlist_ops most_played_ops = {
.pl_set_flag = playlist_generic_set_flag,
};
static struct sys_playlist sys_most_played = {
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played",
@ -331,7 +333,6 @@ static struct sys_playlist sys_most_played = {
.spl_load = sys_pl_load_partial,
.spl_can_select = playlist_generic_can_select,
.spl_update = sys_pl_most_played_update,
.spl_set_flag = playlist_generic_set_flag,
.spl_sort = playlist_generic_sort,
.spl_next = playlist_generic_next,
};
@ -349,7 +350,9 @@ static bool sys_pl_least_played_update(struct playlist *playlist,
return sys_pl_generic_add_front(playlist, track) || true;
}
static struct playlist_ops least_played_ops;
static struct playlist_ops least_played_ops = {
.pl_set_flag = playlist_generic_set_flag,
};
static struct sys_playlist sys_least_played = {
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played",
@ -359,7 +362,6 @@ static struct sys_playlist sys_least_played = {
.spl_load = sys_pl_load_partial,
.spl_can_select = playlist_generic_can_select,
.spl_update = sys_pl_least_played_update,
.spl_set_flag = playlist_generic_set_flag,
.spl_sort = playlist_generic_sort,
.spl_next = playlist_generic_next,
};
@ -514,16 +516,6 @@ static void pl_system_update(const gchar *name)
playlist_generic_update(&sys_pl->spl_playlist, sys_pl->spl_update);
}
static void pl_system_set_flag(const gchar *name, enum queue_flags flag,
bool enabled)
{
struct sys_playlist *sys_pl = __sys_pl_lookup(name);
if (sys_pl) {
sys_pl->spl_set_flag(&sys_pl->spl_playlist, flag, enabled);
__sys_pl_save();
}
}
static void pl_system_sort(const gchar *name, enum compare_t sort, bool reset)
{
struct sys_playlist *sys_pl = __sys_pl_lookup(name);
@ -552,7 +544,6 @@ struct playlist_type pl_system = {
.pl_get_name = pl_system_get_name,
.pl_can_select = pl_system_can_select,
.pl_update = pl_system_update,
.pl_set_flag = pl_system_set_flag,
.pl_sort = pl_system_sort,
.pl_next = pl_system_next,
};

View File

@ -82,9 +82,10 @@ 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,
.pl_add = playlist_generic_add_track,
.pl_delete = pl_user_delete,
.pl_remove = playlist_generic_remove_track,
.pl_set_flag = playlist_generic_set_flag,
};
@ -135,14 +136,6 @@ static void pl_user_update(const gchar *name)
{
}
static void pl_user_set_flag(const gchar *name, enum queue_flags flag,
bool enabled)
{
struct playlist *playlist = __user_pl_lookup(name);
playlist_generic_set_flag(playlist, flag, enabled);
pl_user_save();
}
static void pl_user_sort(const gchar *name, enum compare_t sort, bool reset)
{
struct playlist *playlist = __user_pl_lookup(name);
@ -167,7 +160,6 @@ struct playlist_type pl_user = {
.pl_can_select = pl_user_can_select,
.pl_new = pl_user_new,
.pl_update = pl_user_update,
.pl_set_flag = pl_user_set_flag,
.pl_sort = pl_user_sort,
.pl_next = pl_user_next,
};

View File

@ -124,9 +124,8 @@ void __gui_sidebar_selection_changed(GtkTreeSelection *selection, gpointer data)
__gui_sidebar_filter_iter_convert(&iter, &child);
playlist = gui_sidebar_iter_playlist(&child);
active = playlist_get_random(playlist->pl_type,
playlist->pl_name);
sensitive = (playlist != playlist_get(PL_SYSTEM, "History"));
active = playlist_get_random(playlist);
sensitive = (playlist->pl_ops->pl_set_flag != NULL);
}
gui_treeview_set_playlist(playlist);
@ -163,10 +162,8 @@ void __gui_sidebar_random_toggled(GtkToggleButton *button, gpointer data)
struct playlist *playlist = gui_model_get_playlist();
bool active = gtk_toggle_button_get_active(button);
if (playlist) {
playlist_set_random(playlist->pl_type,
playlist->pl_name, active);
}
if (playlist)
playlist_set_random(playlist, active);
}
void gui_sidebar_init()

View File

@ -53,10 +53,10 @@ unsigned int playlist_size(struct playlist *);
/* Called to set the playlist's random flag. */
void playlist_set_random(enum playlist_type_t, const gchar *, bool);
void playlist_set_random(struct playlist *, bool);
/* Called to check the playlist's random flag. */
bool playlist_get_random(enum playlist_type_t, const gchar *);
bool playlist_get_random(struct playlist *);
/* Called to change the sort order of the playlist. */
void playlist_sort(enum playlist_type_t, const gchar *, enum compare_t, bool);

View File

@ -26,7 +26,6 @@ struct sys_playlist {
void (*spl_load)(struct playlist *, struct file *);
bool (*spl_can_select)(struct playlist *);
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);
struct track *(*spl_next)(struct playlist *);
};

View File

@ -29,6 +29,9 @@ struct playlist_ops {
/* Called to remove a track from the playlist. */
bool (*pl_remove)(struct playlist *, struct track *);
/* Called to set a playlist flag. */
void (*pl_set_flag)(struct playlist *, enum queue_flags, bool);
};
@ -71,9 +74,6 @@ struct playlist_type {
/* Called to update a playlist. */
void (*pl_update)(const gchar *);
/* Called to set a playlist flag. */
void (*pl_set_flag)(const gchar *, enum queue_flags, bool);
/* Called to sort a playlist. */
void (*pl_sort)(const gchar *, enum compare_t, bool);
@ -85,9 +85,6 @@ struct playlist_type {
/* Noop playlist can-select operation. */
bool playlist_noop_can_select(struct playlist *);
/* Noop playlist set_flag operation. */
void playlist_noop_set_flag(struct playlist *, enum queue_flags, bool);
/* Noop playlist sorting operation. */
void playlist_noop_sort(struct playlist *, enum compare_t, bool);

View File

@ -19,6 +19,10 @@ static void test_null()
g_assert_cmpuint(playlist_size(NULL), ==, 0);
g_assert_false(playlist_remove(NULL, NULL));
g_assert_false(playlist_remove(NULL, track_get(0)));
g_assert_false(playlist_get_random(NULL));
playlist_set_random(NULL, true);
g_assert_false(playlist_get_random(NULL));
}
int main(int argc, char **argv)

View File

@ -69,11 +69,11 @@ void test_library()
g_assert_false(playlist_remove(playlist, track_get(1)));
g_assert_cmpuint(playlist_size(playlist), ==, 48);
g_assert_false(playlist_get_random(PL_LIBRARY, "tests/Music"));
playlist_set_random(PL_LIBRARY, "tests/Music", true);
g_assert_true(playlist_get_random(PL_LIBRARY, "tests/Music"));
playlist_set_random(PL_LIBRARY, "tests/Music", false);
g_assert_false(playlist_get_random(PL_LIBRARY, "tests/Music"));
g_assert_false(playlist_get_random(playlist));
playlist_set_random(playlist, true);
g_assert_true(playlist_get_random(playlist));
playlist_set_random(playlist, false);
g_assert_false(playlist_get_random(playlist));
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 3);
playlist_sort(PL_LIBRARY, "tests/Music", COMPARE_ARTIST, true);

View File

@ -23,13 +23,6 @@
__test_playlist_has(name, track_get(0), ex_track0); \
__test_playlist_has(name, track_get(1), ex_track1)
#define __test_playlist_random(name) \
g_assert_false(playlist_get_random(PL_SYSTEM, name)); \
playlist_set_random(PL_SYSTEM, name, true); \
g_assert_true(playlist_get_random(PL_SYSTEM, name)); \
playlist_set_random(PL_SYSTEM, name, false); \
g_assert_false(playlist_get_random(PL_SYSTEM, name))
#define __test_playlist_add(name) \
__test_playlist_state(name, 0, false, false); \
g_assert_true( playlist_add(playlist_get(PL_SYSTEM, name), track_get(0))); \
@ -144,10 +137,6 @@ static void test_invalid()
__test_playlist_noselect("Invalid");
playlist_update(PL_SYSTEM, NULL);
g_assert_false(playlist_get_random(PL_SYSTEM, NULL));
playlist_set_random(PL_SYSTEM, NULL, true);
g_assert_false(playlist_get_random(PL_SYSTEM, NULL));
}
static void test_favorites()
@ -159,7 +148,6 @@ static void test_favorites()
__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);
@ -177,7 +165,6 @@ static void test_hidden()
__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);
@ -195,7 +182,6 @@ static void test_queued()
__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_select("Queued Tracks", SYS_PL_QUEUED);
__test_playlist_reinit("Queued Tracks", 2, true, true);
@ -227,7 +213,6 @@ static void test_collection()
__test_playlist_id("Collection", SYS_PL_COLLECTION);
__test_playlist_select("Collection", SYS_PL_COLLECTION);
__test_playlist_random("Collection");
__test_playlist_update("Collection", 2, true, true);
__test_playlist_hide_track("Collection", 1, false, true);
__test_playlist_reinit("Collection", 1, false, true);
@ -250,10 +235,6 @@ static void test_history()
playlist_sort(PL_SYSTEM, "History", COMPARE_TRACK, true);
g_assert_cmpuint(g_slist_length(queue->q_sort), ==, 0);
g_assert_false(playlist_get_random(PL_SYSTEM, "History"));
playlist_set_random(PL_SYSTEM, "History", true);
g_assert_false(playlist_get_random(PL_SYSTEM, "History"));
__test_playlist_state("History", 0, false, false);
g_assert_true(playlist_add(__test_pl_history(), track_get(0)));
g_assert_true(playlist_add(__test_pl_history(), track_get(0)));
@ -284,7 +265,6 @@ static void test_unplayed()
__test_playlist_id("Unplayed", SYS_PL_UNPLAYED);
__test_playlist_noselect("Unplayed");
__test_playlist_random("Unplayed");
__test_playlist_reinit("Unplayed", 2, true, true);
track_get(1)->tr_count = 1;
@ -324,7 +304,6 @@ static void test_most_played()
__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);
__test_playlist_select("Most Played", SYS_PL_MOST_PLAYED);
@ -356,7 +335,6 @@ static void test_least_played()
__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);
__test_playlist_select("Least Played", SYS_PL_LEAST_PLAYED);
@ -377,6 +355,54 @@ static void test_least_played()
__test_playlist_update("Most Played", 1, true, false);
}
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()));
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);
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()));
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()));
}
static void test_add()
{
struct library *library = library_find("tests/Music");
@ -540,6 +566,7 @@ int main(int argc, char **argv)
g_test_add_func("/Core/Playlists/System/Unplayed Tracks", test_unplayed);
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/Random", test_random);
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);

View File

@ -20,11 +20,11 @@ void test_user()
g_assert_null(playlist_new(PL_USER, "Test Playlist"));
g_assert_cmpuint(db->db_size, ==, 1);
g_assert_false(playlist_get_random(PL_USER, "Test Playlist"));
playlist_set_random(PL_USER, "Test Playlist", true);
g_assert_true(playlist_get_random(PL_USER, "Test Playlist"));
playlist_set_random(PL_USER, "Test Playlist", false);
g_assert_false(playlist_get_random(PL_USER, "Test Playlist"));
g_assert_false(playlist_get_random(playlist));
playlist_set_random(playlist, true);
g_assert_true(playlist_get_random(playlist));
playlist_set_random(playlist, false);
g_assert_false(playlist_get_random(playlist));
g_assert_cmpuint(playlist_get_id(PL_USER, "Test Playlist"), ==, 0);
g_assert_cmpuint(playlist_get_id(PL_USER, "No Playlist"), ==,

View File

@ -102,6 +102,7 @@ static void test_sidebar()
static void test_sidebar_selection()
{
struct playlist *collection;
GtkTreeSelection *selection;
GtkToggleButton *random;
GtkTreeModel *filter;
@ -109,9 +110,10 @@ static void test_sidebar_selection()
GtkTreeIter iter;
unsigned int i, n;
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
filter = GTK_TREE_MODEL(gui_sidebar_filter());
random = gui_random_button();
collection = playlist_get(PL_SYSTEM, "Collection");
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
filter = GTK_TREE_MODEL(gui_sidebar_filter());
random = gui_random_button();
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 6);
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
@ -121,7 +123,7 @@ static void test_sidebar_selection()
gtk_tree_model_filter_refilter(gui_sidebar_filter());
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 8);
playlist_set_random(PL_SYSTEM, "Collection", true);
playlist_set_random(collection, true);
g_assert_true(playlist_select(PL_SYSTEM, "Favorites"));
g_assert(playlist_cur() == playlist_get(PL_SYSTEM, "Favorites"));
@ -132,18 +134,15 @@ static void test_sidebar_selection()
n = gtk_tree_selection_count_selected_rows(selection);
g_assert_cmpuint(n, ==, (i < 2) ? 1 : 0);
if (i == 0) {
g_assert(gui_model_get_playlist() ==
playlist_get(PL_SYSTEM, "Collection"));
g_assert(gui_model_get_playlist() == collection);
g_assert_true(gtk_toggle_button_get_active(random));
g_assert_true(gtk_widget_get_sensitive(
GTK_WIDGET(random)));
gtk_toggle_button_set_active(random, false);
g_assert_false(
playlist_get_random(PL_SYSTEM, "Collection"));
g_assert_false(playlist_get_random(collection));
gtk_toggle_button_set_active(random, true);
g_assert_true(
playlist_get_random(PL_SYSTEM, "Collection"));
g_assert_true(playlist_get_random(collection));
} else if (i == 1) {
g_assert(gui_model_get_playlist() ==
playlist_get(PL_SYSTEM, "History"));