mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-12-12 04:55:19 +01:00
Compare commits
2 Commits
master
...
jsoncpp_te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94f152714b | ||
|
|
406f7e8ba9 |
@@ -2,6 +2,7 @@
|
||||
Checks: 'google-readability-casting,modernize-deprecated-headers,modernize-loop-convert,modernize-use-auto,modernize-use-default-member-init,modernize-use-using,readability-else-after-return,readability-redundant-member-init,readability-redundant-string-cstr'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
AnalyzeTemporaryDtors: false
|
||||
FormatStyle: none
|
||||
CheckOptions:
|
||||
- key: modernize-use-using.IgnoreMacros
|
||||
|
||||
48
BUILD.bazel
48
BUILD.bazel
@@ -1,29 +1,7 @@
|
||||
licenses(["unencumbered"]) # Public Domain or MIT
|
||||
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
|
||||
|
||||
exports_files(["LICENSE"])
|
||||
|
||||
bool_flag(
|
||||
name = "use_exception",
|
||||
build_setting_default = False,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "use_exception_cfg",
|
||||
flag_values = {":use_exception": "true"},
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
name = "has_int64",
|
||||
build_setting_default = True,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "has_int64_cfg",
|
||||
flag_values = {":has_int64": "true"},
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "jsoncpp",
|
||||
srcs = [
|
||||
@@ -44,13 +22,6 @@ cc_library(
|
||||
"include/json/version.h",
|
||||
"include/json/writer.h",
|
||||
],
|
||||
defines = select({
|
||||
":use_exception_cfg": ["JSON_USE_EXCEPTION=1"],
|
||||
"//conditions:default": ["JSON_USE_EXCEPTION=0"],
|
||||
}) + select({
|
||||
":has_int64_cfg": ["JSON_HAS_INT64"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = ["include"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":private"],
|
||||
@@ -60,3 +31,22 @@ cc_library(
|
||||
name = "private",
|
||||
textual_hdrs = ["src/lib_json/json_valueiterator.inl"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "jsontestrunner",
|
||||
srcs = ["src/jsontestrunner/main.cpp"],
|
||||
includes = ["include"],
|
||||
deps = [":jsoncpp"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "jsoncpp_test",
|
||||
srcs = [
|
||||
"src/test_lib_json/jsontest.cpp",
|
||||
"src/test_lib_json/jsontest.h",
|
||||
"src/test_lib_json/main.cpp",
|
||||
"src/test_lib_json/fuzz.h",
|
||||
"src/test_lib_json/fuzz.cpp",
|
||||
],
|
||||
deps = [":jsoncpp"],
|
||||
)
|
||||
|
||||
@@ -12,8 +12,3 @@ module(
|
||||
version = "1.9.7",
|
||||
compatibility_level = 1,
|
||||
)
|
||||
|
||||
bazel_dep(
|
||||
name = "bazel_skylib",
|
||||
version = "1.7.1",
|
||||
)
|
||||
|
||||
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
||||
# JsonCpp
|
||||
|
||||
[](https://conan.io/center/recipes/jsoncpp)
|
||||
[](https://bintray.com/theirix/conan-repo/jsoncpp%3Atheirix)
|
||||
[](https://github.com/open-source-parsers/jsoncpp/blob/master/LICENSE)
|
||||
[](http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html)
|
||||
[](https://coveralls.io/github/open-source-parsers/jsoncpp?branch=master)
|
||||
@@ -52,14 +52,6 @@ You can download and install JsonCpp using the [vcpkg](https://github.com/Micros
|
||||
|
||||
The JsonCpp port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
### Conan package manager
|
||||
|
||||
You can download and install JsonCpp using the [Conan](https://conan.io/) package manager:
|
||||
|
||||
conan install -r conancenter --requires="jsoncpp/[*]" --build=missing
|
||||
|
||||
The JsonCpp package in Conan Center is kept up to date by [ConanCenterIndex](https://github.com/conan-io/conan-center-index) contributors. If the version is out of date, please create an issue or pull request on the Conan Center Index repository.
|
||||
|
||||
### Amalgamated source
|
||||
https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated-(Possibly-outdated)
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
cc_binary(
|
||||
name = "readFromStream_ok",
|
||||
srcs = ["readFromStream/readFromStream.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
args = ["$(location :readFromStream/withComment.json)"],
|
||||
data = ["readFromStream/withComment.json"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "readFromStream_err",
|
||||
srcs = ["readFromStream/readFromStream.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
args = ["$(location :readFromStream/errorFormat.json)"],
|
||||
data = ["readFromStream/errorFormat.json"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "readFromString",
|
||||
srcs = ["readFromString/readFromString.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "streamWrite",
|
||||
srcs = ["streamWrite/streamWrite.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "stringWrite",
|
||||
srcs = ["stringWrite/stringWrite.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
@@ -1,6 +0,0 @@
|
||||
cc_binary(
|
||||
name = "jsontestrunner",
|
||||
srcs = ["main.cpp"],
|
||||
deps = ["//:jsoncpp"],
|
||||
visibility = ["//test:__pkg__"],
|
||||
)
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
@@ -144,12 +143,7 @@ bool Reader::readValue() {
|
||||
// after calling readValue(). parse() executes one nodes_.push(), so > instead
|
||||
// of >=.
|
||||
if (nodes_.size() > stackLimit_g)
|
||||
#if JSON_USE_EXCEPTION
|
||||
throwRuntimeError("Exceeded stackLimit in readValue().");
|
||||
#else
|
||||
// throwRuntimeError aborts. Don't abort here.
|
||||
return false;
|
||||
#endif
|
||||
|
||||
Token token;
|
||||
readTokenSkippingComments(token);
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
cc_test(
|
||||
name = "jsoncpp_test",
|
||||
srcs = [
|
||||
"jsontest.cpp",
|
||||
"jsontest.h",
|
||||
"main.cpp",
|
||||
"fuzz.h",
|
||||
"fuzz.cpp",
|
||||
],
|
||||
deps = ["//:jsoncpp"],
|
||||
)
|
||||
@@ -11,6 +11,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Json {
|
||||
class Exception;
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
Json::CharReaderBuilder builder;
|
||||
|
||||
@@ -41,14 +45,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
|
||||
Json::Value root;
|
||||
const auto data_str = reinterpret_cast<const char*>(data);
|
||||
#if JSON_USE_EXCEPTION
|
||||
try {
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
reader->parse(data_str, data_str + size, &root, nullptr);
|
||||
#if JSON_USE_EXCEPTION
|
||||
} catch (Json::Exception const&) {
|
||||
}
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
// Whether it succeeded or not doesn't matter.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -228,8 +228,6 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
|
||||
JsonTest::ToJsonString(actual), __FILE__, \
|
||||
__LINE__, #expected " == " #actual)
|
||||
|
||||
#if JSON_USE_EXCEPTION
|
||||
|
||||
/// \brief Asserts that a given expression throws an exception
|
||||
#define JSONTEST_ASSERT_THROWS(expr) \
|
||||
do { \
|
||||
@@ -244,8 +242,6 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
|
||||
"expected exception thrown: " #expr); \
|
||||
} while (0)
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
|
||||
/// \brief Begin a fixture test case.
|
||||
#define JSONTEST_FIXTURE(FixtureType, name) \
|
||||
class Test##FixtureType##name : public FixtureType { \
|
||||
|
||||
@@ -1888,7 +1888,7 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, typeChecksThrowExceptions) {
|
||||
JSONTEST_ASSERT_THROWS(objVal.asBool());
|
||||
JSONTEST_ASSERT_THROWS(arrVal.asBool());
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
#endif
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(ValueTest, offsetAccessors) {
|
||||
@@ -3323,8 +3323,6 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithDetailError) {
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
|
||||
#if JSON_USE_EXCEPTION
|
||||
|
||||
Json::CharReaderBuilder b;
|
||||
Json::Value root;
|
||||
char const doc[] = R"({ "property" : "value" })";
|
||||
@@ -3344,8 +3342,6 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
|
||||
JSONTEST_ASSERT_THROWS(
|
||||
reader->parse(doc, doc + std::strlen(doc), &root, &errs));
|
||||
}
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(CharReaderTest, testOperator) {
|
||||
@@ -3965,8 +3961,6 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, indexes) {
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
|
||||
#if JSON_USE_EXCEPTION
|
||||
|
||||
Json::Value const v;
|
||||
JSONTEST_ASSERT_THROWS(
|
||||
Json::Value::iterator it(v.begin())); // Compile, but throw.
|
||||
@@ -3988,8 +3982,6 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
|
||||
}
|
||||
Json::String expected = R"(" 9","10","11",)";
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
|
||||
|
||||
#endif // JSON_USE_EXCEPTION
|
||||
}
|
||||
|
||||
struct RValueTest : JsonTest::TestCase {};
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
filegroup(
|
||||
name = "expected",
|
||||
srcs = glob(["data/**", "jsonchecker/**"], exclude=["**/*.json"]),
|
||||
)
|
||||
|
||||
[py_test(
|
||||
name = "runjson_%s_test" % "_".join(f.split("/")),
|
||||
srcs = ["runjsontests.py"],
|
||||
main = "runjsontests.py",
|
||||
args = [
|
||||
"--with-json-checker",
|
||||
"$(location //src/jsontestrunner:jsontestrunner)",
|
||||
"$(location :%s)" % f,
|
||||
],
|
||||
data = [
|
||||
"//src/jsontestrunner:jsontestrunner",
|
||||
":expected",
|
||||
":%s" % f,
|
||||
],
|
||||
) for f in glob(["**/*.json"])]
|
||||
@@ -66,51 +66,38 @@ class FailError(Exception):
|
||||
def __init__(self, msg):
|
||||
super(Exception, self).__init__(msg)
|
||||
|
||||
def runAllTests(jsontest_executable_path, input_path = None,
|
||||
def runAllTests(jsontest_executable_path, input_dir = None,
|
||||
use_valgrind=False, with_json_checker=False,
|
||||
writerClass='StyledWriter'):
|
||||
if not input_path:
|
||||
input_path = os.path.join(os.getcwd(), 'data')
|
||||
if not input_dir:
|
||||
input_dir = os.path.join(os.getcwd(), 'data')
|
||||
tests = glob(os.path.join(input_dir, '*.json'))
|
||||
if with_json_checker:
|
||||
all_tests = glob(os.path.join(input_dir, '../jsonchecker', '*.json'))
|
||||
# These tests fail with strict json support, but pass with JsonCPP's
|
||||
# extra leniency features. When adding a new exclusion to this list,
|
||||
# remember to add the test's number and reasoning here:
|
||||
known = ["fail{}.json".format(n) for n in [
|
||||
4, 9, # fail because we allow trailing commas
|
||||
7, # fails because we allow commas after close
|
||||
8, # fails because we allow extra close
|
||||
10, # fails because we allow extra values after close
|
||||
13, # fails because we allow leading zeroes in numbers
|
||||
18, # fails because we allow deeply nested values
|
||||
25, # fails because we allow tab characters in strings
|
||||
27, # fails because we allow string line breaks
|
||||
]]
|
||||
test_jsonchecker = [ test for test in all_tests
|
||||
if os.path.basename(test) not in known]
|
||||
|
||||
if os.path.isdir(input_path):
|
||||
tests = [
|
||||
os.path.normpath(os.path.abspath(test))
|
||||
for test in glob(os.path.join(input_path, '*.json'))
|
||||
]
|
||||
|
||||
if with_json_checker:
|
||||
tests += [
|
||||
os.path.normpath(os.path.abspath(test))
|
||||
for test in glob(os.path.join(input_path, '../jsonchecker', '*.json'))
|
||||
]
|
||||
else:
|
||||
tests = [input_path]
|
||||
|
||||
# These tests fail with strict json support, but pass with JsonCPP's
|
||||
# extra leniency features. When adding a new exclusion to this list,
|
||||
# remember to add the test's number and reasoning here:
|
||||
known = ["fail{}.json".format(n) for n in [
|
||||
4, 9, # fail because we allow trailing commas
|
||||
7, # fails because we allow commas after close
|
||||
8, # fails because we allow extra close
|
||||
10, # fails because we allow extra values after close
|
||||
13, # fails because we allow leading zeroes in numbers
|
||||
18, # fails because we allow deeply nested values
|
||||
25, # fails because we allow tab characters in strings
|
||||
27, # fails because we allow string line breaks
|
||||
]]
|
||||
|
||||
tests = [
|
||||
test for test in tests
|
||||
if os.path.basename(test) not in known or
|
||||
os.path.basename(os.path.dirname(test)) != "jsonchecker"
|
||||
]
|
||||
test_jsonchecker = []
|
||||
|
||||
failed_tests = []
|
||||
valgrind_path = use_valgrind and VALGRIND_CMD or ''
|
||||
for input_path in tests:
|
||||
for input_path in tests + test_jsonchecker:
|
||||
expect_failure = os.path.basename(input_path).startswith('fail')
|
||||
is_json_checker_test = os.path.basename(os.path.dirname(input_path)) == "jsonchecker"
|
||||
is_json_checker_test = input_path in test_jsonchecker
|
||||
is_parse_only = is_json_checker_test or expect_failure
|
||||
is_strict_test = ('_strict_' in os.path.basename(input_path)) or is_json_checker_test
|
||||
print('TESTING:', input_path, end=' ')
|
||||
|
||||
Reference in New Issue
Block a user