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