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