root/lib/common/tests/xml/pcmk__xc_create_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. assert_comment
  2. null_doc
  3. with_doc

   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 
  12 #include <crm/common/unittest_internal.h>
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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,
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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));

/* [previous][next][first][last][top][bottom][index][help] */