diff --git a/include/univalue.h b/include/univalue.h index f10f78d432864c..c9a5690eed43d6 100644 --- a/include/univalue.h +++ b/include/univalue.h @@ -105,6 +105,10 @@ class UniValue { UniValue tmpVal(val_); return push_back(tmpVal); } + bool push_back(double val_) { + UniValue tmpVal(val_); + return push_back(tmpVal); + } bool push_backV(const std::vector& vec); bool pushKV(const std::string& key, const UniValue& val); diff --git a/test/object.cpp b/test/object.cpp index f1f2e63b3d6f00..7c4f21c85f57a5 100644 --- a/test/object.cpp +++ b/test/object.cpp @@ -205,14 +205,23 @@ BOOST_AUTO_TEST_CASE(univalue_array) BOOST_CHECK(arr.push_backV(vec)); + BOOST_CHECK(arr.push_back((uint64_t) 400ULL)); + BOOST_CHECK(arr.push_back((int64_t) -400LL)); + BOOST_CHECK(arr.push_back((int) -401)); + BOOST_CHECK(arr.push_back(-40.1)); + BOOST_CHECK_EQUAL(arr.empty(), false); - BOOST_CHECK_EQUAL(arr.size(), 5); + BOOST_CHECK_EQUAL(arr.size(), 9); BOOST_CHECK_EQUAL(arr[0].getValStr(), "1023"); BOOST_CHECK_EQUAL(arr[1].getValStr(), "zippy"); BOOST_CHECK_EQUAL(arr[2].getValStr(), "pippy"); BOOST_CHECK_EQUAL(arr[3].getValStr(), "boing"); BOOST_CHECK_EQUAL(arr[4].getValStr(), "going"); + BOOST_CHECK_EQUAL(arr[5].getValStr(), "400"); + BOOST_CHECK_EQUAL(arr[6].getValStr(), "-400"); + BOOST_CHECK_EQUAL(arr[7].getValStr(), "-401"); + BOOST_CHECK_EQUAL(arr[8].getValStr(), "-40.1"); BOOST_CHECK_EQUAL(arr[999].getValStr(), "");