Anna Schumaker
419d31d4c3
This playlist has been the same as the hidden playlist for several releases now. Let's make the change official! Implements #28: Save hidden playlist as "hidden" instead of "banned" Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
429 lines
16 KiB
C
429 lines
16 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/idle.h>
|
|
#include <core/playlist.h>
|
|
#include <core/settings.h>
|
|
#include <core/tags/tags.h>
|
|
#include <tests/test.h>
|
|
|
|
|
|
#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) \
|
|
g_assert_true(playlist_has(PL_SYSTEM, name, track)); \
|
|
else \
|
|
g_assert_false(playlist_has(PL_SYSTEM, name, track))
|
|
|
|
#define __test_playlist_state(name, ex_size, ex_track0, ex_track1) \
|
|
g_assert_cmpuint(playlist_size(PL_SYSTEM, name), ==, ex_size); \
|
|
__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(PL_SYSTEM, name, track_get(0))); \
|
|
g_assert_false(playlist_add(PL_SYSTEM, name, track_get(0))); \
|
|
g_assert_true( playlist_add(PL_SYSTEM, name, track_get(1))); \
|
|
g_assert_false(playlist_add(PL_SYSTEM, name, track_get(1))); \
|
|
__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))); \
|
|
__test_playlist_state(name, 0, false, false)
|
|
|
|
#define __test_playlist_clear(name, ex_size, ex_track0, ex_track1) \
|
|
g_assert_false(playlist_delete(PL_SYSTEM, name)); \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1)
|
|
|
|
#define __test_playlist_update(name, ex_size, ex_track0, ex_track1) \
|
|
playlist_update(PL_SYSTEM, name); \
|
|
while (idle_run_task()) {}; \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1)
|
|
|
|
#define __test_playlist_hide_track(name, ex_size, ex_track0, ex_track1) \
|
|
g_assert_true(playlist_add(PL_SYSTEM, "Hidden", track_get(0))); \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1); \
|
|
g_assert_false(playlist_add(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))); \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1)
|
|
|
|
#define __test_playlist_clear_hidden(name, ex_size, ex_track0, ex_track1) \
|
|
__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; \
|
|
pl_system_deinit(); \
|
|
pl_system_init(NULL); \
|
|
queue = playlist_get_queue(PL_SYSTEM, name); \
|
|
g_assert_nonnull(queue); \
|
|
__test_playlist_state(name, 0, false, false); \
|
|
while (idle_run_task()) {}; \
|
|
g_assert_false(queue_has_flag(queue, Q_ADD_FRONT)); \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1); \
|
|
} while (0)
|
|
|
|
|
|
static void test_invalid()
|
|
{
|
|
g_assert_null(playlist_get_queue(PL_SYSTEM, NULL));
|
|
g_assert_null(playlist_get_queue(PL_SYSTEM, "Invalid"));
|
|
|
|
g_assert_cmpuint(playlist_get_id(PL_SYSTEM, NULL), ==,
|
|
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));
|
|
|
|
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)));
|
|
g_assert_false(playlist_delete(PL_SYSTEM, NULL));
|
|
g_assert_false(playlist_has(PL_SYSTEM, NULL, track_get(0)));
|
|
g_assert_cmpuint(playlist_size(PL_SYSTEM, NULL), ==, 0);
|
|
|
|
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()
|
|
{
|
|
struct queue *queue = playlist_get_queue(PL_SYSTEM, "Favorites");
|
|
|
|
g_assert_nonnull(queue);
|
|
g_assert_false(queue_has_flag(queue, Q_ADD_FRONT));
|
|
g_assert_true(queue_has_flag(queue, Q_REPEAT));
|
|
|
|
__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);
|
|
__test_playlist_reinit("Favorites", 0, false, false);
|
|
__test_playlist_add("Favorites");
|
|
__test_playlist_remove("Favorites");
|
|
}
|
|
|
|
static void test_hidden()
|
|
{
|
|
struct queue *queue = playlist_get_queue(PL_SYSTEM, "Hidden");
|
|
|
|
g_assert_nonnull(queue);
|
|
g_assert_null(playlist_get_queue(PL_SYSTEM, "Banned"));
|
|
g_assert_false(queue_has_flag(queue, Q_ADD_FRONT));
|
|
g_assert_true(queue_has_flag(queue, Q_REPEAT));
|
|
|
|
__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);
|
|
__test_playlist_reinit("Hidden", 0, false, false);
|
|
__test_playlist_add("Hidden");
|
|
__test_playlist_remove("Hidden");
|
|
}
|
|
|
|
static void test_queued()
|
|
{
|
|
struct queue *queue = playlist_get_queue(PL_SYSTEM, "Queued Tracks");
|
|
|
|
g_assert_nonnull(queue);
|
|
g_assert_false(queue_has_flag(queue, Q_ADD_FRONT));
|
|
g_assert_false(queue_has_flag(queue, Q_NO_SORT));
|
|
g_assert_false(queue_has_flag(queue, Q_REPEAT));
|
|
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_select("Queued Tracks", SYS_PL_QUEUED);
|
|
__test_playlist_reinit("Queued Tracks", 2, true, true);
|
|
|
|
g_assert(playlist_next() == track_get(0));
|
|
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 1);
|
|
playlist_select(PL_SYSTEM, "Collection");
|
|
g_assert(playlist_next() == track_get(0));
|
|
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 1);
|
|
playlist_select(PL_SYSTEM, "Queued Tracks");
|
|
g_assert(playlist_next() == track_get(1));
|
|
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 0);
|
|
g_assert(playlist_next() == track_get(1));
|
|
|
|
__test_playlist_add("Queued Tracks");
|
|
__test_playlist_remove("Queued Tracks");
|
|
__test_playlist_update("Queued Tracks", 0, false, false);
|
|
__test_playlist_add("Queued Tracks");
|
|
__test_playlist_clear("Queued Tracks", 0, false, false);
|
|
__test_playlist_reinit("Queued Tracks", 0, false, false);
|
|
}
|
|
|
|
static void test_collection()
|
|
{
|
|
struct queue *queue = playlist_get_queue(PL_SYSTEM, "Collection");
|
|
|
|
pl_system_deinit();
|
|
pl_system_init(NULL);
|
|
|
|
g_assert_nonnull(queue);
|
|
g_assert_true(queue_has_flag(queue, Q_ADD_FRONT));
|
|
g_assert_true(queue_has_flag(queue, Q_REPEAT));
|
|
|
|
__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);
|
|
__test_playlist_reinit("Collection", 1, false, true);
|
|
__test_playlist_update("Collection", 1, false, true);
|
|
__test_playlist_unhide_track("Collection", 2, true, true);
|
|
__test_playlist_hide_track("Collection", 1, false, true);
|
|
__test_playlist_clear_hidden("Collection", 2, true, true);
|
|
__test_playlist_clear("Collection", 2, true, true);
|
|
}
|
|
|
|
static void test_history()
|
|
{
|
|
struct queue *queue = playlist_get_queue(PL_SYSTEM, "History");
|
|
|
|
g_assert_nonnull(queue);
|
|
g_assert_true(queue_has_flag(queue, Q_ADD_FRONT));
|
|
g_assert_true(queue_has_flag(queue, Q_NO_SORT));
|
|
g_assert_true(queue_has_flag(queue, Q_REPEAT));
|
|
__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);
|
|
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(PL_SYSTEM, "History", track_get(0)));
|
|
g_assert_true(playlist_add(PL_SYSTEM, "History", track_get(0)));
|
|
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));
|
|
g_assert_cmpuint(playlist_size(PL_SYSTEM, "History"), ==, 4);
|
|
g_assert_true(playlist_add(PL_SYSTEM, "History", track_get(1)));
|
|
g_assert_cmpuint(playlist_size(PL_SYSTEM, "History"), ==, 5);
|
|
g_assert(playlist_prev() == track_get(1));
|
|
|
|
__test_playlist_clear("History", 5, true, true);
|
|
__test_playlist_remove("History");
|
|
__test_playlist_update("History", 0, false, false);
|
|
}
|
|
|
|
static void test_unplayed()
|
|
{
|
|
struct queue *queue = playlist_get_queue(PL_SYSTEM, "Unplayed");
|
|
|
|
pl_system_deinit();
|
|
pl_system_init(NULL);
|
|
|
|
g_assert_nonnull(queue);
|
|
g_assert_true(queue_has_flag(queue, Q_ADD_FRONT));
|
|
g_assert_true(queue_has_flag(queue, Q_REPEAT));
|
|
|
|
__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");
|
|
|
|
track_get(1)->tr_count = 1;
|
|
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;
|
|
__test_playlist_update("Unplayed", 1, false, true);
|
|
|
|
track_get(0)->tr_count = 0;
|
|
__test_playlist_update("Unplayed", 2, true, true);
|
|
|
|
__test_playlist_hide_track("Unplayed", 1, false, true);
|
|
__test_playlist_reinit("Unplayed", 1, false, true);
|
|
__test_playlist_update("Unplayed", 1, false, true);
|
|
__test_playlist_unhide_track("Unplayed", 2, true, true);
|
|
__test_playlist_hide_track("Unplayed", 1, false, true);
|
|
__test_playlist_clear_hidden("Unplayed", 2, true, true);
|
|
__test_playlist_clear("Unplayed", 2, true, true);
|
|
}
|
|
|
|
static void test_most_played()
|
|
{
|
|
struct queue *most = playlist_get_queue(PL_SYSTEM, "Most Played");
|
|
|
|
/* Set average = (4 / 2) = 2 */
|
|
track_played(track_get(0));
|
|
track_played(track_get(1));
|
|
track_played(track_get(1));
|
|
track_played(track_get(1));
|
|
|
|
pl_system_deinit();
|
|
pl_system_init(NULL);
|
|
|
|
g_assert_nonnull(most);
|
|
g_assert_true(queue_has_flag(most, Q_ADD_FRONT));
|
|
g_assert_true(queue_has_flag(most, Q_REPEAT));
|
|
|
|
__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);
|
|
|
|
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);
|
|
|
|
g_assert_false(playlist_add(PL_SYSTEM, "Most Played", track_get(0)));
|
|
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;
|
|
__test_playlist_update("Most Played", 1, true, false);
|
|
|
|
__test_playlist_hide_track("Most Played", 0, false, false);
|
|
__test_playlist_reinit("Most Played", 0, false, false);
|
|
__test_playlist_update("Most Played", 0, false, false);
|
|
__test_playlist_unhide_track("Most Played", 1, true, false);
|
|
__test_playlist_hide_track("Most Played", 0, false, false);
|
|
__test_playlist_clear_hidden("Most Played", 1, true, false);
|
|
__test_playlist_clear("Most Played", 1, true, false);
|
|
}
|
|
|
|
static void test_least_played()
|
|
{
|
|
struct queue *least = playlist_get_queue(PL_SYSTEM, "Least Played");
|
|
|
|
/* Reset playcounts so track 1 is "least played" */
|
|
track_get(0)->tr_count = 3;
|
|
track_get(1)->tr_count = 1;
|
|
|
|
pl_system_deinit();
|
|
pl_system_init(NULL);
|
|
|
|
g_assert_nonnull(least);
|
|
g_assert_true(queue_has_flag(least, Q_ADD_FRONT));
|
|
g_assert_true(queue_has_flag(least, Q_REPEAT));
|
|
|
|
__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);
|
|
|
|
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);
|
|
|
|
g_assert_false(playlist_add(PL_SYSTEM, "Least Played", track_get(0)));
|
|
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;
|
|
__test_playlist_update("Least Played", 1, true, false);
|
|
|
|
__test_playlist_hide_track("Least Played", 0, false, false);
|
|
__test_playlist_reinit("Least Played", 0, false, false);
|
|
__test_playlist_update("Least Played", 0, false, false);
|
|
__test_playlist_unhide_track("Least Played", 1, true, false);
|
|
__test_playlist_hide_track("Least Played", 0, false, false);
|
|
__test_playlist_clear_hidden("Least Played", 1, true, false);
|
|
__test_playlist_clear("Least Played", 1, true, false);
|
|
}
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
struct library *library;
|
|
int ret;
|
|
|
|
idle_init_sync();
|
|
settings_init();
|
|
tags_init();
|
|
playlist_init(NULL);
|
|
while (idle_run_task()) {};
|
|
|
|
/* Add tracks to the collection. */
|
|
library = library_find("tests/Music");
|
|
track_add(library, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
|
|
track_add(library, "tests/Music/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
g_test_add_func("/Core/Playlists/System/Invalid", test_invalid);
|
|
g_test_add_func("/Core/Playlists/System/Favorites", test_favorites);
|
|
g_test_add_func("/Core/Playlists/System/Hidden", test_hidden);
|
|
g_test_add_func("/Core/Playlists/System/Queued", test_queued);
|
|
g_test_add_func("/Core/Playlists/System/Collection", test_collection);
|
|
g_test_add_func("/Core/Playlists/System/History", test_history);
|
|
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);
|
|
ret = g_test_run();
|
|
|
|
playlist_deinit();
|
|
tags_deinit();
|
|
settings_deinit();
|
|
idle_deinit();
|
|
return ret;
|
|
}
|