This source file includes following definitions.
- bad_size
- realloc_fails
- realloc_succeeds
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include "mock_private.h"
15
16 static void
17 bad_size(void **state)
18 {
19 char *ptr = NULL;
20
21 pcmk__assert_asserts(pcmk__realloc(ptr, 0));
22 }
23
24 static void
25 realloc_fails(void **state)
26 {
27 char *ptr = NULL;
28
29 pcmk__assert_aborts(
30 {
31 pcmk__mock_realloc = true;
32 expect_any(__wrap_realloc, ptr);
33 expect_value(__wrap_realloc, size, 1000);
34 pcmk__realloc(ptr, 1000);
35 pcmk__mock_realloc = false;
36 }
37 );
38 }
39
40 static void
41 realloc_succeeds(void **state)
42 {
43 char *ptr = NULL;
44
45
46
47
48
49
50
51
52 ptr = pcmk__realloc(ptr, 1000);
53 assert_non_null(ptr);
54
55
56 ptr = pcmk__realloc(ptr, 2000);
57 assert_non_null(ptr);
58
59
60 ptr = pcmk__realloc(ptr, 500);
61 assert_non_null(ptr);
62
63 free(ptr);
64 }
65
66 PCMK__UNIT_TEST(NULL, NULL,
67 cmocka_unit_test(bad_size),
68 cmocka_unit_test(realloc_fails),
69 cmocka_unit_test(realloc_succeeds))