mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
Merge bitcoin/bitcoin#31542: test: Embed univalue json tests in binary
Some checks failed
CI / test each commit (push) Has been cancelled
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Has been cancelled
CI / macOS 14 native, arm64, fuzz (push) Has been cancelled
CI / Win64 native, VS 2022 (push) Has been cancelled
CI / Win64 native fuzz, VS 2022 (push) Has been cancelled
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Has been cancelled
Some checks failed
CI / test each commit (push) Has been cancelled
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Has been cancelled
CI / macOS 14 native, arm64, fuzz (push) Has been cancelled
CI / Win64 native, VS 2022 (push) Has been cancelled
CI / Win64 native fuzz, VS 2022 (push) Has been cancelled
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Has been cancelled
faf7eac364
test: clang-format -i src/univalue/test/unitester.cpp (MarcoFalke)fafa9cc7a5
test: Embed univalue json tests in binary (MarcoFalke)fa044857ca
test: Re-enable univalue test fail18.json (MarcoFalke)63b6b638aa
build: Use character literals for generated headers to avoid narrowing (Lőrinc) Pull request description: All other benchmarks and tests have their data embedded, except for the univalue json tests. This is not only confusing, but also problematic, when the test binary is moved to a different system for testing, because one has to put the test files in the source dir that was used at compile-time. Fix all issues by embedding them. Also, re-enable a disabled test. Also, fix an issue in the GenerateHeaderFromJson.cmake. Requested in https://github.com/bitcoin/bitcoin/pull/31434/files#r1876000910 ACKs for top commit: l0rinc: ACKfaf7eac364
fjahr: tACKfaf7eac364
achow101: ACKfaf7eac364
TheCharlatan: Re-ACKfaf7eac364
hebasto: Re-ACKfaf7eac364
. The commit, which modifies CMake scripts, has been replaced with the one from https://github.com/bitcoin/bitcoin/pull/31547, and a formatting commit has been added since my recent [review](https://github.com/bitcoin/bitcoin/pull/31542#pullrequestreview-2517189261). Tree-SHA512: 72ad202125746f32ccf07411ad3efd2771f27a40525c204cba3c9c83b3ca46d05dd18f6fa5985720c6684bdcbb4c4853fc609ced095ddd1a124832318dd8a55d
This commit is contained in:
commit
4036ee3f2b
6 changed files with 254 additions and 117 deletions
|
@ -6,7 +6,7 @@ cmake_path(GET JSON_SOURCE_PATH STEM json_source_basename)
|
||||||
|
|
||||||
file(READ ${JSON_SOURCE_PATH} hex_content HEX)
|
file(READ ${JSON_SOURCE_PATH} hex_content HEX)
|
||||||
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
|
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
|
||||||
string(REGEX REPLACE "[^\n][^\n]" "0x\\0, " formatted_bytes "${formatted_bytes}")
|
string(REGEX REPLACE "[^\n][^\n]" "'\\\\x\\0'," formatted_bytes "${formatted_bytes}")
|
||||||
|
|
||||||
set(header_content
|
set(header_content
|
||||||
"#include <string_view>
|
"#include <string_view>
|
||||||
|
|
|
@ -6,7 +6,7 @@ cmake_path(GET RAW_SOURCE_PATH STEM raw_source_basename)
|
||||||
|
|
||||||
file(READ ${RAW_SOURCE_PATH} hex_content HEX)
|
file(READ ${RAW_SOURCE_PATH} hex_content HEX)
|
||||||
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
|
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
|
||||||
string(REGEX REPLACE "[^\n][^\n]" "std::byte{0x\\0}, " formatted_bytes "${formatted_bytes}")
|
string(REGEX REPLACE "[^\n][^\n]" "std::byte{0x\\0}," formatted_bytes "${formatted_bytes}")
|
||||||
|
|
||||||
set(header_content
|
set(header_content
|
||||||
"#include <cstddef>
|
"#include <cstddef>
|
||||||
|
|
|
@ -15,10 +15,119 @@ target_include_directories(univalue
|
||||||
target_link_libraries(univalue PRIVATE core_interface)
|
target_link_libraries(univalue PRIVATE core_interface)
|
||||||
|
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
add_executable(unitester test/unitester.cpp)
|
include(GenerateHeaders)
|
||||||
target_compile_definitions(unitester
|
generate_header_from_json(test/fail1.json)
|
||||||
PRIVATE
|
generate_header_from_json(test/fail10.json)
|
||||||
JSON_TEST_SRC=\"${CMAKE_CURRENT_SOURCE_DIR}/test\"
|
generate_header_from_json(test/fail11.json)
|
||||||
|
generate_header_from_json(test/fail12.json)
|
||||||
|
generate_header_from_json(test/fail13.json)
|
||||||
|
generate_header_from_json(test/fail14.json)
|
||||||
|
generate_header_from_json(test/fail15.json)
|
||||||
|
generate_header_from_json(test/fail16.json)
|
||||||
|
generate_header_from_json(test/fail17.json)
|
||||||
|
generate_header_from_json(test/fail18.json)
|
||||||
|
generate_header_from_json(test/fail19.json)
|
||||||
|
generate_header_from_json(test/fail2.json)
|
||||||
|
generate_header_from_json(test/fail20.json)
|
||||||
|
generate_header_from_json(test/fail21.json)
|
||||||
|
generate_header_from_json(test/fail22.json)
|
||||||
|
generate_header_from_json(test/fail23.json)
|
||||||
|
generate_header_from_json(test/fail24.json)
|
||||||
|
generate_header_from_json(test/fail25.json)
|
||||||
|
generate_header_from_json(test/fail26.json)
|
||||||
|
generate_header_from_json(test/fail27.json)
|
||||||
|
generate_header_from_json(test/fail28.json)
|
||||||
|
generate_header_from_json(test/fail29.json)
|
||||||
|
generate_header_from_json(test/fail3.json)
|
||||||
|
generate_header_from_json(test/fail30.json)
|
||||||
|
generate_header_from_json(test/fail31.json)
|
||||||
|
generate_header_from_json(test/fail32.json)
|
||||||
|
generate_header_from_json(test/fail33.json)
|
||||||
|
generate_header_from_json(test/fail34.json)
|
||||||
|
generate_header_from_json(test/fail35.json)
|
||||||
|
generate_header_from_json(test/fail36.json)
|
||||||
|
generate_header_from_json(test/fail37.json)
|
||||||
|
generate_header_from_json(test/fail38.json)
|
||||||
|
generate_header_from_json(test/fail39.json)
|
||||||
|
generate_header_from_json(test/fail4.json)
|
||||||
|
generate_header_from_json(test/fail40.json)
|
||||||
|
generate_header_from_json(test/fail41.json)
|
||||||
|
generate_header_from_json(test/fail42.json)
|
||||||
|
generate_header_from_json(test/fail44.json)
|
||||||
|
generate_header_from_json(test/fail45.json)
|
||||||
|
generate_header_from_json(test/fail5.json)
|
||||||
|
generate_header_from_json(test/fail6.json)
|
||||||
|
generate_header_from_json(test/fail7.json)
|
||||||
|
generate_header_from_json(test/fail8.json)
|
||||||
|
generate_header_from_json(test/fail9.json)
|
||||||
|
generate_header_from_json(test/pass1.json)
|
||||||
|
generate_header_from_json(test/pass2.json)
|
||||||
|
generate_header_from_json(test/pass3.json)
|
||||||
|
generate_header_from_json(test/pass4.json)
|
||||||
|
generate_header_from_json(test/round1.json)
|
||||||
|
generate_header_from_json(test/round2.json)
|
||||||
|
generate_header_from_json(test/round3.json)
|
||||||
|
generate_header_from_json(test/round4.json)
|
||||||
|
generate_header_from_json(test/round5.json)
|
||||||
|
generate_header_from_json(test/round6.json)
|
||||||
|
generate_header_from_json(test/round7.json)
|
||||||
|
add_executable(unitester
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail1.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail10.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail11.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail12.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail13.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail14.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail15.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail16.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail17.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail18.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail19.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail2.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail20.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail21.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail22.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail23.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail24.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail25.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail26.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail27.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail28.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail29.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail3.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail30.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail31.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail32.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail33.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail34.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail35.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail36.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail37.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail38.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail39.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail4.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail40.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail41.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail42.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail44.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail45.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail5.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail6.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail7.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail8.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/fail9.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/pass1.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/pass2.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/pass3.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/pass4.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/round1.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/round2.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/round3.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/round4.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/round5.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/round6.json.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test/round7.json.h
|
||||||
|
test/unitester.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(unitester
|
target_link_libraries(unitester
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
|
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[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2015-present The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or https://opensource.org/licenses/mit-license.php.
|
// file COPYING or https://opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
|
#include <univalue/test/fail1.json.h>
|
||||||
|
#include <univalue/test/fail10.json.h>
|
||||||
|
#include <univalue/test/fail11.json.h>
|
||||||
|
#include <univalue/test/fail12.json.h>
|
||||||
|
#include <univalue/test/fail13.json.h>
|
||||||
|
#include <univalue/test/fail14.json.h>
|
||||||
|
#include <univalue/test/fail15.json.h>
|
||||||
|
#include <univalue/test/fail16.json.h>
|
||||||
|
#include <univalue/test/fail17.json.h>
|
||||||
|
#include <univalue/test/fail18.json.h>
|
||||||
|
#include <univalue/test/fail19.json.h>
|
||||||
|
#include <univalue/test/fail2.json.h>
|
||||||
|
#include <univalue/test/fail20.json.h>
|
||||||
|
#include <univalue/test/fail21.json.h>
|
||||||
|
#include <univalue/test/fail22.json.h>
|
||||||
|
#include <univalue/test/fail23.json.h>
|
||||||
|
#include <univalue/test/fail24.json.h>
|
||||||
|
#include <univalue/test/fail25.json.h>
|
||||||
|
#include <univalue/test/fail26.json.h>
|
||||||
|
#include <univalue/test/fail27.json.h>
|
||||||
|
#include <univalue/test/fail28.json.h>
|
||||||
|
#include <univalue/test/fail29.json.h>
|
||||||
|
#include <univalue/test/fail3.json.h>
|
||||||
|
#include <univalue/test/fail30.json.h>
|
||||||
|
#include <univalue/test/fail31.json.h>
|
||||||
|
#include <univalue/test/fail32.json.h>
|
||||||
|
#include <univalue/test/fail33.json.h>
|
||||||
|
#include <univalue/test/fail34.json.h>
|
||||||
|
#include <univalue/test/fail35.json.h>
|
||||||
|
#include <univalue/test/fail36.json.h>
|
||||||
|
#include <univalue/test/fail37.json.h>
|
||||||
|
#include <univalue/test/fail38.json.h>
|
||||||
|
#include <univalue/test/fail39.json.h>
|
||||||
|
#include <univalue/test/fail4.json.h>
|
||||||
|
#include <univalue/test/fail40.json.h>
|
||||||
|
#include <univalue/test/fail41.json.h>
|
||||||
|
#include <univalue/test/fail42.json.h>
|
||||||
|
#include <univalue/test/fail44.json.h>
|
||||||
|
#include <univalue/test/fail45.json.h>
|
||||||
|
#include <univalue/test/fail5.json.h>
|
||||||
|
#include <univalue/test/fail6.json.h>
|
||||||
|
#include <univalue/test/fail7.json.h>
|
||||||
|
#include <univalue/test/fail8.json.h>
|
||||||
|
#include <univalue/test/fail9.json.h>
|
||||||
|
#include <univalue/test/pass1.json.h>
|
||||||
|
#include <univalue/test/pass2.json.h>
|
||||||
|
#include <univalue/test/pass3.json.h>
|
||||||
|
#include <univalue/test/pass4.json.h>
|
||||||
|
#include <univalue/test/round1.json.h>
|
||||||
|
#include <univalue/test/round2.json.h>
|
||||||
|
#include <univalue/test/round3.json.h>
|
||||||
|
#include <univalue/test/round4.json.h>
|
||||||
|
#include <univalue/test/round5.json.h>
|
||||||
|
#include <univalue/test/round6.json.h>
|
||||||
|
#include <univalue/test/round7.json.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef JSON_TEST_SRC
|
|
||||||
#error JSON_TEST_SRC must point to test source directory
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string srcdir(JSON_TEST_SRC);
|
|
||||||
|
|
||||||
static std::string rtrim(std::string s)
|
static std::string rtrim(std::string s)
|
||||||
{
|
{
|
||||||
s.erase(s.find_last_not_of(" \n\r\t")+1);
|
s.erase(s.find_last_not_of(" \n\r\t") + 1);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void runtest(std::string filename, const std::string& jdata)
|
static void runtest(std::string filename, const std::string& jdata)
|
||||||
{
|
{
|
||||||
std::string prefix = filename.substr(0, 4);
|
std::string prefix = filename.substr(0, 4);
|
||||||
|
|
||||||
bool wantPass = (prefix == "pass") || (prefix == "roun");
|
bool wantPass = (prefix == "pass") || (prefix == "roun");
|
||||||
bool wantFail = (prefix == "fail");
|
bool wantFail = (prefix == "fail");
|
||||||
bool wantRoundTrip = (prefix == "roun");
|
bool wantRoundTrip = (prefix == "roun");
|
||||||
assert(wantPass || wantFail);
|
assert(wantPass || wantFail);
|
||||||
|
|
||||||
UniValue val;
|
UniValue val;
|
||||||
bool testResult = val.read(jdata);
|
bool testResult = val.read(jdata);
|
||||||
|
|
||||||
if (wantPass) {
|
if (wantPass) {
|
||||||
assert(testResult == true);
|
assert(testResult == true);
|
||||||
} else {
|
} else {
|
||||||
assert(testResult == false);
|
assert(testResult == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wantRoundTrip) {
|
if (wantRoundTrip) {
|
||||||
std::string odata = val.write(0, 0);
|
std::string odata = val.write(0, 0);
|
||||||
assert(odata == rtrim(jdata));
|
assert(odata == rtrim(jdata));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void runtest_file(const char *filename_)
|
#define TEST_FILE(name) {#name, json_tests::name}
|
||||||
{
|
inline constexpr std::array tests{std::to_array<std::tuple<std::string_view, std::string_view>>({
|
||||||
std::string basename(filename_);
|
TEST_FILE(fail1),
|
||||||
std::string filename = srcdir + "/" + basename;
|
TEST_FILE(fail10),
|
||||||
FILE *f = fopen(filename.c_str(), "r");
|
TEST_FILE(fail11),
|
||||||
assert(f != nullptr);
|
TEST_FILE(fail12),
|
||||||
|
TEST_FILE(fail13),
|
||||||
std::string jdata;
|
TEST_FILE(fail14),
|
||||||
|
TEST_FILE(fail15),
|
||||||
char buf[4096];
|
TEST_FILE(fail16),
|
||||||
while (!feof(f)) {
|
TEST_FILE(fail17),
|
||||||
int bread = fread(buf, 1, sizeof(buf), f);
|
TEST_FILE(fail18),
|
||||||
assert(!ferror(f));
|
TEST_FILE(fail19),
|
||||||
|
TEST_FILE(fail2),
|
||||||
std::string s(buf, bread);
|
TEST_FILE(fail20),
|
||||||
jdata += s;
|
TEST_FILE(fail21),
|
||||||
}
|
TEST_FILE(fail22),
|
||||||
|
TEST_FILE(fail23),
|
||||||
assert(!ferror(f));
|
TEST_FILE(fail24),
|
||||||
fclose(f);
|
TEST_FILE(fail25),
|
||||||
|
TEST_FILE(fail26),
|
||||||
runtest(basename, jdata);
|
TEST_FILE(fail27),
|
||||||
}
|
TEST_FILE(fail28),
|
||||||
|
TEST_FILE(fail29),
|
||||||
static const char *filenames[] = {
|
TEST_FILE(fail3),
|
||||||
"fail10.json",
|
TEST_FILE(fail30),
|
||||||
"fail11.json",
|
TEST_FILE(fail31),
|
||||||
"fail12.json",
|
TEST_FILE(fail32),
|
||||||
"fail13.json",
|
TEST_FILE(fail33),
|
||||||
"fail14.json",
|
TEST_FILE(fail34),
|
||||||
"fail15.json",
|
TEST_FILE(fail35),
|
||||||
"fail16.json",
|
TEST_FILE(fail36),
|
||||||
"fail17.json",
|
TEST_FILE(fail37),
|
||||||
//"fail18.json", // investigate
|
TEST_FILE(fail38), // invalid unicode: only first half of surrogate pair
|
||||||
"fail19.json",
|
TEST_FILE(fail39), // invalid unicode: only second half of surrogate pair
|
||||||
"fail1.json",
|
TEST_FILE(fail4), // extra comma
|
||||||
"fail20.json",
|
TEST_FILE(fail40), // invalid unicode: broken UTF-8
|
||||||
"fail21.json",
|
TEST_FILE(fail41), // invalid unicode: unfinished UTF-8
|
||||||
"fail22.json",
|
TEST_FILE(fail42), // valid json with garbage following a nul byte
|
||||||
"fail23.json",
|
TEST_FILE(fail44), // unterminated string
|
||||||
"fail24.json",
|
TEST_FILE(fail45), // nested beyond max depth
|
||||||
"fail25.json",
|
TEST_FILE(fail5),
|
||||||
"fail26.json",
|
TEST_FILE(fail6),
|
||||||
"fail27.json",
|
TEST_FILE(fail7),
|
||||||
"fail28.json",
|
TEST_FILE(fail8),
|
||||||
"fail29.json",
|
TEST_FILE(fail9), // extra comma
|
||||||
"fail2.json",
|
TEST_FILE(pass1),
|
||||||
"fail30.json",
|
TEST_FILE(pass2),
|
||||||
"fail31.json",
|
TEST_FILE(pass3),
|
||||||
"fail32.json",
|
TEST_FILE(pass4),
|
||||||
"fail33.json",
|
TEST_FILE(round1), // round-trip test
|
||||||
"fail34.json",
|
TEST_FILE(round2), // unicode
|
||||||
"fail35.json",
|
TEST_FILE(round3), // bare string
|
||||||
"fail36.json",
|
TEST_FILE(round4), // bare number
|
||||||
"fail37.json",
|
TEST_FILE(round5), // bare true
|
||||||
"fail38.json", // invalid unicode: only first half of surrogate pair
|
TEST_FILE(round6), // bare false
|
||||||
"fail39.json", // invalid unicode: only second half of surrogate pair
|
TEST_FILE(round7), // bare null
|
||||||
"fail40.json", // invalid unicode: broken UTF-8
|
})};
|
||||||
"fail41.json", // invalid unicode: unfinished UTF-8
|
|
||||||
"fail42.json", // valid json with garbage following a nul byte
|
|
||||||
"fail44.json", // unterminated string
|
|
||||||
"fail45.json", // nested beyond max depth
|
|
||||||
"fail3.json",
|
|
||||||
"fail4.json", // extra comma
|
|
||||||
"fail5.json",
|
|
||||||
"fail6.json",
|
|
||||||
"fail7.json",
|
|
||||||
"fail8.json",
|
|
||||||
"fail9.json", // extra comma
|
|
||||||
"pass1.json",
|
|
||||||
"pass2.json",
|
|
||||||
"pass3.json",
|
|
||||||
"pass4.json",
|
|
||||||
"round1.json", // round-trip test
|
|
||||||
"round2.json", // unicode
|
|
||||||
"round3.json", // bare string
|
|
||||||
"round4.json", // bare number
|
|
||||||
"round5.json", // bare true
|
|
||||||
"round6.json", // bare false
|
|
||||||
"round7.json", // bare null
|
|
||||||
};
|
|
||||||
|
|
||||||
// Test \u handling
|
// Test \u handling
|
||||||
void unescape_unicode_test()
|
void unescape_unicode_test()
|
||||||
|
@ -156,10 +185,10 @@ void no_nul_test()
|
||||||
assert(val.read({buf + 3, 7}));
|
assert(val.read({buf + 3, 7}));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
for (const auto& f: filenames) {
|
for (const auto& [file, json] : tests) {
|
||||||
runtest_file(f);
|
runtest(std::string{file}, std::string{json});
|
||||||
}
|
}
|
||||||
|
|
||||||
unescape_unicode_test();
|
unescape_unicode_test();
|
||||||
|
@ -167,4 +196,3 @@ int main (int argc, char *argv[])
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue