diff --git a/src/opr/queue.h b/src/opr/queue.h index dd45f68d75..e31c9024fe 100644 --- a/src/opr/queue.h +++ b/src/opr/queue.h @@ -124,6 +124,11 @@ opr_queue_IsOnQueue(struct opr_queue *q) { static_inline int opr_queue_IsEnd(struct opr_queue *q, struct opr_queue *cursor) { + return (cursor == q); +} + +static_inline int +opr_queue_IsLast(struct opr_queue *q, struct opr_queue *cursor) { return (cursor->next == q); } diff --git a/tests/opr/queues-t.c b/tests/opr/queues-t.c index 257e519802..df43f5d3c2 100644 --- a/tests/opr/queues-t.c +++ b/tests/opr/queues-t.c @@ -57,7 +57,7 @@ main(void) { struct opr_queue q1, q2, q3, q4, *cursor; - plan(17); + plan(20); opr_queue_Init(&q1); opr_queue_Init(&q2); @@ -136,5 +136,13 @@ main(void) is_string("ABC", queueAsString(&q3), "Swap Q3"); is_string("123", queueAsString(&q4), "Swap Q4"); + /* IsEnd and IsLast handling */ + ok(opr_queue_IsLast(&q1, &(opr_queue_Last(&q1, struct charqueue, entry)->entry)), + "IsLast is true for last element of a list"); + ok(opr_queue_IsEnd(&q1, + opr_queue_Last(&q1, struct charqueue, entry)->entry.next), + "IsEnd is true for entry after last element"); + ok(opr_queue_IsEnd(&q1, &q1), "IsEnd is true for queue head"); + return 0; }