File: pcmk__xpath_node_id_test.c

package info (click to toggle)
pacemaker 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 68,576 kB
  • sloc: xml: 160,564; ansic: 143,744; python: 5,670; sh: 2,969; makefile: 2,426
file content (60 lines) | stat: -rw-r--r-- 1,885 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Copyright 2021-2024 the Pacemaker project contributors
 *
 * The version control history for this file may have further details.
 *
 * This source code is licensed under the GNU General Public License version 2
 * or later (GPLv2+) WITHOUT ANY WARRANTY.
 */

#include <crm_internal.h>

#include <crm/common/xml.h>
#include <crm/common/unittest_internal.h>
#include <crm/common/xml_internal.h>

static void
empty_input(void **state) {
    assert_null(pcmk__xpath_node_id(NULL, PCMK__XE_LRM));
    assert_null(pcmk__xpath_node_id("", PCMK__XE_LRM));
    assert_null(pcmk__xpath_node_id("/blah/blah", NULL));
    assert_null(pcmk__xpath_node_id("/blah/blah", ""));
    assert_null(pcmk__xpath_node_id(NULL, NULL));
}

static void
no_quotes(void **state) {
    const char *xpath = "/some/xpath/" PCMK__XE_LRM "[@" PCMK_XA_ID "=xyz]";
    pcmk__assert_asserts(pcmk__xpath_node_id(xpath, PCMK__XE_LRM));
}

static void
not_present(void **state) {
    const char *xpath = "/some/xpath/string[@" PCMK_XA_ID "='xyz']";
    assert_null(pcmk__xpath_node_id(xpath, PCMK__XE_LRM));

    xpath = "/some/xpath/containing[@" PCMK_XA_ID "='" PCMK__XE_LRM "']";
    assert_null(pcmk__xpath_node_id(xpath, PCMK__XE_LRM));
}

static void
present(void **state) {
    char *s = NULL;
    const char *xpath = "/some/xpath/containing"
                        "/" PCMK__XE_LRM "[@" PCMK_XA_ID "='xyz']";

    s = pcmk__xpath_node_id(xpath, PCMK__XE_LRM);
    assert_int_equal(strcmp(s, "xyz"), 0);
    free(s);

    xpath = "/some/other/" PCMK__XE_LRM "[@" PCMK_XA_ID "='xyz']/xpath";
    s = pcmk__xpath_node_id(xpath, PCMK__XE_LRM);
    assert_int_equal(strcmp(s, "xyz"), 0);
    free(s);
}

PCMK__UNIT_TEST(NULL, NULL,
                cmocka_unit_test(empty_input),
                cmocka_unit_test(no_quotes),
                cmocka_unit_test(not_present),
                cmocka_unit_test(present))