comparison tests/test-state.c @ 469:0d6206cee6b9

core: state -> mlk_state
author David Demelier <markand@malikania.fr>
date Mon, 27 Feb 2023 11:11:23 +0100
parents 02c1481b7dbb
children ca30ff96bbe0
comparison
equal deleted inserted replaced
468:91ce23a36143 469:0d6206cee6b9
34 unsigned int resume; 34 unsigned int resume;
35 unsigned int end; 35 unsigned int end;
36 unsigned int finish; 36 unsigned int finish;
37 }; 37 };
38 38
39 static struct state *mainstates[16]; 39 static struct mlk_state *mainstates[16];
40 40
41 static void 41 static void
42 my_start(struct state *state) 42 my_start(struct mlk_state *state)
43 { 43 {
44 ((struct invokes *)state->data)->start++; 44 ((struct invokes *)state->data)->start++;
45 } 45 }
46 46
47 static void 47 static void
48 my_handle(struct state *state, const union mlk_event *ev) 48 my_handle(struct mlk_state *state, const union mlk_event *ev)
49 { 49 {
50 (void)ev; 50 (void)ev;
51 51
52 ((struct invokes *)state->data)->handle++; 52 ((struct invokes *)state->data)->handle++;
53 } 53 }
54 54
55 static void 55 static void
56 my_update(struct state *state, unsigned int ticks) 56 my_update(struct mlk_state *state, unsigned int ticks)
57 { 57 {
58 (void)ticks; 58 (void)ticks;
59 59
60 ((struct invokes *)state->data)->update++; 60 ((struct invokes *)state->data)->update++;
61 } 61 }
62 62
63 static void 63 static void
64 my_draw(struct state *state) 64 my_draw(struct mlk_state *state)
65 { 65 {
66 ((struct invokes *)state->data)->draw++; 66 ((struct invokes *)state->data)->draw++;
67 } 67 }
68 68
69 static void 69 static void
70 my_suspend(struct state *state) 70 my_suspend(struct mlk_state *state)
71 { 71 {
72 ((struct invokes *)state->data)->suspend++; 72 ((struct invokes *)state->data)->suspend++;
73 } 73 }
74 74
75 static void 75 static void
76 my_resume(struct state *state) 76 my_resume(struct mlk_state *state)
77 { 77 {
78 ((struct invokes *)state->data)->resume++; 78 ((struct invokes *)state->data)->resume++;
79 } 79 }
80 80
81 static void 81 static void
82 my_end(struct state *state) 82 my_end(struct mlk_state *state)
83 { 83 {
84 ((struct invokes *)state->data)->end++; 84 ((struct invokes *)state->data)->end++;
85 } 85 }
86 86
87 static void 87 static void
88 my_finish(struct state *state) 88 my_finish(struct mlk_state *state)
89 { 89 {
90 ((struct invokes *)state->data)->finish++; 90 ((struct invokes *)state->data)->finish++;
91 } 91 }
92 92
93 #define INIT(pdata) { \ 93 #define INIT(pdata) { \
104 104
105 static void 105 static void
106 test_basics_start(void) 106 test_basics_start(void)
107 { 107 {
108 struct invokes inv = {0}; 108 struct invokes inv = {0};
109 struct state state = INIT(&inv); 109 struct mlk_state state = INIT(&inv);
110 110
111 state_start(&state); 111 mlk_state_start(&state);
112 DT_EQ_UINT(inv.start, 1U); 112 DT_EQ_UINT(inv.start, 1U);
113 DT_EQ_UINT(inv.handle, 0U); 113 DT_EQ_UINT(inv.handle, 0U);
114 DT_EQ_UINT(inv.update, 0U); 114 DT_EQ_UINT(inv.update, 0U);
115 DT_EQ_UINT(inv.draw, 0U); 115 DT_EQ_UINT(inv.draw, 0U);
116 DT_EQ_UINT(inv.end, 0U); 116 DT_EQ_UINT(inv.end, 0U);
119 119
120 static void 120 static void
121 test_basics_handle(void) 121 test_basics_handle(void)
122 { 122 {
123 struct invokes inv = {0}; 123 struct invokes inv = {0};
124 struct state state = INIT(&inv); 124 struct mlk_state state = INIT(&inv);
125 125
126 state_handle(&state, &(const union mlk_event){0}); 126 mlk_state_handle(&state, &(const union mlk_event){0});
127 DT_EQ_UINT(inv.start, 0U); 127 DT_EQ_UINT(inv.start, 0U);
128 DT_EQ_UINT(inv.handle, 1U); 128 DT_EQ_UINT(inv.handle, 1U);
129 DT_EQ_UINT(inv.update, 0U); 129 DT_EQ_UINT(inv.update, 0U);
130 DT_EQ_UINT(inv.draw, 0U); 130 DT_EQ_UINT(inv.draw, 0U);
131 DT_EQ_UINT(inv.end, 0U); 131 DT_EQ_UINT(inv.end, 0U);
134 134
135 static void 135 static void
136 test_basics_update(void) 136 test_basics_update(void)
137 { 137 {
138 struct invokes inv = {0}; 138 struct invokes inv = {0};
139 struct state state = INIT(&inv); 139 struct mlk_state state = INIT(&inv);
140 140
141 state_update(&state, 0); 141 mlk_state_update(&state, 0);
142 DT_EQ_UINT(inv.start, 0U); 142 DT_EQ_UINT(inv.start, 0U);
143 DT_EQ_UINT(inv.handle, 0U); 143 DT_EQ_UINT(inv.handle, 0U);
144 DT_EQ_UINT(inv.update, 1U); 144 DT_EQ_UINT(inv.update, 1U);
145 DT_EQ_UINT(inv.draw, 0U); 145 DT_EQ_UINT(inv.draw, 0U);
146 DT_EQ_UINT(inv.end, 0U); 146 DT_EQ_UINT(inv.end, 0U);
149 149
150 static void 150 static void
151 test_basics_draw(void) 151 test_basics_draw(void)
152 { 152 {
153 struct invokes inv = {0}; 153 struct invokes inv = {0};
154 struct state state = INIT(&inv); 154 struct mlk_state state = INIT(&inv);
155 155
156 state_draw(&state); 156 mlk_state_draw(&state);
157 DT_EQ_UINT(inv.start, 0U); 157 DT_EQ_UINT(inv.start, 0U);
158 DT_EQ_UINT(inv.handle, 0U); 158 DT_EQ_UINT(inv.handle, 0U);
159 DT_EQ_UINT(inv.update, 0U); 159 DT_EQ_UINT(inv.update, 0U);
160 DT_EQ_UINT(inv.draw, 1U); 160 DT_EQ_UINT(inv.draw, 1U);
161 DT_EQ_UINT(inv.end, 0U); 161 DT_EQ_UINT(inv.end, 0U);
164 164
165 static void 165 static void
166 test_basics_end(void) 166 test_basics_end(void)
167 { 167 {
168 struct invokes inv = {0}; 168 struct invokes inv = {0};
169 struct state state = INIT(&inv); 169 struct mlk_state state = INIT(&inv);
170 170
171 state_end(&state); 171 mlk_state_end(&state);
172 DT_EQ_UINT(inv.start, 0U); 172 DT_EQ_UINT(inv.start, 0U);
173 DT_EQ_UINT(inv.handle, 0U); 173 DT_EQ_UINT(inv.handle, 0U);
174 DT_EQ_UINT(inv.update, 0U); 174 DT_EQ_UINT(inv.update, 0U);
175 DT_EQ_UINT(inv.draw, 0U); 175 DT_EQ_UINT(inv.draw, 0U);
176 DT_EQ_UINT(inv.end, 1U); 176 DT_EQ_UINT(inv.end, 1U);
179 179
180 static void 180 static void
181 test_basics_finish(void) 181 test_basics_finish(void)
182 { 182 {
183 struct invokes inv = {0}; 183 struct invokes inv = {0};
184 struct state state = INIT(&inv); 184 struct mlk_state state = INIT(&inv);
185 185
186 state_finish(&state); 186 mlk_state_finish(&state);
187 DT_EQ_UINT(inv.start, 0U); 187 DT_EQ_UINT(inv.start, 0U);
188 DT_EQ_UINT(inv.handle, 0U); 188 DT_EQ_UINT(inv.handle, 0U);
189 DT_EQ_UINT(inv.update, 0U); 189 DT_EQ_UINT(inv.update, 0U);
190 DT_EQ_UINT(inv.draw, 0U); 190 DT_EQ_UINT(inv.draw, 0U);
191 DT_EQ_UINT(inv.end, 0U); 191 DT_EQ_UINT(inv.end, 0U);
195 static void 195 static void
196 test_basics_game(void) 196 test_basics_game(void)
197 { 197 {
198 static struct { 198 static struct {
199 struct invokes inv; 199 struct invokes inv;
200 struct state state; 200 struct mlk_state state;
201 } states[] = { 201 } states[] = {
202 { .state = INIT(&states[0].inv) }, 202 { .state = INIT(&states[0].inv) },
203 { .state = INIT(&states[1].inv) } 203 { .state = INIT(&states[1].inv) }
204 }; 204 };
205 205