Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 1 | /* |
aPiecek | 023f83a | 2021-05-11 07:37:03 +0200 | [diff] [blame] | 2 | * @file test_json.c |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for a generic JSON parser |
| 5 | * |
| 6 | * Copyright (c) 2020 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 | */ |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 14 | #define _UTEST_MAIN_ |
| 15 | #include "utests.h" |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 16 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 17 | #include "context.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 18 | #include "in_internal.h" |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 19 | #include "json.h" |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 20 | static void |
| 21 | test_general(void **state) |
| 22 | { |
| 23 | struct lyjson_ctx *jsonctx; |
| 24 | struct ly_in *in; |
| 25 | const char *str; |
| 26 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 27 | /* empty */ |
| 28 | str = ""; |
| 29 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 30 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 31 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 32 | lyjson_ctx_free(jsonctx); |
| 33 | |
| 34 | str = " \n\t \n"; |
| 35 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 36 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 37 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 38 | lyjson_ctx_free(jsonctx); |
| 39 | |
| 40 | /* constant values */ |
| 41 | str = "true"; |
| 42 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 43 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 44 | assert_int_equal(LYJSON_TRUE, lyjson_ctx_status(jsonctx, 0)); |
| 45 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 46 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 47 | lyjson_ctx_free(jsonctx); |
| 48 | |
| 49 | str = "false"; |
| 50 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 51 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 52 | assert_int_equal(LYJSON_FALSE, lyjson_ctx_status(jsonctx, 0)); |
| 53 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 54 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 55 | lyjson_ctx_free(jsonctx); |
| 56 | |
| 57 | str = "null"; |
| 58 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 59 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 60 | assert_int_equal(LYJSON_NULL, lyjson_ctx_status(jsonctx, 0)); |
| 61 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 62 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 63 | lyjson_ctx_free(jsonctx); |
| 64 | |
| 65 | ly_in_free(in, 0); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void |
| 69 | test_number(void **state) |
| 70 | { |
| 71 | struct lyjson_ctx *jsonctx; |
| 72 | struct ly_in *in; |
| 73 | const char *str; |
| 74 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 75 | /* simple value */ |
| 76 | str = "11"; |
| 77 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 78 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 79 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 80 | assert_string_equal("11", jsonctx->value); |
| 81 | assert_int_equal(2, jsonctx->value_len); |
| 82 | assert_int_equal(0, jsonctx->dynamic); |
| 83 | lyjson_ctx_free(jsonctx); |
| 84 | |
| 85 | /* fraction number */ |
| 86 | str = "37.7668"; |
| 87 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 88 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 89 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 90 | assert_string_equal("37.7668", jsonctx->value); |
| 91 | assert_int_equal(7, jsonctx->value_len); |
| 92 | assert_int_equal(0, jsonctx->dynamic); |
| 93 | lyjson_ctx_free(jsonctx); |
| 94 | |
| 95 | /* negative number */ |
| 96 | str = "-122.3959"; |
| 97 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 98 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 99 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 100 | assert_string_equal("-122.3959", jsonctx->value); |
| 101 | assert_int_equal(9, jsonctx->value_len); |
| 102 | assert_int_equal(0, jsonctx->dynamic); |
| 103 | lyjson_ctx_free(jsonctx); |
| 104 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 105 | /* integer, positive exponent */ |
| 106 | str = "550E3"; |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 107 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 108 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 109 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 110 | assert_string_equal("550000", jsonctx->value); |
| 111 | assert_int_equal(6, jsonctx->value_len); |
| 112 | assert_int_equal(1, jsonctx->dynamic); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 113 | lyjson_ctx_free(jsonctx); |
| 114 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 115 | str = "-550E3"; |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 116 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 117 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 118 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 119 | assert_string_equal("-550000", jsonctx->value); |
| 120 | assert_int_equal(7, jsonctx->value_len); |
| 121 | assert_int_equal(1, jsonctx->dynamic); |
| 122 | lyjson_ctx_free(jsonctx); |
| 123 | |
| 124 | /* integer, negative exponent */ |
| 125 | str = "1E-1"; |
| 126 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 127 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 128 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 129 | assert_string_equal("0.1", jsonctx->value); |
| 130 | assert_int_equal(3, jsonctx->value_len); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 131 | assert_int_equal(1, jsonctx->dynamic); |
| 132 | lyjson_ctx_free(jsonctx); |
| 133 | |
| 134 | str = "15E-1"; |
| 135 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 136 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 137 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 138 | assert_string_equal("1.5", jsonctx->value); |
| 139 | assert_int_equal(3, jsonctx->value_len); |
| 140 | assert_int_equal(1, jsonctx->dynamic); |
| 141 | lyjson_ctx_free(jsonctx); |
| 142 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 143 | str = "-15E-1"; |
aPiecek | 350a6bf | 2021-05-25 07:59:10 +0200 | [diff] [blame] | 144 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 145 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 350a6bf | 2021-05-25 07:59:10 +0200 | [diff] [blame] | 146 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 147 | assert_string_equal("-1.5", jsonctx->value); |
aPiecek | 350a6bf | 2021-05-25 07:59:10 +0200 | [diff] [blame] | 148 | assert_int_equal(4, jsonctx->value_len); |
| 149 | assert_int_equal(1, jsonctx->dynamic); |
| 150 | lyjson_ctx_free(jsonctx); |
| 151 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 152 | str = "16E-2"; |
aPiecek | 350a6bf | 2021-05-25 07:59:10 +0200 | [diff] [blame] | 153 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 154 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 350a6bf | 2021-05-25 07:59:10 +0200 | [diff] [blame] | 155 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 156 | assert_string_equal("0.16", jsonctx->value); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 157 | assert_int_equal(4, jsonctx->value_len); |
| 158 | assert_int_equal(1, jsonctx->dynamic); |
| 159 | lyjson_ctx_free(jsonctx); |
| 160 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 161 | str = "-16E-2"; |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 162 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 163 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 164 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 165 | assert_string_equal("-0.16", jsonctx->value); |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 166 | assert_int_equal(5, jsonctx->value_len); |
| 167 | assert_int_equal(1, jsonctx->dynamic); |
| 168 | lyjson_ctx_free(jsonctx); |
| 169 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 170 | str = "17E-3"; |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 171 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 172 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 173 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 174 | assert_string_equal("0.017", jsonctx->value); |
| 175 | assert_int_equal(5, jsonctx->value_len); |
| 176 | assert_int_equal(1, jsonctx->dynamic); |
| 177 | lyjson_ctx_free(jsonctx); |
| 178 | |
| 179 | str = "-17E-3"; |
| 180 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 181 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 182 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 183 | assert_string_equal("-0.017", jsonctx->value); |
| 184 | assert_int_equal(6, jsonctx->value_len); |
| 185 | assert_int_equal(1, jsonctx->dynamic); |
| 186 | lyjson_ctx_free(jsonctx); |
| 187 | |
| 188 | str = "21000E-2"; |
| 189 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 190 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 191 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 192 | assert_string_equal("210", jsonctx->value); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 193 | assert_int_equal(3, jsonctx->value_len); |
| 194 | assert_int_equal(1, jsonctx->dynamic); |
| 195 | lyjson_ctx_free(jsonctx); |
| 196 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 197 | str = "21000E-4"; |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 198 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 199 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 200 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 201 | assert_string_equal("2.1", jsonctx->value); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 202 | assert_int_equal(3, jsonctx->value_len); |
| 203 | assert_int_equal(1, jsonctx->dynamic); |
| 204 | lyjson_ctx_free(jsonctx); |
| 205 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 206 | str = "21000E-7"; |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 207 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 208 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 209 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 210 | assert_string_equal("0.0021", jsonctx->value); |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 211 | assert_int_equal(6, jsonctx->value_len); |
| 212 | assert_int_equal(1, jsonctx->dynamic); |
| 213 | lyjson_ctx_free(jsonctx); |
| 214 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 215 | /* decimal number, positive exponent */ |
| 216 | str = "5.087E1"; |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 217 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 218 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 219 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 220 | assert_string_equal("50.87", jsonctx->value); |
| 221 | assert_int_equal(5, jsonctx->value_len); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 222 | assert_int_equal(1, jsonctx->dynamic); |
| 223 | lyjson_ctx_free(jsonctx); |
| 224 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 225 | str = "-5.087E1"; |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 226 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 227 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 228 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 229 | assert_string_equal("-50.87", jsonctx->value); |
| 230 | assert_int_equal(6, jsonctx->value_len); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 231 | assert_int_equal(1, jsonctx->dynamic); |
| 232 | lyjson_ctx_free(jsonctx); |
| 233 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 234 | str = "5.087E5"; |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 235 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 236 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 237 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 238 | assert_string_equal("508700", jsonctx->value); |
| 239 | assert_int_equal(6, jsonctx->value_len); |
| 240 | assert_int_equal(1, jsonctx->dynamic); |
| 241 | lyjson_ctx_free(jsonctx); |
| 242 | |
| 243 | str = "59.1e+1"; |
| 244 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 245 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 246 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 247 | assert_string_equal("591", jsonctx->value); |
| 248 | assert_int_equal(3, jsonctx->value_len); |
| 249 | assert_int_equal(1, jsonctx->dynamic); |
| 250 | lyjson_ctx_free(jsonctx); |
| 251 | |
| 252 | str = "0.005087E1"; |
| 253 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 254 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 255 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 256 | assert_string_equal("0.05087", jsonctx->value); |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 257 | assert_int_equal(7, jsonctx->value_len); |
| 258 | assert_int_equal(1, jsonctx->dynamic); |
| 259 | lyjson_ctx_free(jsonctx); |
| 260 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 261 | str = "0.005087E2"; |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 262 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 263 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 264 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 265 | assert_string_equal("0.5087", jsonctx->value); |
aPiecek | 58e46a5 | 2021-05-05 10:04:47 +0200 | [diff] [blame] | 266 | assert_int_equal(6, jsonctx->value_len); |
| 267 | assert_int_equal(1, jsonctx->dynamic); |
| 268 | lyjson_ctx_free(jsonctx); |
| 269 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 270 | str = "0.005087E6"; |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 271 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 272 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 273 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 274 | assert_string_equal("5087", jsonctx->value); |
aPiecek | a40b466 | 2021-05-13 15:47:03 +0200 | [diff] [blame] | 275 | assert_int_equal(4, jsonctx->value_len); |
| 276 | assert_int_equal(1, jsonctx->dynamic); |
| 277 | lyjson_ctx_free(jsonctx); |
| 278 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 279 | str = "0.05087E6"; |
| 280 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 281 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 282 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 283 | assert_string_equal("50870", jsonctx->value); |
| 284 | assert_int_equal(5, jsonctx->value_len); |
| 285 | assert_int_equal(1, jsonctx->dynamic); |
| 286 | lyjson_ctx_free(jsonctx); |
| 287 | |
| 288 | str = "0.005087E8"; |
| 289 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 290 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 291 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 292 | assert_string_equal("508700", jsonctx->value); |
| 293 | assert_int_equal(6, jsonctx->value_len); |
| 294 | assert_int_equal(1, jsonctx->dynamic); |
| 295 | lyjson_ctx_free(jsonctx); |
| 296 | |
| 297 | /* decimal number, negative exponent */ |
| 298 | str = "35.94e-1"; |
| 299 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 300 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 301 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 302 | assert_string_equal("3.594", jsonctx->value); |
| 303 | assert_int_equal(5, jsonctx->value_len); |
| 304 | assert_int_equal(1, jsonctx->dynamic); |
| 305 | lyjson_ctx_free(jsonctx); |
| 306 | |
| 307 | str = "-35.94e-1"; |
| 308 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 309 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 310 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 311 | assert_string_equal("-3.594", jsonctx->value); |
| 312 | assert_int_equal(6, jsonctx->value_len); |
| 313 | assert_int_equal(1, jsonctx->dynamic); |
| 314 | lyjson_ctx_free(jsonctx); |
| 315 | |
| 316 | str = "35.94e-2"; |
| 317 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 318 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 319 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 320 | assert_string_equal("0.3594", jsonctx->value); |
| 321 | assert_int_equal(6, jsonctx->value_len); |
| 322 | assert_int_equal(1, jsonctx->dynamic); |
| 323 | lyjson_ctx_free(jsonctx); |
| 324 | |
| 325 | str = "35.94e-3"; |
| 326 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 327 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 328 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 329 | assert_string_equal("0.03594", jsonctx->value); |
| 330 | assert_int_equal(7, jsonctx->value_len); |
| 331 | assert_int_equal(1, jsonctx->dynamic); |
| 332 | lyjson_ctx_free(jsonctx); |
| 333 | |
| 334 | str = "0.3594e-1"; |
| 335 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 336 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 337 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 338 | assert_string_equal("0.03594", jsonctx->value); |
| 339 | assert_int_equal(7, jsonctx->value_len); |
| 340 | assert_int_equal(1, jsonctx->dynamic); |
| 341 | lyjson_ctx_free(jsonctx); |
| 342 | |
| 343 | str = "0.03594e-1"; |
| 344 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 345 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 346 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 347 | assert_string_equal("0.003594", jsonctx->value); |
| 348 | assert_int_equal(8, jsonctx->value_len); |
| 349 | assert_int_equal(1, jsonctx->dynamic); |
| 350 | lyjson_ctx_free(jsonctx); |
| 351 | |
| 352 | str = "0.003594e-1"; |
| 353 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 354 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 355 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 356 | assert_string_equal("0.0003594", jsonctx->value); |
| 357 | assert_int_equal(9, jsonctx->value_len); |
| 358 | assert_int_equal(1, jsonctx->dynamic); |
| 359 | lyjson_ctx_free(jsonctx); |
| 360 | |
| 361 | str = "0.3594e-2"; |
| 362 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 363 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 364 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 365 | assert_string_equal("0.003594", jsonctx->value); |
| 366 | assert_int_equal(8, jsonctx->value_len); |
| 367 | assert_int_equal(1, jsonctx->dynamic); |
| 368 | lyjson_ctx_free(jsonctx); |
| 369 | |
| 370 | str = "0.03594e-2"; |
| 371 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 372 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 373 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 374 | assert_string_equal("0.0003594", jsonctx->value); |
| 375 | assert_int_equal(9, jsonctx->value_len); |
| 376 | assert_int_equal(1, jsonctx->dynamic); |
| 377 | lyjson_ctx_free(jsonctx); |
| 378 | |
| 379 | str = "0.003594e-2"; |
| 380 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 381 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 382 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 383 | assert_string_equal("0.00003594", jsonctx->value); |
| 384 | assert_int_equal(10, jsonctx->value_len); |
| 385 | assert_int_equal(1, jsonctx->dynamic); |
| 386 | lyjson_ctx_free(jsonctx); |
| 387 | |
| 388 | /* zero */ |
| 389 | str = "0"; |
| 390 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 391 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 392 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 393 | assert_true(jsonctx->value[0] == '0'); |
| 394 | assert_int_equal(1, jsonctx->value_len); |
| 395 | assert_int_equal(0, jsonctx->dynamic); |
| 396 | lyjson_ctx_free(jsonctx); |
| 397 | |
| 398 | str = "-0"; |
| 399 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 400 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 401 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 402 | assert_true(jsonctx->value[0] == '-'); |
| 403 | assert_true(jsonctx->value[1] == '0'); |
| 404 | assert_int_equal(2, jsonctx->value_len); |
| 405 | assert_int_equal(0, jsonctx->dynamic); |
| 406 | lyjson_ctx_free(jsonctx); |
| 407 | |
| 408 | str = "94E0"; |
| 409 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 410 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 411 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 412 | assert_true(jsonctx->value[0] == '9'); |
| 413 | assert_true(jsonctx->value[1] == '4'); |
| 414 | assert_int_equal(2, jsonctx->value_len); |
| 415 | assert_int_equal(0, jsonctx->dynamic); |
| 416 | lyjson_ctx_free(jsonctx); |
| 417 | |
| 418 | str = "0E2"; |
| 419 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 420 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 421 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 422 | assert_true(jsonctx->value[0] == '0'); |
| 423 | assert_int_equal(1, jsonctx->value_len); |
| 424 | assert_int_equal(0, jsonctx->dynamic); |
| 425 | lyjson_ctx_free(jsonctx); |
| 426 | |
| 427 | str = "-0E2"; |
| 428 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 429 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 430 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 431 | assert_true(jsonctx->value[0] == '-'); |
| 432 | assert_true(jsonctx->value[1] == '0'); |
| 433 | assert_int_equal(2, jsonctx->value_len); |
| 434 | assert_int_equal(0, jsonctx->dynamic); |
| 435 | lyjson_ctx_free(jsonctx); |
| 436 | |
| 437 | str = "5.320e+2"; |
| 438 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 439 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 440 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 441 | assert_string_equal("532", jsonctx->value); |
| 442 | assert_int_equal(3, jsonctx->value_len); |
| 443 | assert_int_equal(1, jsonctx->dynamic); |
| 444 | lyjson_ctx_free(jsonctx); |
| 445 | |
| 446 | str = "5.320e-1"; |
| 447 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 448 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 449 | assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0)); |
| 450 | assert_string_equal("0.532", jsonctx->value); |
| 451 | assert_int_equal(5, jsonctx->value_len); |
| 452 | assert_int_equal(1, jsonctx->dynamic); |
| 453 | lyjson_ctx_free(jsonctx); |
| 454 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 455 | /* various invalid inputs */ |
| 456 | str = "-x"; |
| 457 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 458 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 459 | CHECK_LOG_CTX("Invalid character in JSON Number value (\"x\").", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 460 | |
| 461 | str = " -"; |
| 462 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 463 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 464 | CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 465 | |
| 466 | str = "--1"; |
| 467 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 468 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 469 | CHECK_LOG_CTX("Invalid character in JSON Number value (\"-\").", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 470 | |
| 471 | str = "+1"; |
| 472 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 473 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 474 | CHECK_LOG_CTX("Invalid character sequence \"+1\", expected a JSON value.", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 475 | |
| 476 | str = " 1.x "; |
| 477 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 478 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 479 | CHECK_LOG_CTX("Invalid character in JSON Number value (\"x\").", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 480 | |
| 481 | str = "1."; |
| 482 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 483 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 484 | CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 485 | |
| 486 | str = " 1eo "; |
| 487 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 488 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 489 | CHECK_LOG_CTX("Invalid character in JSON Number value (\"o\").", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 490 | |
| 491 | str = "1e"; |
| 492 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 493 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 494 | CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 495 | |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 496 | str = "1E1000"; |
| 497 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 498 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 499 | CHECK_LOG_CTX("Number encoded as a string exceeded the LY_NUMBER_MAXLEN limit.", "Line number 1."); |
| 500 | |
| 501 | str = "1e9999999999999999999"; |
| 502 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 503 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 76034c3 | 2021-06-08 15:03:11 +0200 | [diff] [blame] | 504 | CHECK_LOG_CTX("Exponent out-of-bounds in a JSON Number value (1e9999999999999999999).", "Line number 1."); |
| 505 | |
aPiecek | 0ba088e | 2021-06-15 12:53:17 +0200 | [diff] [blame] | 506 | str = "1.1e66000"; |
| 507 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 508 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 0ba088e | 2021-06-15 12:53:17 +0200 | [diff] [blame] | 509 | CHECK_LOG_CTX("Exponent out-of-bounds in a JSON Number value (1.1e66000).", "Line number 1."); |
| 510 | |
| 511 | str = "1.1e-66000"; |
| 512 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 513 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 0ba088e | 2021-06-15 12:53:17 +0200 | [diff] [blame] | 514 | CHECK_LOG_CTX("Exponent out-of-bounds in a JSON Number value (1.1e-66000).", "Line number 1."); |
| 515 | |
aPiecek | 28e101a | 2021-06-10 09:09:31 +0200 | [diff] [blame] | 516 | str = "-2.1e0."; |
| 517 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 518 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
aPiecek | 28e101a | 2021-06-10 09:09:31 +0200 | [diff] [blame] | 519 | CHECK_LOG_CTX("Unexpected character \".\" after JSON number.", "Line number 1."); |
| 520 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 521 | ly_in_free(in, 0); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Radek Iša | 447abb8 | 2021-03-04 14:08:56 +0100 | [diff] [blame] | 524 | /* now string is tested in file ./tests/utests/types/string.c */ |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 525 | static void |
| 526 | test_string(void **state) |
| 527 | { |
| 528 | struct lyjson_ctx *jsonctx; |
Radek Iša | 447abb8 | 2021-03-04 14:08:56 +0100 | [diff] [blame] | 529 | struct ly_in *in = NULL; |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 530 | const char *str; |
| 531 | |
Radek Iša | 447abb8 | 2021-03-04 14:08:56 +0100 | [diff] [blame] | 532 | str = ""; |
| 533 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
| 534 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 535 | /* unterminated string */ |
| 536 | str = "\"unterminated string"; |
| 537 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 538 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 539 | CHECK_LOG_CTX("Missing quotation-mark at the end of a JSON string.", "Line number 1."); |
Michal Vasko | 62af369 | 2023-02-09 14:00:09 +0100 | [diff] [blame] | 540 | CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 541 | |
| 542 | ly_in_free(in, 0); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static void |
| 546 | test_object(void **state) |
| 547 | { |
| 548 | struct lyjson_ctx *jsonctx; |
| 549 | struct ly_in *in; |
| 550 | const char *str; |
| 551 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 552 | /* empty */ |
| 553 | str = " { } "; |
| 554 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 555 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 556 | assert_int_equal(LYJSON_OBJECT_EMPTY, lyjson_ctx_status(jsonctx, 0)); |
| 557 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 558 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 559 | lyjson_ctx_free(jsonctx); |
| 560 | |
| 561 | /* simple value */ |
| 562 | str = "{\"name\" : \"Radek\"}"; |
| 563 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 564 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 565 | assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0)); |
| 566 | assert_ptr_equal(&str[2], jsonctx->value); |
| 567 | assert_int_equal(4, jsonctx->value_len); |
| 568 | assert_int_equal(0, jsonctx->dynamic); |
| 569 | assert_string_equal("\"Radek\"}", jsonctx->in->current); |
| 570 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 571 | assert_int_equal(LYJSON_STRING, lyjson_ctx_status(jsonctx, 0)); |
| 572 | assert_string_equal("Radek\"}", jsonctx->value); |
| 573 | assert_int_equal(5, jsonctx->value_len); |
| 574 | assert_int_equal(0, jsonctx->dynamic); |
| 575 | assert_string_equal("}", jsonctx->in->current); |
| 576 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 577 | assert_int_equal(LYJSON_OBJECT_CLOSED, lyjson_ctx_status(jsonctx, 0)); |
| 578 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 579 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 580 | lyjson_ctx_free(jsonctx); |
| 581 | |
| 582 | /* two values */ |
| 583 | str = "{\"smart\" : true,\"handsom\":false}"; |
| 584 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 585 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 586 | assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0)); |
| 587 | assert_string_equal("smart\" : true,\"handsom\":false}", jsonctx->value); |
| 588 | assert_int_equal(5, jsonctx->value_len); |
| 589 | assert_int_equal(0, jsonctx->dynamic); |
| 590 | assert_string_equal("true,\"handsom\":false}", jsonctx->in->current); |
| 591 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 592 | assert_int_equal(LYJSON_TRUE, lyjson_ctx_status(jsonctx, 0)); |
| 593 | assert_string_equal(",\"handsom\":false}", jsonctx->in->current); |
| 594 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 595 | assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0)); |
| 596 | assert_string_equal("handsom\":false}", jsonctx->value); |
| 597 | assert_int_equal(7, jsonctx->value_len); |
| 598 | assert_int_equal(0, jsonctx->dynamic); |
| 599 | assert_string_equal("false}", jsonctx->in->current); |
| 600 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 601 | assert_int_equal(LYJSON_FALSE, lyjson_ctx_status(jsonctx, 0)); |
| 602 | assert_string_equal("}", jsonctx->in->current); |
| 603 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 604 | assert_int_equal(LYJSON_OBJECT_CLOSED, lyjson_ctx_status(jsonctx, 0)); |
| 605 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 606 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 607 | lyjson_ctx_free(jsonctx); |
| 608 | |
| 609 | /* inherited objects */ |
| 610 | str = "{\"person\" : {\"name\":\"Radek\"}}"; |
| 611 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 612 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 613 | assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0)); |
| 614 | assert_string_equal("person\" : {\"name\":\"Radek\"}}", jsonctx->value); |
| 615 | assert_int_equal(6, jsonctx->value_len); |
| 616 | assert_int_equal(0, jsonctx->dynamic); |
| 617 | assert_string_equal("{\"name\":\"Radek\"}}", jsonctx->in->current); |
| 618 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 619 | assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0)); |
| 620 | assert_string_equal("name\":\"Radek\"}}", jsonctx->value); |
| 621 | assert_int_equal(4, jsonctx->value_len); |
| 622 | assert_int_equal(0, jsonctx->dynamic); |
| 623 | assert_string_equal("\"Radek\"}}", jsonctx->in->current); |
| 624 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 625 | assert_int_equal(LYJSON_STRING, lyjson_ctx_status(jsonctx, 0)); |
| 626 | assert_string_equal("Radek\"}}", jsonctx->value); |
| 627 | assert_int_equal(5, jsonctx->value_len); |
| 628 | assert_int_equal(0, jsonctx->dynamic); |
| 629 | assert_string_equal("}}", jsonctx->in->current); |
| 630 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 631 | assert_int_equal(LYJSON_OBJECT_CLOSED, lyjson_ctx_status(jsonctx, 0)); |
| 632 | assert_string_equal("}", jsonctx->in->current); |
| 633 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 634 | assert_int_equal(LYJSON_OBJECT_CLOSED, lyjson_ctx_status(jsonctx, 0)); |
| 635 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 636 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 637 | lyjson_ctx_free(jsonctx); |
| 638 | |
| 639 | /* new line is allowed only as escaped character in JSON */ |
| 640 | str = "{ unquoted : \"data\"}"; |
| 641 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 642 | assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 643 | CHECK_LOG_CTX("Invalid character sequence \"unquoted : \"data\"}\", expected a JSON object's member.", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 644 | |
| 645 | ly_in_free(in, 0); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static void |
| 649 | test_array(void **state) |
| 650 | { |
| 651 | struct lyjson_ctx *jsonctx; |
| 652 | struct ly_in *in; |
| 653 | const char *str; |
| 654 | |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 655 | /* empty */ |
| 656 | str = " [ ] "; |
| 657 | assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 658 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 659 | assert_int_equal(LYJSON_ARRAY_EMPTY, lyjson_ctx_status(jsonctx, 0)); |
| 660 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 661 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 662 | lyjson_ctx_free(jsonctx); |
| 663 | |
| 664 | /* simple value */ |
| 665 | str = "[ null]"; |
| 666 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 667 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 668 | assert_int_equal(LYJSON_ARRAY, lyjson_ctx_status(jsonctx, 0)); |
| 669 | assert_null(jsonctx->value); |
| 670 | assert_int_equal(0, jsonctx->value_len); |
| 671 | assert_int_equal(0, jsonctx->dynamic); |
| 672 | assert_string_equal("null]", jsonctx->in->current); |
| 673 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 674 | assert_int_equal(LYJSON_NULL, lyjson_ctx_status(jsonctx, 0)); |
| 675 | assert_string_equal("]", jsonctx->in->current); |
| 676 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 677 | assert_int_equal(LYJSON_ARRAY_CLOSED, lyjson_ctx_status(jsonctx, 0)); |
| 678 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 679 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 680 | lyjson_ctx_free(jsonctx); |
| 681 | |
| 682 | /* two values */ |
| 683 | str = "[{\"a\":null},\"x\"]"; |
| 684 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 685 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 686 | assert_int_equal(LYJSON_ARRAY, lyjson_ctx_status(jsonctx, 0)); |
| 687 | assert_null(jsonctx->value); |
| 688 | assert_int_equal(0, jsonctx->value_len); |
| 689 | assert_int_equal(0, jsonctx->dynamic); |
| 690 | assert_string_equal("{\"a\":null},\"x\"]", jsonctx->in->current); |
| 691 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 692 | assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0)); |
| 693 | assert_string_equal("a\":null},\"x\"]", jsonctx->value); |
| 694 | assert_int_equal(1, jsonctx->value_len); |
| 695 | assert_int_equal(0, jsonctx->dynamic); |
| 696 | assert_string_equal("null},\"x\"]", jsonctx->in->current); |
| 697 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 698 | assert_int_equal(LYJSON_NULL, lyjson_ctx_status(jsonctx, 0)); |
| 699 | assert_string_equal("},\"x\"]", jsonctx->in->current); |
| 700 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 701 | assert_int_equal(LYJSON_OBJECT_CLOSED, lyjson_ctx_status(jsonctx, 0)); |
| 702 | assert_string_equal(",\"x\"]", jsonctx->in->current); |
| 703 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 704 | assert_int_equal(LYJSON_STRING, lyjson_ctx_status(jsonctx, 0)); |
| 705 | assert_string_equal("x\"]", jsonctx->value); |
| 706 | assert_int_equal(1, jsonctx->value_len); |
| 707 | assert_int_equal(0, jsonctx->dynamic); |
| 708 | assert_string_equal("]", jsonctx->in->current); |
| 709 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 710 | assert_int_equal(LYJSON_ARRAY_CLOSED, lyjson_ctx_status(jsonctx, 0)); |
| 711 | assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL)); |
| 712 | assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0)); |
| 713 | lyjson_ctx_free(jsonctx); |
| 714 | |
| 715 | /* new line is allowed only as escaped character in JSON */ |
| 716 | str = "[ , null]"; |
| 717 | assert_non_null(ly_in_memory(in, str)); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 718 | assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx)); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 719 | assert_int_equal(LY_EVALID, lyjson_ctx_next(jsonctx, NULL)); |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 720 | CHECK_LOG_CTX("Invalid character sequence \", null]\", expected a JSON value.", "Line number 1."); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 721 | lyjson_ctx_free(jsonctx); |
| 722 | |
| 723 | ly_in_free(in, 0); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 724 | } |
| 725 | |
Radek Krejci | b4ac5a9 | 2020-11-23 17:54:33 +0100 | [diff] [blame] | 726 | int |
| 727 | main(void) |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 728 | { |
| 729 | const struct CMUnitTest tests[] = { |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 730 | UTEST(test_general), |
| 731 | UTEST(test_number), |
| 732 | UTEST(test_string), |
| 733 | UTEST(test_object), |
| 734 | UTEST(test_array), |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 735 | }; |
| 736 | |
Radek Iša | 56ca9e4 | 2020-09-08 18:42:00 +0200 | [diff] [blame] | 737 | return cmocka_run_group_tests(tests, NULL, NULL); |
Radek Krejci | 50f0c6b | 2020-06-18 16:31:48 +0200 | [diff] [blame] | 738 | } |