test-prio-queue: use xmalloc
[gitweb.git] / t / helper / test-prio-queue.c
index 9807b649b14c0002bee6d10b200c27bb89a54812..f4028442e37e39d7ec35abf00c237d4d2cbac892 100644 (file)
@@ -22,15 +22,25 @@ int cmd__prio_queue(int argc, const char **argv)
        struct prio_queue pq = { intcmp };
 
        while (*++argv) {
-               if (!strcmp(*argv, "get"))
-                       show(prio_queue_get(&pq));
-               else if (!strcmp(*argv, "dump")) {
-                       int *v;
-                       while ((v = prio_queue_get(&pq)))
-                              show(v);
-               }
-               else {
-                       int *v = malloc(sizeof(*v));
+               if (!strcmp(*argv, "get")) {
+                       void *peek = prio_queue_peek(&pq);
+                       void *get = prio_queue_get(&pq);
+                       if (peek != get)
+                               BUG("peek and get results do not match");
+                       show(get);
+               } else if (!strcmp(*argv, "dump")) {
+                       void *peek;
+                       void *get;
+                       while ((peek = prio_queue_peek(&pq))) {
+                               get = prio_queue_get(&pq);
+                               if (peek != get)
+                                       BUG("peek and get results do not match");
+                               show(get);
+                       }
+               } else if (!strcmp(*argv, "stack")) {
+                       pq.compare = NULL;
+               } else {
+                       int *v = xmalloc(sizeof(*v));
                        *v = atoi(*argv);
                        prio_queue_put(&pq, v);
                }