]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-prio-queue.c
Merge branch 'ob/t9001-indent-fix'
[thirdparty/git.git] / t / helper / test-prio-queue.c
1 #include "test-tool.h"
2 #include "prio-queue.h"
3
4 static int intcmp(const void *va, const void *vb, void *data UNUSED)
5 {
6 const int *a = va, *b = vb;
7 return *a - *b;
8 }
9
10 static void show(int *v)
11 {
12 if (!v)
13 printf("NULL\n");
14 else
15 printf("%d\n", *v);
16 free(v);
17 }
18
19 int cmd__prio_queue(int argc UNUSED, const char **argv)
20 {
21 struct prio_queue pq = { intcmp };
22
23 while (*++argv) {
24 if (!strcmp(*argv, "get")) {
25 void *peek = prio_queue_peek(&pq);
26 void *get = prio_queue_get(&pq);
27 if (peek != get)
28 BUG("peek and get results do not match");
29 show(get);
30 } else if (!strcmp(*argv, "dump")) {
31 void *peek;
32 void *get;
33 while ((peek = prio_queue_peek(&pq))) {
34 get = prio_queue_get(&pq);
35 if (peek != get)
36 BUG("peek and get results do not match");
37 show(get);
38 }
39 } else if (!strcmp(*argv, "stack")) {
40 pq.compare = NULL;
41 } else {
42 int *v = xmalloc(sizeof(*v));
43 *v = atoi(*argv);
44 prio_queue_put(&pq, v);
45 }
46 }
47
48 clear_prio_queue(&pq);
49
50 return 0;
51 }