2013-12-22 22:21:19 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
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-12-14 13:55:50 -05:00
|
|
|
#include <core/tempq.h>
|
|
|
|
#include <tests/test.h>
|
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
|
|
|
{
|
2016-07-28 16:15:29 -04:00
|
|
|
idle_init_sync();
|
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-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_next(), NULL);
|
2016-02-25 08:14:25 -05:00
|
|
|
|
2015-12-13 09:27:52 -05:00
|
|
|
tempq_init(NULL);
|
2016-02-25 08:14:25 -05:00
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_next(), NULL);
|
2015-12-14 10:01:08 -05:00
|
|
|
tempq_move(NULL, 1);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_get(0), NULL);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 0);
|
2016-01-13 16:23:37 -05:00
|
|
|
test_equal(tempq_index(NULL), (unsigned int)-1);
|
2015-12-14 09:05:54 -05:00
|
|
|
}
|
2013-12-22 22:21:19 -05:00
|
|
|
|
2015-12-14 11:08:17 -05:00
|
|
|
static void test_alloc()
|
2015-12-14 09:05:54 -05:00
|
|
|
{
|
|
|
|
struct queue *q0, *q1;
|
|
|
|
|
2016-01-21 10:42:20 -05:00
|
|
|
q0 = tempq_alloc(0);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_not_equal((void *)q0, NULL);
|
|
|
|
test_equal(queue_has_flag(q0, Q_ENABLED), (bool)true);
|
|
|
|
test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false);
|
|
|
|
test_equal(queue_has_flag(q0, Q_SAVE_SORT), (bool)true);
|
|
|
|
test_equal(queue_has_flag(q0, Q_SAVE_FLAGS), (bool)true);
|
|
|
|
test_equal((void *)tempq_get(0), (void *)q0);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 1);
|
2016-01-13 16:23:37 -05:00
|
|
|
test_equal(tempq_index(q0), 0);
|
2015-12-14 09:05:54 -05:00
|
|
|
|
2016-01-21 10:42:20 -05:00
|
|
|
q1 = tempq_alloc(Q_RANDOM);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_not_equal((void *)q1, NULL);
|
|
|
|
test_equal(queue_has_flag(q1, Q_ENABLED), (bool)true);
|
|
|
|
test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true);
|
|
|
|
test_equal(queue_has_flag(q1, Q_SAVE_SORT), (bool)true);
|
|
|
|
test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), (bool)true);
|
|
|
|
test_equal((void *)tempq_get(1), (void *)q1);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 2);
|
2016-01-13 16:23:37 -05:00
|
|
|
test_equal(tempq_index(q1), 1);
|
2015-12-14 09:05:54 -05:00
|
|
|
|
2015-12-14 11:08:17 -05:00
|
|
|
tempq_deinit();
|
|
|
|
test_equal(tempq_count(), 0);
|
|
|
|
tempq_init(NULL);
|
2016-02-25 08:14:25 -05:00
|
|
|
test_equal(tempq_count(), 0);
|
|
|
|
while (idle_run_task()) {};
|
|
|
|
test_equal(tempq_count(), 2);
|
2015-12-14 11:08:17 -05:00
|
|
|
|
|
|
|
q0 = tempq_get(0);
|
|
|
|
q1 = tempq_get(1);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false);
|
|
|
|
test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true);
|
2015-12-14 11:08:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_move()
|
|
|
|
{
|
|
|
|
struct queue *q0 = tempq_get(0);
|
|
|
|
struct queue *q1 = tempq_get(1);
|
|
|
|
|
2015-12-14 14:06:46 -05:00
|
|
|
tempq_move(NULL, 0);
|
|
|
|
|
2015-12-14 10:01:08 -05:00
|
|
|
tempq_move(q1, 0);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_get(0), (void *)q1);
|
|
|
|
test_equal((void *)tempq_get(1), (void *)q0);
|
|
|
|
test_equal((void *)tempq_get(2), NULL);
|
2015-12-14 10:01:08 -05:00
|
|
|
|
|
|
|
tempq_move(q0, 1);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_get(0), (void *)q1);
|
|
|
|
test_equal((void *)tempq_get(1), (void *)q0);
|
|
|
|
test_equal((void *)tempq_get(2), NULL);
|
2015-12-14 10:01:08 -05:00
|
|
|
|
2015-12-14 11:08:17 -05:00
|
|
|
tempq_deinit();
|
|
|
|
test_equal(tempq_count(), 0);
|
|
|
|
tempq_init(NULL);
|
2016-02-25 08:14:25 -05:00
|
|
|
while (idle_run_task()) {};
|
2015-12-14 11:08:17 -05:00
|
|
|
|
|
|
|
q0 = tempq_get(1);
|
|
|
|
q1 = tempq_get(0);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false);
|
|
|
|
test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true);
|
2015-12-14 11:08:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_free()
|
|
|
|
{
|
|
|
|
struct queue *q0 = tempq_get(1);
|
|
|
|
struct queue *q1 = tempq_get(0);
|
|
|
|
|
2015-12-14 09:26:58 -05:00
|
|
|
tempq_free(q0);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_get(0), (void *)q1);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 1);
|
2015-12-14 09:50:38 -05:00
|
|
|
|
2015-12-14 09:26:58 -05:00
|
|
|
tempq_free(q1);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_get(0), NULL);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 0);
|
2015-12-14 11:08:17 -05:00
|
|
|
|
|
|
|
tempq_deinit();
|
|
|
|
tempq_init(NULL);
|
|
|
|
test_equal(tempq_count(), 0);
|
2013-12-22 22:21:19 -05:00
|
|
|
}
|
2014-05-26 22:20:07 -04:00
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
static void test_next()
|
2013-12-22 22:21:19 -05:00
|
|
|
{
|
2015-12-14 10:24:36 -05:00
|
|
|
const struct database *track_db = track_db_get();
|
|
|
|
struct queue *q0, *q1;
|
|
|
|
unsigned int i;
|
2015-12-13 09:27:52 -05:00
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
collection_add("tests/Music/Hyrule Symphony");
|
|
|
|
while (idle_run_task()) {};
|
2014-05-26 22:20:07 -04:00
|
|
|
|
2016-01-21 10:42:20 -05:00
|
|
|
q0 = tempq_alloc(0);
|
|
|
|
q1 = tempq_alloc(0);
|
2015-12-14 10:24:36 -05:00
|
|
|
for (i = 0; i < track_db->db_size; i++) {
|
2015-11-25 08:24:04 -05:00
|
|
|
queue_add(q0, track_get(i));
|
2015-12-14 10:24:36 -05:00
|
|
|
queue_add(q1, track_get(i));
|
2014-05-26 22:20:07 -04:00
|
|
|
}
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-12-14 14:04:23 -05:00
|
|
|
tempq_save(NULL, Q_ENABLED);
|
|
|
|
tempq_deinit();
|
|
|
|
tempq_init(NULL);
|
2016-02-25 08:14:25 -05:00
|
|
|
while (idle_run_task()) {};
|
2015-12-14 14:04:23 -05:00
|
|
|
test_equal(tempq_count(), 2);
|
|
|
|
q0 = tempq_get(0);
|
|
|
|
q1 = tempq_get(1);
|
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
for (i = 0; i < track_db->db_size; i++) {
|
|
|
|
test_loop_equal(queue_size(q0), track_db->db_size - i, i);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_loop_equal((void *)tempq_next(), (void *)track_get(i), i);
|
2015-12-14 10:24:36 -05:00
|
|
|
} test_loop_passed();
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_get(0), (void *)q1);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 1);
|
|
|
|
test_equal(queue_size(q1), track_db->db_size);
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-12-14 14:04:23 -05:00
|
|
|
tempq_deinit();
|
|
|
|
tempq_init(NULL);
|
2016-02-25 08:14:25 -05:00
|
|
|
while (idle_run_task()) {};
|
2015-12-14 14:04:23 -05:00
|
|
|
test_equal(tempq_count(), 1);
|
|
|
|
q1 = tempq_get(0);
|
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
for (i = 0; i < track_db->db_size; i++) {
|
|
|
|
test_loop_equal(queue_size(q1), track_db->db_size - i, i);
|
2015-12-14 13:55:50 -05:00
|
|
|
test_loop_equal((void *)tempq_next(), (void *)track_get(i), i);
|
2015-12-14 10:24:36 -05:00
|
|
|
} test_loop_passed();
|
2015-12-14 13:55:50 -05:00
|
|
|
test_equal((void *)tempq_get(0), NULL);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 0);
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-12-14 10:56:39 -05:00
|
|
|
tempq_deinit();
|
2015-12-14 10:24:36 -05:00
|
|
|
history_deinit();
|
|
|
|
collection_deinit();
|
|
|
|
playlist_deinit();
|
|
|
|
tags_deinit();
|
|
|
|
filter_deinit();
|
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 11:08:17 -05:00
|
|
|
UNIT_TEST("Temporary Queue Alloc", test_alloc),
|
|
|
|
UNIT_TEST("Temporary Queue Move", test_move),
|
|
|
|
UNIT_TEST("Temporary Queue Free", test_free),
|
2015-12-14 10:24:36 -05:00
|
|
|
UNIT_TEST("Temporary Queue Next Track", test_next),
|
2015-08-31 08:17:07 -04:00
|
|
|
);
|