ocarina/tests/core/deck.cpp

135 lines
3.3 KiB
C++
Raw Normal View History

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/deck.h>
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/history.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
}
#include "test.h"
static queue *Q_NULL = NULL;
static void test_init()
{
filter_init();
tags_init();
playlist_init(NULL);
collection_init(NULL);
history_init(NULL);
test_equal(deck :: next(), NULL);
tempq_init(NULL);
test_equal(deck :: next(), NULL);
test_equal(deck :: get(0), NULL);
test_equal(deck :: get_queues().size(), (size_t)0);
}
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);
tempq_free(q0);
tempq_free(q1);
history_deinit();
collection_deinit();
playlist_deinit();
tags_deinit();
filter_deinit();
}
static void test_create_mv_destroy()
{
queue *q1, *q2;
test_cp_data_dir();
filter_init();
tags_init();
playlist_init(NULL);
collection_init(NULL);
history_init(NULL);
tempq_init(NULL);
q1 = tempq_alloc(NULL, Q_RANDOM);
test_not_equal(q1, Q_NULL);
test_equal(queue_has_flag(q1, Q_ENABLED), true);
test_equal(queue_has_flag(q1, Q_RANDOM), true);
test_equal(deck :: get(2), q1);
q2 = tempq_alloc(NULL, 0);
test_not_equal(q2, Q_NULL);
test_equal(queue_has_flag(q2, Q_ENABLED), true);
test_equal(queue_has_flag(q2, Q_RANDOM), false);
test_equal(deck :: get(3), q2);
deck :: move(q1, 3);
deck :: move(q1, 3);
deck :: move(q1, 2);
tempq_free(q1);
tempq_free(q2);
test_equal(deck :: get(3), Q_NULL);
}
static void test_next_prev()
{
std::list<TempQueue>::iterator it = deck :: get_queues().begin();
queue *q = history_get_queue();
queue *q0 = deck :: get(0);
queue *q1 = deck :: get(1);
queue_unset_flag(q0, Q_RANDOM);
for (unsigned int i = 0; i < 4; i++)
queue_add(q0, track_get(i));
test_not_equal(q, Q_NULL);
test_equal(queue_size(q), (unsigned)0);
for (unsigned int i = 0; i < 2; i++) {
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);
}
test_equal(deck :: get_queues().size(), (size_t)1);
queue_unset_flag(q1, Q_ENABLED);
queue_unset_flag(collection_get_queue(), Q_RANDOM);
test_equal(queue_size(q1), (unsigned)5);
deck :: next();
test_equal(queue_size(q1), (unsigned)5);
queue_set_flag(q1, Q_ENABLED);
for (unsigned int i = 0; i < 5; i++)
deck :: next();
test_equal(deck :: get_queues().size(), (size_t)0);
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Temporary Queue Initialization", test_init),
UNIT_TEST("Temporary Queue", test_tempq),
UNIT_TEST("Deck Create, Move, and Destroy", test_create_mv_destroy),
UNIT_TEST("Deck Next and Prev", test_next_prev),
);