2014-05-18 21:09:46 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-12-10 08:26:51 -05:00
|
|
|
#include <core/idle.h>
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/playlist.h>
|
2015-12-10 13:59:21 -05:00
|
|
|
#include <core/tags/tags.h>
|
|
|
|
#include <tests/test.h>
|
2014-05-18 21:09:46 -04:00
|
|
|
|
|
|
|
static void test_init()
|
|
|
|
{
|
2016-05-06 08:05:21 -04:00
|
|
|
struct queue *q = playlist_get_queue(PL_SYSTEM, "Most Played");
|
2015-12-11 09:21:10 -05:00
|
|
|
struct library *library;
|
2015-12-09 08:11:21 -05:00
|
|
|
GSList *list;
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2016-07-28 16:15:29 -04:00
|
|
|
idle_init_sync();
|
2015-11-12 10:24:27 -05:00
|
|
|
tags_init();
|
2015-12-09 08:11:21 -05:00
|
|
|
playlist_init(NULL);
|
2016-04-22 14:35:35 -04:00
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
2016-05-06 08:05:21 -04:00
|
|
|
test_not_equal((void *)playlist_get_queue(PL_SYSTEM, "Favorites"), NULL);
|
|
|
|
test_not_equal((void *)playlist_get_queue(PL_SYSTEM, "Hidden"), NULL);
|
|
|
|
test_not_equal((void *)playlist_get_queue(PL_SYSTEM, "Unplayed"), NULL);
|
|
|
|
test_not_equal((void *)playlist_get_queue(PL_SYSTEM, "Most Played"), NULL);
|
|
|
|
test_not_equal((void *)playlist_get_queue(PL_SYSTEM, "Least Played"), NULL);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-12-10 13:59:21 -05:00
|
|
|
test_not_equal((void *)q, NULL);
|
|
|
|
test_equal(queue_has_flag(q, Q_ENABLED), (bool)true);
|
|
|
|
test_equal(queue_has_flag(q, Q_REPEAT), (bool)true);
|
2016-04-27 08:10:25 -04:00
|
|
|
test_equal(queue_has_flag(q, Q_NO_SORT), (bool)false);
|
2015-12-09 08:11:21 -05:00
|
|
|
test_equal(queue_size(q), 0);
|
|
|
|
|
|
|
|
list = q->q_sort;
|
|
|
|
test_equal(g_slist_length(q->q_sort), 3);
|
|
|
|
test_equal(GPOINTER_TO_INT(list->data), COMPARE_ARTIST);
|
|
|
|
list = g_slist_next(list);
|
|
|
|
test_equal(GPOINTER_TO_INT(list->data), COMPARE_YEAR);
|
|
|
|
list = g_slist_next(list);
|
|
|
|
test_equal(GPOINTER_TO_INT(list->data), COMPARE_TRACK);
|
2015-12-09 09:20:18 -05:00
|
|
|
|
2015-12-10 08:26:51 -05:00
|
|
|
/* Add tracks to the collection. */
|
2015-12-11 09:21:10 -05:00
|
|
|
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");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/03 - Hyrule Field.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/04 - Hyrule Castle.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/05 - Lon Lon Ranch.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/06 - Kakariko Village.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/07 - Death Mountain.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/08 - Zora's Domain.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/09 - Gerudo Valley.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/10 - Ganondorf.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/11 - Princess Zelda.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/12 - Ocarina Medley.ogg");
|
|
|
|
track_add(library,
|
|
|
|
"tests/Music/Hyrule Symphony/13 - The Legend of Zelda Medley.ogg");
|
2015-12-10 08:26:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add()
|
|
|
|
{
|
|
|
|
struct track *track = track_get(0);
|
|
|
|
|
2016-05-06 08:05:21 -04:00
|
|
|
test_equal(playlist_add(PL_SYSTEM, "Favorites", NULL), (bool)false);
|
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Favorites", NULL), (bool)false);
|
2015-12-10 08:26:51 -05:00
|
|
|
|
2016-05-06 08:05:21 -04:00
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Favorites", track), (bool)false);
|
|
|
|
test_equal(playlist_add(PL_SYSTEM, "Favorites", track), (bool)true);
|
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Favorites", track), (bool)true);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Favorites"), 1);
|
|
|
|
test_equal(playlist_add(PL_SYSTEM, "Favorites", track), (bool)false);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Favorites"), 1);
|
|
|
|
test_equal(playlist_add(PL_SYSTEM, "Favorites", track_get(1)), (bool)true);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Favorites"), 2);
|
2015-12-10 08:26:51 -05:00
|
|
|
|
|
|
|
track = track_get(2);
|
2016-05-06 08:05:21 -04:00
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Hidden", track), (bool)false);
|
|
|
|
test_equal(playlist_add(PL_SYSTEM, "Hidden", track), (bool)true);
|
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Hidden", track), (bool)true);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Hidden"), 1);
|
2015-12-10 09:20:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_remove()
|
|
|
|
{
|
|
|
|
struct track *track = track_get(0);
|
|
|
|
|
|
|
|
/* The important thing here is that we don't crash */
|
2016-05-06 08:05:21 -04:00
|
|
|
test_equal(playlist_remove(PL_SYSTEM, "Favorites", NULL), (bool)false);
|
|
|
|
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Favorites"), 2);
|
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Favorites", track), (bool)true);
|
|
|
|
test_equal(playlist_remove(PL_SYSTEM, "Favorites", track), (bool)true);
|
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Favorites", track), (bool)false);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Favorites"), 1);
|
|
|
|
test_equal(playlist_remove(PL_SYSTEM, "Favorites", track), (bool)false);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Favorites"), 1);
|
|
|
|
test_equal(playlist_remove(PL_SYSTEM, "Favorites", track_get(1)), (bool)true);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Favorites"), 0);
|
2015-12-10 09:20:42 -05:00
|
|
|
|
|
|
|
track = track_get(2);
|
2016-05-06 08:05:21 -04:00
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Hidden"), 1);
|
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Hidden", track), (bool)true);
|
|
|
|
test_equal(playlist_remove(PL_SYSTEM, "Hidden", track), (bool)true);
|
|
|
|
test_equal(playlist_has(PL_SYSTEM, "Hidden", track), (bool)false);
|
|
|
|
test_equal(playlist_size(PL_SYSTEM, "Hidden"), 0);
|
2014-05-18 21:09:46 -04:00
|
|
|
}
|
|
|
|
|
2015-12-09 09:20:18 -05:00
|
|
|
static void test_deinit()
|
|
|
|
{
|
|
|
|
playlist_deinit();
|
|
|
|
tags_deinit();
|
|
|
|
}
|
|
|
|
|
2015-08-31 08:14:13 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
2015-12-09 08:11:21 -05:00
|
|
|
UNIT_TEST("Playlist Initialization", test_init),
|
2015-12-10 08:26:51 -05:00
|
|
|
UNIT_TEST("Playlist Add Track", test_add),
|
2015-12-10 09:20:42 -05:00
|
|
|
UNIT_TEST("Playlist Remove Track", test_remove),
|
2015-12-09 09:20:18 -05:00
|
|
|
UNIT_TEST("Playlist Deinit", test_deinit),
|
2015-08-31 08:14:13 -04:00
|
|
|
);
|