2013-12-22 22:21:19 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/deck.h>
|
2015-11-10 10:19:45 -05:00
|
|
|
extern "C" {
|
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-11-10 10:19:45 -05:00
|
|
|
}
|
2015-08-31 08:17:07 -04:00
|
|
|
#include "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
|
|
|
{
|
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 10:24:36 -05:00
|
|
|
test_equal(tempq_next(), NULL);
|
2015-12-13 09:27:52 -05:00
|
|
|
tempq_init(NULL);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_next(), NULL);
|
2015-12-14 10:01:08 -05:00
|
|
|
tempq_move(NULL, 1);
|
2015-12-14 09:50:38 -05:00
|
|
|
test_equal(tempq_get(0), NULL);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 0);
|
2015-12-14 09:05:54 -05:00
|
|
|
}
|
2013-12-22 22:21:19 -05:00
|
|
|
|
2015-12-14 09:05:54 -05:00
|
|
|
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);
|
2015-12-14 09:50:38 -05:00
|
|
|
test_equal(tempq_get(0), q0);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 1);
|
2015-12-14 09:05:54 -05:00
|
|
|
|
|
|
|
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);
|
2015-12-14 09:50:38 -05:00
|
|
|
test_equal(tempq_get(1), q1);
|
2015-12-14 10:24:36 -05:00
|
|
|
test_equal(tempq_count(), 2);
|
2015-12-14 09:05:54 -05:00
|
|
|
|
2015-12-14 10:01:08 -05:00
|
|
|
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);
|
|
|
|
|
2015-12-14 09:26:58 -05:00
|
|
|
tempq_free(q0);
|
2015-12-14 09:50:38 -05:00
|
|
|
test_equal(tempq_get(0), 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 09:50:38 -05:00
|
|
|
test_equal(tempq_get(0), NULL);
|
2015-12-14 10:24:36 -05:00
|
|
|
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
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
q0 = tempq_alloc(NULL, 0);
|
|
|
|
q1 = tempq_alloc(NULL, 0);
|
|
|
|
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 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);
|
|
|
|
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);
|
2013-12-23 10:37:22 -05:00
|
|
|
|
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);
|
|
|
|
test_loop_equal(tempq_next(), track_get(i), i);
|
|
|
|
} test_loop_passed();
|
|
|
|
test_equal(tempq_get(0), NULL);
|
|
|
|
test_equal(tempq_count(), 0);
|
2013-12-23 10:37:22 -05:00
|
|
|
|
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 09:05:54 -05:00
|
|
|
UNIT_TEST("Temporary Queue", test_tempq),
|
2015-12-14 10:24:36 -05:00
|
|
|
UNIT_TEST("Temporary Queue Next Track", test_next),
|
2015-08-31 08:17:07 -04:00
|
|
|
);
|