584 lines
22 KiB
C
584 lines
22 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); \
|
|
|
|
#define __test_playlist_has(name, track, expected) \
|
|
if (expected) \
|
|
g_assert_true(playlist_has(playlist_lookup(PL_SYSTEM, name), track)); \
|
|
else \
|
|
g_assert_false(playlist_has(playlist_lookup(PL_SYSTEM, name), track))
|
|
|
|
#define __test_playlist_state(name, ex_size, ex_track0, ex_track1) \
|
|
g_assert_cmpuint(playlist_size(playlist_lookup(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_lookup(PL_SYSTEM, name), track_get(0))); \
|
|
g_assert_false(playlist_add(playlist_lookup(PL_SYSTEM, name), track_get(0))); \
|
|
g_assert_true( playlist_add(playlist_lookup(PL_SYSTEM, name), track_get(1))); \
|
|
g_assert_false(playlist_add(playlist_lookup(PL_SYSTEM, name), track_get(1))); \
|
|
__test_playlist_state(name, 2, true, true)
|
|
|
|
#define __test_playlist_remove(name) \
|
|
g_assert_true( playlist_remove(playlist_lookup(PL_SYSTEM, name), track_get(0))); \
|
|
g_assert_false(playlist_remove(playlist_lookup(PL_SYSTEM, name), track_get(0))); \
|
|
g_assert_true( playlist_remove(playlist_lookup(PL_SYSTEM, name), track_get(1))); \
|
|
g_assert_false(playlist_remove(playlist_lookup(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_lookup(PL_SYSTEM, "Hidden"), track_get(0))); \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1); \
|
|
g_assert_false(playlist_add(playlist_lookup(PL_SYSTEM, name), track_get(0)))
|
|
|
|
#define __test_playlist_unhide_track(name, ex_size, ex_track0, ex_track1) \
|
|
g_assert_true(playlist_remove(playlist_lookup(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_lookup(PL_SYSTEM, "Hidden"))); \
|
|
__test_playlist_state("Hidden", 0, false, false); \
|
|
__test_playlist_state(name, ex_size, ex_track0, ex_track1);
|
|
|
|
#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_lookup(PL_SYSTEM, "Favorites"); }
|
|
static inline struct playlist *__test_pl_hidden(void)
|
|
{ return playlist_lookup(PL_SYSTEM, "Hidden"); }
|
|
static inline struct playlist *__test_pl_queued(void)
|
|
{ return playlist_lookup(PL_SYSTEM, "Queued Tracks"); }
|
|
static inline struct playlist *__test_pl_collection(void)
|
|
{ return playlist_lookup(PL_SYSTEM, "Collection"); }
|
|
static inline struct playlist *__test_pl_history(void)
|
|
{ return playlist_lookup(PL_SYSTEM, "History"); }
|
|
static inline struct playlist *__test_pl_unplayed(void)
|
|
{ return playlist_lookup(PL_SYSTEM, "Unplayed"); }
|
|
static inline struct playlist *__test_pl_most_played(void)
|
|
{ return playlist_lookup(PL_SYSTEM, "Most Played"); }
|
|
static inline struct playlist *__test_pl_least_played(void)
|
|
{ return playlist_lookup(PL_SYSTEM, "Least Played"); }
|
|
|
|
|
|
static void test_init()
|
|
{
|
|
struct library *library = library_find("tests/Music");
|
|
struct playlist *playlist;
|
|
unsigned int i;
|
|
|
|
g_assert(playlist_cur() == __test_pl_collection());
|
|
|
|
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);
|
|
g_assert_false(playlist_select(playlist));
|
|
}
|
|
|
|
/* 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"));
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
|
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()
|
|
{
|
|
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);
|
|
|
|
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_add("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_add("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_add("Queued Tracks");
|
|
__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(__test_pl_collection());
|
|
g_assert(playlist_next() == track_get(0));
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
|
playlist_select(__test_pl_queued());
|
|
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_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_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);
|
|
|
|
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_reinit("Unplayed", 2, true, true);
|
|
|
|
track_get(1)->tr_count = 1;
|
|
__test_playlist_update("Unplayed", 1, true, false);
|
|
|
|
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_reinit("Most Played", 1, false, true);
|
|
|
|
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_reinit("Least Played", 1, false, true);
|
|
|
|
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()
|
|
{
|
|
struct playlist *playlist;
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
|
|
|
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(playlist, false);
|
|
g_assert_false(playlist_get_random(playlist));
|
|
}
|
|
}
|
|
|
|
static void test_sort()
|
|
{
|
|
struct playlist *playlist;
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
|
|
|
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()
|
|
{
|
|
struct library *library = library_find("tests/Music");
|
|
struct playlist *playlist;
|
|
unsigned int i;
|
|
|
|
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)));
|
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
|
|
|
switch (i) {
|
|
case SYS_PL_FAVORITES:
|
|
case SYS_PL_HIDDEN:
|
|
case SYS_PL_QUEUED:
|
|
g_assert_true( playlist_select(playlist));
|
|
g_assert_false(playlist_select(playlist));
|
|
g_assert(playlist_cur() == playlist);
|
|
break;
|
|
default:
|
|
g_assert_false(playlist_select(playlist));
|
|
g_assert(playlist_cur() != playlist);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void test_remove()
|
|
{
|
|
struct playlist *playlist;
|
|
unsigned int i;
|
|
|
|
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)));
|
|
g_assert_true(playlist_remove(__test_pl_hidden(), track_get(0)));
|
|
|
|
g_assert_true(playlist_select(__test_pl_least_played()));
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
|
|
|
switch (i) {
|
|
case SYS_PL_FAVORITES:
|
|
case SYS_PL_HIDDEN:
|
|
case SYS_PL_QUEUED:
|
|
case SYS_PL_HISTORY:
|
|
g_assert_false(playlist_select(playlist));
|
|
g_assert(playlist_cur() != playlist);
|
|
break;
|
|
default:
|
|
g_assert_true( playlist_select(playlist));
|
|
g_assert_false(playlist_select(playlist));
|
|
g_assert(playlist_cur() == playlist);
|
|
}
|
|
}
|
|
}
|
|
|
|
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));
|
|
|
|
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);
|
|
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()
|
|
{
|
|
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)));
|
|
|
|
pl_system_delete_track(track_get(0));
|
|
pl_system_delete_track(track_get(1));
|
|
pl_system_delete_track(track_get(2));
|
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++)
|
|
g_assert_cmpuint(playlist_size(playlist_get(PL_SYSTEM, i)), ==, 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/Sort", test_sort);
|
|
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;
|
|
}
|