bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainenstatic int cmp_int(const void *p1, const void *p2)
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen struct pq_test_item *item, items[PQ_MAX_ITEMS];
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen unsigned int i, j;
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen pool = pool_alloconly_create("priorityq items", 1024);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen /* simple tests with popping only */
2a51b74d417285de5885460c659d92417f64b127Timo Sirainen test_assert(priorityq_count(pq) == N_ELEMENTS(output));
2a51b74d417285de5885460c659d92417f64b127Timo Sirainen test_assert(item->num <= output[N_ELEMENTS(output)-1]);
2a51b74d417285de5885460c659d92417f64b127Timo Sirainen test_assert(priorityq_count(pq) == N_ELEMENTS(output) - j);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen item = (struct pq_test_item *)priorityq_peek(pq);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen item = (struct pq_test_item *)priorityq_pop(pq);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen /* randomized tests, remove elements */
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (i = 0; i < 100; i++) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (j = 0; j < PQ_MAX_ITEMS; j++) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (j = 0; j < PQ_MAX_ITEMS; j++) {
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen item = (struct pq_test_item *)priorityq_pop(pq);
2a51b74d417285de5885460c659d92417f64b127Timo Sirainen test_assert(item->num >= 0 && prev <= item->num);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen for (j = 0; j < PQ_MAX_ITEMS; j++) {