From c23132bcf4da3db8fe514bf56b8b0830215bd882 Mon Sep 17 00:00:00 2001 From: Karel Bilek Date: Sun, 24 Sep 2017 23:35:24 +0200 Subject: [PATCH 1/2] Pushing boolean value to univalue correctly --- include/univalue.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/univalue.h b/include/univalue.h index 3f8f3441460..10ce39aec8b 100644 --- a/include/univalue.h +++ b/include/univalue.h @@ -130,6 +130,10 @@ class UniValue { UniValue tmpVal(val_); return pushKV(key, tmpVal); } + bool pushKV(const std::string& key, bool val_) { + UniValue tmpVal((bool)val_); + return pushKV(key, tmpVal); + } bool pushKV(const std::string& key, int val_) { UniValue tmpVal((int64_t)val_); return pushKV(key, tmpVal); From 72392fb227155f07ffc57c806cf7a177474b224c Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 12 Dec 2017 13:07:19 -0500 Subject: [PATCH 2/2] [tests] test pushKV for boolean values --- test/object.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/object.cpp b/test/object.cpp index 6641a764a59..15b043d0ebd 100644 --- a/test/object.cpp +++ b/test/object.cpp @@ -260,6 +260,12 @@ BOOST_AUTO_TEST_CASE(univalue_object) strKey = "temperature"; BOOST_CHECK(obj.pushKV(strKey, (double) 90.012)); + strKey = "moon"; + BOOST_CHECK(obj.pushKV(strKey, true)); + + strKey = "spoon"; + BOOST_CHECK(obj.pushKV(strKey, false)); + UniValue obj2(UniValue::VOBJ); BOOST_CHECK(obj2.pushKV("cat1", 9000)); BOOST_CHECK(obj2.pushKV("cat2", 12345)); @@ -267,7 +273,7 @@ BOOST_AUTO_TEST_CASE(univalue_object) BOOST_CHECK(obj.pushKVs(obj2)); BOOST_CHECK_EQUAL(obj.empty(), false); - BOOST_CHECK_EQUAL(obj.size(), 9); + BOOST_CHECK_EQUAL(obj.size(), 11); BOOST_CHECK_EQUAL(obj["age"].getValStr(), "100"); BOOST_CHECK_EQUAL(obj["first"].getValStr(), "John"); @@ -276,6 +282,8 @@ BOOST_AUTO_TEST_CASE(univalue_object) BOOST_CHECK_EQUAL(obj["time"].getValStr(), "3600"); BOOST_CHECK_EQUAL(obj["calories"].getValStr(), "12"); BOOST_CHECK_EQUAL(obj["temperature"].getValStr(), "90.012"); + BOOST_CHECK_EQUAL(obj["moon"].getValStr(), "1"); + BOOST_CHECK_EQUAL(obj["spoon"].getValStr(), ""); BOOST_CHECK_EQUAL(obj["cat1"].getValStr(), "9000"); BOOST_CHECK_EQUAL(obj["cat2"].getValStr(), "12345"); @@ -288,6 +296,8 @@ BOOST_AUTO_TEST_CASE(univalue_object) BOOST_CHECK(obj.exists("time")); BOOST_CHECK(obj.exists("calories")); BOOST_CHECK(obj.exists("temperature")); + BOOST_CHECK(obj.exists("moon")); + BOOST_CHECK(obj.exists("spoon")); BOOST_CHECK(obj.exists("cat1")); BOOST_CHECK(obj.exists("cat2")); @@ -301,6 +311,8 @@ BOOST_AUTO_TEST_CASE(univalue_object) objTypes["time"] = UniValue::VNUM; objTypes["calories"] = UniValue::VNUM; objTypes["temperature"] = UniValue::VNUM; + objTypes["moon"] = UniValue::VBOOL; + objTypes["spoon"] = UniValue::VBOOL; objTypes["cat1"] = UniValue::VNUM; objTypes["cat2"] = UniValue::VNUM; BOOST_CHECK(obj.checkObject(objTypes));