t/helper: merge test-prio-queue into test-tool
[git.git] / t / helper / test-prio-queue.c
blob9807b649b14c0002bee6d10b200c27bb89a54812
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "prio-queue.h"
5 static int intcmp(const void *va, const void *vb, void *data)
7 const int *a = va, *b = vb;
8 return *a - *b;
11 static void show(int *v)
13 if (!v)
14 printf("NULL\n");
15 else
16 printf("%d\n", *v);
17 free(v);
20 int cmd__prio_queue(int argc, const char **argv)
22 struct prio_queue pq = { intcmp };
24 while (*++argv) {
25 if (!strcmp(*argv, "get"))
26 show(prio_queue_get(&pq));
27 else if (!strcmp(*argv, "dump")) {
28 int *v;
29 while ((v = prio_queue_get(&pq)))
30 show(v);
32 else {
33 int *v = malloc(sizeof(*v));
34 *v = atoi(*argv);
35 prio_queue_put(&pq, v);
39 return 0;