File: pcmk__xe_next_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 (93 lines) | stat: -rw-r--r-- 2,479 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright 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
null_xml(void **state)
{
    assert_null(pcmk__xe_next(NULL, NULL));
    assert_null(pcmk__xe_next(NULL, "test"));
}


#define XML_NO_SIBLINGS             \
    "<xml>\n"                       \
    "  <!-- comment -->"            \
    "  <foo id='child1'>text</foo>" \
    "  <!-- another comment -->"    \
    "</xml>"

static void
no_siblings(void **state)
{
    xmlNode *xml = pcmk__xml_parse(XML_NO_SIBLINGS);
    xmlNode *child = NULL;

    assert_non_null(xml);

    child = pcmk__xe_first_child(xml, NULL, NULL, NULL);
    assert_non_null(child);
    assert_string_equal(pcmk__xe_id(child), "child1");

    assert_null(pcmk__xe_next(child, NULL));
    assert_null(pcmk__xe_next(child, "foo"));

    pcmk__xml_free(xml);
}

#define XML_SIBLINGS                    \
    "<xml>\n"                           \
    "  <!-- comment -->"                \
    "  <foo id='child1'>text</foo>"     \
    "  <!-- another comment -->"        \
    "  <bar id='child2'>text</bar>"     \
    "  <!-- yet another comment -->"    \
    "  <foo id='child3'>text</foo>"     \
    "</xml>"

static void
with_siblings(void **state)
{
    xmlNode *xml = pcmk__xml_parse(XML_SIBLINGS);
    xmlNode *child = NULL;
    xmlNode *next = NULL;

    assert_non_null(xml);

    child = pcmk__xe_first_child(xml, NULL, NULL, NULL);
    assert_non_null(child);
    assert_string_equal(pcmk__xe_id(child), "child1");

    next = pcmk__xe_next(child, NULL);
    assert_non_null(next);
    assert_string_equal(pcmk__xe_id(next), "child2");

    next = pcmk__xe_next(child, "bar");
    assert_non_null(next);
    assert_string_equal(pcmk__xe_id(next), "child2");

    next = pcmk__xe_next(child, "foo");
    assert_non_null(next);
    assert_string_equal(pcmk__xe_id(next), "child3");

    next = pcmk__xe_next(child, "foobar");
    assert_null(next);

    pcmk__xml_free(xml);
}

PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
                cmocka_unit_test(null_xml),
                cmocka_unit_test(no_siblings),
                cmocka_unit_test(with_siblings));