08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering/***
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering This file is part of systemd.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering Copyright 2013 Lennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering systemd is free software; you can redistribute it and/or modify it
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering under the terms of the GNU Lesser General Public License as published by
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering (at your option) any later version.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering systemd is distributed in the hope that it will be useful, but
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering Lesser General Public License for more details.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering You should have received a copy of the GNU Lesser General Public License
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering***/
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering#include <stdarg.h>
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "string-util.h"
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering#include "util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "xml.h"
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poetteringstatic void test_one(const char *data, ...) {
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering void *state = NULL;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering va_list ap;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering va_start(ap, data);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering for (;;) {
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering _cleanup_free_ char *name = NULL;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering int t, tt;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering const char *nn;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
bcf3295d2b0d87caefad2e73d221aac080d0c11eLennart Poettering t = xml_tokenize(&data, &name, &state, NULL);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering assert_se(t >= 0);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering tt = va_arg(ap, int);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering assert_se(tt >= 0);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering assert_se(t == tt);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering if (t == XML_END)
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering break;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering nn = va_arg(ap, const char *);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering assert_se(streq_ptr(nn, name));
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering }
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering va_end(ap);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering}
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poetteringint main(int argc, char *argv[]) {
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering test_one("", XML_END);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering test_one("<foo></foo>",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TAG_OPEN, "foo",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TAG_CLOSE, "foo",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_END);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering test_one("<foo waldo=piep meh=\"huhu\"/>",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TAG_OPEN, "foo",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_ATTRIBUTE_NAME, "waldo",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_ATTRIBUTE_VALUE, "piep",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_ATTRIBUTE_NAME, "meh",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_ATTRIBUTE_VALUE, "huhu",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TAG_CLOSE_EMPTY, NULL,
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_END);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering test_one("xxxx\n"
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering "<foo><?xml foo?> <!-- zzzz --> </foo>",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TEXT, "xxxx\n",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TAG_OPEN, "foo",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TEXT, " ",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TEXT, " ",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_TAG_CLOSE, "foo",
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering XML_END);
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering return 0;
08bcebf36eb85f5e75b968de8c648e6614cc534bLennart Poettering}