Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-ctest/tests/ctest_ut/assertfailurestests.c

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #include "ctest.h"
5
6 CTEST_BEGIN_TEST_SUITE(AssertFailureTests)
7
8 typedef struct mystruct_tag
9 {
10 unsigned char x;
11 } mystruct;
12
13 CTEST_COMPARE(mystruct_ptr, mystruct*)
14 {
15 return (left->x != right->x);
16 }
17
18 CTEST_TO_STRING(mystruct_ptr, mystruct*, string, bufferSize, value)
19 {
20 (void)snprintf(string, bufferSize, "{ %d }", (int)value->x);
21 }
22
23 /* CTEST_ASSERT_FAIL */
24
25 CTEST_FUNCTION(AssertFail_Fails)
26 {
27 CTEST_ASSERT_FAIL("This test should fail.");
28 }
29
30 /* CTEST_ASSERT_ARE_EQUAL */
31
32 CTEST_FUNCTION(Assert_Are_Equal_2_Ints_Fails)
33 {
34 CTEST_ASSERT_ARE_EQUAL(int, 0, 1);
35 }
36
37 CTEST_FUNCTION(Assert_Are_Equal_2_Chars_Fails)
38 {
39 CTEST_ASSERT_ARE_EQUAL(char, (char)0, (char)1);
40 }
41
42 CTEST_FUNCTION(Assert_Are_Equal_2_Shorts_Fails)
43 {
44 CTEST_ASSERT_ARE_EQUAL(short, (short)0, (short)1);
45 }
46
47 CTEST_FUNCTION(Assert_Are_Equal_2_Longs_Fails)
48 {
49 CTEST_ASSERT_ARE_EQUAL(long, (long)0, (long)1);
50 }
51
52 CTEST_FUNCTION(Assert_Are_Equal_2_uint8_t_Fails)
53 {
54 CTEST_ASSERT_ARE_EQUAL(uint8_t, (uint8_t)0, (uint8_t)1);
55 }
56
57 CTEST_FUNCTION(Assert_Are_Equal_2_int8_t_Fails)
58 {
59 CTEST_ASSERT_ARE_EQUAL(int8_t, (int8_t)0, (int8_t)1);
60 }
61
62 CTEST_FUNCTION(Assert_Are_Equal_2_uint16_t_Fails)
63 {
64 CTEST_ASSERT_ARE_EQUAL(uint16_t, (uint16_t)0, (uint16_t)1);
65 }
66
67 CTEST_FUNCTION(Assert_Are_Equal_2_int16_t_Fails)
68 {
69 CTEST_ASSERT_ARE_EQUAL(int16_t, (int16_t)0, (int16_t)1);
70 }
71
72 CTEST_FUNCTION(Assert_Are_Equal_2_uint32_t_Fails)
73 {
74 CTEST_ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0, (uint32_t)1);
75 }
76
77 CTEST_FUNCTION(Assert_Are_Equal_2_int32_t_Fails)
78 {
79 CTEST_ASSERT_ARE_EQUAL(int32_t, (int32_t)0, (int32_t)1);
80 }
81
82 CTEST_FUNCTION(Assert_Are_Equal_2_uint64_t_Fails)
83 {
84 CTEST_ASSERT_ARE_EQUAL(uint64_t, (uint64_t)0, (uint64_t)1);
85 }
86
87 CTEST_FUNCTION(Assert_Are_Equal_2_int64_t_Fails)
88 {
89 CTEST_ASSERT_ARE_EQUAL(int64_t, (int64_t)0, (int64_t)1);
90 }
91
92 CTEST_FUNCTION(Assert_Are_Equal_2_strings_With_To_String_Type_Fails)
93 {
94 CTEST_ASSERT_ARE_EQUAL(char_ptr, "test", "dan");
95 }
96
97 CTEST_FUNCTION(Assert_Are_Equal_2_wide_strings_With_To_String_Type_Fails)
98 {
99 CTEST_ASSERT_ARE_EQUAL(wchar_ptr, L"test", L"matt");
100 }
101
102 CTEST_FUNCTION(Assert_Are_Equal_2_void_ptr_With_To_Different_Addresses_Fails)
103 {
104 char c1, c2;
105 CTEST_ASSERT_ARE_EQUAL(void_ptr, &c1, &c2);
106 }
107
108 CTEST_FUNCTION(Assert_Are_Equal_2_Structures_Fails)
109 {
110 mystruct a = { 1 };
111 mystruct b = { 42 };
112
113 CTEST_ASSERT_ARE_EQUAL(mystruct_ptr, &a, &b);
114 }
115
116 /* CTEST_ASSERT_ARE_EQUAL with custom message string */
117
118 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_Ints_Fails)
119 {
120 CTEST_ASSERT_ARE_EQUAL(int, 0, 1, "Test message");
121 }
122
123 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_Chars_Fails)
124 {
125 CTEST_ASSERT_ARE_EQUAL(char, (char)0, (char)1, "Test message");
126 }
127
128 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_Shorts_Fails)
129 {
130 CTEST_ASSERT_ARE_EQUAL(short, (short)0, (short)1, "Test message");
131 }
132
133 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_Longs_Fails)
134 {
135 CTEST_ASSERT_ARE_EQUAL(long, (long)0, (long)1, "Test message");
136 }
137
138 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_uint8_t_Fails)
139 {
140 CTEST_ASSERT_ARE_EQUAL(uint8_t, (uint8_t)0, (uint8_t)1, "Test message");
141 }
142
143 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_int8_t_Fails)
144 {
145 CTEST_ASSERT_ARE_EQUAL(int8_t, (int8_t)0, (int8_t)1, "Test message");
146 }
147
148 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_uint16_t_Fails)
149 {
150 CTEST_ASSERT_ARE_EQUAL(uint16_t, (uint16_t)0, (uint16_t)1, "Test message");
151 }
152
153 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_int16_t_Fails)
154 {
155 CTEST_ASSERT_ARE_EQUAL(int16_t, (int16_t)0, (int16_t)1, "Test message");
156 }
157
158 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_uint32_t_Fails)
159 {
160 CTEST_ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0, (uint32_t)1, "Test message");
161 }
162
163 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_int32_t_Fails)
164 {
165 CTEST_ASSERT_ARE_EQUAL(int32_t, (int32_t)0, (int32_t)1, "Test message");
166 }
167
168 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_uint64_t_Fails)
169 {
170 CTEST_ASSERT_ARE_EQUAL(uint64_t, (uint64_t)0, (uint64_t)1, "Test message");
171 }
172
173 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_int64_t_Fails)
174 {
175 CTEST_ASSERT_ARE_EQUAL(int64_t, (int64_t)0, (int64_t)1, "Test message");
176 }
177
178 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_strings_With_To_String_Type_Fails)
179 {
180 CTEST_ASSERT_ARE_EQUAL(char_ptr, "test", "dan", "Test message");
181 }
182
183 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_wide_strings_With_To_String_Type_Fails)
184 {
185 CTEST_ASSERT_ARE_EQUAL(wchar_ptr, L"test", L"matt", "Test message");
186 }
187
188 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_void_ptr_Different_Addresses_Fails)
189 {
190 char c1, c2;
191 CTEST_ASSERT_ARE_EQUAL(void_ptr, &c1, &c2, "Test message");
192 }
193
194 CTEST_FUNCTION(Assert_Are_Equal_With_Msg_2_Structures_Fails)
195 {
196 mystruct a = { 1 };
197 mystruct b = { 42 };
198
199 CTEST_ASSERT_ARE_EQUAL(mystruct_ptr, &a, &b, "Test message");
200 }
201
202 /* CTEST_ASSERT_ARE_NOT_EQUAL */
203
204 CTEST_FUNCTION(Assert_Are_Not_Equal_2_Ints_Fails)
205 {
206 CTEST_ASSERT_ARE_NOT_EQUAL(int, 1, 1);
207 }
208
209 CTEST_FUNCTION(Assert_Are_Not_Equal_2_Chars_Fails)
210 {
211 CTEST_ASSERT_ARE_NOT_EQUAL(char, (char)1, (char)1);
212 }
213
214 CTEST_FUNCTION(Assert_Are_Not_Equal_2_Shorts_Fails)
215 {
216 CTEST_ASSERT_ARE_NOT_EQUAL(short, (short)1, (short)1);
217 }
218
219 CTEST_FUNCTION(Assert_Are_Not_Equal_2_Longs_Fails)
220 {
221 CTEST_ASSERT_ARE_NOT_EQUAL(long, (long)1, (long)1);
222 }
223
224 CTEST_FUNCTION(Assert_Are_Not_Equal_2_Unsigned_Longs_Fails)
225 {
226 CTEST_ASSERT_ARE_NOT_EQUAL(unsigned_long, 1, 1);
227 }
228
229 #if defined CTEST_USE_STDINT
230
231 CTEST_FUNCTION(Assert_Are_Not_Equal_2_uint8_t_Fails)
232 {
233 CTEST_ASSERT_ARE_NOT_EQUAL(uint8_t, (uint8_t)1, (uint8_t)1);
234 }
235
236 CTEST_FUNCTION(Assert_Are_Not_Equal_2_int8_t_Fails)
237 {
238 CTEST_ASSERT_ARE_NOT_EQUAL(int8_t, (int8_t)1, (int8_t)1);
239 }
240
241 CTEST_FUNCTION(Assert_Are_Not_Equal_2_uint16_t_Fails)
242 {
243 CTEST_ASSERT_ARE_NOT_EQUAL(uint16_t, (uint16_t)1, (uint16_t)1);
244 }
245
246 CTEST_FUNCTION(Assert_Are_Not_Equal_2_int16_t_Fails)
247 {
248 CTEST_ASSERT_ARE_NOT_EQUAL(int16_t, (int16_t)1, (int16_t)1);
249 }
250
251 CTEST_FUNCTION(Assert_Are_Not_Equal_2_uint32_t_Fails)
252 {
253 CTEST_ASSERT_ARE_NOT_EQUAL(uint32_t, (uint32_t)1, (uint32_t)1);
254 }
255
256 CTEST_FUNCTION(Assert_Are_Not_Equal_2_int32_t_Fails)
257 {
258 CTEST_ASSERT_ARE_NOT_EQUAL(int32_t, (int32_t)1, (int32_t)1);
259 }
260
261 CTEST_FUNCTION(Assert_Are_Not_Equal_2_uint64_t_Fails)
262 {
263 CTEST_ASSERT_ARE_NOT_EQUAL(uint64_t, (uint64_t)1, (uint64_t)1);
264 }
265
266 CTEST_FUNCTION(Assert_Are_Not_Equal_2_int64_t_Fails)
267 {
268 CTEST_ASSERT_ARE_NOT_EQUAL(int64_t, (int64_t)1, (int64_t)1);
269 }
270
271 #endif
272
273 CTEST_FUNCTION(Assert_Are_Not_Equal_2_strings_With_To_String_Type_Fails)
274 {
275 CTEST_ASSERT_ARE_NOT_EQUAL(char_ptr, "dan", "dan");
276 }
277
278 CTEST_FUNCTION(Assert_Are_Not_Equal_2_wide_strings_With_To_String_Type_Fails)
279 {
280 CTEST_ASSERT_ARE_NOT_EQUAL(wchar_ptr, L"matt", L"matt");
281 }
282
283 CTEST_FUNCTION(Assert_Are_Not_Equal_2_void_ptr_With_2_same_addresses_Fails)
284 {
285 char c1;
286 CTEST_ASSERT_ARE_NOT_EQUAL(void_ptr, &c1, &c1);
287 }
288
289 CTEST_FUNCTION(Assert_Are_Not_Equal_2_Structures_Fails)
290 {
291 mystruct a = { 1 };
292 mystruct b = { 1 };
293
294 CTEST_ASSERT_ARE_NOT_EQUAL(mystruct_ptr, &a, &b);
295 }
296
297 /* CTEST_ASSERT_ARE_NOT_EQUAL */
298
299 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_Ints_Fails)
300 {
301 CTEST_ASSERT_ARE_NOT_EQUAL(int, 1, 1, "Test message");
302 }
303
304 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_Chars_Fails)
305 {
306 CTEST_ASSERT_ARE_NOT_EQUAL(char, (char)1, (char)1, "Test message");
307 }
308
309 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_Shorts_Fails)
310 {
311 CTEST_ASSERT_ARE_NOT_EQUAL(short, (short)1, (short)1, "Test message");
312 }
313
314 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_Longs_Fails)
315 {
316 CTEST_ASSERT_ARE_NOT_EQUAL(long, (long)1, (long)1, "Test message");
317 }
318
319 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_Unsigned_Longs_Fails)
320 {
321 CTEST_ASSERT_ARE_NOT_EQUAL(unsigned_long, 1, 1, "Test message");
322 }
323
324 #if defined CTEST_USE_STDINT
325
326 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_uint8_t_Fails)
327 {
328 CTEST_ASSERT_ARE_NOT_EQUAL(uint8_t, (uint8_t)1, (uint8_t)1, "Test message");
329 }
330
331 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_int8_t_Fails)
332 {
333 CTEST_ASSERT_ARE_NOT_EQUAL(int8_t, (int8_t)1, (int8_t)1, "Test message");
334 }
335
336 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_uint16_t_Fails)
337 {
338 CTEST_ASSERT_ARE_NOT_EQUAL(uint16_t, (uint16_t)1, (uint16_t)1, "Test message");
339 }
340
341 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_int16_t_Fails)
342 {
343 CTEST_ASSERT_ARE_NOT_EQUAL(int16_t, (int16_t)1, (int16_t)1, "Test message");
344 }
345
346 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_uint32_t_Fails)
347 {
348 CTEST_ASSERT_ARE_NOT_EQUAL(uint32_t, (uint32_t)1, (uint32_t)1, "Test message");
349 }
350
351 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_int32_t_Fails)
352 {
353 CTEST_ASSERT_ARE_NOT_EQUAL(int32_t, (int32_t)1, (int32_t)1, "Test message");
354 }
355
356 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_uint64_t_Fails)
357 {
358 CTEST_ASSERT_ARE_NOT_EQUAL(uint64_t, (uint64_t)1, (uint64_t)1, "Test message");
359 }
360
361 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_int64_t_Fails)
362 {
363 CTEST_ASSERT_ARE_NOT_EQUAL(int64_t, (int64_t)1, (int64_t)1, "Test message");
364 }
365
366 #endif
367
368 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_strings_With_To_String_Type_Fails)
369 {
370 CTEST_ASSERT_ARE_NOT_EQUAL(char_ptr, "dan", "dan", "Test message");
371 }
372
373 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_wide_strings_With_To_String_Type_Fails)
374 {
375 CTEST_ASSERT_ARE_NOT_EQUAL(wchar_ptr, L"matt", L"matt", "Test message");
376 }
377
378 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_void_ptr_with_same_address_Fails)
379 {
380 char c1;
381 CTEST_ASSERT_ARE_NOT_EQUAL(void_ptr, &c1, &c1, "Test message");
382 }
383
384 CTEST_FUNCTION(Assert_Are_Not_Equal_With_Msg_2_Structures_Fails)
385 {
386 mystruct a = { 1 };
387 mystruct b = { 1 };
388
389 CTEST_ASSERT_ARE_NOT_EQUAL(mystruct_ptr, &a, &b, "Test message");
390 }
391
392 /* CTEST_ASSERT_IS_NULL */
393
394 CTEST_FUNCTION(Assert_Is_NULL_Fails)
395 {
396 int a;
397 int *ptr = &a;
398 CTEST_ASSERT_IS_NULL(ptr);
399 }
400
401 /* CTEST_ASSERT_IS_NULL with custom message string */
402
403 CTEST_FUNCTION(Assert_Is_NULL_With_Msg_Fails)
404 {
405 int a;
406 int *ptr = &a;
407 CTEST_ASSERT_IS_NULL(ptr, "Test message");
408 }
409
410 /* CTEST_ASSERT_IS_NOT_NULL */
411
412 CTEST_FUNCTION(Assert_Is_Not_NULL_Fails)
413 {
414 void* test_value = NULL;
415 CTEST_ASSERT_IS_NOT_NULL(test_value);
416 }
417
418 /* CTEST_ASSERT_IS_NOT_NULL with custom message string */
419
420 CTEST_FUNCTION(Assert_Is_Not_NULL_With_Msg_Fails)
421 {
422 void* test_value = NULL;
423 CTEST_ASSERT_IS_NOT_NULL(test_value, "Test message");
424 }
425
426 /* CTEST_ASSERT_IS_TRUE */
427
428 CTEST_FUNCTION(Assert_Is_True_Fails)
429 {
430 int tested_value = 0;
431 CTEST_ASSERT_IS_TRUE(tested_value);
432 }
433
434 /* CTEST_ASSERT_IS_TRUE with custom message string */
435
436 CTEST_FUNCTION(Assert_Is_True_With_Msg_Fails)
437 {
438 int tested_value = 0;
439 CTEST_ASSERT_IS_TRUE(tested_value, "Test message");
440 }
441
442 /* CTEST_ASSERT_IS_FALSE */
443
444 CTEST_FUNCTION(Assert_Is_False_Fails)
445 {
446 int tested_value = 1;
447 CTEST_ASSERT_IS_FALSE(tested_value);
448 }
449
450 /* CTEST_ASSERT_IS_FALSE with custom message string */
451
452 CTEST_FUNCTION(Assert_Is_False_With_Msg_Fails)
453 {
454 int tested_value = 1;
455 CTEST_ASSERT_IS_FALSE(tested_value, "Test message");
456 }
457
458 CTEST_END_TEST_SUITE(AssertFailureTests)