2016-04-24 10:36:15 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/idle.h>
|
2016-05-13 11:25:43 -04:00
|
|
|
#include <core/playlist.h>
|
2016-08-01 09:41:10 -04:00
|
|
|
#include <core/settings.h>
|
2016-04-24 10:36:15 -04:00
|
|
|
#include <core/tags/tags.h>
|
|
|
|
#include <tests/test.h>
|
|
|
|
|
|
|
|
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_favorites(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "Favorites"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_hidden(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "Hidden"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_queued(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "Queued Tracks"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_collection(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "Collection"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_history(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "History"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_unplayed(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "Unplayed"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_most_played(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "Most Played"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
static inline struct playlist *__test_pl_least_played(void)
|
2016-09-12 13:49:27 -04:00
|
|
|
{ return playlist_lookup(PL_SYSTEM, "Least Played"); }
|
2016-09-10 12:08:11 -04:00
|
|
|
|
2016-04-24 10:36:15 -04:00
|
|
|
|
2016-09-09 10:43:00 -04:00
|
|
|
static void test_init()
|
|
|
|
{
|
|
|
|
struct library *library = library_find("tests/Music");
|
2016-09-12 10:59:46 -04:00
|
|
|
struct playlist *playlist;
|
|
|
|
unsigned int i;
|
2016-09-09 10:43:00 -04:00
|
|
|
|
2016-09-12 16:02:46 -04:00
|
|
|
g_assert(playlist_current() == __test_pl_collection());
|
2016-09-12 13:08:24 -04:00
|
|
|
|
|
|
|
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);
|
2016-09-12 15:42:56 -04:00
|
|
|
g_assert_cmpuint(playlist->pl_id, ==, i);
|
2016-09-12 13:08:24 -04:00
|
|
|
g_assert_false(playlist_select(playlist));
|
2016-09-13 08:47:45 -04:00
|
|
|
|
|
|
|
if (i == SYS_PL_QUEUED || i == SYS_PL_HISTORY) {
|
|
|
|
g_assert_cmpuint(
|
|
|
|
g_slist_length(playlist->pl_queue.q_sort), ==, 0);
|
|
|
|
} else
|
|
|
|
g_assert_cmpuint(
|
|
|
|
g_slist_length(playlist->pl_queue.q_sort), ==, 3);
|
2016-09-12 13:08:24 -04:00
|
|
|
}
|
|
|
|
|
2016-09-09 10:43:00 -04:00
|
|
|
/* 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");
|
2016-09-13 10:59:20 -04:00
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/03 - Hyrule Field.ogg");
|
2016-09-09 10:43:00 -04:00
|
|
|
pl_system_new_track(track_get(0));
|
|
|
|
pl_system_new_track(track_get(1));
|
2016-09-13 10:59:20 -04:00
|
|
|
pl_system_new_track(track_get(2));
|
2016-09-09 10:43:00 -04:00
|
|
|
|
2016-09-09 08:35:52 -04:00
|
|
|
g_assert_null(playlist_new(PL_SYSTEM, "New Playlist"));
|
2016-09-12 10:59:46 -04:00
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
2016-09-12 15:42:56 -04:00
|
|
|
|
2016-09-12 10:59:46 -04:00
|
|
|
if (i == SYS_PL_COLLECTION || i == SYS_PL_UNPLAYED)
|
2016-09-13 10:59:20 -04:00
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 3);
|
2016-09-12 10:59:46 -04:00
|
|
|
else
|
|
|
|
g_assert_cmpuint(playlist_size(playlist), ==, 0);
|
|
|
|
}
|
2016-09-09 10:43:00 -04:00
|
|
|
}
|
|
|
|
|
2016-09-12 08:17:41 -04:00
|
|
|
static void test_random()
|
|
|
|
{
|
2016-09-12 10:59:46 -04:00
|
|
|
struct playlist *playlist;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
|
|
|
|
2016-09-19 10:55:29 -04:00
|
|
|
g_assert_false(playlist->pl_random);
|
2016-09-12 10:59:46 -04:00
|
|
|
playlist_set_random(playlist, true);
|
|
|
|
if (i == SYS_PL_HISTORY)
|
2016-09-19 10:55:29 -04:00
|
|
|
g_assert_false(playlist->pl_random);
|
2016-09-12 10:59:46 -04:00
|
|
|
else
|
2016-09-19 10:55:29 -04:00
|
|
|
g_assert_true(playlist->pl_random);
|
2016-09-12 10:59:46 -04:00
|
|
|
|
|
|
|
playlist_set_random(playlist, false);
|
2016-09-19 10:55:29 -04:00
|
|
|
g_assert_false(playlist->pl_random);
|
2016-09-12 10:59:46 -04:00
|
|
|
}
|
2016-09-12 08:17:41 -04:00
|
|
|
}
|
|
|
|
|
2016-09-12 09:49:35 -04:00
|
|
|
static void test_sort()
|
|
|
|
{
|
2016-09-12 10:59:46 -04:00
|
|
|
struct playlist *playlist;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
|
|
|
playlist = playlist_get(PL_SYSTEM, i);
|
2016-09-16 15:48:42 -04:00
|
|
|
playlist_clear_sort(playlist);
|
2016-09-12 10:59:46 -04:00
|
|
|
|
|
|
|
if (i == SYS_PL_HISTORY) {
|
2016-09-16 15:48:42 -04:00
|
|
|
g_assert_false(playlist_sort(playlist, COMPARE_TRACK));
|
2016-09-12 10:59:46 -04:00
|
|
|
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 0);
|
2016-09-16 15:48:42 -04:00
|
|
|
g_assert_false(playlist_sort(playlist, COMPARE_YEAR));
|
2016-09-12 10:59:46 -04:00
|
|
|
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 0);
|
|
|
|
} else {
|
2016-09-16 15:48:42 -04:00
|
|
|
g_assert_true(playlist_sort(playlist, COMPARE_TRACK));
|
2016-09-12 10:59:46 -04:00
|
|
|
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 1);
|
2016-09-16 15:48:42 -04:00
|
|
|
g_assert_true(playlist_sort(playlist, COMPARE_YEAR));
|
2016-09-12 10:59:46 -04:00
|
|
|
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 2);
|
|
|
|
}
|
|
|
|
}
|
2016-09-12 09:49:35 -04:00
|
|
|
}
|
|
|
|
|
2016-09-13 10:59:20 -04:00
|
|
|
static void test_played()
|
|
|
|
{
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_unplayed()), ==, 3);
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_most_played()), ==, 0);
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_least_played()), ==, 0);
|
|
|
|
|
|
|
|
track_played(track_get(0));
|
|
|
|
playlist_played(track_get(0));
|
|
|
|
while (idle_run_task()) {}
|
|
|
|
|
|
|
|
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()), ==, 1);
|
|
|
|
|
|
|
|
g_assert_true(playlist_has(__test_pl_least_played(), track_get(0)));
|
|
|
|
g_assert_true(playlist_has(__test_pl_unplayed(), track_get(1)));
|
|
|
|
g_assert_true(playlist_has(__test_pl_unplayed(), track_get(2)));
|
|
|
|
|
|
|
|
track_played(track_get(0));
|
|
|
|
track_played(track_get(0));
|
|
|
|
track_played(track_get(1));
|
|
|
|
playlist_played(track_get(0));
|
|
|
|
playlist_played(track_get(1));
|
|
|
|
while (idle_run_task()) {}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:08:11 -04:00
|
|
|
static void test_add()
|
2016-09-09 10:17:37 -04:00
|
|
|
{
|
2016-09-12 13:08:24 -04:00
|
|
|
struct playlist *playlist;
|
|
|
|
unsigned int i;
|
|
|
|
|
2016-09-10 12:08:11 -04:00
|
|
|
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)));
|
|
|
|
|
2016-09-10 14:31:43 -04:00
|
|
|
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);
|
2016-09-10 12:08:11 -04:00
|
|
|
|
2016-09-10 13:46:30 -04:00
|
|
|
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)));
|
2016-09-10 12:08:11 -04:00
|
|
|
|
|
|
|
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)));
|
|
|
|
|
2016-09-10 14:31:43 -04:00
|
|
|
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);
|
2016-09-10 12:08:11 -04:00
|
|
|
|
2016-09-10 13:46:30 -04:00
|
|
|
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)));
|
2016-09-12 13:08:24 -04:00
|
|
|
|
|
|
|
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));
|
2016-09-12 16:02:46 -04:00
|
|
|
g_assert(playlist_current() == playlist);
|
2016-09-12 13:08:24 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_false(playlist_select(playlist));
|
2016-09-12 16:02:46 -04:00
|
|
|
g_assert(playlist_current() != playlist);
|
2016-09-12 13:08:24 -04:00
|
|
|
}
|
|
|
|
}
|
2016-09-10 12:08:11 -04:00
|
|
|
}
|
|
|
|
|
2016-09-10 13:11:18 -04:00
|
|
|
static void test_remove()
|
|
|
|
{
|
2016-09-12 13:08:24 -04:00
|
|
|
struct playlist *playlist;
|
|
|
|
unsigned int i;
|
|
|
|
|
2016-09-10 13:11:18 -04:00
|
|
|
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)));
|
|
|
|
|
2016-09-10 14:31:43 -04:00
|
|
|
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);
|
2016-09-10 13:11:18 -04:00
|
|
|
|
2016-09-10 13:46:30 -04:00
|
|
|
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)));
|
2016-09-10 13:11:18 -04:00
|
|
|
|
|
|
|
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)));
|
|
|
|
|
2016-09-10 14:31:43 -04:00
|
|
|
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);
|
2016-09-10 13:11:18 -04:00
|
|
|
|
2016-09-10 13:46:30 -04:00
|
|
|
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)));
|
2016-09-10 13:11:18 -04:00
|
|
|
|
|
|
|
g_assert_true(playlist_remove(__test_pl_collection(), track_get(0)));
|
2016-09-10 14:31:43 -04:00
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_hidden()), ==, 1);
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 2);
|
2016-09-10 13:46:30 -04:00
|
|
|
g_assert_true (playlist_has(__test_pl_hidden(), track_get(0)));
|
|
|
|
g_assert_false(playlist_has(__test_pl_collection(), track_get(0)));
|
2016-09-12 13:08:24 -04:00
|
|
|
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));
|
2016-09-12 16:02:46 -04:00
|
|
|
g_assert(playlist_current() != playlist);
|
2016-09-12 13:08:24 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_true( playlist_select(playlist));
|
|
|
|
g_assert_false(playlist_select(playlist));
|
2016-09-12 16:02:46 -04:00
|
|
|
g_assert(playlist_current() == playlist);
|
2016-09-12 13:08:24 -04:00
|
|
|
}
|
|
|
|
}
|
2016-09-10 13:11:18 -04:00
|
|
|
}
|
|
|
|
|
2016-09-10 12:08:11 -04:00
|
|
|
static void test_delete()
|
|
|
|
{
|
2016-09-12 10:59:46 -04:00
|
|
|
unsigned int i;
|
|
|
|
|
2016-09-10 12:08:11 -04:00
|
|
|
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));
|
2016-09-09 10:17:37 -04:00
|
|
|
|
2016-09-12 10:59:46 -04:00
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++)
|
|
|
|
g_assert_false(playlist_delete(playlist_get(PL_SYSTEM, i)));
|
2016-09-09 10:17:37 -04:00
|
|
|
|
2016-09-10 14:31:43 -04:00
|
|
|
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);
|
2016-05-13 11:25:43 -04:00
|
|
|
}
|
2016-04-27 08:48:25 -04:00
|
|
|
|
2016-09-13 08:47:45 -04:00
|
|
|
static void test_next()
|
|
|
|
{
|
|
|
|
playlist_select(__test_pl_collection());
|
|
|
|
g_assert_cmpuint(playlist_next()->tr_track, ==, 1);
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 3);
|
|
|
|
g_assert_cmpuint(playlist_next()->tr_track, ==, 2);
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 3);
|
|
|
|
g_assert_cmpuint(playlist_next()->tr_track, ==, 3);
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 3);
|
|
|
|
g_assert_cmpuint(playlist_next()->tr_track, ==, 1);
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_collection()), ==, 3);
|
|
|
|
|
|
|
|
playlist_add(__test_pl_queued(), track_get(0));
|
|
|
|
playlist_add(__test_pl_queued(), track_get(1));
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 2);
|
|
|
|
g_assert(playlist_current() == __test_pl_queued());
|
|
|
|
|
|
|
|
g_assert(playlist_next() == track_get(0));
|
2016-09-20 10:00:12 -04:00
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 2);
|
|
|
|
playlist_selected(track_get(0));
|
2016-09-13 08:47:45 -04:00
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
|
|
|
g_assert(playlist_current() == __test_pl_queued());
|
|
|
|
|
|
|
|
g_assert(playlist_next() == track_get(1));
|
2016-09-20 10:00:12 -04:00
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 1);
|
|
|
|
playlist_selected(track_get(1));
|
2016-09-13 08:47:45 -04:00
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_queued()), ==, 0);
|
|
|
|
g_assert(playlist_current() == __test_pl_collection());
|
|
|
|
|
2016-09-21 08:15:47 -04:00
|
|
|
playlist_generic_clear(__test_pl_history());
|
2016-09-13 08:47:45 -04:00
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 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(2)));
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 3);
|
|
|
|
g_assert(playlist_prev() == track_get(1));
|
|
|
|
g_assert(playlist_prev() == track_get(0));
|
|
|
|
g_assert(playlist_prev() == track_get(2));
|
|
|
|
g_assert_cmpuint(playlist_size(__test_pl_history()), ==, 3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-09 10:43:00 -04:00
|
|
|
static void test_delete_tracks()
|
|
|
|
{
|
2016-09-12 10:59:46 -04:00
|
|
|
unsigned int i;
|
|
|
|
|
2016-09-10 12:08:11 -04:00
|
|
|
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)));
|
2016-09-09 10:43:00 -04:00
|
|
|
|
|
|
|
pl_system_delete_track(track_get(0));
|
|
|
|
pl_system_delete_track(track_get(1));
|
2016-09-09 10:17:37 -04:00
|
|
|
pl_system_delete_track(track_get(2));
|
2016-09-09 10:43:00 -04:00
|
|
|
|
2016-09-12 10:59:46 -04:00
|
|
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++)
|
|
|
|
g_assert_cmpuint(playlist_size(playlist_get(PL_SYSTEM, i)), ==, 0);
|
2016-09-09 10:43:00 -04:00
|
|
|
}
|
|
|
|
|
2016-05-13 11:25:43 -04:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
idle_init_sync();
|
2016-08-01 09:41:10 -04:00
|
|
|
settings_init();
|
2016-05-13 11:25:43 -04:00
|
|
|
tags_init();
|
2016-09-17 09:30:11 -04:00
|
|
|
playlist_init(NULL, NULL);
|
2016-05-13 11:25:43 -04:00
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
2016-09-09 10:43:00 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Init", test_init);
|
2016-09-12 08:17:41 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Random", test_random);
|
2016-09-12 09:49:35 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Sort", test_sort);
|
2016-09-13 10:59:20 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Played", test_played);
|
2016-09-10 12:08:11 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Add Tracks", test_add);
|
2016-09-10 13:11:18 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Remove Tracks", test_remove);
|
2016-09-09 10:17:37 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Delete", test_delete);
|
2016-09-13 08:47:45 -04:00
|
|
|
g_test_add_func("/Core/Playlists/System/Next", test_next);
|
2016-09-09 10:43:00 -04:00
|
|
|
g_test_add_func("/Core/PLaylists/System/Delete Tracks", test_delete_tracks);
|
2016-05-13 11:25:43 -04:00
|
|
|
ret = g_test_run();
|
2016-04-24 10:36:15 -04:00
|
|
|
|
2016-08-01 09:41:10 -04:00
|
|
|
playlist_deinit();
|
2016-05-19 12:35:54 -04:00
|
|
|
tags_deinit();
|
2016-08-01 09:41:10 -04:00
|
|
|
settings_deinit();
|
2016-05-19 12:35:54 -04:00
|
|
|
idle_deinit();
|
2016-05-13 11:25:43 -04:00
|
|
|
return ret;
|
2016-04-24 10:36:15 -04:00
|
|
|
}
|