root/lib/common/tests/nvpair/pcmk__xe_attr_is_true_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_internal.h>
  11 #include <crm/common/xml_internal.h>
  12 
  13 #include <stdarg.h>
  14 #include <stddef.h>
  15 #include <stdint.h>
  16 #include <stdlib.h>
  17 #include <string.h>
  18 #include <setjmp.h>
  19 #include <cmocka.h>
  20 
  21 static void
  22 empty_input(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  23 {
  24     xmlNode *node = string2xml("<node/>");
  25 
  26     assert_false(pcmk__xe_attr_is_true(NULL, NULL));
  27     assert_false(pcmk__xe_attr_is_true(NULL, "whatever"));
  28     assert_false(pcmk__xe_attr_is_true(node, NULL));
  29 
  30     free_xml(node);
  31 }
  32 
  33 static void
  34 attr_missing(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36     xmlNode *node = string2xml("<node a=\"true\" b=\"false\"/>");
  37 
  38     assert_false(pcmk__xe_attr_is_true(node, "c"));
  39     free_xml(node);
  40 }
  41 
  42 static void
  43 attr_present(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45     xmlNode *node = string2xml("<node a=\"true\" b=\"false\"/>");
  46 
  47     assert_true(pcmk__xe_attr_is_true(node, "a"));
  48     assert_false(pcmk__xe_attr_is_true(node, "b"));
  49 
  50     free_xml(node);
  51 }
  52 
  53 int
  54 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56     const struct CMUnitTest tests[] = {
  57         cmocka_unit_test(empty_input),
  58         cmocka_unit_test(attr_missing),
  59         cmocka_unit_test(attr_present),
  60     };
  61 
  62     cmocka_set_message_output(CM_OUTPUT_TAP);
  63     return cmocka_run_group_tests(tests, NULL, NULL);
  64 }

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