2013-12-22 22:21:19 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
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-03-16 08:26:36 -04:00
|
|
|
g_assert_null(tempq_next());
|
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()) {};
|
|
|
|
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_null(tempq_next());
|
2015-12-14 10:01:08 -05:00
|
|
|
tempq_move(NULL, 1);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_null(tempq_get(0));
|
|
|
|
g_assert_cmpuint(tempq_count(), ==, 0);
|
|
|
|
g_assert_cmpuint(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);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_nonnull(q0);
|
|
|
|
g_assert_true(queue_has_flag(q0, Q_ENABLED));
|
|
|
|
g_assert_false(queue_has_flag(q0, Q_RANDOM));
|
|
|
|
g_assert_true(queue_has_flag(q0, Q_SAVE_SORT));
|
|
|
|
g_assert_true(queue_has_flag(q0, Q_SAVE_FLAGS));
|
|
|
|
g_assert(tempq_get(0) == q0);
|
|
|
|
g_assert_cmpuint(tempq_count(), ==, 1);
|
|
|
|
g_assert_cmpuint(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);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_nonnull(q1);
|
|
|
|
g_assert_true(queue_has_flag(q1, Q_ENABLED));
|
|
|
|
g_assert_true(queue_has_flag(q1, Q_RANDOM));
|
|
|
|
g_assert_true(queue_has_flag(q1, Q_SAVE_SORT));
|
|
|
|
g_assert_true(queue_has_flag(q1, Q_SAVE_FLAGS));
|
|
|
|
g_assert(tempq_get(1) == q1);
|
|
|
|
g_assert_cmpuint(tempq_count(), ==, 2);
|
|
|
|
g_assert_cmpuint(tempq_index(q1), ==, 1);
|
2015-12-14 09:05:54 -05:00
|
|
|
|
2015-12-14 11:08:17 -05:00
|
|
|
tempq_deinit();
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(tempq_count(), ==, 0);
|
2015-12-14 11:08:17 -05:00
|
|
|
tempq_init(NULL);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(tempq_count(), ==, 0);
|
2016-02-25 08:14:25 -05:00
|
|
|
while (idle_run_task()) {};
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(tempq_count(), ==, 2);
|
2015-12-14 11:08:17 -05:00
|
|
|
|
|
|
|
q0 = tempq_get(0);
|
|
|
|
q1 = tempq_get(1);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_false(queue_has_flag(q0, Q_RANDOM));
|
|
|
|
g_assert_true(queue_has_flag(q1, Q_RANDOM));
|
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);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert(tempq_get(0) == q1);
|
|
|
|
g_assert(tempq_get(1) == q0);
|
|
|
|
g_assert_null(tempq_get(2));
|
2015-12-14 10:01:08 -05:00
|
|
|
|
|
|
|
tempq_move(q0, 1);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert(tempq_get(0) == q1);
|
|
|
|
g_assert(tempq_get(1) == q0);
|
|
|
|
g_assert_null(tempq_get(2));
|
2015-12-14 10:01:08 -05:00
|
|
|
|
2015-12-14 11:08:17 -05:00
|
|
|
tempq_deinit();
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(tempq_count(), ==, 0);
|
2015-12-14 11:08:17 -05:00
|
|
|
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);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_false(queue_has_flag(q0, Q_RANDOM));
|
|
|
|
g_assert_true(queue_has_flag(q1, Q_RANDOM));
|
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);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert(tempq_get(0) == q1);
|
|
|
|
g_assert_cmpuint(tempq_count(), ==, 1);
|
2015-12-14 09:50:38 -05:00
|
|
|
|
2015-12-14 09:26:58 -05:00
|
|
|
tempq_free(q1);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_null(tempq_get(0));
|
|
|
|
g_assert_cmpuint(tempq_count(), ==, 0);
|
2015-12-14 11:08:17 -05:00
|
|
|
|
|
|
|
tempq_deinit();
|
|
|
|
tempq_init(NULL);
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(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
|
|
|
|
2016-05-11 11:13:42 -04:00
|
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
2015-12-14 10:24:36 -05:00
|
|
|
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()) {};
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(tempq_count(), ==, 2);
|
2015-12-14 14:04:23 -05:00
|
|
|
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++) {
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(queue_size(q0), ==, track_db->db_size - i);
|
|
|
|
g_assert(tempq_next() == track_get(i));
|
|
|
|
}
|
|
|
|
g_assert(tempq_get(0) == q1);
|
|
|
|
g_assert_cmpuint(tempq_count(), ==, 1);
|
|
|
|
g_assert_cmpuint(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()) {};
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(tempq_count(), ==, 1);
|
2015-12-14 14:04:23 -05:00
|
|
|
q1 = tempq_get(0);
|
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
for (i = 0; i < track_db->db_size; i++) {
|
2016-03-16 08:26:36 -04:00
|
|
|
g_assert_cmpuint(queue_size(q1), ==, track_db->db_size - i);
|
|
|
|
g_assert(tempq_next() == track_get(i));
|
|
|
|
}
|
|
|
|
g_assert_null(tempq_get(0));
|
|
|
|
g_assert_cmpuint(tempq_count(), ==, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
idle_init_sync();
|
|
|
|
tags_init();
|
|
|
|
playlist_init(NULL);
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Core/Temporary Queue/Initialization", test_init);
|
|
|
|
g_test_add_func("/Core/Temporary Queue/Alloc", test_alloc);
|
|
|
|
g_test_add_func("/Core/Temporary Queue/Move", test_move);
|
|
|
|
g_test_add_func("/Core/Temporary Queue/Free", test_free);
|
|
|
|
g_test_add_func("/Core/Temporary Queue/Next Track", test_next);
|
|
|
|
ret = g_test_run();
|
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
|
|
|
playlist_deinit();
|
|
|
|
tags_deinit();
|
2016-03-16 08:26:36 -04:00
|
|
|
idle_deinit();
|
|
|
|
return ret;
|
2013-12-23 10:22:37 -05:00
|
|
|
}
|