diff --git a/lib/common/tests/strings/pcmk__add_word_test.c b/lib/common/tests/strings/pcmk__add_word_test.c index 214a5ac27a..600e8e8dd5 100644 --- a/lib/common/tests/strings/pcmk__add_word_test.c +++ b/lib/common/tests/strings/pcmk__add_word_test.c @@ -1,98 +1,104 @@ /* - * Copyright 2020 the Pacemaker project contributors + * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include #include static void add_words(void) { char *list = NULL; size_t list_len = 0; pcmk__add_word(&list, &list_len, "hello"); pcmk__add_word(&list, &list_len, "world"); g_assert_cmpint(strcmp(list, "hello world"), ==, 0); + free(list); } static void add_with_no_len(void) { char *list = NULL; pcmk__add_word(&list, NULL, "hello"); pcmk__add_word(&list, NULL, "world"); g_assert_cmpint(strcmp(list, "hello world"), ==, 0); + free(list); } static void add_nothing(void) { char *list = NULL; pcmk__add_word(&list, NULL, "hello"); pcmk__add_word(&list, NULL, NULL); pcmk__add_word(&list, NULL, ""); g_assert_cmpint(strcmp(list, "hello"), ==, 0); + free(list); } static void add_with_null(void) { char *list = NULL; size_t list_len = 0; pcmk__add_separated_word(&list, &list_len, "hello", NULL); pcmk__add_separated_word(&list, &list_len, "world", NULL); pcmk__add_separated_word(&list, &list_len, "I am a unit test", NULL); g_assert_cmpint(strcmp(list, "hello world I am a unit test"), ==, 0); + free(list); } static void add_with_comma(void) { char *list = NULL; size_t list_len = 0; pcmk__add_separated_word(&list, &list_len, "hello", ","); pcmk__add_separated_word(&list, &list_len, "world", ","); pcmk__add_separated_word(&list, &list_len, "I am a unit test", ","); g_assert_cmpint(strcmp(list, "hello,world,I am a unit test"), ==, 0); + free(list); } static void add_with_comma_and_space(void) { char *list = NULL; size_t list_len = 0; pcmk__add_separated_word(&list, &list_len, "hello", ", "); pcmk__add_separated_word(&list, &list_len, "world", ", "); pcmk__add_separated_word(&list, &list_len, "I am a unit test", ", "); g_assert_cmpint(strcmp(list, "hello, world, I am a unit test"), ==, 0); + free(list); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/strings/add_word/add_words", add_words); g_test_add_func("/common/strings/add_word/add_with_no_len", add_with_no_len); g_test_add_func("/common/strings/add_word/add_nothing", add_nothing); g_test_add_func("/common/strings/add_word/add_with_null", add_with_null); g_test_add_func("/common/strings/add_word/add_with_comma", add_with_comma); g_test_add_func("/common/strings/add_word/add_with_comma_and_space", add_with_comma_and_space); return g_test_run(); } diff --git a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c index f6b5c106e9..c7176daf6c 100644 --- a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c +++ b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c @@ -1,43 +1,50 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include static void empty_input(void) { g_assert_null(pcmk__xpath_node_id(NULL, "lrm")); g_assert_null(pcmk__xpath_node_id("", "lrm")); g_assert_null(pcmk__xpath_node_id("/blah/blah", NULL)); g_assert_null(pcmk__xpath_node_id("/blah/blah", "")); g_assert_null(pcmk__xpath_node_id(NULL, NULL)); } static void not_present(void) { g_assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm")); g_assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm")); } static void present(void) { - g_assert_cmpint(strcmp(pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm"), "xyz"), ==, 0); - g_assert_cmpint(strcmp(pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm"), "xyz"), ==, 0); + char *s = NULL; + + s = pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm"); + g_assert_cmpint(strcmp(s, "xyz"), ==, 0); + free(s); + + s = pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm"); + g_assert_cmpint(strcmp(s, "xyz"), ==, 0); + free(s); } int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/common/xpath/node_id/empty_input", empty_input); g_test_add_func("/common/xpath/node_id/not_present", not_present); g_test_add_func("/common/xpath/node_id/present", present); return g_test_run(); }