root/lib/common/tests/nodes/pcmk__xe_add_node_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. bad_input
  2. expected_input
  3. repeated_use

   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/xml.h>
  13 #include <crm/common/unittest_internal.h>
  14 #include <crm/common/xml_internal.h>
  15 
  16 static void
  17 bad_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  18     xmlNode *node = NULL;
  19 
  20     pcmk__assert_asserts(pcmk__xe_add_node(NULL, NULL, 0));
  21 
  22     node = pcmk__xe_create(NULL, "test");
  23 
  24     pcmk__xe_add_node(node, NULL, 0);
  25     assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST));
  26     assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST_ID));
  27 
  28     pcmk__xe_add_node(node, NULL, -100);
  29     assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST));
  30     assert_null(xmlHasProp(node, (pcmkXmlStr) PCMK__XA_ATTR_HOST_ID));
  31 
  32     free_xml(node);
  33 }
  34 
  35 static void
  36 expected_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  37     xmlNode *node = pcmk__xe_create(NULL, "test");
  38     int i;
  39 
  40     pcmk__xe_add_node(node, "somenode", 47);
  41     assert_string_equal("somenode",
  42                         crm_element_value(node, PCMK__XA_ATTR_HOST));
  43     assert_int_equal(pcmk_rc_ok,
  44                      crm_element_value_int(node, PCMK__XA_ATTR_HOST_ID, &i));
  45     assert_int_equal(i, 47);
  46 
  47     free_xml(node);
  48 }
  49 
  50 static void
  51 repeated_use(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  52     xmlNode *node = pcmk__xe_create(NULL, "test");
  53     int i;
  54 
  55     /* Later calls override settings from earlier calls. */
  56     pcmk__xe_add_node(node, "nodeA", 1);
  57     pcmk__xe_add_node(node, "nodeB", 2);
  58     pcmk__xe_add_node(node, "nodeC", 3);
  59 
  60     assert_string_equal("nodeC", crm_element_value(node, PCMK__XA_ATTR_HOST));
  61     assert_int_equal(pcmk_rc_ok,
  62                      crm_element_value_int(node, PCMK__XA_ATTR_HOST_ID, &i));
  63     assert_int_equal(i, 3);
  64 
  65     free_xml(node);
  66 }
  67 
  68 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, NULL,
  69                 cmocka_unit_test(bad_input),
  70                 cmocka_unit_test(expected_input),
  71                 cmocka_unit_test(repeated_use))

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