2014-05-18 21:09:46 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-11-10 10:19:45 -05:00
|
|
|
extern "C" {
|
2015-09-29 16:25:16 -04:00
|
|
|
#include <core/filter.h>
|
2015-11-10 10:19:45 -05:00
|
|
|
}
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/library.h>
|
|
|
|
#include <core/playlist.h>
|
2014-12-02 08:16:22 -05:00
|
|
|
#include <core/tags/tags.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 Queue *Q_NULL = NULL;
|
|
|
|
|
|
|
|
static void test_init()
|
|
|
|
{
|
2015-10-21 10:41:42 -04:00
|
|
|
index_entry *ent;
|
2014-05-18 21:09:46 -04:00
|
|
|
Queue *q = playlist :: get_queue();
|
|
|
|
|
|
|
|
test_not_equal(q, Q_NULL);
|
|
|
|
test_equal(q->has_flag(Q_ENABLED), true);
|
|
|
|
test_equal(q->has_flag(Q_REPEAT), true);
|
|
|
|
test_equal(q->has_flag(Q_NO_SORT), true);
|
|
|
|
|
2014-06-06 08:20:15 -04:00
|
|
|
/* init should work even if playlist.db doesn't exist! */
|
|
|
|
playlist :: init();
|
|
|
|
|
2015-08-31 08:14:13 -04:00
|
|
|
test_cp_data_dir();
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2014-12-02 08:16:22 -05:00
|
|
|
tags :: init();
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: init();
|
2014-05-18 21:09:46 -04:00
|
|
|
playlist :: init();
|
|
|
|
|
|
|
|
ent = playlist :: get_tracks("Banned");
|
2015-10-21 15:57:21 -04:00
|
|
|
test_equal(set_size(&ent->ie_set), (size_t)4);
|
2015-10-23 10:21:12 -04:00
|
|
|
test_equal(collection :: get_queue()->size(), (unsigned)20);
|
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);
|
2014-05-18 21:09:46 -04:00
|
|
|
ent = playlist :: get_tracks("No Such Playlist");
|
|
|
|
test_equal(ent, IDX_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_queue()
|
|
|
|
{
|
|
|
|
Queue *q = playlist :: get_queue();
|
|
|
|
|
|
|
|
playlist :: select("Banned");
|
|
|
|
test_equal(q->size(), (unsigned)4);
|
|
|
|
|
|
|
|
playlist :: select("Favorites");
|
|
|
|
test_equal(q->size(), (unsigned)8);
|
2015-02-06 14:31:37 -05:00
|
|
|
|
|
|
|
playlist :: select("Unplayed");
|
|
|
|
test_equal(q->size(), (unsigned)3);
|
2015-02-06 15:08:31 -05:00
|
|
|
|
|
|
|
playlist :: select("Most Played");
|
|
|
|
test_equal(q->size(), (unsigned)10);
|
2015-02-06 15:32:59 -05:00
|
|
|
|
|
|
|
playlist :: select("Least Played");
|
|
|
|
test_equal(q->size(), (unsigned)12);
|
2014-05-18 21:09:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add()
|
|
|
|
{
|
2015-10-21 10:41:42 -04:00
|
|
|
index_entry *ent;
|
2014-05-18 21:09:46 -04:00
|
|
|
Queue *q = playlist :: get_queue();
|
2015-10-23 10:21:12 -04:00
|
|
|
Queue *l = collection :: get_queue();
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-02-06 14:31:37 -05:00
|
|
|
playlist :: select("Favorites");
|
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
playlist :: add(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)5);
|
2014-05-18 21:09:46 -04:00
|
|
|
test_equal(q->size(), (unsigned)8);
|
2014-05-24 13:31:45 -04:00
|
|
|
test_equal(l->size(), (unsigned)19);
|
2014-05-18 21:09:46 -04:00
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
playlist :: add(track_get(16), "Favorites");
|
|
|
|
playlist :: add(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)9);
|
2014-05-18 21:09:46 -04:00
|
|
|
test_equal(q->size(), (unsigned)9);
|
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
playlist :: add(track_get(6), "No Playlist");
|
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;
|
2014-05-18 21:09:46 -04:00
|
|
|
Queue *q = playlist :: get_queue();
|
2015-10-23 10:21:12 -04:00
|
|
|
Queue *l = collection :: 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);
|
2014-05-18 21:09:46 -04:00
|
|
|
test_equal(q->size(), (unsigned)9);
|
2014-05-24 13:31:45 -04:00
|
|
|
test_equal(l->size(), (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);
|
2014-05-18 21:09:46 -04:00
|
|
|
test_equal(q->size(), (unsigned)8);
|
|
|
|
|
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
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 24; i++) {
|
2015-09-28 15:54:21 -04:00
|
|
|
track = track_get(i);
|
2015-08-31 08:14:13 -04:00
|
|
|
test_loop_equal(playlist :: has(track, "Banned"),
|
|
|
|
(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-08-31 08:14:13 -04:00
|
|
|
test_loop_equal(playlist :: has(track, "Favorites"),
|
|
|
|
(i >= 16) ? true : false, i);
|
|
|
|
} test_loop_passed();
|
2014-05-18 21:09:46 -04:00
|
|
|
}
|
|
|
|
|
2015-08-31 08:14:13 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
|
|
|
UNIT_TEST("Playlist Init", 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),
|
|
|
|
);
|