core/queue: Add a queue_has() function

Used to check if a track is on a queue.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-04-16 16:42:54 -04:00 committed by Anna Schumaker
parent afb2653f65
commit 9ec2497ac5
3 changed files with 20 additions and 1 deletions

View File

@ -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;

View File

@ -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 *);

View File

@ -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;