]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-xml.c
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / test / test-xml.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <stdarg.h>
4
5 #include "alloc-util.h"
6 #include "string-util.h"
7 #include "util.h"
8 #include "xml.h"
9
10 static void test_one(const char *data, ...) {
11 void *state = NULL;
12 va_list ap;
13
14 va_start(ap, data);
15
16 for (;;) {
17 _cleanup_free_ char *name = NULL;
18 int t, tt;
19 const char *nn;
20
21 t = xml_tokenize(&data, &name, &state, NULL);
22 assert_se(t >= 0);
23
24 tt = va_arg(ap, int);
25 assert_se(tt >= 0);
26
27 assert_se(t == tt);
28 if (t == XML_END)
29 break;
30
31 nn = va_arg(ap, const char *);
32 assert_se(streq_ptr(nn, name));
33 }
34
35 va_end(ap);
36 }
37
38 int main(int argc, char *argv[]) {
39
40 test_one("", XML_END);
41
42 test_one("<foo></foo>",
43 XML_TAG_OPEN, "foo",
44 XML_TAG_CLOSE, "foo",
45 XML_END);
46
47 test_one("<foo waldo=piep meh=\"huhu\"/>",
48 XML_TAG_OPEN, "foo",
49 XML_ATTRIBUTE_NAME, "waldo",
50 XML_ATTRIBUTE_VALUE, "piep",
51 XML_ATTRIBUTE_NAME, "meh",
52 XML_ATTRIBUTE_VALUE, "huhu",
53 XML_TAG_CLOSE_EMPTY, NULL,
54 XML_END);
55
56 test_one("xxxx\n"
57 "<foo><?xml foo?> <!-- zzzz --> </foo>",
58 XML_TEXT, "xxxx\n",
59 XML_TAG_OPEN, "foo",
60 XML_TEXT, " ",
61 XML_TEXT, " ",
62 XML_TAG_CLOSE, "foo",
63 XML_END);
64
65 return 0;
66 }