1 #include "test_RecordedArg.h"
2 #include <RecordedArg.h>
32 void SetUp_RecordedArg(
void){}
33 void TearDown_RecordedArg(
void){}
34 void SetupRecord_uint8_t_points_pArg_at_a_uint8_t(
void)
38 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint8_t);
39 *((uint8_t *)record_of_arg1->pArg) = b1;
41 TEST_ASSERT_EQUAL_UINT8(b1, *((uint8_t *)record_of_arg1->pArg));
43 RecordedArg_destroy(record_of_arg1);
44 record_of_arg1 = NULL;
46 void Destroy_for_SetupRecord_uint8_t_frees_a_uint8_t(
void)
50 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint8_t);
51 *((uint8_t *)record_of_arg1->pArg) = b1;
53 TEST_ASSERT_NOT_EQUAL(NULL, record_of_arg1->Destroy);
55 RecordedArg_destroy(record_of_arg1);
56 record_of_arg1 = NULL;
58 void Print_for_SetupRecord_uint8_t_prints_a_uint8_t_to_a_string(
void)
62 GString *expected = g_string_new(
"(uint8_t)0x12");
63 GString *actual = g_string_new(NULL);
64 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint8_t);
65 *((uint8_t *)record_of_arg1->pArg) = b1;
67 record_of_arg1->Print(actual, record_of_arg1);
69 TEST_ASSERT_EQUAL_STRING( expected->str, actual->str);
71 g_string_free(expected,
true);
72 g_string_free(actual,
true);
73 RecordedArg_destroy(record_of_arg1);
74 record_of_arg1 = NULL;
76 void Match_for_SetupRecord_uint8_t_checks_if_uint8_t_values_match(
void)
79 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint8_t);
80 RecordedArg *record_of_arg2 = RecordedArg_new(SetupRecord_uint8_t);
81 RecordedArg *record_of_arg3 = RecordedArg_new(SetupRecord_uint8_t);
84 *((uint8_t *)record_of_arg1->pArg) = b9;
85 *((uint8_t *)record_of_arg2->pArg) = b9;
86 *((uint8_t *)record_of_arg3->pArg) = b3;
88 TEST_ASSERT_TRUE (record_of_arg1->Match(record_of_arg1, record_of_arg2));
89 TEST_ASSERT_FALSE(record_of_arg1->Match(record_of_arg1, record_of_arg3));
91 RecordedArg_destroy(record_of_arg1);
92 record_of_arg1 = NULL;
93 RecordedArg_destroy(record_of_arg2);
94 record_of_arg2 = NULL;
95 RecordedArg_destroy(record_of_arg3);
96 record_of_arg3 = NULL;
99 void SetupRecord_uint16_t_points_pArg_at_a_uint16_t(
void)
103 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint16_t);
104 *((uint16_t *)record_of_arg1->pArg) = b1;
106 TEST_ASSERT_EQUAL_UINT8(b1, *((uint16_t *)record_of_arg1->pArg));
108 RecordedArg_destroy(record_of_arg1);
109 record_of_arg1 = NULL;
111 void Destroy_for_SetupRecord_uint16_t_frees_a_uint16_t(
void)
115 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint16_t);
116 *((uint16_t *)record_of_arg1->pArg) = b1;
118 TEST_ASSERT_NOT_EQUAL(NULL, record_of_arg1->Destroy);
120 RecordedArg_destroy(record_of_arg1);
121 record_of_arg1 = NULL;
123 void Print_for_SetupRecord_uint16_t_prints_a_uint16_t_to_a_string(
void)
126 uint16_t b1 = 0x1234;
127 GString *expected = g_string_new(
"(uint16_t)0x1234");
128 GString *actual = g_string_new(NULL);
129 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint16_t);
130 *((uint16_t *)record_of_arg1->pArg) = b1;
132 record_of_arg1->Print(actual, record_of_arg1);
134 TEST_ASSERT_EQUAL_STRING( expected->str, actual->str);
136 g_string_free(expected,
true);
137 g_string_free(actual,
true);
138 RecordedArg_destroy(record_of_arg1);
139 record_of_arg1 = NULL;
141 void Match_for_SetupRecord_uint16_t_checks_if_uint16_t_values_match(
void)
144 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint16_t);
145 RecordedArg *record_of_arg2 = RecordedArg_new(SetupRecord_uint16_t);
146 RecordedArg *record_of_arg3 = RecordedArg_new(SetupRecord_uint16_t);
149 *((uint16_t *)record_of_arg1->pArg) = b9;
150 *((uint16_t *)record_of_arg2->pArg) = b9;
151 *((uint16_t *)record_of_arg3->pArg) = b3;
153 TEST_ASSERT_TRUE (record_of_arg1->Match(record_of_arg1, record_of_arg2));
154 TEST_ASSERT_FALSE(record_of_arg1->Match(record_of_arg1, record_of_arg3));
156 RecordedArg_destroy(record_of_arg1);
157 record_of_arg1 = NULL;
158 RecordedArg_destroy(record_of_arg2);
159 record_of_arg2 = NULL;
160 RecordedArg_destroy(record_of_arg3);
161 record_of_arg3 = NULL;
164 void SetupRecord_GString_points_pArg_at_a_GString(
void)
167 GString *pGS1 = g_string_new(
"string 1");
168 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_GString);
169 record_of_arg1->pArg = (
void *)g_string_new(pGS1->str);
171 TEST_ASSERT_EQUAL_STRING(pGS1->str, ((GString *)record_of_arg1->pArg)->str);
173 g_string_free(pGS1,
true);
174 RecordedArg_destroy(record_of_arg1);
175 record_of_arg1 = NULL;
177 void Destroy_for_SetupRecord_GString_frees_a_GString(
void)
180 GString *pGS1 = g_string_new(
"string 1");
181 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_GString);
182 record_of_arg1->pArg = (
void *)g_string_new(pGS1->str);
184 TEST_ASSERT_NOT_EQUAL(NULL, record_of_arg1->Destroy);
186 RecordedArg_destroy(record_of_arg1);
187 record_of_arg1 = NULL;
189 void Print_for_SetupRecord_GString_prints_a_GString_to_a_string(
void)
192 GString *expected = g_string_new(
"(GString)bob");
193 GString *actual = g_string_new(NULL);
194 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_GString);
195 record_of_arg1->pArg = (
void *)g_string_new(
"bob");
197 record_of_arg1->Print(actual, record_of_arg1);
199 TEST_ASSERT_EQUAL_STRING( expected->str, actual->str);
201 g_string_free(expected,
true);
202 g_string_free(actual,
true);
203 RecordedArg_destroy(record_of_arg1);
204 record_of_arg1 = NULL;
206 void Match_for_SetupRecord_GString_checks_if_GString_values_match(
void)
209 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_GString);
210 RecordedArg *record_of_arg2 = RecordedArg_new(SetupRecord_GString);
211 RecordedArg *record_of_arg3 = RecordedArg_new(SetupRecord_GString);
212 GString *str3 = g_string_new(
"string 3");
213 GString *str9 = g_string_new(
"string 9");
214 record_of_arg1->pArg = (
void *)g_string_new(str9->str);
215 record_of_arg2->pArg = (
void *)g_string_new(str9->str);
216 record_of_arg3->pArg = (
void *)g_string_new(str3->str);
218 TEST_ASSERT_TRUE (record_of_arg1->Match(record_of_arg1, record_of_arg2));
219 TEST_ASSERT_FALSE(record_of_arg1->Match(record_of_arg1, record_of_arg3));
221 g_string_free(str3,
true);
222 g_string_free(str9,
true);
223 RecordedArg_destroy(record_of_arg1);
224 record_of_arg1 = NULL;
225 RecordedArg_destroy(record_of_arg2);
226 record_of_arg2 = NULL;
227 RecordedArg_destroy(record_of_arg3);
228 record_of_arg3 = NULL;
231 void SetupRecord_p_uint8_t_points_pArg_at_a_pointer_to_an_uint8_t(
void)
235 uint8_t *b1_address = &b1;
236 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_uint8_t);
237 *((uint8_t **)record_of_arg1->pArg) = b1_address;
240 TEST_ASSERT_EQUAL_PTR(b1_address, *((uint8_t **)record_of_arg1->pArg));
242 RecordedArg_destroy(record_of_arg1);
243 record_of_arg1 = NULL;
245 void Destroy_for_SetupRecord_p_uint8_t_frees_a_pointer_to_an_uint8_t(
void)
249 uint8_t *b1_address = &b1;
250 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_uint8_t);
251 *((uint8_t **)record_of_arg1->pArg) = b1_address;
253 TEST_ASSERT_NOT_EQUAL(NULL, record_of_arg1->Destroy);
255 RecordedArg_destroy(record_of_arg1);
256 record_of_arg1 = NULL;
258 void Print_for_SetupRecord_p_uint8_t_derefs_and_prints_value_to_a_string(
void)
261 GString *expected = g_string_new(
"(uint8_t)0x12"); uint8_t b1 = 0x12;
262 uint8_t *b1_address = &b1;
263 GString *actual = g_string_new(NULL);
264 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_uint8_t);
265 *((uint8_t **)record_of_arg1->pArg) = b1_address;
267 record_of_arg1->Print(actual, record_of_arg1);
269 TEST_ASSERT_EQUAL_STRING( expected->str, actual->str);
271 g_string_free(expected,
true);
272 g_string_free(actual,
true);
273 RecordedArg_destroy(record_of_arg1);
274 record_of_arg1 = NULL;
276 void Match_for_SetupRecord_p_uint8_t_derefs_and_checks_if_values_match(
void)
279 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_uint8_t);
280 RecordedArg *record_of_arg2 = RecordedArg_new(SetupRecord_p_uint8_t);
281 RecordedArg *record_of_arg3 = RecordedArg_new(SetupRecord_p_uint8_t);
282 uint8_t b3 = 0x03; uint8_t *b3_address = &b3;
283 uint8_t b9 = 0x09; uint8_t *b9_address = &b9;
284 *((uint8_t **)record_of_arg1->pArg) = b9_address;
285 *((uint8_t **)record_of_arg2->pArg) = b9_address;
286 *((uint8_t **)record_of_arg3->pArg) = b3_address;
288 TEST_ASSERT_TRUE (record_of_arg1->Match(record_of_arg1, record_of_arg2));
289 TEST_ASSERT_FALSE(record_of_arg1->Match(record_of_arg1, record_of_arg3));
291 RecordedArg_destroy(record_of_arg1);
292 record_of_arg1 = NULL;
293 RecordedArg_destroy(record_of_arg2);
294 record_of_arg2 = NULL;
295 RecordedArg_destroy(record_of_arg3);
296 record_of_arg3 = NULL;
299 void SetupRecord_p_GString_points_pArg_at_a_pointer_to_a_GString(
void)
302 GString *p_gstring_arg1 = g_string_new(
"string 1");
303 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_GString);
304 *((GString **)record_of_arg1->pArg) = p_gstring_arg1;
306 TEST_ASSERT_EQUAL_STRING(
308 (*((GString **)record_of_arg1->pArg))->str
311 g_string_free(p_gstring_arg1,
true);
312 RecordedArg_destroy(record_of_arg1);
313 record_of_arg1 = NULL;
315 void Destroy_for_SetupRecord_p_GString_frees_a_pointer_to_a_GString(
void)
318 GString *p_gstring_arg1 = g_string_new(
"string 1");
319 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_GString);
320 *((GString **)record_of_arg1->pArg) = p_gstring_arg1;
322 TEST_ASSERT_NOT_EQUAL(NULL, record_of_arg1->Destroy);
324 RecordedArg_destroy(record_of_arg1);
325 record_of_arg1 = NULL;
327 void Print_for_SetupRecord_p_GString_derefs_and_prints_value_to_a_string(
void)
330 GString *expected = g_string_new(
"(GString *)bob");
331 GString *actual = g_string_new(NULL);
332 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_GString);
333 GString *p_gstring_arg1 = g_string_new(
"bob");
334 *((GString **)record_of_arg1->pArg) = p_gstring_arg1;
336 record_of_arg1->Print(actual, record_of_arg1);
338 TEST_ASSERT_EQUAL_STRING( expected->str, actual->str);
340 g_string_free(expected,
true);
341 g_string_free(actual,
true);
342 RecordedArg_destroy(record_of_arg1);
343 record_of_arg1 = NULL;
345 void Match_for_SetupRecord_p_GString_derefs_and_checks_if_values_match(
void)
348 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_p_GString);
349 RecordedArg *record_of_arg2 = RecordedArg_new(SetupRecord_p_GString);
350 RecordedArg *record_of_arg3 = RecordedArg_new(SetupRecord_p_GString);
351 GString *str9 = g_string_new(
"string 9");
352 GString *str3 = g_string_new(
"string 3");
353 *((GString **)record_of_arg1->pArg) = str9;
354 *((GString **)record_of_arg2->pArg) = str9;
355 *((GString **)record_of_arg3->pArg) = str3;
357 TEST_ASSERT_TRUE (record_of_arg1->Match(record_of_arg1, record_of_arg2));
358 TEST_ASSERT_FALSE(record_of_arg1->Match(record_of_arg1, record_of_arg3));
360 g_string_free(str3,
true);
361 g_string_free(str9,
true);
362 RecordedArg_destroy(record_of_arg1);
363 record_of_arg1 = NULL;
364 RecordedArg_destroy(record_of_arg2);
365 record_of_arg2 = NULL;
366 RecordedArg_destroy(record_of_arg3);
367 record_of_arg3 = NULL;