157 lines
3.7 KiB
C++
157 lines
3.7 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
extern "C" {
|
|
#include <core/collection.h>
|
|
#include <core/filter.h>
|
|
#include <core/tags/tags.h>
|
|
}
|
|
#include <core/playlist.h>
|
|
#include "test.h"
|
|
|
|
static index_entry *IDX_NULL = NULL;
|
|
|
|
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);
|
|
|
|
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("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);
|
|
}
|
|
|
|
static void test_add()
|
|
{
|
|
index_entry *ent;
|
|
queue *q = playlist :: get_queue();
|
|
queue *l = collection_get_queue();
|
|
|
|
playlist :: select("Favorites");
|
|
|
|
playlist :: add(track_get(5), "Banned");
|
|
ent = playlist :: get_tracks("Banned");
|
|
test_equal(set_size(&ent->ie_set), (size_t)5);
|
|
test_equal(queue_size(q), (unsigned)8);
|
|
test_equal(queue_size(l), (unsigned)19);
|
|
|
|
playlist :: add(track_get(16), "Favorites");
|
|
playlist :: add(track_get(5), "Favorites");
|
|
ent = playlist :: get_tracks("Favorites");
|
|
test_equal(set_size(&ent->ie_set), (size_t)9);
|
|
test_equal(queue_size(q), (unsigned)9);
|
|
|
|
playlist :: add(track_get(6), "No Playlist");
|
|
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);
|
|
}
|
|
|
|
static void test_delete()
|
|
{
|
|
index_entry *ent;
|
|
queue *q = playlist :: get_queue();
|
|
queue *l = collection_get_queue();
|
|
|
|
playlist :: del(track_get(5), "Banned");
|
|
ent = playlist :: get_tracks("Banned");
|
|
test_equal(set_size(&ent->ie_set), (size_t)4);
|
|
test_equal(queue_size(q), (unsigned)9);
|
|
test_equal(queue_size(l), (unsigned)20);
|
|
|
|
playlist :: del(track_get(5), "Favorites");
|
|
ent = playlist :: get_tracks("Favorites");
|
|
test_equal(set_size(&ent->ie_set), (size_t)8);
|
|
test_equal(queue_size(q), (unsigned)8);
|
|
|
|
playlist :: del(track_get(6), "No Playlist");
|
|
test_equal(playlist :: get_tracks("No Playlist"), IDX_NULL);
|
|
}
|
|
|
|
|
|
static void test_has()
|
|
{
|
|
struct track *track;
|
|
|
|
test_equal(playlist_has("Favorites", NULL), false);
|
|
test_equal(playlist_has(NULL, track_get(0)), false);
|
|
|
|
for (unsigned int i = 0; i < 24; i++) {
|
|
track = track_get(i);
|
|
test_loop_equal(playlist_has("Banned", track),
|
|
(i <= 3) ? true : false, i);
|
|
} test_loop_passed();
|
|
|
|
for (unsigned int i = 0; i < 24; i++) {
|
|
track = track_get(i);
|
|
test_loop_equal(playlist_has("Favorites", track),
|
|
(i >= 16) ? true : false, i);
|
|
} test_loop_passed();
|
|
}
|
|
|
|
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 Queue", test_queue),
|
|
UNIT_TEST("Playlist Add", test_add),
|
|
UNIT_TEST("Playlist Delete", test_delete),
|
|
UNIT_TEST("Playlist Has", test_has),
|
|
UNIT_TEST("Playlist Deinit", test_deinit),
|
|
);
|