diff --git a/lib/common/tests/xml/pcmk__xml_escape_test.c b/lib/common/tests/xml/pcmk__xml_escape_test.c index 04163527dd..28b0186a08 100644 --- a/lib/common/tests/xml/pcmk__xml_escape_test.c +++ b/lib/common/tests/xml/pcmk__xml_escape_test.c @@ -1,261 +1,182 @@ /* * Copyright 2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU General Public License version 2 * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void -null_empty(void **state) +assert_escape(const char *str, const char *reference, + enum pcmk__xml_escape_type type) { - gchar *str = NULL; - - str = pcmk__xml_escape(NULL, pcmk__xml_escape_text); - assert_null(str); + gchar *buf = pcmk__xml_escape(str, type); - str = pcmk__xml_escape(NULL, pcmk__xml_escape_attr); - assert_null(str); + assert_string_equal(buf, reference); + g_free(buf); +} - str = pcmk__xml_escape("", pcmk__xml_escape_text); - assert_string_equal(str, ""); - g_free(str); +static void +null_empty(void **state) +{ + assert_null(pcmk__xml_escape(NULL, pcmk__xml_escape_text)); + assert_null(pcmk__xml_escape(NULL, pcmk__xml_escape_attr)); - str = pcmk__xml_escape("", pcmk__xml_escape_attr); - assert_string_equal(str, ""); - g_free(str); + assert_escape("", "", pcmk__xml_escape_text); + assert_escape("", "", pcmk__xml_escape_attr); } static void invalid_type(void **state) { const enum pcmk__xml_escape_type type = (enum pcmk__xml_escape_type) -1; - gchar *str = NULL; // Easier to ignore invalid type for NULL or empty string assert_null(pcmk__xml_escape(NULL, type)); - - str = pcmk__xml_escape("", type); - assert_string_equal(str, ""); - g_free(str); + assert_escape("", "", type); // Otherwise, assert if we somehow passed an invalid type pcmk__assert_asserts(pcmk__xml_escape("he<>llo", type)); } static void escape_unchanged(void **state) { // No escaped characters (note: this string includes single quote at end) const char *unchanged = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "`~!@#$%^*()-_=+/|\\[]{}?.,'"; - gchar *str = NULL; - - str = pcmk__xml_escape(unchanged, pcmk__xml_escape_text); - assert_string_equal(str, unchanged); - g_free(str); - str = pcmk__xml_escape(unchanged, pcmk__xml_escape_attr); - assert_string_equal(str, unchanged); - g_free(str); + assert_escape(unchanged, unchanged, pcmk__xml_escape_text); + assert_escape(unchanged, unchanged, pcmk__xml_escape_attr); } // Ensure special characters get escaped at start, middle, and end static void escape_left_angle(void **state) { const char *l_angle = "