2b426cff48
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
90 lines
2.4 KiB
C
90 lines
2.4 KiB
C
/*
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/history.h>
|
|
#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 <tests/test.h>
|
|
|
|
static void test_init()
|
|
{
|
|
struct queue *q = history_get_queue();
|
|
|
|
idle_init();
|
|
filter_init();
|
|
tags_init();
|
|
playlist_init(NULL);
|
|
collection_init(NULL);
|
|
history_init(NULL);
|
|
|
|
test_not_equal((void *)q, NULL);
|
|
test_equal(queue_has_flag(q, Q_ENABLED), (bool)true);
|
|
test_equal(queue_has_flag(q, Q_REPEAT), (bool)true);
|
|
test_equal(queue_has_flag(q, Q_NO_SORT), (bool)true);
|
|
test_equal(queue_has_flag(q, Q_ADD_FRONT), (bool)true);
|
|
test_equal(queue_has_flag(q, Q_SAVE_SORT), (bool)false);
|
|
test_equal(queue_has_flag(q, Q_SAVE_FLAGS), (bool)false);
|
|
test_equal((void *)q->q_sort, NULL);
|
|
test_equal(queue_size(q), 0);
|
|
|
|
collection_add("tests/Music/Hyrule Symphony");
|
|
while (idle_run_task()) {};
|
|
}
|
|
|
|
static void test_history()
|
|
{
|
|
const struct database *track_db = track_db_get();
|
|
struct queue *q = history_get_queue();
|
|
struct track *prev = track_get(0);
|
|
struct db_entry *track, *next;
|
|
unsigned int i = 0;
|
|
|
|
test_equal((void *)history_prev(), NULL);
|
|
|
|
/* Add tracks once */
|
|
db_for_each(track, next, track_db) {
|
|
history_add(TRACK(track));
|
|
test_loop_equal(queue_size(q), i + 1, i);
|
|
test_loop_equal(q->q_cur.it_pos, 0, i);
|
|
test_loop_equal((void *)queue_at(q, 0), (void *)TRACK(track), i);
|
|
test_loop_equal((void *)history_prev(), (void *)prev, i);
|
|
prev = TRACK(track);
|
|
i++;
|
|
} test_loop_passed();
|
|
test_equal(queue_size(q), track_db->db_size);
|
|
|
|
/* Cycle through the history queue. */
|
|
queue_iter_set(q, &q->q_cur, 0);
|
|
for (i = 2; i <= track_db->db_size; i++) {
|
|
test_loop_equal((void *)history_prev(),
|
|
(void *)track_get(track_db->db_size - i), i);
|
|
} test_loop_passed();
|
|
|
|
i = 0;
|
|
/* Add tracks again, old tracks should remain */
|
|
db_for_each(track, next, track_db) {
|
|
history_add(TRACK(track));
|
|
test_loop_equal(queue_size(q), track_db->db_size + i + 1, i);
|
|
test_loop_equal((void *)queue_at(q, 0), (void *)TRACK(track), i);
|
|
test_loop_equal((void *)queue_at(q, track_db->db_size),
|
|
(void *)TRACK(track), i);
|
|
i++;
|
|
} test_loop_passed();
|
|
test_equal(queue_size(q), 2 * track_db->db_size);
|
|
|
|
history_deinit();
|
|
collection_deinit();
|
|
playlist_deinit();
|
|
tags_deinit();
|
|
filter_deinit();
|
|
}
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("History Initialization", test_init),
|
|
UNIT_TEST("History Queue", test_history),
|
|
);
|