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