summaryrefslogtreecommitdiffstats
path: root/lib/common/tests/xpath
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:53:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 06:53:20 +0000
commite5a812082ae033afb1eed82c0f2df3d0f6bdc93f (patch)
treea6716c9275b4b413f6c9194798b34b91affb3cc7 /lib/common/tests/xpath
parentInitial commit. (diff)
downloadpacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.tar.xz
pacemaker-e5a812082ae033afb1eed82c0f2df3d0f6bdc93f.zip
Adding upstream version 2.1.6.upstream/2.1.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/common/tests/xpath')
-rw-r--r--lib/common/tests/xpath/Makefile.am16
-rw-r--r--lib/common/tests/xpath/pcmk__xpath_node_id_test.c59
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/common/tests/xpath/Makefile.am b/lib/common/tests/xpath/Makefile.am
new file mode 100644
index 0000000..94abeee
--- /dev/null
+++ b/lib/common/tests/xpath/Makefile.am
@@ -0,0 +1,16 @@
+#
+# Copyright 2021-2022 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 $(top_srcdir)/mk/tap.mk
+include $(top_srcdir)/mk/unittest.mk
+
+# Add "_test" to the end of all test program names to simplify .gitignore.
+check_PROGRAMS = pcmk__xpath_node_id_test
+
+TESTS = $(check_PROGRAMS)
diff --git a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c
new file mode 100644
index 0000000..3922b34
--- /dev/null
+++ b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2021-2022 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 <crm_internal.h>
+
+#include <crm/msg_xml.h>
+#include <crm/common/unittest_internal.h>
+#include <crm/common/xml_internal.h>
+
+static void
+empty_input(void **state) {
+ assert_null(pcmk__xpath_node_id(NULL, "lrm"));
+ assert_null(pcmk__xpath_node_id("", "lrm"));
+ assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
+ assert_null(pcmk__xpath_node_id("/blah/blah", ""));
+ assert_null(pcmk__xpath_node_id(NULL, NULL));
+}
+
+static void
+no_quotes(void **state) {
+ const char *xpath = "/some/xpath/lrm[@" XML_ATTR_ID "=xyz]";
+ pcmk__assert_asserts(pcmk__xpath_node_id(xpath, "lrm"));
+}
+
+static void
+not_present(void **state) {
+ const char *xpath = "/some/xpath/string[@" XML_ATTR_ID "='xyz']";
+ assert_null(pcmk__xpath_node_id(xpath, "lrm"));
+
+ xpath = "/some/xpath/containing[@" XML_ATTR_ID "='lrm']";
+ assert_null(pcmk__xpath_node_id(xpath, "lrm"));
+}
+
+static void
+present(void **state) {
+ char *s = NULL;
+ const char *xpath = "/some/xpath/containing/lrm[@" XML_ATTR_ID "='xyz']";
+
+ s = pcmk__xpath_node_id(xpath, "lrm");
+ assert_int_equal(strcmp(s, "xyz"), 0);
+ free(s);
+
+ xpath = "/some/other/lrm[@" XML_ATTR_ID "='xyz']/xpath";
+ s = pcmk__xpath_node_id(xpath, "lrm");
+ assert_int_equal(strcmp(s, "xyz"), 0);
+ free(s);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(empty_input),
+ cmocka_unit_test(no_quotes),
+ cmocka_unit_test(not_present),
+ cmocka_unit_test(present))