This source file includes following definitions.
- assert_comment
- null_doc
- with_doc
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include "crmcommon_private.h"
15
16
17
18
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
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,
47 pcmk__xf_dirty|pcmk__xf_created));
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 {
57 pcmk__assert_asserts(pcmk__xc_create(NULL, NULL));
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
75 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
76 cmocka_unit_test(null_doc),
77 cmocka_unit_test(with_doc));