pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk__add_word_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2022 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
13
14static void
15add_words(void **state)
16{
17 GString *list = NULL;
18
19 pcmk__add_word(&list, 16, "hello");
20 pcmk__add_word(&list, 16, "world");
21 assert_int_equal(strcmp((const char *) list->str, "hello world"), 0);
22 g_string_free(list, TRUE);
23}
24
25static void
26add_with_no_len(void **state)
27{
28 GString *list = NULL;
29
30 pcmk__add_word(&list, 0, "hello");
31 pcmk__add_word(&list, 0, "world");
32 assert_int_equal(strcmp((const char *) list->str, "hello world"), 0);
33 g_string_free(list, TRUE);
34}
35
36static void
37add_nothing(void **state)
38{
39 GString *list = NULL;
40
41 pcmk__add_word(&list, 0, "hello");
42 pcmk__add_word(&list, 0, NULL);
43 pcmk__add_word(&list, 0, "");
44 assert_int_equal(strcmp((const char *) list->str, "hello"), 0);
45 g_string_free(list, TRUE);
46}
47
48static void
49add_with_null(void **state)
50{
51 GString *list = NULL;
52
53 pcmk__add_separated_word(&list, 32, "hello", NULL);
54 pcmk__add_separated_word(&list, 32, "world", NULL);
55 pcmk__add_separated_word(&list, 32, "I am a unit test", NULL);
56 assert_int_equal(strcmp((const char *) list->str,
57 "hello world I am a unit test"), 0);
58 g_string_free(list, TRUE);
59}
60
61static void
62add_with_comma(void **state)
63{
64 GString *list = NULL;
65
66 pcmk__add_separated_word(&list, 32, "hello", ",");
67 pcmk__add_separated_word(&list, 32, "world", ",");
68 pcmk__add_separated_word(&list, 32, "I am a unit test", ",");
69 assert_int_equal(strcmp((const char *) list->str,
70 "hello,world,I am a unit test"), 0);
71 g_string_free(list, TRUE);
72}
73
74static void
75add_with_comma_and_space(void **state)
76{
77 GString *list = NULL;
78
79 pcmk__add_separated_word(&list, 32, "hello", ", ");
80 pcmk__add_separated_word(&list, 32, "world", ", ");
81 pcmk__add_separated_word(&list, 32, "I am a unit test", ", ");
82 assert_int_equal(strcmp((const char *) list->str,
83 "hello, world, I am a unit test"), 0);
84 g_string_free(list, TRUE);
85}
86
87PCMK__UNIT_TEST(NULL, NULL,
88 cmocka_unit_test(add_words),
89 cmocka_unit_test(add_with_no_len),
90 cmocka_unit_test(add_nothing),
91 cmocka_unit_test(add_with_null),
92 cmocka_unit_test(add_with_comma),
93 cmocka_unit_test(add_with_comma_and_space))
void pcmk__add_separated_word(GString **list, size_t init_size, const char *word, const char *separator)
Definition strings.c:796
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)