]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-xml.c
util-lib: split out allocation calls into alloc-util.[ch]
[thirdparty/systemd.git] / src / test / test-xml.c
CommitLineData
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
b5efdb8a 24#include "alloc-util.h"
07630cea 25#include "string-util.h"
08bcebf3 26#include "util.h"
07630cea 27#include "xml.h"
08bcebf3
LP
28
29static void test_one(const char *data, ...) {
30 void *state = NULL;
31 va_list ap;
32
33 va_start(ap, data);
34
35 for (;;) {
36 _cleanup_free_ char *name = NULL;
37 int t, tt;
38 const char *nn;
39
bcf3295d 40 t = xml_tokenize(&data, &name, &state, NULL);
08bcebf3
LP
41 assert_se(t >= 0);
42
43 tt = va_arg(ap, int);
44 assert_se(tt >= 0);
45
46 assert_se(t == tt);
47 if (t == XML_END)
48 break;
49
50 nn = va_arg(ap, const char *);
51 assert_se(streq_ptr(nn, name));
52 }
53
54 va_end(ap);
55}
56
57int main(int argc, char *argv[]) {
58
59 test_one("", XML_END);
60
61 test_one("<foo></foo>",
62 XML_TAG_OPEN, "foo",
63 XML_TAG_CLOSE, "foo",
64 XML_END);
65
66 test_one("<foo waldo=piep meh=\"huhu\"/>",
67 XML_TAG_OPEN, "foo",
68 XML_ATTRIBUTE_NAME, "waldo",
69 XML_ATTRIBUTE_VALUE, "piep",
70 XML_ATTRIBUTE_NAME, "meh",
71 XML_ATTRIBUTE_VALUE, "huhu",
72 XML_TAG_CLOSE_EMPTY, NULL,
73 XML_END);
74
75 test_one("xxxx\n"
76 "<foo><?xml foo?> <!-- zzzz --> </foo>",
77 XML_TEXT, "xxxx\n",
78 XML_TAG_OPEN, "foo",
79 XML_TEXT, " ",
80 XML_TEXT, " ",
81 XML_TAG_CLOSE, "foo",
82 XML_END);
83
84 return 0;
85}