2014-04-13 12:26:32 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/queue.h>
|
2015-09-09 09:00:17 -04:00
|
|
|
extern "C" {
|
2015-11-10 10:19:45 -05:00
|
|
|
#include <core/filter.h>
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/random.h>
|
2014-12-02 08:16:22 -05:00
|
|
|
#include <core/tags/tags.h>
|
2015-11-12 10:42:21 -05:00
|
|
|
}
|
2015-08-28 09:26:22 -04:00
|
|
|
#include "test.h"
|
2014-04-13 12:26:32 -04:00
|
|
|
|
2014-04-13 18:38:49 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
unsigned int count_added = 0;
|
|
|
|
unsigned int count_deleted = 0;
|
2014-05-11 18:32:53 -04:00
|
|
|
unsigned int count_updated = 0;
|
2014-05-11 10:40:54 -04:00
|
|
|
|
|
|
|
|
2015-04-03 10:30:46 -04:00
|
|
|
static class TestNotifier : public QNotifier {
|
|
|
|
public:
|
|
|
|
TestNotifier() : QNotifier() {}
|
2015-11-13 11:14:40 -05:00
|
|
|
void on_track_added(unsigned int i) { count_added++; }
|
|
|
|
void on_track_removed(unsigned int i) { count_deleted++; }
|
|
|
|
void on_track_updated(unsigned int i) { count_updated++; }
|
2015-04-03 10:30:46 -04:00
|
|
|
} test_notifier;
|
|
|
|
|
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
static void __test_init_core()
|
2014-04-13 12:26:32 -04:00
|
|
|
{
|
2015-11-13 11:14:40 -05:00
|
|
|
struct library *library;
|
2014-04-13 12:26:32 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
filter_init();
|
|
|
|
tags_init();
|
|
|
|
|
|
|
|
library = library_find("tests/Music");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/03 - Hyrule Field.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/04 - Hyrule Castle.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/05 - Lon Lon Ranch.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/06 - Kakariko Village.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/07 - Death Mountain.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/08 - Zora's Domain.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/09 - Gerudo Valley.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/10 - Ganondorf.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/11 - Princess Zelda.ogg");
|
|
|
|
track_add(library, "tests/Music/Hyrule Symphony/12 - Ocarina Medley.ogg");
|
|
|
|
track_add(library,
|
|
|
|
"tests/Music/Hyrule Symphony/13 - The Legend of Zelda Medley.ogg");
|
2014-04-13 12:26:32 -04:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
static void __test_deinit_core()
|
2014-04-13 18:38:49 -04:00
|
|
|
{
|
2015-11-13 11:14:40 -05:00
|
|
|
tags_deinit();
|
|
|
|
filter_deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_init()
|
|
|
|
{
|
2015-11-16 09:12:15 -05:00
|
|
|
struct queue q;
|
2014-04-13 18:38:49 -04:00
|
|
|
|
2015-11-16 09:12:15 -05:00
|
|
|
__test_init_core();
|
|
|
|
|
|
|
|
test_equal(q.q_cur, (unsigned int)-1);
|
2015-11-18 08:04:00 -05:00
|
|
|
test_equal(q.q_flags, 0);
|
|
|
|
test_equal(q.q_length, 0);
|
2015-11-16 09:12:15 -05:00
|
|
|
test_equal(q.q_sort.size(), (size_t)0);
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q), (struct track *)NULL);
|
2015-11-16 09:12:15 -05:00
|
|
|
test_not_equal(q.q_notify, NULL);
|
|
|
|
|
|
|
|
q = queue(Q_ENABLED | Q_RANDOM);
|
2015-11-20 10:19:14 -05:00
|
|
|
q.q_notify = &test_notifier;
|
2015-11-13 11:14:40 -05:00
|
|
|
|
2015-11-16 09:12:15 -05:00
|
|
|
test_equal(q.q_cur, (unsigned int )-1);
|
2015-11-18 08:04:00 -05:00
|
|
|
test_equal(q.q_flags, Q_ENABLED | Q_RANDOM);
|
|
|
|
test_equal(q.q_length, 0);
|
2015-11-16 09:12:15 -05:00
|
|
|
test_equal(q.q_sort.size(), 0);
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q), (struct track *)NULL);
|
2015-11-16 09:12:15 -05:00
|
|
|
test_equal(q.q_notify, &test_notifier);
|
2014-04-26 11:00:44 -04:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
static void test_flags()
|
2014-04-26 11:00:44 -04:00
|
|
|
{
|
2015-11-16 09:12:15 -05:00
|
|
|
struct queue q(0);
|
2014-04-26 11:00:44 -04:00
|
|
|
|
2015-11-16 09:12:15 -05:00
|
|
|
test_equal(q.q_flags, 0);
|
2015-11-20 08:18:54 -05:00
|
|
|
test_equal(queue_has_flag(&q, Q_ENABLED), false);
|
|
|
|
test_equal(queue_has_flag(&q, Q_RANDOM), false);
|
|
|
|
test_equal(queue_has_flag(&q, Q_REPEAT), false);
|
|
|
|
test_equal(queue_has_flag(&q, Q_NO_SORT), false);
|
2014-04-26 11:00:44 -04:00
|
|
|
|
|
|
|
q.set_flag(Q_ENABLED);
|
2015-11-16 09:12:15 -05:00
|
|
|
test_equal(q.q_flags, Q_ENABLED);
|
2014-04-26 11:00:44 -04:00
|
|
|
|
|
|
|
q.unset_flag(Q_ENABLED);
|
2015-11-16 09:12:15 -05:00
|
|
|
test_equal(q.q_flags, 0);
|
2014-04-26 11:00:44 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
q.set_flag(Q_ENABLED);
|
2014-04-26 11:00:44 -04:00
|
|
|
q.set_flag(Q_RANDOM);
|
2015-11-13 11:14:40 -05:00
|
|
|
q.set_flag(Q_REPEAT);
|
|
|
|
q.set_flag(Q_NO_SORT);
|
2015-11-20 08:18:54 -05:00
|
|
|
test_equal(queue_has_flag(&q, Q_ENABLED), true);
|
|
|
|
test_equal(queue_has_flag(&q, Q_RANDOM), true);
|
|
|
|
test_equal(queue_has_flag(&q, Q_REPEAT), true);
|
|
|
|
test_equal(queue_has_flag(&q, Q_NO_SORT), true);
|
2015-04-04 09:37:03 -04:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
static void test_stress(unsigned int N)
|
2014-05-11 10:40:54 -04:00
|
|
|
{
|
2015-11-13 11:14:40 -05:00
|
|
|
unsigned int ex_length = 0;
|
|
|
|
unsigned int ex_size = N;
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *track;
|
2015-11-16 09:12:15 -05:00
|
|
|
struct queue q(0);
|
2015-11-13 11:14:40 -05:00
|
|
|
unsigned int i;
|
2015-08-28 09:26:22 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
count_added = 0;
|
|
|
|
count_deleted = 0;
|
|
|
|
count_updated = 0;
|
2015-11-20 10:19:14 -05:00
|
|
|
q.q_notify = &test_notifier;
|
2014-05-11 19:52:08 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* Queue :: add() */
|
|
|
|
for (i = 0; i < N; i++) {
|
|
|
|
track = track_get(i % 13);
|
|
|
|
ex_length += track->tr_length;
|
2015-08-28 09:26:22 -04:00
|
|
|
test_loop_equal(q.add(track), i, i);
|
2015-11-13 11:14:40 -05:00
|
|
|
test_loop_equal(count_added, i + 1, i);
|
2015-08-28 09:26:22 -04:00
|
|
|
} test_loop_passed();
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(q.q_length, ex_length);
|
|
|
|
test_equal(queue_size(&q), ex_size);
|
2014-05-11 11:23:15 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* Queue :: del(struct track *) */
|
|
|
|
track = track_get(0);
|
|
|
|
ex_length -= track->tr_length * (N / 13);
|
|
|
|
ex_size -= (N / 13);
|
|
|
|
q.del(track);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(q.q_length, ex_length);
|
|
|
|
test_equal(queue_size(&q), ex_size);
|
2015-11-13 11:14:40 -05:00
|
|
|
|
|
|
|
/* Queue :: del(unsigned int) */
|
|
|
|
track = track_get(1);
|
|
|
|
ex_length -= track->tr_length * (N / 13);
|
|
|
|
ex_size -= (N / 13);
|
|
|
|
for (i = 0; i < ex_size; i += 11) {
|
2015-11-19 13:50:08 -05:00
|
|
|
test_loop_equal(queue_at(&q, i), track, i);
|
2015-11-13 11:14:40 -05:00
|
|
|
q.del(i);
|
2015-08-28 09:26:22 -04:00
|
|
|
} test_loop_passed();
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(q.q_length, ex_length);
|
|
|
|
test_equal(queue_size(&q), ex_size);
|
2014-05-11 11:23:15 -04:00
|
|
|
|
2015-11-20 08:02:54 -05:00
|
|
|
/* queue_updated() */
|
2015-11-13 11:14:40 -05:00
|
|
|
track = track_get(2);
|
2015-11-20 08:02:54 -05:00
|
|
|
queue_updated(&q, track);
|
2015-11-13 11:14:40 -05:00
|
|
|
test_equal(count_updated, N / 13);
|
2014-05-11 11:23:15 -04:00
|
|
|
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q), NULL);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&q), ex_size);
|
2014-05-11 11:23:15 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* Tracks should not be removed. */
|
|
|
|
q.set_flag(Q_ENABLED);
|
|
|
|
q.set_flag(Q_REPEAT);
|
|
|
|
for (i = 0; i < ex_size; i++) {
|
2015-11-19 08:25:53 -05:00
|
|
|
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
|
2015-11-19 08:08:14 -05:00
|
|
|
queue_selected(&q, i);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_loop_equal(queue_size(&q), ex_size, i);
|
2015-08-28 09:26:22 -04:00
|
|
|
} test_loop_passed();
|
2014-05-11 11:23:15 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* Tracks should be removed. */
|
|
|
|
q.unset_flag(Q_REPEAT);
|
|
|
|
for (i = 0; i < ex_size; i++) {
|
2015-11-19 08:25:53 -05:00
|
|
|
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_loop_equal(queue_size(&q), ex_size - (i + 1), i);
|
2015-08-28 09:26:22 -04:00
|
|
|
} test_loop_passed();
|
2014-05-11 10:40:54 -04:00
|
|
|
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(q.q_length, 0);
|
|
|
|
test_equal(queue_size(&q), 0);
|
2015-01-04 17:56:54 -05:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
static void test_basics() { test_stress(13); }
|
|
|
|
static void test_stress_0() { test_stress(0); }
|
|
|
|
static void test_stress_100K() { test_stress(100009); }
|
|
|
|
|
|
|
|
static void test_rand_select()
|
2014-05-11 18:32:53 -04:00
|
|
|
{
|
2015-11-16 09:12:15 -05:00
|
|
|
struct queue q(Q_ENABLED | Q_RANDOM);
|
2015-11-13 11:14:40 -05:00
|
|
|
unsigned int i;
|
2014-05-11 18:32:53 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
random_seed(0);
|
2014-05-11 18:32:53 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* Call next() on an empty queue. */
|
|
|
|
for (i = 0; i < 13; i++) {
|
2015-11-19 08:25:53 -05:00
|
|
|
test_loop_equal(queue_next(&q), NULL, i);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_loop_equal(queue_size(&q), 0, i);
|
2015-08-28 09:26:22 -04:00
|
|
|
} test_loop_passed();
|
2014-05-11 18:32:53 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
for (i = 0; i < 13; i++)
|
|
|
|
q.add(track_get(i));
|
2014-05-11 18:32:53 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/*
|
|
|
|
* The comments below use the following notation:
|
|
|
|
* <val>: The value pointed to by q._cur.
|
|
|
|
* (val): The value selected by q.track_selected().
|
|
|
|
* [val]: The value picked by q.next().
|
|
|
|
*/
|
2015-08-28 09:26:22 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* rand() = 2, q = { <>, 0, [1], 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q)->tr_dbe.dbe_index, 1);
|
2015-01-04 17:56:54 -05:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* select = 6, q = { <0>, 2, 3, 4, 5, 6, (7), 8, 9, 10, 11, 12 } */
|
2015-11-19 08:08:14 -05:00
|
|
|
queue_selected(&q, 6);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&q), 11);
|
2014-05-18 11:08:58 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* rand() = 3, q = { 0, 2, 3, 4, 5, <6>, 8, 9, [10], 11, 12 } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q)->tr_dbe.dbe_index, 10);
|
2014-05-18 11:08:58 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* select = 7, q = { 0, 2, 3, 4, 5, 6, 8, (<9>), 11, 12 } */
|
2015-11-19 08:08:14 -05:00
|
|
|
queue_selected(&q, 7);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&q), 9);
|
2014-05-18 11:08:58 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* rand() = 4, q = { 0, 2, 3, 4, 5, 6, <8>, [11], 12 } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q)->tr_dbe.dbe_index, 11);
|
2014-05-18 11:08:58 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* select = 2, q = { 0, 2, (3), 4, 5, 6, <8>, 12 } */
|
2015-11-19 08:08:14 -05:00
|
|
|
queue_selected(&q, 2);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&q), 7);
|
2014-05-18 11:08:58 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* rand() = 1, q = { 0, <2>, [4], 5, 6, 8, 12 } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q)->tr_dbe.dbe_index, 4);
|
2014-05-18 11:08:58 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* select = 1, q = { 0, <2>, 5, 6, 8, (12) } */
|
2015-11-19 08:08:14 -05:00
|
|
|
queue_selected(&q, 5);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&q), 5);
|
2014-05-18 11:08:58 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* rand() = 1, q = { [0], 2, 5, 6, <8>, } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q)->tr_dbe.dbe_index, 0);
|
2014-05-18 14:24:46 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* rand() = 1, q = { <>, [2], 5, 6, 8, } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q)->tr_dbe.dbe_index, 2);
|
2015-01-04 17:56:54 -05:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* select = 1, q = { <>, 5, (6), 8, } */
|
2015-11-19 08:08:14 -05:00
|
|
|
queue_selected(&q, 1);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&q), 2);
|
2014-05-18 14:24:46 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* rand() = 1, q = { <5>, [8], } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q)->tr_dbe.dbe_index, 8);
|
2014-05-18 14:24:46 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* select = 1, q = { <[5]> } */
|
2015-11-19 08:08:14 -05:00
|
|
|
queue_selected(&q, 0);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&q), 0);
|
2015-01-04 17:56:54 -05:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
/* q = { } */
|
2015-11-19 08:25:53 -05:00
|
|
|
test_equal(queue_next(&q), NULL);
|
2015-11-13 11:14:40 -05:00
|
|
|
}
|
2014-05-18 14:11:21 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
static void test_sorting()
|
2014-05-18 14:11:21 -04:00
|
|
|
{
|
2015-11-13 11:14:40 -05:00
|
|
|
unsigned int ex_count[] = { 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3, 4, 5 };
|
|
|
|
unsigned int ex_title[] = { 6, 9, 8, 3, 2, 5, 1, 4, 11, 10, 12, 0, 7 };
|
|
|
|
unsigned int ex_co_ti[] = { 3, 2, 5, 1, 4, 0, 6, 9, 8, 11, 10, 12, 7 };
|
|
|
|
struct track *track;
|
2015-11-16 09:12:15 -05:00
|
|
|
struct queue q(0);
|
2015-11-13 11:14:40 -05:00
|
|
|
unsigned int i;
|
2014-05-18 14:11:21 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
for (i = 0; i < 13; i++) {
|
|
|
|
track = track_get(i);
|
|
|
|
track->tr_count = (i < 6) ? 4 : 2;
|
|
|
|
q.add(track);
|
|
|
|
}
|
2014-05-18 14:11:21 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
q.sort(COMPARE_COUNT, true);
|
|
|
|
for (i = 0; i < 13; i++) {
|
2015-11-19 13:50:08 -05:00
|
|
|
track = queue_at(&q, i);
|
|
|
|
test_loop_not_equal(track, NULL, i);
|
|
|
|
test_loop_equal(track->tr_dbe.dbe_index, ex_count[i], i);
|
2015-11-13 11:14:40 -05:00
|
|
|
} test_loop_passed();
|
2014-05-18 14:11:21 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
q.set_flag(Q_NO_SORT);
|
|
|
|
q.sort(COMPARE_TITLE, true);
|
|
|
|
for (i = 0; i < 13; i++) {
|
2015-11-19 13:50:08 -05:00
|
|
|
track = queue_at(&q, i);
|
|
|
|
test_loop_not_equal(track, NULL, i);
|
|
|
|
test_loop_equal(track->tr_dbe.dbe_index, ex_count[i], i);
|
2015-11-13 11:14:40 -05:00
|
|
|
} test_loop_passed();
|
2014-05-18 14:11:21 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
q.unset_flag(Q_NO_SORT);
|
|
|
|
q.sort(COMPARE_TITLE, true);
|
|
|
|
for (i = 0; i < 13; i++) {
|
2015-11-19 13:50:08 -05:00
|
|
|
track = queue_at(&q, i);
|
|
|
|
test_loop_not_equal(track, NULL, i);
|
|
|
|
test_loop_equal(track->tr_dbe.dbe_index, ex_title[i], i);
|
2015-11-13 11:14:40 -05:00
|
|
|
} test_loop_passed();
|
|
|
|
|
|
|
|
q.sort(COMPARE_COUNT, true);
|
2015-11-16 09:54:47 -05:00
|
|
|
q.sort(COMPARE_TITLE, false);
|
2015-11-13 11:14:40 -05:00
|
|
|
q.sort(COMPARE_COUNT, false);
|
|
|
|
for (i = 0; i < 13; i++) {
|
2015-11-19 13:50:08 -05:00
|
|
|
track = queue_at(&q, i);
|
|
|
|
test_loop_not_equal(track, NULL, i);
|
|
|
|
test_loop_equal(track->tr_dbe.dbe_index, ex_co_ti[i], i);
|
2015-11-13 11:14:40 -05:00
|
|
|
} test_loop_passed();
|
2015-01-04 17:56:54 -05:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
q.sort(COMPARE_ARTIST, true);
|
|
|
|
q.sort(COMPARE_ALBUM, false);
|
|
|
|
q.sort(COMPARE_TRACK, false);
|
|
|
|
q.sort(COMPARE_TRACK, false);
|
|
|
|
for (i = 0; i < 13; i++) {
|
2015-11-19 13:50:08 -05:00
|
|
|
track = queue_at(&q, i);
|
|
|
|
test_loop_not_equal(track, NULL, i);
|
|
|
|
test_loop_equal(track->tr_dbe.dbe_index, 12 - i, i);
|
2015-11-13 11:14:40 -05:00
|
|
|
} test_loop_passed();
|
|
|
|
}
|
2015-01-04 17:56:54 -05:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
static void test_save_load()
|
2014-05-18 14:39:20 -04:00
|
|
|
{
|
2015-11-16 09:12:15 -05:00
|
|
|
struct queue q(Q_RANDOM), r(0);
|
2015-11-19 13:50:08 -05:00
|
|
|
struct track *track;
|
2015-11-13 11:14:40 -05:00
|
|
|
unsigned int i;
|
|
|
|
struct file f;
|
2014-05-18 14:39:20 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
for (i = 0; i < 13; i++)
|
|
|
|
q.add(track_get(i));
|
|
|
|
q.sort(COMPARE_TRACK, true);
|
|
|
|
q.sort(COMPARE_TRACK, false);
|
2014-05-18 14:39:20 -04:00
|
|
|
|
2015-09-10 10:33:24 -04:00
|
|
|
file_init(&f, "test.q", 0);
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_WRITE);
|
2014-05-18 14:39:20 -04:00
|
|
|
q.write(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2014-05-18 14:39:20 -04:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_READ);
|
2014-05-18 14:39:20 -04:00
|
|
|
r.read(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2014-05-18 14:39:20 -04:00
|
|
|
|
2015-11-20 08:18:54 -05:00
|
|
|
test_equal(queue_has_flag(&r, Q_RANDOM), true);
|
2015-11-18 08:04:00 -05:00
|
|
|
test_equal(r.q_length, q.q_length);
|
2015-11-19 13:48:59 -05:00
|
|
|
test_equal(queue_size(&r), 13);
|
2015-11-13 11:14:40 -05:00
|
|
|
|
|
|
|
for (i = 0; i < 13; i++) {
|
2015-11-19 13:50:08 -05:00
|
|
|
track = queue_at(&q, i);
|
|
|
|
test_loop_not_equal(track, NULL ,i);
|
|
|
|
test_loop_equal(track->tr_dbe.dbe_index, 12 - i, i);
|
2015-11-13 11:14:40 -05:00
|
|
|
} test_loop_passed();
|
2014-05-11 10:18:48 -04:00
|
|
|
|
2015-11-13 11:14:40 -05:00
|
|
|
__test_deinit_core();
|
2014-04-13 12:26:32 -04:00
|
|
|
}
|
2015-08-28 09:26:22 -04:00
|
|
|
|
|
|
|
DECLARE_UNIT_TESTS(
|
2015-11-13 11:14:40 -05:00
|
|
|
UNIT_TEST("Queue Initialization", test_init),
|
2015-08-28 09:26:22 -04:00
|
|
|
UNIT_TEST("Queue Flags", test_flags),
|
2015-11-13 11:14:40 -05:00
|
|
|
UNIT_TEST("Queue Basics", test_basics),
|
|
|
|
UNIT_TEST("Queue Stress (n = 0)", test_stress_0),
|
|
|
|
UNIT_TEST("Queue Stress (n = 100,000)", test_stress_100K),
|
|
|
|
UNIT_TEST("Queue Random Next and Selection", test_rand_select),
|
2015-08-28 09:26:22 -04:00
|
|
|
UNIT_TEST("Queue Sorting", test_sorting),
|
2015-11-13 11:14:40 -05:00
|
|
|
UNIT_TEST("Queue Save and Load", test_save_load),
|
2015-08-28 09:26:22 -04:00
|
|
|
);
|