Wrote a test around the mpsc_queue
[sandbox] / vm / mpsc_queue_test.c
1 #include <assert.h>
2 #include <stdio.h>
3
4 #include "mpsc_queue.c"
5
6 void noopFreer(void* _) { }
7
8 bool test_single_threaded()
9 {
10   Queue queue;
11   initializeQueue(&queue);
12
13   int inputs[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
14
15   for(int i = 0; i < 10; i++)
16   {
17     enqueue(&queue, &(inputs[i]));
18   }
19
20   int* outputs[10];
21   int index = 0;
22
23   while(!isEmpty(&queue))
24   {
25     outputs[index++] = dequeue(&queue);
26   }
27
28   for(int i = 0; i < 10; i++)
29   {
30     assert(i == *(outputs[i]));
31   }
32
33   freeQueue(&queue, noopFreer);
34
35   return true;
36 }
37
38 int main(int argc, char** argv)
39 {
40   #define TEST_COUNT 1
41   bool (*tests[TEST_COUNT])() = {
42     test_single_threaded
43   };
44
45   for(int i = 0; i < TEST_COUNT; i++)
46   {
47     if(tests[i]())
48     {
49       printf(".");
50     }
51
52     else
53     {
54       printf("F");
55     }
56   }
57
58   return EXIT_SUCCESS;
59 }