2013-12-22 22:21:19 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/deck.h>
|
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-12 09:04:25 -05:00
|
|
|
#include <core/history.h>
|
2015-12-13 09:27:52 -05:00
|
|
|
#include <core/idle.h>
|
2015-12-11 09:21:10 -05:00
|
|
|
#include <core/playlist.h>
|
2015-11-12 10:42:21 -05:00
|
|
|
#include <core/tags/tags.h>
|
2015-11-10 10:19:45 -05:00
|
|
|
}
|
2015-08-31 08:17:07 -04:00
|
|
|
#include "test.h"
|
2014-05-26 19:10:24 -04:00
|
|
|
|
2015-11-16 09:12:15 -05:00
|
|
|
static queue *Q_NULL = NULL;
|
2014-05-26 19:10:24 -04:00
|
|
|
|
2014-05-26 22:20:07 -04:00
|
|
|
static void test_init()
|
2014-05-26 19:10:24 -04:00
|
|
|
{
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2015-11-12 10:24:27 -05:00
|
|
|
tags_init();
|
2015-12-11 09:21:10 -05:00
|
|
|
playlist_init(NULL);
|
2015-12-05 08:55:24 -05:00
|
|
|
collection_init(NULL);
|
2015-12-12 09:18:26 -05:00
|
|
|
history_init(NULL);
|
2014-05-26 22:20:07 -04:00
|
|
|
|
2015-12-13 09:27:52 -05:00
|
|
|
test_equal(deck :: next(), NULL);
|
|
|
|
tempq_init(NULL);
|
|
|
|
test_equal(deck :: next(), NULL);
|
|
|
|
test_equal(deck :: get(0), NULL);
|
|
|
|
test_equal(deck :: index(NULL), 0);
|
|
|
|
test_equal(deck :: get_queues().size(), (size_t)0);
|
2015-12-14 09:05:54 -05:00
|
|
|
}
|
2013-12-22 22:21:19 -05:00
|
|
|
|
2015-12-14 09:05:54 -05:00
|
|
|
static void test_tempq()
|
|
|
|
{
|
|
|
|
struct queue *q0, *q1;
|
|
|
|
|
|
|
|
q0 = tempq_alloc(NULL, 0);
|
|
|
|
test_not_equal(q0, NULL);
|
|
|
|
test_equal(queue_has_flag(q0, Q_ENABLED), true);
|
|
|
|
test_equal(queue_has_flag(q0, Q_RANDOM), false);
|
|
|
|
test_equal(queue_has_flag(q0, Q_SAVE_SORT), true);
|
|
|
|
test_equal(queue_has_flag(q0, Q_SAVE_FLAGS), true);
|
|
|
|
|
|
|
|
q1 = tempq_alloc(NULL, Q_RANDOM);
|
|
|
|
test_not_equal(q1, NULL);
|
|
|
|
test_equal(queue_has_flag(q1, Q_ENABLED), true);
|
|
|
|
test_equal(queue_has_flag(q1, Q_RANDOM), true);
|
|
|
|
test_equal(queue_has_flag(q1, Q_SAVE_SORT), true);
|
|
|
|
test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), true);
|
|
|
|
|
|
|
|
deck :: destroy(q0);
|
|
|
|
deck :: destroy(q1);
|
2015-12-13 09:27:52 -05:00
|
|
|
history_deinit();
|
|
|
|
collection_deinit();
|
|
|
|
playlist_deinit();
|
|
|
|
tags_deinit();
|
|
|
|
filter_deinit();
|
2013-12-22 22:21:19 -05:00
|
|
|
}
|
2014-05-26 22:20:07 -04:00
|
|
|
|
|
|
|
static void test_create_mv_destroy()
|
2013-12-22 22:21:19 -05:00
|
|
|
{
|
2015-11-16 09:12:15 -05:00
|
|
|
queue *q1, *q2;
|
2014-05-26 22:20:07 -04:00
|
|
|
|
2015-12-13 09:27:52 -05:00
|
|
|
test_cp_data_dir();
|
|
|
|
filter_init();
|
|
|
|
tags_init();
|
|
|
|
playlist_init(NULL);
|
|
|
|
collection_init(NULL);
|
|
|
|
history_init(NULL);
|
|
|
|
tempq_init(NULL);
|
|
|
|
|
2015-12-14 09:05:54 -05:00
|
|
|
q1 = tempq_alloc(NULL, Q_RANDOM);
|
2014-05-26 22:20:07 -04:00
|
|
|
test_not_equal(q1, Q_NULL);
|
2015-11-20 08:18:54 -05:00
|
|
|
test_equal(queue_has_flag(q1, Q_ENABLED), true);
|
|
|
|
test_equal(queue_has_flag(q1, Q_RANDOM), true);
|
2014-05-26 22:20:07 -04:00
|
|
|
test_equal(deck :: index(q1), (unsigned)2);
|
2014-06-05 11:04:55 -04:00
|
|
|
test_equal(deck :: get(2), q1);
|
2014-05-26 22:20:07 -04:00
|
|
|
|
2015-12-14 09:05:54 -05:00
|
|
|
q2 = tempq_alloc(NULL, 0);
|
2014-05-26 22:20:07 -04:00
|
|
|
test_not_equal(q2, Q_NULL);
|
2015-11-20 08:18:54 -05:00
|
|
|
test_equal(queue_has_flag(q2, Q_ENABLED), true);
|
|
|
|
test_equal(queue_has_flag(q2, Q_RANDOM), false);
|
2014-05-26 22:20:07 -04:00
|
|
|
test_equal(deck :: index(q2), (unsigned)3);
|
2014-06-05 11:04:55 -04:00
|
|
|
test_equal(deck :: get(3), q2);
|
2014-05-26 22:20:07 -04:00
|
|
|
|
|
|
|
deck :: move(q1, 3);
|
|
|
|
test_equal(deck :: index(q1), (unsigned)3);
|
|
|
|
deck :: move(q1, 3);
|
|
|
|
test_equal(deck :: index(q1), (unsigned)3);
|
|
|
|
deck :: move(q1, 2);
|
|
|
|
test_equal(deck :: index(q1), (unsigned)2);
|
|
|
|
|
|
|
|
deck :: destroy(q1);
|
|
|
|
test_equal(deck :: index(q1), (unsigned)3);
|
|
|
|
test_equal(deck :: index(q2), (unsigned)2);
|
|
|
|
|
|
|
|
deck :: destroy(q2);
|
|
|
|
test_equal(deck :: index(q2), (unsigned)2);
|
2014-06-05 11:04:55 -04:00
|
|
|
|
|
|
|
test_equal(deck :: get(3), Q_NULL);
|
2013-12-22 22:21:19 -05:00
|
|
|
}
|
|
|
|
|
2014-05-26 22:20:07 -04:00
|
|
|
static void test_next_prev()
|
2013-12-23 10:22:37 -05:00
|
|
|
{
|
2014-05-31 09:09:44 -04:00
|
|
|
std::list<TempQueue>::iterator it = deck :: get_queues().begin();
|
2015-12-12 09:04:25 -05:00
|
|
|
queue *q = history_get_queue();
|
2015-11-23 08:36:29 -05:00
|
|
|
queue *q0 = deck :: get(0);
|
|
|
|
queue *q1 = deck :: get(1);
|
2014-05-26 22:20:07 -04:00
|
|
|
|
2015-12-03 13:41:39 -05:00
|
|
|
queue_unset_flag(q0, Q_RANDOM);
|
2014-05-26 22:20:07 -04:00
|
|
|
for (unsigned int i = 0; i < 4; i++)
|
2015-11-25 08:24:04 -05:00
|
|
|
queue_add(q0, track_get(i));
|
2014-05-26 22:20:07 -04:00
|
|
|
|
|
|
|
test_not_equal(q, Q_NULL);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q), (unsigned)0);
|
2014-05-26 22:20:07 -04:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 2; i++) {
|
2015-11-12 08:41:46 -05:00
|
|
|
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)0);
|
|
|
|
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)1);
|
|
|
|
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)2);
|
|
|
|
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)3);
|
2014-05-26 22:20:07 -04:00
|
|
|
}
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2014-05-26 22:20:07 -04:00
|
|
|
test_equal(deck :: get_queues().size(), (size_t)1);
|
|
|
|
test_equal(deck :: index(q1), (unsigned)0);
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-12-03 13:41:39 -05:00
|
|
|
queue_unset_flag(q1, Q_ENABLED);
|
2015-12-05 12:12:01 -05:00
|
|
|
queue_unset_flag(collection_get_queue(), Q_RANDOM);
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q1), (unsigned)5);
|
2014-05-26 22:20:07 -04:00
|
|
|
deck :: next();
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(q1), (unsigned)5);
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-12-03 13:41:39 -05:00
|
|
|
queue_set_flag(q1, Q_ENABLED);
|
2014-05-26 22:20:07 -04:00
|
|
|
for (unsigned int i = 0; i < 5; i++)
|
|
|
|
deck :: next();
|
|
|
|
test_equal(deck :: get_queues().size(), (size_t)0);
|
2013-12-23 10:22:37 -05:00
|
|
|
}
|
|
|
|
|
2015-08-31 08:17:07 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
2015-12-13 09:27:52 -05:00
|
|
|
UNIT_TEST("Temporary Queue Initialization", test_init),
|
2015-12-14 09:05:54 -05:00
|
|
|
UNIT_TEST("Temporary Queue", test_tempq),
|
2015-08-31 08:17:07 -04:00
|
|
|
UNIT_TEST("Deck Create, Move, and Destroy", test_create_mv_destroy),
|
|
|
|
UNIT_TEST("Deck Next and Prev", test_next_prev),
|
|
|
|
);
|