root/lib/common/tests/nvpair/pcmk__xe_get_bool_attr_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. empty_input
  2. attr_missing
  3. attr_present

   1 /*
   2  * Copyright 2021-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 #include <crm/common/xml_internal.h>
  14 
  15 static void
  16 empty_input(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18     xmlNode *node = pcmk__xml_parse("<node/>");
  19     bool value;
  20 
  21     assert_int_equal(pcmk__xe_get_bool_attr(NULL, NULL, &value), ENODATA);
  22     assert_int_equal(pcmk__xe_get_bool_attr(NULL, "whatever", &value), ENODATA);
  23     assert_int_equal(pcmk__xe_get_bool_attr(node, NULL, &value), EINVAL);
  24     assert_int_equal(pcmk__xe_get_bool_attr(node, "whatever", NULL), EINVAL);
  25 
  26     free_xml(node);
  27 }
  28 
  29 static void
  30 attr_missing(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32     xmlNode *node = pcmk__xml_parse("<node a=\"true\" b=\"false\"/>");
  33     bool value;
  34 
  35     assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), ENODATA);
  36     free_xml(node);
  37 }
  38 
  39 static void
  40 attr_present(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42     xmlNode *node = pcmk__xml_parse("<node a=\"true\" b=\"false\" "
  43                                                  "c=\"blah\"/>");
  44     bool value;
  45 
  46     value = false;
  47     assert_int_equal(pcmk__xe_get_bool_attr(node, "a", &value), pcmk_rc_ok);
  48     assert_true(value);
  49     value = true;
  50     assert_int_equal(pcmk__xe_get_bool_attr(node, "b", &value), pcmk_rc_ok);
  51     assert_false(value);
  52     assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), pcmk_rc_bad_input);
  53 
  54     free_xml(node);
  55 }
  56 
  57 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
  58                 cmocka_unit_test(empty_input),
  59                 cmocka_unit_test(attr_missing),
  60                 cmocka_unit_test(attr_present))

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