diff options
author | Elliott Hughes <enh@google.com> | 2021-12-07 09:43:38 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2021-12-07 09:43:38 -0800 |
commit | 1601ea0835d235a9f5c498e637e2b559da58e17b (patch) | |
tree | 5015100cb583ba035d40917cc21d3846f42adc89 /src/test_lib_json/main.cpp | |
parent | 51fd5436a52846f49fc68197a55304025e86f25b (diff) | |
download | jsoncpp-1601ea0835d235a9f5c498e637e2b559da58e17b.tar.gz |
Upgrade jsoncpp to 1.9.5
Test: make
Change-Id: I0be1376ee1502a2fd9db2733b503f30f2777a02a
Diffstat (limited to 'src/test_lib_json/main.cpp')
-rw-r--r-- | src/test_lib_json/main.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 991c247..d0f5364 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -12,6 +12,7 @@ #include "fuzz.h" #include "jsontest.h" +#include <algorithm> #include <cmath> #include <cstring> #include <functional> @@ -24,6 +25,7 @@ #include <memory> #include <sstream> #include <string> +#include <vector> using CharReaderPtr = std::unique_ptr<Json::CharReader>; @@ -347,6 +349,17 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, resizeArray) { JSONTEST_ASSERT_EQUAL(array.size(), 0); } } + +JSONTEST_FIXTURE_LOCAL(ValueTest, resizePopulatesAllMissingElements) { + Json::ArrayIndex n = 10; + Json::Value v; + v.resize(n); + JSONTEST_ASSERT_EQUAL(n, v.size()); + JSONTEST_ASSERT_EQUAL(n, std::distance(v.begin(), v.end())); + for (const Json::Value& e : v) + JSONTEST_ASSERT_EQUAL(e, Json::Value{}); +} + JSONTEST_FIXTURE_LOCAL(ValueTest, getArrayValue) { Json::Value array; for (Json::ArrayIndex i = 0; i < 5; i++) @@ -2005,6 +2018,34 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, precision) { result = Json::writeString(b, v); JSONTEST_ASSERT_STRING_EQUAL(expected, result); + b.settings_["precision"] = 0; + b.settings_["precisionType"] = "decimal"; + v = 123.56345694873740545068; + expected = "124"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + b.settings_["precision"] = 1; + b.settings_["precisionType"] = "decimal"; + v = 1230.001; + expected = "1230.0"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + b.settings_["precision"] = 0; + b.settings_["precisionType"] = "decimal"; + v = 1230.001; + expected = "1230"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + b.settings_["precision"] = 0; + b.settings_["precisionType"] = "decimal"; + v = 1231.5; + expected = "1232"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + b.settings_["precision"] = 10; b.settings_["precisionType"] = "decimal"; v = 0.23300000; @@ -3916,6 +3957,15 @@ JSONTEST_FIXTURE_LOCAL(MemberTemplateIs, BehavesSameAsNamedIs) { } } +class VersionTest : public JsonTest::TestCase {}; + +JSONTEST_FIXTURE_LOCAL(VersionTest, VersionNumbersMatch) { + std::ostringstream vstr; + vstr << JSONCPP_VERSION_MAJOR << '.' << JSONCPP_VERSION_MINOR << '.' + << JSONCPP_VERSION_PATCH; + JSONTEST_ASSERT_EQUAL(vstr.str(), std::string(JSONCPP_VERSION_STRING)); +} + #if defined(__GNUC__) #pragma GCC diagnostic pop #endif |