diff --git a/core/queue.c b/core/queue.c index c5466e0c..e91a9ecd 100644 --- a/core/queue.c +++ b/core/queue.c @@ -220,6 +220,17 @@ void queue_clear(struct queue *queue) __queue_clear(queue, n); } +bool queue_has(struct queue *queue, struct track *track) +{ + struct queue_iter it; + + queue_for_each(queue, &it) { + if (queue_iter_val(&it) == track) + return true; + } + return false; +} + void queue_updated(struct queue *queue, struct track *track) { struct queue_iter it; diff --git a/include/core/queue.h b/include/core/queue.h index 623c931d..bfe4bad9 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -161,6 +161,9 @@ unsigned int queue_remove_all(struct queue *, struct track *); /* Called to remove all tracks from the queue. */ void queue_clear(struct queue *); +/* Called to check if a queue has a track. */ +bool queue_has(struct queue *, struct track *); + /* Called to tell the queue that a track has been updated. */ void queue_updated(struct queue *, struct track *); diff --git a/tests/core/queue.c b/tests/core/queue.c index 8e76de3d..5ef290b6 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -238,13 +238,18 @@ static void test_stress(unsigned int N) g_assert_cmpuint(i, ==, N); g_assert_cmpuint(queue_size(&q), ==, ex_size); - /* queue_remove_all() */ + /* queue_remove_all() and queue_has() */ track = track_get(0); ex_length -= track->tr_length * (N / 13); ex_size -= (N / 13); + if (N > 0) + test_equal(queue_has(&q, track), (bool)true); + else + test_equal(queue_has(&q, track), (bool)false); test_equal(queue_remove_all(&q, track), N / 13); test_equal(q.q_length, ex_length); test_equal(queue_size(&q), ex_size); + test_equal(queue_has(&q, track), (bool)false); /* queue_erase() = false */ can_erase = false;