582 lines
24 KiB
C
582 lines
24 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(playlist_get(PL_SYSTEM, name), track)); \
|
|
else \
|
|
g_assert_false(playlist_has(playlist_get(PL_SYSTEM, name), track))
|
|
|
|
#define __test_playlist_state(name, ex_size, ex_track0, ex_track1) \
|
|
g_assert_cmpuint(playlist_size(playlist_get(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_add(name) \
|
|
__test_playlist_state(name, 0, false, false); \
|
|
g_assert_true( playlist_add(playlist_get(PL_SYSTEM, name), track_get(0))); \
|
|
g_assert_false(playlist_add(playlist_get(PL_SYSTEM, name), track_get(0))); \
|
|
g_assert_true( playlist_add(playlist_get(PL_SYSTEM, name), track_get(1))); \
|
|
g_assert_false(playlist_add(playlist_get(PL_SYSTEM, name), track_get(1))); \
|
|
__test_playlist_state(name, 2, true, true)
|
|
|
|
#define __test_playlist_remove(name) \
|
|
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) \
|
|
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(playlist_get(PL_SYSTEM, "Hidden"), track_get(0))); \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1); \
|
|
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(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) \
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "Hidden"))); \
|
|
__test_playlist_state("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); \
|
|
g_assert(playlist_cur() == playlist_get(PL_SYSTEM, name))
|
|
|
|
#define __test_playlist_noselect(name) \
|
|
do { \
|
|
unsigned int id = settings_get("core.playlist.cur.id"); \
|
|
struct playlist *cur = playlist_cur(); \
|
|
g_assert_false(playlist_select(PL_SYSTEM, name)); \
|
|
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, id); \
|
|
g_assert(playlist_cur() == cur); \
|
|
} 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()) {}; \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1); \
|
|
} while (0)
|
|
|
|
static inline struct playlist *__test_pl_favorites(void)
|
|
{ return playlist_get(PL_SYSTEM, "Favorites"); }
|
|
static inline struct playlist *__test_pl_hidden(void)
|
|
{ return playlist_get(PL_SYSTEM, "Hidden"); }
|
|
static inline struct playlist *__test_pl_queued(void)
|
|
{ return playlist_get(PL_SYSTEM, "Queued Tracks"); }
|
|
static inline struct playlist *__test_pl_collection(void)
|
|
{ return playlist_get(PL_SYSTEM, "Collection"); }
|
|
static inline struct playlist *__test_pl_history(void)
|
|
{ return playlist_get(PL_SYSTEM, "History"); }
|
|
static inline struct playlist *__test_pl_unplayed(void)
|
|
{ return playlist_get(PL_SYSTEM, "Unplayed"); }
|
|
static inline struct playlist *__test_pl_most_played(void)
|
|
{ return playlist_get(PL_SYSTEM, "Most Played"); }
|
|
static inline struct playlist *__test_pl_least_played(void)
|
|
{ return playlist_get(PL_SYSTEM, "Least Played"); }
|
|
|
|
|
|
static void test_init()
|
|
{
|
|
struct library *library = library_find("tests/Music");
|
|
|
|
/* Add tracks to the collection. */
|
|
track_add(library, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
|
|
track_add(library, "tests/Music/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
|
pl_system_new_track(track_get(0));
|
|
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);
|
|
}
|
|
|
|
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));
|
|
|
|
__test_playlist_noselect(NULL);
|
|
__test_playlist_noselect("Invalid");
|
|
|
|
playlist_update(PL_SYSTEM, NULL);
|
|
}
|
|
|
|
static void test_favorites()
|
|
{
|
|
struct queue *queue = playlist_get_queue(PL_SYSTEM, "Favorites");
|
|
|
|
g_assert_nonnull(queue);
|
|
g_assert_true(queue_has_flag(queue, Q_REPEAT));
|
|
|
|
__test_playlist_id("Favorites", SYS_PL_FAVORITES);
|
|
__test_playlist_noselect("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_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_true(queue_has_flag(queue, Q_REPEAT));
|
|
|
|
__test_playlist_id("Hidden", SYS_PL_HIDDEN);
|
|
__test_playlist_noselect("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_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_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_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(__test_pl_queued()), ==, 1);
|
|
playlist_select(PL_SYSTEM, "Collection");
|
|
g_assert(playlist_next() == track_get(0));
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
|
playlist_select(PL_SYSTEM, "Queued Tracks");
|
|
g_assert(playlist_next() == track_get(1));
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 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);
|
|
}
|
|
|
|
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_REPEAT));
|
|
|
|
__test_playlist_id("Collection", SYS_PL_COLLECTION);
|
|
__test_playlist_select("Collection", SYS_PL_COLLECTION);
|
|
__test_playlist_update("Collection", 2, true, true);
|
|
__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);
|
|
}
|
|
|
|
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_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);
|
|
|
|
__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)));
|
|
g_assert_true(playlist_add(__test_pl_history(), track_get(1)));
|
|
g_assert_true(playlist_add(__test_pl_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(__test_pl_history()), ==, 4);
|
|
g_assert_true(playlist_add(__test_pl_history(), track_get(1)));
|
|
g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 5);
|
|
g_assert(playlist_prev() == track_get(1));
|
|
|
|
__test_playlist_update("History", 5, true, true);
|
|
}
|
|
|
|
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_REPEAT));
|
|
|
|
__test_playlist_id("Unplayed", SYS_PL_UNPLAYED);
|
|
__test_playlist_noselect("Unplayed");
|
|
__test_playlist_reinit("Unplayed", 2, true, true);
|
|
|
|
track_get(1)->tr_count = 1;
|
|
__test_playlist_update("Unplayed", 1, true, false);
|
|
__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);
|
|
}
|
|
|
|
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_REPEAT));
|
|
|
|
__test_playlist_id("Most Played", SYS_PL_MOST_PLAYED);
|
|
__test_playlist_noselect("Most Played");
|
|
__test_playlist_reinit("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);
|
|
}
|
|
|
|
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_REPEAT));
|
|
|
|
__test_playlist_id("Least Played", SYS_PL_LEAST_PLAYED);
|
|
__test_playlist_noselect("Least Played");
|
|
__test_playlist_reinit("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);
|
|
|
|
track_get(0)->tr_count = 3;
|
|
track_get(1)->tr_count = 1;
|
|
__test_playlist_update("Least Played", 1, false, true);
|
|
__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");
|
|
track_add(library, "tests/Music/Hyrule Symphony/03 - Hyrule Field.ogg");
|
|
pl_system_new_track(track_get(2));
|
|
|
|
g_assert_true( playlist_add(__test_pl_favorites(), track_get(0)));
|
|
g_assert_false(playlist_add(__test_pl_favorites(), track_get(0)));
|
|
g_assert_true( playlist_add(__test_pl_queued(), track_get(0)));
|
|
g_assert_false(playlist_add(__test_pl_queued(), track_get(0)));
|
|
g_assert_true( playlist_add(__test_pl_history(), track_get(0)));
|
|
g_assert_true( playlist_add(__test_pl_history(), track_get(0)));
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_favorites()), ==, 1);
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
|
g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 2);
|
|
|
|
g_assert_true(playlist_has(__test_pl_favorites(), track_get(0)));
|
|
g_assert_true(playlist_has(__test_pl_queued(), track_get(0)));
|
|
g_assert_true(playlist_has(__test_pl_history(), track_get(0)));
|
|
|
|
g_assert_true( playlist_add(__test_pl_hidden(), track_get(0)));
|
|
g_assert_true( playlist_add(__test_pl_hidden(), track_get(1)));
|
|
g_assert_true( playlist_add(__test_pl_hidden(), track_get(2)));
|
|
g_assert_false(playlist_add(__test_pl_collection(), track_get(0)));
|
|
g_assert_false(playlist_add(__test_pl_collection(), track_get(1)));
|
|
g_assert_false(playlist_add(__test_pl_collection(), track_get(2)));
|
|
g_assert_false(playlist_add(__test_pl_most_played(), track_get(0)));
|
|
g_assert_false(playlist_add(__test_pl_least_played(), track_get(1)));
|
|
g_assert_false(playlist_add(__test_pl_unplayed(), track_get(2)));
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_hidden()), ==, 3);
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 0);
|
|
g_assert_cmpuint(playlist_size(__test_pl_most_played()), ==, 0);
|
|
g_assert_cmpuint(playlist_size(__test_pl_least_played()), ==, 0);
|
|
g_assert_cmpuint(playlist_size(__test_pl_unplayed()), ==, 0);
|
|
|
|
g_assert_true( playlist_has(__test_pl_hidden(), track_get(0)));
|
|
g_assert_true( playlist_has(__test_pl_hidden(), track_get(1)));
|
|
g_assert_true( playlist_has(__test_pl_hidden(), track_get(2)));
|
|
g_assert_false(playlist_has(__test_pl_collection(), track_get(0)));
|
|
g_assert_false(playlist_has(__test_pl_collection(), track_get(1)));
|
|
g_assert_false(playlist_has(__test_pl_collection(), track_get(2)));
|
|
g_assert_false(playlist_has(__test_pl_most_played(), track_get(0)));
|
|
g_assert_false(playlist_has(__test_pl_least_played(), track_get(1)));
|
|
g_assert_false(playlist_has(__test_pl_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(__test_pl_favorites()), ==, 0);
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 0);
|
|
g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 2);
|
|
|
|
g_assert_false(playlist_has(__test_pl_favorites(), track_get(0)));
|
|
g_assert_false(playlist_has(__test_pl_queued(), track_get(0)));
|
|
g_assert_true( playlist_has(__test_pl_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(__test_pl_hidden()), ==, 0);
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 3);
|
|
g_assert_cmpuint(playlist_size(__test_pl_most_played()), ==, 1);
|
|
g_assert_cmpuint(playlist_size(__test_pl_least_played()), ==, 1);
|
|
g_assert_cmpuint(playlist_size(__test_pl_unplayed()), ==, 1);
|
|
|
|
g_assert_false(playlist_has(__test_pl_hidden(), track_get(0)));
|
|
g_assert_false(playlist_has(__test_pl_hidden(), track_get(1)));
|
|
g_assert_false(playlist_has(__test_pl_hidden(), track_get(2)));
|
|
g_assert_true( playlist_has(__test_pl_collection(), track_get(0)));
|
|
g_assert_true( playlist_has(__test_pl_collection(), track_get(1)));
|
|
g_assert_true( playlist_has(__test_pl_collection(), track_get(2)));
|
|
g_assert_true( playlist_has(__test_pl_most_played(), track_get(0)));
|
|
g_assert_true( playlist_has(__test_pl_least_played(), track_get(1)));
|
|
g_assert_true( playlist_has(__test_pl_unplayed(), track_get(2)));
|
|
|
|
g_assert_true(playlist_remove(__test_pl_collection(), track_get(0)));
|
|
g_assert_cmpuint(playlist_size(__test_pl_hidden()), ==, 1);
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 2);
|
|
g_assert_true (playlist_has(__test_pl_hidden(), track_get(0)));
|
|
g_assert_false(playlist_has(__test_pl_collection(), track_get(0)));
|
|
}
|
|
|
|
static void test_delete()
|
|
{
|
|
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(playlist_get(PL_SYSTEM, "Favorites")));
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "Hidden")));
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "Queued Tracks")));
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "Collection")));
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "History")));
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "Unplayed")));
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "Most Played")));
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, "Least Played")));
|
|
|
|
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()), ==, 3);
|
|
g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 3);
|
|
g_assert_cmpuint(playlist_size(__test_pl_unplayed()), ==, 1);
|
|
g_assert_cmpuint(playlist_size(__test_pl_most_played()), ==, 1);
|
|
g_assert_cmpuint(playlist_size(__test_pl_least_played()), ==, 1);
|
|
}
|
|
|
|
static void test_delete_tracks()
|
|
{
|
|
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)));
|
|
|
|
pl_system_delete_track(track_get(0));
|
|
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);
|
|
}
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int ret;
|
|
|
|
idle_init_sync();
|
|
settings_init();
|
|
tags_init();
|
|
playlist_init(NULL);
|
|
while (idle_run_task()) {};
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
g_test_add_func("/Core/Playlists/System/Init", test_init);
|
|
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);
|
|
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);
|
|
g_test_add_func("/Core/PLaylists/System/Delete Tracks", test_delete_tracks);
|
|
ret = g_test_run();
|
|
|
|
playlist_deinit();
|
|
tags_deinit();
|
|
settings_deinit();
|
|
idle_deinit();
|
|
return ret;
|
|
}
|