summaryrefslogtreecommitdiff
path: root/src/test/mock_queue_tests.c
blob: 92d7cdf19782bbc18ef6bb39236330bf7de6742f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "test/minunit.h"
#include "test/mock_queue.h"

#include <stdbool.h>

mu_test mock_queue_int();
mu_test mock_queue_int_seq();
mu_test mock_queue_pop_multi();
mu_test mock_queue_clean_finish();
mu_test mock_queue_push_multidata();


void mock_queue_tests()
{
   mu_run_test("push and pop integer to mock queue", mock_queue_int);
   mu_run_test("push and pop integer sequence", mock_queue_int_seq);
   mu_run_test("pop multiple times with empty queue", mock_queue_pop_multi);
   mu_run_test("clean up mock queue", mock_queue_clean_finish);
   mu_run_test("push and pop multiple data types", mock_queue_push_multidata);
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

mu_test mock_queue_int()
{
   mock_queue(int, 5);
   mu_assert_unequal(mock_queue_len(), 0);
   mu_assert_equal(mock_front(int), 5);

   mock_pop();

   mu_assert_equal(mock_queue_len(), 0);

   return 0;
}


mu_test mock_queue_int_seq()
{
   mock_queue(int, 2);
   mock_queue(int, 1);
   mock_queue(int, 3);
   mock_queue(int, 4);

   mu_assert_unequal(mock_queue_len(), 0);
   mu_assert_equal(mock_queue_len(), 4);
   mu_assert_equal(mock_front(int), 2);

   mock_pop();

   mu_assert_unequal(mock_queue_len(), 0);
   mu_assert_equal(mock_queue_len(), 3);
   mu_assert_equal(mock_front(int), 1);

   mock_pop();

   mu_assert_unequal(mock_queue_len(), 0);
   mu_assert_equal(mock_queue_len(), 2);
   mu_assert_equal(mock_front(int), 3);

   mock_pop();

   mu_assert_unequal(mock_queue_len(), 0);
   mu_assert_equal(mock_queue_len(), 1);
   mu_assert_equal(mock_front(int), 4);

   mock_pop();

   mu_assert_equal(mock_queue_len(), 0);

   return 0;
}


mu_test mock_queue_pop_multi()
{
   mu_assert_equal(mock_queue_len(), 0);

   mock_pop();
   mock_pop();
   mock_pop();

   mu_assert_equal(mock_queue_len(), 0);
   return 0;
}


mu_test mock_queue_clean_finish()
{
   mu_assert_equal(mock_queue_len(), 0);

   mock_queue(int, 5);
   mock_queue(int, 5);
   mock_queue(int, 5);

   mu_assert_equal(mock_queue_len(), 3);

   mock_queue_cleanup();

   mu_assert_equal(mock_queue_len(), 0);

   return 0;
}


mu_test mock_queue_push_multidata()
{
   mock_queue_cleanup();
   mu_assert_equal(mock_queue_len(), 0);

   mock_queue(const char *, "hello, world!");
   mock_queue(bool, true);
   mock_queue(float, 4.20f);

   mu_assert_equal(mock_queue_len(), 3);

   mu_assert_streq(mock_front(const char *), "hello, world!");
   mock_pop();
   mu_assert_equal(mock_front(bool), true);
   mock_pop();
   mu_assert_equal(mock_front(float), 4.20f);
   mock_pop();

   mu_assert_equal(mock_queue_len(), 0);
   return 0;
}