ocarina/tests/core/history.c
Anna Schumaker 779969f28b core/idle: Let tests run without the thread pool
The thread pool is used to fetch album art in the background, but this
can slow down most tests that aren't interested in album art.  Adding a
(testing-only) function for running without the thread pool speeds
things up a bit.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2016-07-28 16:17:43 -04:00

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_sync();
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),
);