Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * @file xml.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from xml.c |
| 5 | * |
| 6 | * Copyright (c) 2018 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 15 | #define _DEFAULT_SOURCE |
| 16 | #define _GNU_SOURCE |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 17 | |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 18 | #include <stdarg.h> |
| 19 | #include <stddef.h> |
| 20 | #include <setjmp.h> |
| 21 | #include <cmocka.h> |
| 22 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 23 | #include <stdlib.h> |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame] | 27 | #include "context.h" |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 28 | #include "parser.h" |
| 29 | #include "parser_internal.h" |
| 30 | #include "xml.h" |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 31 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 32 | LY_ERR lyxml_ns_add(struct lyxml_ctx *xmlctx, const char *prefix, size_t prefix_len, char *uri); |
| 33 | LY_ERR lyxml_ns_rm(struct lyxml_ctx *xmlctx); |
| 34 | |
| 35 | static int |
| 36 | setup(void **state) |
| 37 | { |
| 38 | if (ly_ctx_new(NULL, 0, (struct ly_ctx **)state)) { |
| 39 | return 1; |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int |
| 46 | teardown(void **state) |
| 47 | { |
| 48 | ly_ctx_destroy(*state, NULL); |
| 49 | return 0; |
| 50 | } |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 51 | |
| 52 | #define BUFSIZE 1024 |
| 53 | char logbuf[BUFSIZE] = {0}; |
| 54 | |
| 55 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
| 56 | #define ENABLE_LOGGER_CHECKING 1 |
| 57 | |
| 58 | static void |
| 59 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 60 | { |
| 61 | (void) level; /* unused */ |
| 62 | |
| 63 | if (path) { |
| 64 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 65 | } else { |
| 66 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | static int |
| 71 | logger_setup(void **state) |
| 72 | { |
| 73 | (void) state; /* unused */ |
| 74 | #if ENABLE_LOGGER_CHECKING |
| 75 | ly_set_log_clb(logger, 1); |
| 76 | #endif |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | logbuf_clean(void) |
| 82 | { |
| 83 | logbuf[0] = '\0'; |
| 84 | } |
| 85 | |
| 86 | #if ENABLE_LOGGER_CHECKING |
| 87 | # define logbuf_assert(str) assert_string_equal(logbuf, str) |
| 88 | #else |
| 89 | # define logbuf_assert(str) |
| 90 | #endif |
| 91 | |
| 92 | static void |
| 93 | test_element(void **state) |
| 94 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 95 | struct lyxml_ctx *xmlctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 96 | struct ly_in *in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 97 | const char *str; |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 98 | |
| 99 | /* empty */ |
| 100 | str = ""; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 101 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 102 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 103 | assert_int_equal(LYXML_END, xmlctx->status); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 104 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 105 | ly_in_free(in, 0); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 106 | |
Radek Krejci | b189064 | 2018-10-03 14:05:40 +0200 | [diff] [blame] | 107 | /* end element */ |
| 108 | str = "</element>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 109 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 110 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 111 | logbuf_assert("Stray closing element tag (\"element\"). Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 112 | ly_in_free(in, 0); |
Radek Krejci | b189064 | 2018-10-03 14:05:40 +0200 | [diff] [blame] | 113 | |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 114 | /* no element */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 115 | //logbuf_clean(); |
| 116 | str = "no data present"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 117 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 118 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 119 | logbuf_assert("Invalid character sequence \"no data present\", expected element tag start ('<'). Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 120 | ly_in_free(in, 0); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 121 | |
| 122 | /* not supported DOCTYPE */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 123 | str = "<!DOCTYPE greeting SYSTEM \"hello.dtd\"><greeting/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 124 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 125 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 126 | logbuf_assert("Document Type Declaration not supported. Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 127 | ly_in_free(in, 0); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 128 | |
Radek Krejci | c5c31bb | 2019-04-08 14:40:52 +0200 | [diff] [blame] | 129 | /* invalid XML */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 130 | str = "<!NONSENSE/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 131 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 132 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 133 | logbuf_assert("Unknown XML section \"<!NONSENSE/>\". Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 134 | ly_in_free(in, 0); |
Radek Krejci | c5c31bb | 2019-04-08 14:40:52 +0200 | [diff] [blame] | 135 | |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 136 | /* unqualified element */ |
| 137 | str = " < element/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 138 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 139 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 140 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 141 | assert_null(xmlctx->prefix); |
| 142 | assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len)); |
| 143 | assert_int_equal(1, xmlctx->elements.count); |
Radek Krejci | 28e8cb5 | 2019-03-08 11:31:31 +0100 | [diff] [blame] | 144 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 145 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 146 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 147 | assert_true(!strncmp("", xmlctx->value, xmlctx->value_len)); |
| 148 | |
| 149 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 150 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 151 | |
| 152 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 153 | assert_int_equal(LYXML_END, xmlctx->status); |
| 154 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 155 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 156 | |
| 157 | /* element with attribute */ |
Radek Krejci | 28e8cb5 | 2019-03-08 11:31:31 +0100 | [diff] [blame] | 158 | str = " < element attr=\'x\'/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 159 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 160 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 161 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 162 | assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len)); |
| 163 | assert_null(xmlctx->prefix); |
| 164 | assert_int_equal(1, xmlctx->elements.count); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 165 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 166 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 167 | assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status); |
| 168 | assert_true(!strncmp("attr", xmlctx->name, xmlctx->name_len)); |
| 169 | assert_null(xmlctx->prefix); |
| 170 | |
| 171 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 172 | assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status); |
| 173 | assert_int_equal(1, xmlctx->elements.count); |
| 174 | assert_true(!strncmp("x", xmlctx->value, xmlctx->value_len)); |
| 175 | |
| 176 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 177 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 178 | |
| 179 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 180 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 181 | assert_int_equal(0, xmlctx->elements.count); |
| 182 | |
| 183 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 184 | assert_int_equal(LYXML_END, xmlctx->status); |
| 185 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 186 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 187 | |
| 188 | /* headers and comments */ |
Radek Krejci | fb7c658 | 2018-09-21 16:12:45 +0200 | [diff] [blame] | 189 | str = "<?xml version=\"1.0\"?> <!-- comment --> <![CDATA[<greeting>Hello, world!</greeting>]]> <?TEST xxx?> <element/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 190 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 191 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 192 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 193 | assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len)); |
| 194 | assert_null(xmlctx->prefix); |
| 195 | assert_int_equal(1, xmlctx->elements.count); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 196 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 197 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 198 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 199 | |
| 200 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 201 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 202 | |
| 203 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 204 | assert_int_equal(LYXML_END, xmlctx->status); |
| 205 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 206 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 207 | |
| 208 | /* separate opening and closing tags, neamespaced parsed internally */ |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 209 | str = "<element xmlns=\"urn\"></element>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 210 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 211 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 212 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 213 | assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len)); |
| 214 | assert_null(xmlctx->prefix); |
| 215 | assert_int_equal(1, xmlctx->elements.count); |
| 216 | assert_int_equal(1, xmlctx->ns.count); |
| 217 | |
| 218 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 219 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 220 | |
| 221 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 222 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 223 | assert_int_equal(0, xmlctx->elements.count); |
| 224 | assert_int_equal(0, xmlctx->ns.count); |
| 225 | |
| 226 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 227 | assert_int_equal(LYXML_END, xmlctx->status); |
| 228 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 229 | ly_in_free(in, 0); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 230 | |
| 231 | /* qualified element */ |
| 232 | str = " < yin:element/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 233 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 234 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 235 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 236 | assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len)); |
| 237 | assert_true(!strncmp("yin", xmlctx->prefix, xmlctx->prefix_len)); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 238 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 239 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 240 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 241 | |
| 242 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 243 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 244 | |
| 245 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 246 | assert_int_equal(LYXML_END, xmlctx->status); |
| 247 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 248 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 249 | |
| 250 | /* non-matching closing tag */ |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 251 | str = "<yin:element xmlns=\"urn\"></element>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 252 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 253 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 254 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 255 | assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len)); |
| 256 | assert_true(!strncmp("yin", xmlctx->prefix, xmlctx->prefix_len)); |
| 257 | assert_int_equal(1, xmlctx->elements.count); |
| 258 | assert_int_equal(1, xmlctx->ns.count); |
| 259 | |
| 260 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 261 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 262 | |
| 263 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 264 | logbuf_assert("Opening (\"yin:element\") and closing (\"element\") elements tag mismatch. Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 265 | lyxml_ctx_free(xmlctx); |
| 266 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 267 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 268 | /* invalid closing tag */ |
| 269 | str = "<yin:element xmlns=\"urn\"></yin:element/>"; |
| 270 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 271 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
| 272 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 273 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 274 | logbuf_assert("Invalid character sequence \"/>\", expected element tag termination ('>'). Line number 1."); |
| 275 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 276 | ly_in_free(in, 0); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 277 | |
| 278 | /* UTF8 characters */ |
| 279 | str = "<𠜎€𠜎Øn:𠜎€𠜎Øn/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 280 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 281 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 282 | assert_true(!strncmp("𠜎€𠜎Øn", xmlctx->name, xmlctx->name_len)); |
| 283 | assert_true(!strncmp("𠜎€𠜎Øn", xmlctx->prefix, xmlctx->prefix_len)); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 284 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 285 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 286 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 287 | |
| 288 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 289 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 290 | |
| 291 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 292 | assert_int_equal(LYXML_END, xmlctx->status); |
| 293 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 294 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 295 | |
| 296 | /* invalid UTF-8 characters */ |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 297 | str = "<¢:element>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 298 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 299 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 300 | logbuf_assert("Identifier \"¢:element>\" starts with an invalid character. Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 301 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 302 | |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 303 | str = "<yin:c⁐element>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 304 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 305 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 306 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 307 | logbuf_assert("Invalid character sequence \"⁐element>\", expected element tag end ('>' or '/>') or an attribute. Line number 1."); |
| 308 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 309 | ly_in_free(in, 0); |
Radek Krejci | 339e2de | 2019-05-17 14:28:24 +0200 | [diff] [blame] | 310 | |
| 311 | /* mixed content */ |
| 312 | str = "<a>text <b>x</b></a>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 313 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 314 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 315 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 316 | assert_true(!strncmp("a", xmlctx->name, xmlctx->name_len)); |
| 317 | assert_null(xmlctx->prefix); |
Radek Krejci | 339e2de | 2019-05-17 14:28:24 +0200 | [diff] [blame] | 318 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 319 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 320 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 321 | assert_true(!strncmp("text ", xmlctx->value, xmlctx->value_len)); |
| 322 | |
| 323 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 324 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 325 | assert_true(!strncmp("b", xmlctx->name, xmlctx->name_len)); |
| 326 | assert_null(xmlctx->prefix); |
| 327 | |
| 328 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 329 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 330 | assert_true(!strncmp("x", xmlctx->value, xmlctx->value_len)); |
| 331 | |
| 332 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 333 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 334 | |
| 335 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 336 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
| 337 | |
| 338 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 339 | assert_int_equal(LYXML_END, xmlctx->status); |
| 340 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 341 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 342 | |
| 343 | /* tag mismatch */ |
David Sedlák | 54a6f13 | 2019-07-16 15:14:18 +0200 | [diff] [blame] | 344 | str = "<a>text</b>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 345 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 346 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 347 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 348 | assert_true(!strncmp("a", xmlctx->name, xmlctx->name_len)); |
| 349 | assert_null(xmlctx->prefix); |
David Sedlák | 54a6f13 | 2019-07-16 15:14:18 +0200 | [diff] [blame] | 350 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 351 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 352 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 353 | assert_true(!strncmp("text", xmlctx->value, xmlctx->value_len)); |
| 354 | |
| 355 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 356 | logbuf_assert("Opening (\"a\") and closing (\"b\") elements tag mismatch. Line number 1."); |
| 357 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 358 | ly_in_free(in, 0); |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static void |
| 362 | test_attribute(void **state) |
| 363 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 364 | const char *str; |
| 365 | struct lyxml_ctx *xmlctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 366 | struct ly_in *in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 367 | struct lyxml_ns *ns; |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 368 | |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 369 | /* not an attribute */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 370 | str = "<e unknown/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 371 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 372 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 373 | logbuf_assert("Invalid character sequence \"/>\", expected '='. Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 374 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 375 | |
| 376 | str = "<e xxx=/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 377 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 378 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 379 | logbuf_assert("Invalid character sequence \"/>\", expected either single or double quotation mark. Line number 1."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 380 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 381 | |
| 382 | str = "<e xxx\n = yyy/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 383 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 384 | assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx)); |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 385 | logbuf_assert("Invalid character sequence \"yyy/>\", expected either single or double quotation mark. Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 386 | ly_in_free(in, 0); |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 387 | |
| 388 | /* valid attribute */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 389 | str = "<e attr=\"val\""; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 390 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 391 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 392 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 393 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 394 | assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status); |
| 395 | assert_true(!strncmp("attr", xmlctx->name, xmlctx->name_len)); |
| 396 | assert_null(xmlctx->prefix); |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 397 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 398 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 399 | assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status); |
| 400 | assert_true(!strncmp("val", xmlctx->name, xmlctx->name_len)); |
| 401 | assert_int_equal(xmlctx->ws_only, 0); |
| 402 | assert_int_equal(xmlctx->dynamic, 0); |
| 403 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 404 | ly_in_free(in, 0); |
Radek Krejci | 28e8cb5 | 2019-03-08 11:31:31 +0100 | [diff] [blame] | 405 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 406 | /* valid namespace with prefix */ |
| 407 | str = "<e xmlns:nc\n = \'urn\'/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 408 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 409 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 410 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 411 | assert_int_equal(1, xmlctx->ns.count); |
| 412 | ns = (struct lyxml_ns *)xmlctx->ns.objs[0]; |
| 413 | assert_string_equal(ns->prefix, "nc"); |
| 414 | assert_string_equal(ns->uri, "urn"); |
| 415 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 416 | ly_in_free(in, 0); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 419 | static void |
| 420 | test_text(void **state) |
| 421 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 422 | const char *str; |
| 423 | struct lyxml_ctx *xmlctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 424 | struct ly_in *in; |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 425 | |
| 426 | /* empty attribute value */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 427 | str = "<e a=\"\""; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 428 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 429 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 430 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 431 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 432 | assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status); |
Radek Krejci | b189064 | 2018-10-03 14:05:40 +0200 | [diff] [blame] | 433 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 434 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 435 | assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status); |
| 436 | assert_true(!strncmp("", xmlctx->value, xmlctx->value_len)); |
| 437 | assert_int_equal(xmlctx->ws_only, 1); |
| 438 | assert_int_equal(xmlctx->dynamic, 0); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 439 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 440 | |
| 441 | /* empty value but in single quotes */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 442 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'\'", &in)); |
| 443 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 444 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 445 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 446 | assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status); |
| 447 | assert_true(!strncmp("", xmlctx->value, xmlctx->value_len)); |
| 448 | assert_int_equal(xmlctx->ws_only, 1); |
| 449 | assert_int_equal(xmlctx->dynamic, 0); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 450 | ly_in_free(in, 0); |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 451 | |
Radek Krejci | ed6c6ad | 2018-09-26 09:10:18 +0200 | [diff] [blame] | 452 | /* empty element content - only formating before defining child */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 453 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(">\n <y>", &in)); |
| 454 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 455 | xmlctx->status = LYXML_ELEMENT; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 456 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 457 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 458 | assert_true(!strncmp("\n ", xmlctx->value, xmlctx->value_len)); |
| 459 | assert_int_equal(xmlctx->ws_only, 1); |
| 460 | assert_int_equal(xmlctx->dynamic, 0); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 461 | ly_in_free(in, 0); |
Radek Krejci | ed6c6ad | 2018-09-26 09:10:18 +0200 | [diff] [blame] | 462 | |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 463 | /* empty element content is invalid - missing content terminating character < */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 464 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("", &in)); |
| 465 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 466 | xmlctx->status = LYXML_ELEM_CONTENT; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 467 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
Radek Krejci | 0a1d0d4 | 2019-05-16 15:14:51 +0200 | [diff] [blame] | 468 | logbuf_assert("Unexpected end-of-input. Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 469 | ly_in_free(in, 0); |
Radek Krejci | ed6c6ad | 2018-09-26 09:10:18 +0200 | [diff] [blame] | 470 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 471 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("xxx", &in)); |
| 472 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 473 | xmlctx->status = LYXML_ELEM_CONTENT; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 474 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 475 | logbuf_assert("Invalid character sequence \"xxx\", expected element tag start ('<'). Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 476 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 477 | |
| 478 | lyxml_ctx_free(xmlctx); |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 479 | |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 480 | /* valid strings */ |
Radek Krejci | 339e2de | 2019-05-17 14:28:24 +0200 | [diff] [blame] | 481 | str = "<a>€𠜎Øn \n<&"'> ROK</a>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 482 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 483 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 484 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
| 485 | |
| 486 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 487 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
| 488 | assert_true(!strncmp("€𠜎Øn \n<&\"\'> ROK", xmlctx->value, xmlctx->value_len)); |
| 489 | assert_int_equal(xmlctx->ws_only, 0); |
| 490 | assert_int_equal(xmlctx->dynamic, 1); |
| 491 | free((char *)xmlctx->value); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 492 | ly_in_free(in, 0); |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 493 | |
Radek Krejci | 117d208 | 2018-09-26 10:05:14 +0200 | [diff] [blame] | 494 | /* test using n-bytes UTF8 hexadecimal code points */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 495 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'$¢€𐍈\'", &in)); |
| 496 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 497 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 498 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 499 | assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status); |
| 500 | assert_true(!strncmp("$¢€𐍈", xmlctx->value, xmlctx->value_len)); |
| 501 | assert_int_equal(xmlctx->ws_only, 0); |
| 502 | assert_int_equal(xmlctx->dynamic, 1); |
| 503 | free((char *)xmlctx->value); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 504 | ly_in_free(in, 0); |
Radek Krejci | d70d107 | 2018-10-09 14:20:47 +0200 | [diff] [blame] | 505 | |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 506 | /* invalid characters in string */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 507 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'R\'", &in)); |
| 508 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 509 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 510 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 511 | logbuf_assert("Invalid character sequence \"'\", expected ;. Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 512 | ly_in_free(in, 0); |
Radek Krejci | 117d208 | 2018-09-26 10:05:14 +0200 | [diff] [blame] | 513 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 514 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\"R\"", &in)); |
| 515 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 516 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 517 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 518 | logbuf_assert("Invalid character sequence \"\"\", expected ;. Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 519 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 520 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 521 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\"&nonsense;\"", &in)); |
| 522 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 523 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 524 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 525 | logbuf_assert("Entity reference \"&nonsense;\" not supported, only predefined references allowed. Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 526 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 527 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 528 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(">&#o122;", &in)); |
| 529 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 530 | xmlctx->status = LYXML_ELEMENT; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 531 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 532 | logbuf_assert("Invalid character reference \"&#o122;\". Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 533 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 534 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 535 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'\'", &in)); |
| 536 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 537 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 538 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 539 | logbuf_assert("Invalid character reference \"\'\" (0x00000006). Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 540 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 541 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 542 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'\'", &in)); |
| 543 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 544 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 545 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 546 | logbuf_assert("Invalid character reference \"\'\" (0x0000fdd0). Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 547 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 548 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 549 | assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'\'", &in)); |
| 550 | xmlctx->in = in; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 551 | xmlctx->status = LYXML_ATTRIBUTE; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 552 | assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx)); |
| 553 | logbuf_assert("Invalid character reference \"\'\" (0x0000ffff). Line number 2."); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 554 | ly_in_free(in, 0); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 555 | |
| 556 | lyxml_ctx_free(xmlctx); |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 557 | } |
| 558 | |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 559 | static void |
| 560 | test_ns(void **state) |
| 561 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 562 | const char *str; |
| 563 | struct lyxml_ctx *xmlctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 564 | struct ly_in *in; |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 565 | const struct lyxml_ns *ns; |
| 566 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 567 | /* opening element1 */ |
| 568 | str = "<element1/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 569 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 570 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 571 | |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 572 | /* processing namespace definitions */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 573 | assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, NULL, 0, strdup("urn:default"))); |
| 574 | assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, "nc", 2, strdup("urn:nc1"))); |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 575 | /* simulate adding open element2 into context */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 576 | xmlctx->elements.count++; |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 577 | /* processing namespace definitions */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 578 | assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, "nc", 2, strdup("urn:nc2"))); |
| 579 | assert_int_equal(3, xmlctx->ns.count); |
| 580 | assert_int_not_equal(0, xmlctx->ns.size); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 581 | |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 582 | ns = lyxml_ns_get(&xmlctx->ns, NULL, 0); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 583 | assert_non_null(ns); |
| 584 | assert_null(ns->prefix); |
| 585 | assert_string_equal("urn:default", ns->uri); |
| 586 | |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 587 | ns = lyxml_ns_get(&xmlctx->ns, "nc", 2); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 588 | assert_non_null(ns); |
| 589 | assert_string_equal("nc", ns->prefix); |
| 590 | assert_string_equal("urn:nc2", ns->uri); |
| 591 | |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 592 | /* simulate closing element2 */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 593 | xmlctx->elements.count--; |
| 594 | lyxml_ns_rm(xmlctx); |
| 595 | assert_int_equal(2, xmlctx->ns.count); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 596 | |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 597 | ns = lyxml_ns_get(&xmlctx->ns, "nc", 2); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 598 | assert_non_null(ns); |
| 599 | assert_string_equal("nc", ns->prefix); |
| 600 | assert_string_equal("urn:nc1", ns->uri); |
| 601 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 602 | /* close element1 */ |
| 603 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 604 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 605 | assert_int_equal(0, xmlctx->ns.count); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 606 | |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 607 | assert_null(lyxml_ns_get(&xmlctx->ns, "nc", 2)); |
| 608 | assert_null(lyxml_ns_get(&xmlctx->ns, NULL, 0)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 609 | |
| 610 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 611 | ly_in_free(in, 0); |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 612 | } |
| 613 | |
David Sedlák | b3bed7a | 2019-03-08 11:53:37 +0100 | [diff] [blame] | 614 | static void |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 615 | test_ns2(void **state) |
| 616 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 617 | const char *str; |
| 618 | struct lyxml_ctx *xmlctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 619 | struct ly_in *in; |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 620 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 621 | /* opening element1 */ |
| 622 | str = "<element1/>"; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 623 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 624 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 625 | |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 626 | /* default namespace defined in parent element1 */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 627 | assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, NULL, 0, strdup("urn:default"))); |
| 628 | assert_int_equal(1, xmlctx->ns.count); |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 629 | /* going into child element1 */ |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 630 | /* simulate adding open element1 into context */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 631 | xmlctx->elements.count++; |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 632 | /* no namespace defined, going out (first, simulate closing of so far open element) */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 633 | xmlctx->elements.count--; |
| 634 | lyxml_ns_rm(xmlctx); |
| 635 | assert_int_equal(1, xmlctx->ns.count); |
| 636 | |
| 637 | /* nothing else, going out of the parent element1 */ |
| 638 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 639 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 640 | assert_int_equal(0, xmlctx->ns.count); |
| 641 | |
| 642 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 643 | ly_in_free(in, 0); |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 644 | } |
| 645 | |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 646 | static void |
| 647 | test_simple_xml(void **state) |
| 648 | { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 649 | struct lyxml_ctx *xmlctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 650 | struct ly_in *in; |
Radek Krejci | e553e6d | 2019-06-07 15:33:18 +0200 | [diff] [blame] | 651 | const char *test_input = "<elem1 attr1=\"value\"> <elem2 attr2=\"value\" /> </elem1>"; |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 652 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 653 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(test_input, &in)); |
| 654 | assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 655 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 656 | assert_string_equal(xmlctx->in->current, "attr1=\"value\"> <elem2 attr2=\"value\" /> </elem1>"); |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 657 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 658 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 659 | assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 660 | assert_string_equal(xmlctx->in->current, "=\"value\"> <elem2 attr2=\"value\" /> </elem1>"); |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 661 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 662 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 663 | assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 664 | assert_string_equal(xmlctx->in->current, "> <elem2 attr2=\"value\" /> </elem1>"); |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 665 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 666 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 667 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 668 | assert_string_equal(xmlctx->in->current, "<elem2 attr2=\"value\" /> </elem1>"); |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 669 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 670 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 671 | assert_int_equal(LYXML_ELEMENT, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 672 | assert_string_equal(xmlctx->in->current, "attr2=\"value\" /> </elem1>"); |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 673 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 674 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 675 | assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 676 | assert_string_equal(xmlctx->in->current, "=\"value\" /> </elem1>"); |
Radek Krejci | e553e6d | 2019-06-07 15:33:18 +0200 | [diff] [blame] | 677 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 678 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 679 | assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 680 | assert_string_equal(xmlctx->in->current, " /> </elem1>"); |
Radek Krejci | e553e6d | 2019-06-07 15:33:18 +0200 | [diff] [blame] | 681 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 682 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 683 | assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 684 | assert_string_equal(xmlctx->in->current, "/> </elem1>"); |
Radek Krejci | e553e6d | 2019-06-07 15:33:18 +0200 | [diff] [blame] | 685 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 686 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 687 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 688 | assert_string_equal(xmlctx->in->current, " </elem1>"); |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 689 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 690 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 691 | assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 692 | assert_string_equal(xmlctx->in->current, ""); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 693 | |
| 694 | assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx)); |
| 695 | assert_int_equal(LYXML_END, xmlctx->status); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 696 | assert_string_equal(xmlctx->in->current, ""); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 697 | |
| 698 | lyxml_ctx_free(xmlctx); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 699 | ly_in_free(in, 0); |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 700 | } |
| 701 | |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 702 | int main(void) |
| 703 | { |
| 704 | const struct CMUnitTest tests[] = { |
Radek Krejci | d972c25 | 2018-09-25 13:23:39 +0200 | [diff] [blame] | 705 | cmocka_unit_test_setup(test_element, logger_setup), |
| 706 | cmocka_unit_test_setup(test_attribute, logger_setup), |
Radek Krejci | 7a7fa90 | 2018-09-25 17:08:21 +0200 | [diff] [blame] | 707 | cmocka_unit_test_setup(test_text, logger_setup), |
Radek Krejci | 4b74d5e | 2018-09-26 14:30:55 +0200 | [diff] [blame] | 708 | cmocka_unit_test_setup(test_ns, logger_setup), |
Radek Krejci | e0734d2 | 2019-04-05 15:54:28 +0200 | [diff] [blame] | 709 | cmocka_unit_test_setup(test_ns2, logger_setup), |
Radek Krejci | fad79c9 | 2019-06-04 11:43:30 +0200 | [diff] [blame] | 710 | cmocka_unit_test_setup(test_simple_xml, logger_setup), |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 711 | }; |
| 712 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 713 | return cmocka_run_group_tests(tests, setup, teardown); |
Radek Krejci | d91dbaf | 2018-09-21 15:51:39 +0200 | [diff] [blame] | 714 | } |