This source file includes following definitions.
- update_null
- update_same
- update_different
- strdup_fails
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 update_null(void **state) {
18 char *str = NULL;
19
20
21 pcmk__str_update(NULL, NULL);
22 pcmk__str_update(NULL, "value");
23
24
25 pcmk__str_update(&str, NULL);
26 assert_null(str);
27
28
29 str = strdup("hello");
30 pcmk__str_update(&str, NULL);
31 assert_null(str);
32 }
33
34 static void
35 update_same(void **state) {
36 char *str = NULL;
37 char *saved = NULL;
38
39 str = strdup("hello");
40 saved = str;
41 pcmk__str_update(&str, "hello");
42 assert_ptr_equal(saved, str);
43 free(str);
44 }
45
46 static void
47 update_different(void **state) {
48 char *str = NULL;
49
50 str = strdup("hello");
51 pcmk__str_update(&str, "world");
52 assert_string_equal(str, "world");
53 free(str);
54 }
55
56 static void
57 strdup_fails(void **state) {
58 char *str = NULL;
59
60 str = strdup("hello");
61
62 pcmk__assert_exits(
63 CRM_EX_OSERR,
64 {
65 pcmk__mock_strdup = true;
66 expect_string(__wrap_strdup, s, "world");
67 pcmk__str_update(&str, "world");
68 pcmk__mock_strdup = false;
69 }
70 );
71
72 free(str);
73 }
74
75 PCMK__UNIT_TEST(NULL, NULL,
76 cmocka_unit_test(update_null),
77 cmocka_unit_test(update_same),
78 cmocka_unit_test(update_different),
79 cmocka_unit_test(strdup_fails))