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
  4. main

   1 /*
   2  * Copyright 2021 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 Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include "crm/common/results.h"
  11 #include <crm_internal.h>
  12 #include <crm/common/xml_internal.h>
  13 
  14 #include <stdarg.h>
  15 #include <stddef.h>
  16 #include <stdint.h>
  17 #include <stdlib.h>
  18 #include <string.h>
  19 #include <setjmp.h>
  20 #include <cmocka.h>
  21 
  22 static void
  23 empty_input(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25     xmlNode *node = string2xml("<node/>");
  26     bool value;
  27 
  28     assert_int_equal(pcmk__xe_get_bool_attr(NULL, NULL, &value), ENODATA);
  29     assert_int_equal(pcmk__xe_get_bool_attr(NULL, "whatever", &value), ENODATA);
  30     assert_int_equal(pcmk__xe_get_bool_attr(node, NULL, &value), EINVAL);
  31     assert_int_equal(pcmk__xe_get_bool_attr(node, "whatever", NULL), EINVAL);
  32 
  33     free_xml(node);
  34 }
  35 
  36 static void
  37 attr_missing(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     xmlNode *node = string2xml("<node a=\"true\" b=\"false\"/>");
  40     bool value;
  41 
  42     assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), ENODATA);
  43     free_xml(node);
  44 }
  45 
  46 static void
  47 attr_present(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     xmlNode *node = string2xml("<node a=\"true\" b=\"false\" c=\"blah\"/>");
  50     bool value;
  51 
  52     value = false;
  53     assert_int_equal(pcmk__xe_get_bool_attr(node, "a", &value), pcmk_rc_ok);
  54     assert_true(value);
  55     value = true;
  56     assert_int_equal(pcmk__xe_get_bool_attr(node, "b", &value), pcmk_rc_ok);
  57     assert_false(value);
  58     assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), pcmk_rc_unknown_format);
  59 
  60     free_xml(node);
  61 }
  62 
  63 int
  64 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66     const struct CMUnitTest tests[] = {
  67         cmocka_unit_test(empty_input),
  68         cmocka_unit_test(attr_missing),
  69         cmocka_unit_test(attr_present),
  70     };
  71 
  72     cmocka_set_message_output(CM_OUTPUT_TAP);
  73     return cmocka_run_group_tests(tests, NULL, NULL);
  74 }

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