2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 #include <grub/test.h>
22 #include <grub/misc.h>
23 #include <grub/priority_queue.h>
34 compar (const void *a_, const void *b_)
46 priority_queue_test (void)
48 priority_queue <int> pq;
49 grub_priority_queue_t pq2;
52 pq2 = grub_priority_queue_new (sizeof (int), compar);
56 "priority queue: queue creating failed\n");
61 for (counter = 0; counter < 1000000; counter++)
63 int op = rand () % 10;
64 if (s && *(int *) grub_priority_queue_top (pq2) != pq.top ())
66 printf ("Error at %d\n", counter);
68 "priority queue: error at %d\n", counter);
73 grub_priority_queue_pop (pq2);
81 if (grub_priority_queue_push (pq2, &v) != 0)
84 "priority queue: push failed");
92 if (*(int *) grub_priority_queue_top (pq2) != pq.top ())
95 "priority queue: Error at the end. %d elements remaining.\n", s);
98 grub_priority_queue_pop (pq2);
102 printf ("priority_queue: passed successfully\n");
105 GRUB_UNIT_TEST ("priority_queue_unit_test", priority_queue_test);