summaryrefslogtreecommitdiff
path: root/src/test/test-prioq.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-01-26 11:27:18 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-01-26 12:42:46 +0100
commitef21b3b5bf824e652addf850bcfd9374c7b33ce8 (patch)
treef3eb16a2502e026aaa6e803d3a686f93c6a84f19 /src/test/test-prioq.c
parentc482724aa5c5d0b1391fcf958a9a3ea6ce73a085 (diff)
downloadsystemd-ef21b3b5bf824e652addf850bcfd9374c7b33ce8.tar.gz
basic/prioq: add prioq_peek_item()
Diffstat (limited to 'src/test/test-prioq.c')
-rw-r--r--src/test/test-prioq.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/test-prioq.c b/src/test/test-prioq.c
index bc5fdd15b2..53c9e090a7 100644
--- a/src/test/test-prioq.c
+++ b/src/test/test-prioq.c
@@ -69,6 +69,11 @@ static void test_struct(void) {
assert_se(q = prioq_new((compare_func_t) test_compare));
assert_se(s = set_new(&test_hash_ops));
+ assert_se(prioq_peek(q) == NULL);
+ assert_se(prioq_peek_by_index(q, 0) == NULL);
+ assert_se(prioq_peek_by_index(q, 1) == NULL);
+ assert_se(prioq_peek_by_index(q, (unsigned) -1) == NULL);
+
for (i = 0; i < SET_SIZE; i++) {
assert_se(t = new0(struct test, 1));
t->value = (unsigned) rand();
@@ -79,6 +84,17 @@ static void test_struct(void) {
assert_se(set_consume(s, t) >= 0);
}
+ for (i = 0; i < SET_SIZE; i++)
+ assert_se(prioq_peek_by_index(q, i));
+ assert_se(prioq_peek_by_index(q, SET_SIZE) == NULL);
+
+ unsigned count = 0;
+ PRIOQ_FOREACH_ITEM(q, t) {
+ assert_se(t);
+ count++;
+ }
+ assert_se(count == SET_SIZE);
+
while ((t = set_steal_first(s))) {
assert_se(prioq_remove(q, t, &t->idx) == 1);
assert_se(prioq_remove(q, t, &t->idx) == 0);