| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "tests.h" |
| 5 |
#include "xml.h" |
| 6 |
|
| 7 |
static void test_one(const char *data, ...) { |
| 8 |
void *state = NULL; |
| 9 |
va_list ap; |
| 10 |
|
| 11 |
va_start(ap, data); |
| 12 |
|
| 13 |
for (;;) { |
| 14 |
_cleanup_free_ char *name = NULL; |
| 15 |
int t, tt; |
| 16 |
const char *nn; |
| 17 |
|
| 18 |
t = xml_tokenize(&data, &name, &state, NULL); |
| 19 |
ASSERT_OK(t); |
| 20 |
|
| 21 |
tt = va_arg(ap, int); |
| 22 |
ASSERT_GE(tt, 0); |
| 23 |
|
| 24 |
ASSERT_EQ(t, tt); |
| 25 |
if (t == XML_END) |
| 26 |
break; |
| 27 |
|
| 28 |
nn = va_arg(ap, const char *); |
| 29 |
ASSERT_STREQ(nn, name); |
| 30 |
} |
| 31 |
|
| 32 |
va_end(ap); |
| 33 |
} |
| 34 |
|
| 35 |
int main(int argc, char *argv[]) { |
| 36 |
|
| 37 |
test_setup_logging(LOG_DEBUG); |
| 38 |
|
| 39 |
test_one("", XML_END); |
| 40 |
|
| 41 |
test_one("<foo></foo>", |
| 42 |
XML_TAG_OPEN, "foo", |
| 43 |
XML_TAG_CLOSE, "foo", |
| 44 |
XML_END); |
| 45 |
|
| 46 |
test_one("<foo waldo=piep meh=\"huhu\"/>", |
| 47 |
XML_TAG_OPEN, "foo", |
| 48 |
XML_ATTRIBUTE_NAME, "waldo", |
| 49 |
XML_ATTRIBUTE_VALUE, "piep", |
| 50 |
XML_ATTRIBUTE_NAME, "meh", |
| 51 |
XML_ATTRIBUTE_VALUE, "huhu", |
| 52 |
XML_TAG_CLOSE_EMPTY, NULL, |
| 53 |
XML_END); |
| 54 |
|
| 55 |
test_one("xxxx\n" |
| 56 |
"<foo><?xml foo?> <!-- zzzz --> </foo>", |
| 57 |
XML_TEXT, "xxxx\n", |
| 58 |
XML_TAG_OPEN, "foo", |
| 59 |
XML_TEXT, " ", |
| 60 |
XML_TEXT, " ", |
| 61 |
XML_TAG_CLOSE, "foo", |
| 62 |
XML_END); |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |