pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__xc_create_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2024 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 
14 #include "crmcommon_private.h"
15 
16 /* This tests new_private_data() indirectly for comment nodes. Testing
17  * free_private_data() would be much less straightforward and is not worth the
18  * hassle.
19  */
20 
21 static void
22 assert_comment(xmlDoc *doc, const char *content)
23 {
24  xmlNode *node = NULL;
25  xml_node_private_t *nodepriv = NULL;
26  xml_doc_private_t *docpriv = doc->_private;
27 
28  // Also clears existing doc flags
29  xml_track_changes((xmlNode *) doc, NULL, NULL, false);
30 
31  node = pcmk__xc_create(doc, content);
32  assert_non_null(node);
33  assert_int_equal(node->type, XML_COMMENT_NODE);
34  assert_ptr_equal(node->doc, doc);
35 
36  if (content == NULL) {
37  assert_null(node->content);
38  } else {
39  assert_non_null(node->content);
40  assert_string_equal((const char *) node->content, content);
41  }
42 
43  nodepriv = node->_private;
44  assert_non_null(nodepriv);
45  assert_int_equal(nodepriv->check, PCMK__XML_NODE_PRIVATE_MAGIC);
46  assert_true(pcmk_all_flags_set(nodepriv->flags,
48 
49  assert_true(pcmk_is_set(docpriv->flags, pcmk__xf_dirty));
50 
51  free_xml(node);
52 }
53 
54 static void
55 null_doc(void **state)
56 {
58  pcmk__assert_asserts(pcmk__xc_create(NULL, "some content"));
59 }
60 
61 static void
62 with_doc(void **state)
63 {
64  xmlDoc *doc = pcmk__xml_new_doc();
65 
66  assert_non_null(doc);
67  assert_non_null(doc->_private);
68 
69  assert_comment(doc, NULL);
70  assert_comment(doc, "some content");
71 
72  pcmk__xml_free_doc(doc);
73 }
74 
76  cmocka_unit_test(null_doc),
77  cmocka_unit_test(with_doc));
void xml_track_changes(xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
Definition: xml.c:344
G_GNUC_INTERNAL xmlDoc * pcmk__xml_new_doc(void)
Definition: xml.c:803
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:94
int pcmk__xml_test_setup_group(void **state)
Definition: unittest.c:85
#define pcmk__assert_asserts(stmt)
PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group, cmocka_unit_test(null_doc), cmocka_unit_test(with_doc))
void free_xml(xmlNode *child)
Definition: xml.c:958
int pcmk__xml_test_teardown_group(void **state)
Definition: unittest.c:104
#define PCMK__XML_NODE_PRIVATE_MAGIC
xmlNode * pcmk__xc_create(xmlDoc *doc, const char *content)
Definition: xml_comment.c:28
void pcmk__xml_free_doc(xmlDoc *doc)
Definition: xml.c:819