]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
08bcebf3 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2013 Lennart Poettering | |
08bcebf3 LP |
6 | ***/ |
7 | ||
8 | #include <stdarg.h> | |
9 | ||
b5efdb8a | 10 | #include "alloc-util.h" |
07630cea | 11 | #include "string-util.h" |
08bcebf3 | 12 | #include "util.h" |
07630cea | 13 | #include "xml.h" |
08bcebf3 LP |
14 | |
15 | static void test_one(const char *data, ...) { | |
16 | void *state = NULL; | |
17 | va_list ap; | |
18 | ||
19 | va_start(ap, data); | |
20 | ||
21 | for (;;) { | |
22 | _cleanup_free_ char *name = NULL; | |
23 | int t, tt; | |
24 | const char *nn; | |
25 | ||
bcf3295d | 26 | t = xml_tokenize(&data, &name, &state, NULL); |
08bcebf3 LP |
27 | assert_se(t >= 0); |
28 | ||
29 | tt = va_arg(ap, int); | |
30 | assert_se(tt >= 0); | |
31 | ||
32 | assert_se(t == tt); | |
33 | if (t == XML_END) | |
34 | break; | |
35 | ||
36 | nn = va_arg(ap, const char *); | |
37 | assert_se(streq_ptr(nn, name)); | |
38 | } | |
39 | ||
40 | va_end(ap); | |
41 | } | |
42 | ||
43 | int main(int argc, char *argv[]) { | |
44 | ||
45 | test_one("", XML_END); | |
46 | ||
47 | test_one("<foo></foo>", | |
48 | XML_TAG_OPEN, "foo", | |
49 | XML_TAG_CLOSE, "foo", | |
50 | XML_END); | |
51 | ||
52 | test_one("<foo waldo=piep meh=\"huhu\"/>", | |
53 | XML_TAG_OPEN, "foo", | |
54 | XML_ATTRIBUTE_NAME, "waldo", | |
55 | XML_ATTRIBUTE_VALUE, "piep", | |
56 | XML_ATTRIBUTE_NAME, "meh", | |
57 | XML_ATTRIBUTE_VALUE, "huhu", | |
58 | XML_TAG_CLOSE_EMPTY, NULL, | |
59 | XML_END); | |
60 | ||
61 | test_one("xxxx\n" | |
62 | "<foo><?xml foo?> <!-- zzzz --> </foo>", | |
63 | XML_TEXT, "xxxx\n", | |
64 | XML_TAG_OPEN, "foo", | |
65 | XML_TEXT, " ", | |
66 | XML_TEXT, " ", | |
67 | XML_TAG_CLOSE, "foo", | |
68 | XML_END); | |
69 | ||
70 | return 0; | |
71 | } |