169 lines
4.2 KiB
C++
169 lines
4.2 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
extern "C" {
|
|
#include <core/collection.h>
|
|
#include <core/filter.h>
|
|
#include <core/idle.h>
|
|
#include <core/tags/tags.h>
|
|
}
|
|
#include <core/playlist.h>
|
|
#include "test.h"
|
|
|
|
static void test_init()
|
|
{
|
|
queue *q = playlist_get_queue();
|
|
GSList *list;
|
|
|
|
filter_init();
|
|
tags_init();
|
|
collection_init(NULL);
|
|
playlist_init(NULL);
|
|
|
|
test_not_equal(q, NULL);
|
|
test_equal(queue_has_flag(q, Q_ENABLED), true);
|
|
test_equal(queue_has_flag(q, Q_REPEAT), true);
|
|
test_equal(queue_has_flag(q, Q_NO_SORT), true);
|
|
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. */
|
|
collection_add("tests/Music/Hyrule Symphony/");
|
|
while (idle_run_task());
|
|
}
|
|
|
|
static void test_add()
|
|
{
|
|
struct queue *c = collection_get_queue();
|
|
struct queue *q = playlist_get_queue();
|
|
struct track *track = track_get(0);
|
|
|
|
playlist_add(NULL, track);
|
|
test_equal(playlist_has(NULL, track), false);
|
|
|
|
playlist_add("Favorites", NULL);
|
|
test_equal(playlist_has("Favorites", NULL), false);
|
|
|
|
playlist_add("No Playlist", track);
|
|
test_equal(playlist_has("No Playlist", track), false);
|
|
|
|
test_equal(playlist_has("Favorites", track), false);
|
|
playlist_add("Favorites", track);
|
|
test_equal(playlist_has("Favorites", track), true);
|
|
test_equal(queue_size(q), 0);
|
|
|
|
playlist_select("Favorites");
|
|
test_equal(queue_size(q), 1);
|
|
playlist_add("Favorites", track);
|
|
test_equal(queue_size(q), 1);
|
|
playlist_add("Favorites", track_get(1));
|
|
test_equal(queue_size(q), 2);
|
|
|
|
track = track_get(2);
|
|
playlist_select("Banned");
|
|
test_equal(queue_size(q), 0);
|
|
test_equal(queue_size(c), 13);
|
|
test_equal(playlist_has("Banned", track), false);
|
|
playlist_add("Banned", track);
|
|
test_equal(playlist_has("Banned", track), true);
|
|
test_equal(queue_size(q), 1);
|
|
test_equal(queue_size(c), 12);
|
|
}
|
|
|
|
static void test_remove()
|
|
{
|
|
struct queue *c = collection_get_queue();
|
|
struct queue *q = playlist_get_queue();
|
|
struct track *track = track_get(0);
|
|
|
|
/* The important thing here is that we don't crash */
|
|
playlist_remove(NULL, track);
|
|
playlist_remove("Favorites", NULL);
|
|
playlist_remove("No Playlist", track);
|
|
|
|
playlist_select("Favorites");
|
|
test_equal(queue_size(q), 2);
|
|
test_equal(playlist_has("Favorites", track), true);
|
|
playlist_remove("Favorites", track);
|
|
test_equal(playlist_has("Favorites", track), false);
|
|
test_equal(queue_size(q), 1);
|
|
|
|
playlist_remove("Favorites", track);
|
|
test_equal(queue_size(q), 1);
|
|
playlist_remove("Favorites", track_get(1));
|
|
test_equal(queue_size(q), 0);
|
|
|
|
track = track_get(2);
|
|
playlist_select("Banned");
|
|
test_equal(queue_size(q), 1);
|
|
test_equal(queue_size(c), 12);
|
|
test_equal(playlist_has("Banned", track), true);
|
|
playlist_remove("Banned", track);
|
|
test_equal(playlist_has("Banned", track), false);
|
|
test_equal(queue_size(q), 0);
|
|
test_equal(queue_size(c), 13);
|
|
|
|
playlist_deinit();
|
|
collection_deinit();
|
|
tags_deinit();
|
|
filter_deinit();
|
|
}
|
|
|
|
static void test_queue()
|
|
{
|
|
queue *q = playlist_get_queue();
|
|
|
|
test_cp_data_dir();
|
|
filter_init();
|
|
tags_init();
|
|
collection_init(NULL);
|
|
playlist_init(NULL);
|
|
|
|
playlist_select(NULL);
|
|
playlist_select("Banned");
|
|
test_equal(queue_size(q), (unsigned)4);
|
|
|
|
playlist_select("Favorites");
|
|
test_equal(queue_size(q), (unsigned)8);
|
|
|
|
playlist_select("Unplayed");
|
|
test_equal(queue_size(q), (unsigned)3);
|
|
|
|
playlist_select("Most Played");
|
|
test_equal(queue_size(q), (unsigned)10);
|
|
|
|
playlist_select("Least Played");
|
|
test_equal(queue_size(q), (unsigned)12);
|
|
|
|
playlist_select("No Such Playlist");
|
|
test_equal(queue_size(q), (unsigned)12);
|
|
}
|
|
|
|
static void test_deinit()
|
|
{
|
|
struct queue *q = playlist_get_queue();
|
|
|
|
playlist_deinit();
|
|
collection_deinit();
|
|
tags_deinit();
|
|
filter_deinit();
|
|
|
|
test_equal(queue_size(q), 0);
|
|
test_equal(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 Queue", test_queue),
|
|
UNIT_TEST("Playlist Deinit", test_deinit),
|
|
);
|