ocarina/tests/core/playlist.c

126 lines
4.5 KiB
C

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/filter.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
#include <tests/test.h>
static void test_init()
{
struct queue *q = playlist_get_queue("Most Played");
struct library *library;
GSList *list;
idle_init_sync();
filter_init();
tags_init();
playlist_init(NULL);
while (idle_run_task()) {};
test_not_equal((void *)playlist_get_queue("Favorites"), NULL);
test_not_equal((void *)playlist_get_queue("Hidden"), NULL);
test_not_equal((void *)playlist_get_queue("Unplayed"), NULL);
test_not_equal((void *)playlist_get_queue("Most Played"), NULL);
test_not_equal((void *)playlist_get_queue("Least Played"), NULL);
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);
test_equal(queue_has_flag(q, Q_NO_SORT), (bool)false);
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);
/* 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");
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");
}
static void test_add()
{
struct track *track = track_get(0);
test_equal(playlist_add("Favorites", NULL), (bool)false);
test_equal(playlist_has("Favorites", NULL), (bool)false);
test_equal(playlist_has("Favorites", track), (bool)false);
test_equal(playlist_add("Favorites", track), (bool)true);
test_equal(playlist_has("Favorites", track), (bool)true);
test_equal(playlist_size("Favorites"), 1);
test_equal(playlist_add("Favorites", track), (bool)false);
test_equal(playlist_size("Favorites"), 1);
test_equal(playlist_add("Favorites", track_get(1)), (bool)true);
test_equal(playlist_size("Favorites"), 2);
track = track_get(2);
test_equal(playlist_has("Hidden", track), (bool)false);
test_equal(playlist_add("Hidden", track), (bool)true);
test_equal(playlist_has("Hidden", track), (bool)true);
test_equal(playlist_size("Hidden"), 1);
}
static void test_remove()
{
struct track *track = track_get(0);
/* The important thing here is that we don't crash */
test_equal(playlist_remove("Favorites", NULL), (bool)false);
test_equal(playlist_size("Favorites"), 2);
test_equal(playlist_has("Favorites", track), (bool)true);
test_equal(playlist_remove("Favorites", track), (bool)true);
test_equal(playlist_has("Favorites", track), (bool)false);
test_equal(playlist_size("Favorites"), 1);
test_equal(playlist_remove("Favorites", track), (bool)false);
test_equal(playlist_size("Favorites"), 1);
test_equal(playlist_remove("Favorites", track_get(1)), (bool)true);
test_equal(playlist_size("Favorites"), 0);
track = track_get(2);
test_equal(playlist_size("Hidden"), 1);
test_equal(playlist_has("Hidden", track), (bool)true);
test_equal(playlist_remove("Hidden", track), (bool)true);
test_equal(playlist_has("Hidden", track), (bool)false);
test_equal(playlist_size("Hidden"), 0);
}
static void test_deinit()
{
struct queue *q = playlist_get_queue("Unplayed");
playlist_deinit();
tags_deinit();
filter_deinit();
test_equal(queue_size(q), 0);
test_equal((void *)q->q_sort, NULL);
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Playlist Initialization", test_init),
UNIT_TEST("Playlist Add Track", test_add),
UNIT_TEST("Playlist Remove Track", test_remove),
UNIT_TEST("Playlist Deinit", test_deinit),
);