aboutsummaryrefslogtreecommitdiff
path: root/src/test_lib_json/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test_lib_json/main.cpp')
-rw-r--r--src/test_lib_json/main.cpp50
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