root/lib/common/tests/xpath/pcmk__xpath_node_id_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. empty_input
  2. no_quotes
  3. not_present
  4. present

   1 /*
   2  * Copyright 2021-2022 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 
  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     assert_null(pcmk__xpath_node_id(NULL, "lrm"));
  18     assert_null(pcmk__xpath_node_id("", "lrm"));
  19     assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
  20     assert_null(pcmk__xpath_node_id("/blah/blah", ""));
  21     assert_null(pcmk__xpath_node_id(NULL, NULL));
  22 }
  23 
  24 static void
  25 no_quotes(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  26     pcmk__assert_asserts(pcmk__xpath_node_id("/some/xpath/lrm[@id=xyz]", "lrm"));
  27 }
  28 
  29 static void
  30 not_present(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  31     assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm"));
  32     assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm"));
  33 }
  34 
  35 static void
  36 present(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  37     char *s = NULL;
  38 
  39     s = pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm");
  40     assert_int_equal(strcmp(s, "xyz"), 0);
  41     free(s);
  42 
  43     s = pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm");
  44     assert_int_equal(strcmp(s, "xyz"), 0);
  45     free(s);
  46 }
  47 
  48 PCMK__UNIT_TEST(NULL, NULL,
  49                 cmocka_unit_test(empty_input),
  50                 cmocka_unit_test(no_quotes),
  51                 cmocka_unit_test(not_present),
  52                 cmocka_unit_test(present))

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