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
|
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <stdarg.h>
#include "alloc-util.h"
#include "string-util.h"
#include "util.h"
#include "xml.h"
static void test_one(const char *data, ...) {
void *state = NULL;
va_list ap;
va_start(ap, data);
for (;;) {
_cleanup_free_ char *name = NULL;
int t, tt;
const char *nn;
t = xml_tokenize(&data, &name, &state, NULL);
assert_se(t >= 0);
tt = va_arg(ap, int);
assert_se(tt >= 0);
assert_se(t == tt);
if (t == XML_END)
break;
nn = va_arg(ap, const char *);
assert_se(streq_ptr(nn, name));
}
va_end(ap);
}
int main(int argc, char *argv[]) {
test_one("", XML_END);
test_one("<foo></foo>",
XML_TAG_OPEN, "foo",
XML_TAG_CLOSE, "foo",
XML_END);
test_one("<foo waldo=piep meh=\"huhu\"/>",
XML_TAG_OPEN, "foo",
XML_ATTRIBUTE_NAME, "waldo",
XML_ATTRIBUTE_VALUE, "piep",
XML_ATTRIBUTE_NAME, "meh",
XML_ATTRIBUTE_VALUE, "huhu",
XML_TAG_CLOSE_EMPTY, NULL,
XML_END);
test_one("xxxx\n"
"<foo><?xml foo?> <!-- zzzz --> </foo>",
XML_TEXT, "xxxx\n",
XML_TAG_OPEN, "foo",
XML_TEXT, " ",
XML_TEXT, " ",
XML_TAG_CLOSE, "foo",
XML_END);
return 0;
}
|