2014-05-18 21:09:46 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-11-10 10:19:45 -05:00
|
|
|
extern "C" {
|
2015-12-07 09:35:58 -05:00
|
|
|
#include <core/collection.h>
|
2015-09-29 16:25:16 -04:00
|
|
|
#include <core/filter.h>
|
2015-12-10 08:26:51 -05:00
|
|
|
#include <core/idle.h>
|
2015-11-12 10:42:21 -05:00
|
|
|
#include <core/tags/tags.h>
|
2015-11-10 10:19:45 -05:00
|
|
|
}
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/playlist.h>
|
2015-08-31 08:14:13 -04:00
|
|
|
#include "test.h"
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-10-21 10:41:42 -04:00
|
|
|
static index_entry *IDX_NULL = NULL;
|
2014-05-18 21:09:46 -04:00
|
|
|
|
|
|
|
static void test_init()
|
|
|
|
{
|
2015-12-09 10:38:57 -05:00
|
|
|
queue *q = playlist_get_queue();
|
2015-12-09 08:11:21 -05:00
|
|
|
GSList *list;
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2015-11-12 10:24:27 -05:00
|
|
|
tags_init();
|
2015-12-05 08:55:24 -05:00
|
|
|
collection_init(NULL);
|
2015-12-09 08:11:21 -05:00
|
|
|
playlist_init(NULL);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-12-09 08:11:21 -05:00
|
|
|
test_not_equal(q, NULL);
|
2015-11-23 08:36:29 -05:00
|
|
|
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);
|
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. */
|
|
|
|
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);
|
|
|
|
|
2015-12-09 09:20:18 -05:00
|
|
|
playlist_deinit();
|
|
|
|
collection_deinit();
|
|
|
|
tags_deinit();
|
|
|
|
filter_deinit();
|
2014-05-18 21:09:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_queue()
|
|
|
|
{
|
2015-12-09 10:38:57 -05:00
|
|
|
queue *q = playlist_get_queue();
|
2015-12-09 09:20:18 -05:00
|
|
|
|
2015-12-09 08:11:21 -05:00
|
|
|
test_cp_data_dir();
|
2015-12-09 09:20:18 -05:00
|
|
|
filter_init();
|
|
|
|
tags_init();
|
|
|
|
collection_init(NULL);
|
|
|
|
playlist_init(NULL);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-12-09 09:55:55 -05:00
|
|
|
playlist_select(NULL);
|
|
|
|
playlist_select("Banned");
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)4);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-12-09 09:55:55 -05:00
|
|
|
playlist_select("Favorites");
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)8);
|
2015-02-06 14:31:37 -05:00
|
|
|
|
2015-12-09 09:55:55 -05:00
|
|
|
playlist_select("Unplayed");
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)3);
|
2015-02-06 15:08:31 -05:00
|
|
|
|
2015-12-09 09:55:55 -05:00
|
|
|
playlist_select("Most Played");
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)10);
|
2015-02-06 15:32:59 -05:00
|
|
|
|
2015-12-09 09:55:55 -05:00
|
|
|
playlist_select("Least Played");
|
|
|
|
test_equal(queue_size(q), (unsigned)12);
|
|
|
|
|
|
|
|
playlist_select("No Such Playlist");
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)12);
|
2014-05-18 21:09:46 -04:00
|
|
|
}
|
|
|
|
|
2015-12-10 08:26:51 -05:00
|
|
|
static void test_add_old()
|
2014-05-18 21:09:46 -04:00
|
|
|
{
|
2015-12-05 12:12:01 -05:00
|
|
|
queue *l = collection_get_queue();
|
2015-12-09 10:38:57 -05:00
|
|
|
queue *q = playlist_get_queue();
|
|
|
|
index_entry *ent;
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-12-09 09:55:55 -05:00
|
|
|
playlist_select("Favorites");
|
2015-02-06 14:31:37 -05:00
|
|
|
|
2015-12-10 08:26:51 -05:00
|
|
|
playlist_add("Banned", track_get(5));
|
2014-05-18 21:09:46 -04:00
|
|
|
ent = playlist :: get_tracks("Banned");
|
2015-10-21 15:57:21 -04:00
|
|
|
test_equal(set_size(&ent->ie_set), (size_t)5);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)8);
|
|
|
|
test_equal(queue_size(l), (unsigned)19);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-12-10 08:26:51 -05:00
|
|
|
playlist_add("Favorites", track_get(16));
|
|
|
|
playlist_add("Favorites", track_get(5));
|
2014-05-18 21:09:46 -04:00
|
|
|
ent = playlist :: get_tracks("Favorites");
|
2015-10-21 15:57:21 -04:00
|
|
|
test_equal(set_size(&ent->ie_set), (size_t)9);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)9);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-12-10 08:26:51 -05:00
|
|
|
playlist_add("No Playlist", track_get(6));
|
2014-05-18 21:09:46 -04:00
|
|
|
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_delete()
|
|
|
|
{
|
2015-10-21 10:41:42 -04:00
|
|
|
index_entry *ent;
|
2015-12-05 12:12:01 -05:00
|
|
|
queue *l = collection_get_queue();
|
2015-12-09 10:38:57 -05:00
|
|
|
queue *q = playlist_get_queue();
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
playlist :: del(track_get(5), "Banned");
|
2014-05-18 21:09:46 -04:00
|
|
|
ent = playlist :: get_tracks("Banned");
|
2015-10-21 15:57:21 -04:00
|
|
|
test_equal(set_size(&ent->ie_set), (size_t)4);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)9);
|
|
|
|
test_equal(queue_size(l), (unsigned)20);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
playlist :: del(track_get(5), "Favorites");
|
2014-05-18 21:09:46 -04:00
|
|
|
ent = playlist :: get_tracks("Favorites");
|
2015-10-21 15:57:21 -04:00
|
|
|
test_equal(set_size(&ent->ie_set), (size_t)8);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)8);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
playlist :: del(track_get(6), "No Playlist");
|
2014-05-18 21:09:46 -04:00
|
|
|
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);
|
|
|
|
}
|
|
|
|
|
2015-01-04 17:56:54 -05:00
|
|
|
|
2014-05-18 21:09:46 -04:00
|
|
|
static void test_has()
|
|
|
|
{
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *track;
|
2015-08-31 08:14:13 -04:00
|
|
|
|
2015-12-09 09:31:12 -05:00
|
|
|
test_equal(playlist_has("Favorites", NULL), false);
|
|
|
|
test_equal(playlist_has(NULL, track_get(0)), false);
|
|
|
|
|
2015-08-31 08:14:13 -04:00
|
|
|
for (unsigned int i = 0; i < 24; i++) {
|
2015-09-28 15:54:21 -04:00
|
|
|
track = track_get(i);
|
2015-12-09 09:31:12 -05:00
|
|
|
test_loop_equal(playlist_has("Banned", track),
|
2015-08-31 08:14:13 -04:00
|
|
|
(i <= 3) ? true : false, i);
|
|
|
|
} test_loop_passed();
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 24; i++) {
|
2015-09-28 15:54:21 -04:00
|
|
|
track = track_get(i);
|
2015-12-09 09:31:12 -05:00
|
|
|
test_loop_equal(playlist_has("Favorites", track),
|
2015-08-31 08:14:13 -04:00
|
|
|
(i >= 16) ? true : false, i);
|
|
|
|
} test_loop_passed();
|
2014-05-18 21:09:46 -04:00
|
|
|
}
|
|
|
|
|
2015-12-09 09:20:18 -05:00
|
|
|
static void test_deinit()
|
|
|
|
{
|
2015-12-09 10:38:57 -05:00
|
|
|
struct queue *q = playlist_get_queue();
|
2015-12-09 09:20:18 -05:00
|
|
|
|
|
|
|
playlist_deinit();
|
|
|
|
collection_deinit();
|
|
|
|
tags_deinit();
|
|
|
|
filter_deinit();
|
|
|
|
|
|
|
|
test_equal(queue_size(q), 0);
|
|
|
|
test_equal(q->q_sort, NULL);
|
|
|
|
}
|
|
|
|
|
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-08-31 08:14:13 -04:00
|
|
|
UNIT_TEST("Playlist Queue", test_queue),
|
2015-12-10 08:26:51 -05:00
|
|
|
UNIT_TEST("Playlist Add", test_add_old),
|
2015-08-31 08:14:13 -04:00
|
|
|
UNIT_TEST("Playlist Delete", test_delete),
|
|
|
|
UNIT_TEST("Playlist Has", test_has),
|
2015-12-09 09:20:18 -05:00
|
|
|
UNIT_TEST("Playlist Deinit", test_deinit),
|
2015-08-31 08:14:13 -04:00
|
|
|
);
|