|
MXL : Media eXchange Layer
MXL
|
#include <cmath>#include <cstdint>#include <stdexcept>#include <string>#include <catch2/catch_test_macros.hpp>#include "mxl-internal/JsonUtils.hpp"
Go to the source code of this file.
Classes | |
| struct | JsonLimits |
| Limits applied by parseJson(). More... | |
Functions | |
| template<std::integral T> | |
| T | jsonToInteger (picojson::value const &value, std::string_view name) |
| std::string | parseJson (picojson::value &out, std::string_view text, JsonLimits const &limits={}) |
| TEST_CASE ("jsonToInteger : converts whole numbers in range", "[json]") | |
| TEST_CASE ("jsonToInteger : rejects values that do not convert exactly", "[json]") | |
| TEST_CASE ("parseJson : accepts a valid document", "[json]") | |
| TEST_CASE ("parseJson : limits the container size", "[json]") | |
| TEST_CASE ("parseJson : limits the input size", "[json]") | |
| TEST_CASE ("parseJson : limits the nesting depth", "[json]") | |
| TEST_CASE ("parseJson : rejects duplicate keys", "[json]") | |
| TEST_CASE ("parseJson : rejects syntax errors and trailing content", "[json]") | |
| TEST_CASE ("parseJson : reports a number out of double range as an error", "[json]") | |
|
inline |
Convert a JSON number to the integer type T.
Converting a double that is outside the range of an integer type is undefined behavior in C++, so the value is checked before the conversion.
| value | The JSON value. |
| name | The field name, used in the error message. |
| std::invalid_argument | If the value is not a number, not a whole number, or outside the range of T. |
Definition at line 236 of file JsonUtils.hpp.
|
inline |
Parse a JSON document with the limits in limits.
Unlike picojson::parse(value&, std::string const&), this rejects any content after the first value other than whitespace, and rejects objects with duplicate keys.
| out | Receives the parsed value. Its content is unspecified on error. |
| text | The JSON document. |
| limits | The limits to apply. |
Definition at line 193 of file JsonUtils.hpp.
| TEST_CASE | ( | "jsonToInteger : converts whole numbers in range" | , |
| "" | [json] ) |
Definition at line 120 of file test_jsonutils.cpp.
| TEST_CASE | ( | "jsonToInteger : rejects values that do not convert exactly" | , |
| "" | [json] ) |
Definition at line 129 of file test_jsonutils.cpp.
| TEST_CASE | ( | "parseJson : accepts a valid document" | , |
| "" | [json] ) |
Definition at line 48 of file test_jsonutils.cpp.
| TEST_CASE | ( | "parseJson : limits the container size" | , |
| "" | [json] ) |
Definition at line 95 of file test_jsonutils.cpp.
| TEST_CASE | ( | "parseJson : limits the input size" | , |
| "" | [json] ) |
Definition at line 70 of file test_jsonutils.cpp.
| TEST_CASE | ( | "parseJson : limits the nesting depth" | , |
| "" | [json] ) |
Definition at line 82 of file test_jsonutils.cpp.
| TEST_CASE | ( | "parseJson : rejects duplicate keys" | , |
| "" | [json] ) |
Definition at line 105 of file test_jsonutils.cpp.
| TEST_CASE | ( | "parseJson : rejects syntax errors and trailing content" | , |
| "" | [json] ) |
Definition at line 61 of file test_jsonutils.cpp.
| TEST_CASE | ( | "parseJson : reports a number out of double range as an error" | , |
| "" | [json] ) |
Definition at line 113 of file test_jsonutils.cpp.