ocarina/tests/core/deck.cpp

116 lines
2.8 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 void test_init()
{
filter_init();
tags_init();
playlist_init(NULL);
collection_init(NULL);
history_init(NULL);
test_equal(tempq_next(), NULL);
tempq_init(NULL);
test_equal(tempq_next(), NULL);
tempq_move(NULL, 1);
test_equal(tempq_get(0), NULL);
test_equal(tempq_count(), 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);
test_equal(tempq_get(0), q0);
test_equal(tempq_count(), 1);
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);
test_equal(tempq_get(1), q1);
test_equal(tempq_count(), 2);
tempq_move(q1, 0);
test_equal(tempq_get(0), q1);
test_equal(tempq_get(1), q0);
test_equal(tempq_get(2), NULL);
tempq_move(q0, 1);
test_equal(tempq_get(0), q1);
test_equal(tempq_get(1), q0);
test_equal(tempq_get(2), NULL);
tempq_free(q0);
test_equal(tempq_get(0), q1);
test_equal(tempq_count(), 1);
tempq_free(q1);
test_equal(tempq_get(0), NULL);
test_equal(tempq_count(), 0);
}
static void test_next()
{
const struct database *track_db = track_db_get();
struct queue *q0, *q1;
unsigned int i;
collection_add("tests/Music/Hyrule Symphony");
while (idle_run_task()) {};
q0 = tempq_alloc(NULL, 0);
q1 = tempq_alloc(NULL, 0);
for (i = 0; i < track_db->db_size; i++) {
queue_add(q0, track_get(i));
queue_add(q1, track_get(i));
}
for (i = 0; i < track_db->db_size; i++) {
test_loop_equal(queue_size(q0), track_db->db_size - i, i);
test_loop_equal(tempq_next(), track_get(i), i);
} test_loop_passed();
test_equal(tempq_get(0), q1);
test_equal(tempq_count(), 1);
test_equal(queue_size(q1), track_db->db_size);
for (i = 0; i < track_db->db_size; i++) {
test_loop_equal(queue_size(q1), track_db->db_size - i, i);
test_loop_equal(tempq_next(), track_get(i), i);
} test_loop_passed();
test_equal(tempq_get(0), NULL);
test_equal(tempq_count(), 0);
history_deinit();
collection_deinit();
playlist_deinit();
tags_deinit();
filter_deinit();
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Temporary Queue Initialization", test_init),
UNIT_TEST("Temporary Queue", test_tempq),
UNIT_TEST("Temporary Queue Next Track", test_next),
);