]>
Commit | Line | Data |
---|---|---|
08bcebf3 LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include <stdarg.h> | |
23 | ||
07630cea | 24 | #include "string-util.h" |
08bcebf3 | 25 | #include "util.h" |
07630cea | 26 | #include "xml.h" |
08bcebf3 LP |
27 | |
28 | static void test_one(const char *data, ...) { | |
29 | void *state = NULL; | |
30 | va_list ap; | |
31 | ||
32 | va_start(ap, data); | |
33 | ||
34 | for (;;) { | |
35 | _cleanup_free_ char *name = NULL; | |
36 | int t, tt; | |
37 | const char *nn; | |
38 | ||
bcf3295d | 39 | t = xml_tokenize(&data, &name, &state, NULL); |
08bcebf3 LP |
40 | assert_se(t >= 0); |
41 | ||
42 | tt = va_arg(ap, int); | |
43 | assert_se(tt >= 0); | |
44 | ||
45 | assert_se(t == tt); | |
46 | if (t == XML_END) | |
47 | break; | |
48 | ||
49 | nn = va_arg(ap, const char *); | |
50 | assert_se(streq_ptr(nn, name)); | |
51 | } | |
52 | ||
53 | va_end(ap); | |
54 | } | |
55 | ||
56 | int main(int argc, char *argv[]) { | |
57 | ||
58 | test_one("", XML_END); | |
59 | ||
60 | test_one("<foo></foo>", | |
61 | XML_TAG_OPEN, "foo", | |
62 | XML_TAG_CLOSE, "foo", | |
63 | XML_END); | |
64 | ||
65 | test_one("<foo waldo=piep meh=\"huhu\"/>", | |
66 | XML_TAG_OPEN, "foo", | |
67 | XML_ATTRIBUTE_NAME, "waldo", | |
68 | XML_ATTRIBUTE_VALUE, "piep", | |
69 | XML_ATTRIBUTE_NAME, "meh", | |
70 | XML_ATTRIBUTE_VALUE, "huhu", | |
71 | XML_TAG_CLOSE_EMPTY, NULL, | |
72 | XML_END); | |
73 | ||
74 | test_one("xxxx\n" | |
75 | "<foo><?xml foo?> <!-- zzzz --> </foo>", | |
76 | XML_TEXT, "xxxx\n", | |
77 | XML_TAG_OPEN, "foo", | |
78 | XML_TEXT, " ", | |
79 | XML_TEXT, " ", | |
80 | XML_TAG_CLOSE, "foo", | |
81 | XML_END); | |
82 | ||
83 | return 0; | |
84 | } |