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

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