This source file includes following definitions.
- update_null
- update_same
- update_different
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17
18 static void
19 update_null(void **state) {
20 char *str = NULL;
21
22
23 pcmk__str_update(NULL, NULL);
24 pcmk__str_update(NULL, "value");
25
26
27 pcmk__str_update(&str, NULL);
28 assert_null(str);
29
30
31 str = strdup("hello");
32 pcmk__str_update(&str, NULL);
33 assert_null(str);
34 }
35
36 static void
37 update_same(void **state) {
38 char *str = NULL;
39 char *saved = NULL;
40
41 str = strdup("hello");
42 saved = str;
43 pcmk__str_update(&str, "hello");
44 assert_ptr_equal(saved, str);
45 free(str);
46 }
47
48 static void
49 update_different(void **state) {
50 char *str = NULL;
51
52 str = strdup("hello");
53 pcmk__str_update(&str, "world");
54 assert_string_equal(str, "world");
55 free(str);
56 }
57
58 int
59 main(int argc, char **argv)
60 {
61 const struct CMUnitTest tests[] = {
62 cmocka_unit_test(update_null),
63 cmocka_unit_test(update_same),
64 cmocka_unit_test(update_different),
65 };
66
67 cmocka_set_message_output(CM_OUTPUT_TAP);
68 return cmocka_run_group_tests(tests, NULL, NULL);
69 }