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. not_present
  3. 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 static void
  14 empty_input(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  15     g_assert_null(pcmk__xpath_node_id(NULL, "lrm"));
  16     g_assert_null(pcmk__xpath_node_id("", "lrm"));
  17     g_assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
  18     g_assert_null(pcmk__xpath_node_id("/blah/blah", ""));
  19     g_assert_null(pcmk__xpath_node_id(NULL, NULL));
  20 }
  21 
  22 static void
  23 not_present(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  24     g_assert_null(pcmk__xpath_node_id("/some/xpath/string[@id='xyz']", "lrm"));
  25     g_assert_null(pcmk__xpath_node_id("/some/xpath/containing[@id='lrm']", "lrm"));
  26 }
  27 
  28 static void
  29 present(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  30     char *s = NULL;
  31 
  32     s = pcmk__xpath_node_id("/some/xpath/containing/lrm[@id='xyz']", "lrm");
  33     g_assert_cmpint(strcmp(s, "xyz"), ==, 0);
  34     free(s);
  35 
  36     s = pcmk__xpath_node_id("/some/other/lrm[@id='xyz']/xpath", "lrm");
  37     g_assert_cmpint(strcmp(s, "xyz"), ==, 0);
  38     free(s);
  39 }
  40 
  41 int
  42 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44     g_test_init(&argc, &argv, NULL);
  45 
  46     g_test_add_func("/common/xpath/node_id/empty_input", empty_input);
  47     g_test_add_func("/common/xpath/node_id/not_present", not_present);
  48     g_test_add_func("/common/xpath/node_id/present", present);
  49     return g_test_run();
  50 }

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