chiark / gitweb /
service: rename StartLimitAction enum to FailureAction
[elogind.git] / src / test / test-xml.c
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
24 #include "xml.h"
25 #include "util.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);
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 }