core/collection: Add functions to ban and unban tracks

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-11 08:06:49 -05:00
parent 3b5bbf14af
commit beda9bfa3f
3 changed files with 41 additions and 0 deletions

View File

@ -198,6 +198,18 @@ void collection_update_all()
collection_update(LIBRARY(library));
}
bool collection_ban(struct track *track)
{
queue_remove_all(&c_queue, track);
return true;
}
bool collection_unban(struct track *track)
{
queue_add(&c_queue, track);
return true;
}
void collection_set_enabled(struct library *library, bool enabled)
{
struct db_entry *dbe, *next;

View File

@ -38,6 +38,12 @@ void collection_update(struct library *);
/* Called to update all library paths. */
void collection_update_all();
/* Called to ban a track from the collection. */
bool collection_ban(struct track *);
/* Called to unban a track from the collection. */
bool collection_unban(struct track *);
/* Called to enable or disable a library directory. */
void collection_set_enabled(struct library *, bool);

View File

@ -136,6 +136,28 @@ static void test_enable()
test_equal(queue_size(q), 48);
}
static void test_ban()
{
struct queue *q = collection_get_queue();
struct db_entry *track, *next;
unsigned int i = 0;
db_for_each(track, next, track_db_get()) {
test_loop_equal(collection_ban(TRACK(track)), (bool)true, i);
test_loop_equal(queue_size(q), track_db_get()->db_size - (i + 1), i);
i++;
} test_loop_passed();
test_equal(queue_size(q), 0);
i = 0;
db_for_each(track, next, track_db_get()) {
test_loop_equal(collection_unban(TRACK(track)), (bool)true, i);
test_loop_equal(queue_size(q), i + 1, i);
i++;
} test_loop_passed();
test_equal(queue_size(q), track_db_get()->db_size);
}
static void test_save_load()
{
struct queue *q = collection_get_queue();
@ -187,6 +209,7 @@ DECLARE_UNIT_TESTS(
UNIT_TEST("Collection Add Path", test_add),
UNIT_TEST("Collection Update Path", test_update),
UNIT_TEST("Collection Enable and Disable", test_enable),
UNIT_TEST("Collection Ban and Unban", test_ban),
UNIT_TEST("Collection Save and Load", test_save_load),
UNIT_TEST("Collection Remove Path", test_remove),
);