Skip to content

Commit f05f667

Browse files
committedMar 16, 2025
#ifdef stuff that should only be used with JSON_USE_EXCEPTION.
1 parent 8bcea02 commit f05f667

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎src/test_lib_json/jsontest.h

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
228228
JsonTest::ToJsonString(actual), __FILE__, \
229229
__LINE__, #expected " == " #actual)
230230

231+
#if JSON_USE_EXCEPTION
232+
231233
/// \brief Asserts that a given expression throws an exception
232234
#define JSONTEST_ASSERT_THROWS(expr) \
233235
do { \
@@ -242,6 +244,8 @@ TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
242244
"expected exception thrown: " #expr); \
243245
} while (0)
244246

247+
#endif // JSON_USE_EXCEPTION
248+
245249
/// \brief Begin a fixture test case.
246250
#define JSONTEST_FIXTURE(FixtureType, name) \
247251
class Test##FixtureType##name : public FixtureType { \

‎src/test_lib_json/main.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, typeChecksThrowExceptions) {
18881888
JSONTEST_ASSERT_THROWS(objVal.asBool());
18891889
JSONTEST_ASSERT_THROWS(arrVal.asBool());
18901890

1891-
#endif
1891+
#endif // JSON_USE_EXCEPTION
18921892
}
18931893

18941894
JSONTEST_FIXTURE_LOCAL(ValueTest, offsetAccessors) {
@@ -3323,6 +3323,8 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithDetailError) {
33233323
}
33243324

33253325
JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
3326+
#if JSON_USE_EXCEPTION
3327+
33263328
Json::CharReaderBuilder b;
33273329
Json::Value root;
33283330
char const doc[] = R"({ "property" : "value" })";
@@ -3342,6 +3344,8 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
33423344
JSONTEST_ASSERT_THROWS(
33433345
reader->parse(doc, doc + std::strlen(doc), &root, &errs));
33443346
}
3347+
3348+
#endif // JSON_USE_EXCEPTION
33453349
}
33463350

33473351
JSONTEST_FIXTURE_LOCAL(CharReaderTest, testOperator) {
@@ -3961,6 +3965,8 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, indexes) {
39613965
}
39623966

39633967
JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
3968+
#if JSON_USE_EXCEPTION
3969+
39643970
Json::Value const v;
39653971
JSONTEST_ASSERT_THROWS(
39663972
Json::Value::iterator it(v.begin())); // Compile, but throw.
@@ -3982,6 +3988,8 @@ JSONTEST_FIXTURE_LOCAL(IteratorTest, constness) {
39823988
}
39833989
Json::String expected = R"(" 9","10","11",)";
39843990
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
3991+
3992+
#endif // JSON_USE_EXCEPTION
39853993
}
39863994

39873995
struct RValueTest : JsonTest::TestCase {};

0 commit comments

Comments
 (0)