core/history: Add history_add() function

I decided that having a uniqueue history queue doesn't really get me
anything, so I dropped that portion of the behavior.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-12 09:46:29 -05:00
parent 75c039f22d
commit c125b3893e
6 changed files with 61 additions and 8 deletions

View File

@ -145,7 +145,7 @@ void audio :: load_track(struct track *track)
return;
_load_track(track, cur_driver->is_playing());
queue_add(history_get_queue(), cur_track);
history_add(cur_track);
}
struct track *audio :: current_track()

View File

@ -217,12 +217,8 @@ struct track *deck :: next()
if (!track)
track = queue_next(collection_get_queue());
if (track) {
queue_remove_all(history_get_queue(), track);
queue_add(history_get_queue(), track);
_q_iter_set(&history_get_queue()->q_tracks,
&history_get_queue()->q_cur, 0);
}
if (track)
history_add(track);
return track;
}

View File

@ -17,6 +17,12 @@ void history_deinit()
queue_deinit(&history_queue);
}
void history_add(struct track *track)
{
queue_add(&history_queue, track);
_q_iter_set(&history_queue.q_tracks, &history_queue.q_cur, 0);
}
struct queue *history_get_queue()
{
return &history_queue;

View File

@ -13,6 +13,10 @@ void history_init(struct queue_ops *);
void history_deinit();
/* Called to add a track to the history queue. */
void history_add(struct track *);
/* Called to access the queue of recent tracks. */
struct queue *history_get_queue();

View File

@ -123,7 +123,7 @@ static void test_next_prev()
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)1);
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)2);
test_equal(deck :: next()->tr_dbe.dbe_index, (unsigned)3);
test_equal(queue_size(q), (unsigned)4);
test_equal(queue_size(q), 4 * (i + 1));
}
for (unsigned int i = 0; i < 2; i++) {

View File

@ -2,12 +2,22 @@
* 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();
filter_init();
tags_init();
playlist_init(NULL);
collection_init(NULL);
history_init(NULL);
test_not_equal((void *)q, NULL);
@ -20,9 +30,46 @@ static void test_init()
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 db_entry *track, *next;
unsigned int i = 0;
/* 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((void *)queue_at(q, 0), (void *)TRACK(track), i);
i++;
} test_loop_passed();
test_equal(queue_size(q), track_db->db_size);
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),
);