mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Bump univalue subtree
This commit is contained in:
commit
fa0cc61b7f
3 changed files with 15 additions and 76 deletions
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
Rearrange tree for easier 'git subtree' style use
|
|
||||||
|
|
||||||
Move towards C++11 etc.
|
|
||||||
|
|
||||||
Namespace support - must come up with useful shorthand, avoiding
|
|
||||||
long Univalue::Univalue::Univalue usages forced upon library users.
|
|
||||||
|
|
||||||
Improve test suite
|
|
||||||
|
|
|
@ -83,66 +83,10 @@ public:
|
||||||
bool isObject() const { return (typ == VOBJ); }
|
bool isObject() const { return (typ == VOBJ); }
|
||||||
|
|
||||||
bool push_back(const UniValue& val);
|
bool push_back(const UniValue& val);
|
||||||
bool push_back(const std::string& val_) {
|
|
||||||
UniValue tmpVal(VSTR, val_);
|
|
||||||
return push_back(tmpVal);
|
|
||||||
}
|
|
||||||
bool push_back(const char *val_) {
|
|
||||||
std::string s(val_);
|
|
||||||
return push_back(s);
|
|
||||||
}
|
|
||||||
bool push_back(uint64_t val_) {
|
|
||||||
UniValue tmpVal(val_);
|
|
||||||
return push_back(tmpVal);
|
|
||||||
}
|
|
||||||
bool push_back(int64_t val_) {
|
|
||||||
UniValue tmpVal(val_);
|
|
||||||
return push_back(tmpVal);
|
|
||||||
}
|
|
||||||
bool push_back(bool val_) {
|
|
||||||
UniValue tmpVal(val_);
|
|
||||||
return push_back(tmpVal);
|
|
||||||
}
|
|
||||||
bool push_back(int val_) {
|
|
||||||
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<UniValue>& vec);
|
bool push_backV(const std::vector<UniValue>& vec);
|
||||||
|
|
||||||
void __pushKV(const std::string& key, const UniValue& val);
|
void __pushKV(const std::string& key, const UniValue& val);
|
||||||
bool pushKV(const std::string& key, const UniValue& val);
|
bool pushKV(const std::string& key, const UniValue& val);
|
||||||
bool pushKV(const std::string& key, const std::string& val_) {
|
|
||||||
UniValue tmpVal(VSTR, val_);
|
|
||||||
return pushKV(key, tmpVal);
|
|
||||||
}
|
|
||||||
bool pushKV(const std::string& key, const char *val_) {
|
|
||||||
std::string _val(val_);
|
|
||||||
return pushKV(key, _val);
|
|
||||||
}
|
|
||||||
bool pushKV(const std::string& key, int64_t val_) {
|
|
||||||
UniValue tmpVal(val_);
|
|
||||||
return pushKV(key, tmpVal);
|
|
||||||
}
|
|
||||||
bool pushKV(const std::string& key, uint64_t val_) {
|
|
||||||
UniValue tmpVal(val_);
|
|
||||||
return pushKV(key, tmpVal);
|
|
||||||
}
|
|
||||||
bool pushKV(const std::string& key, bool val_) {
|
|
||||||
UniValue tmpVal(val_);
|
|
||||||
return pushKV(key, tmpVal);
|
|
||||||
}
|
|
||||||
bool pushKV(const std::string& key, int val_) {
|
|
||||||
UniValue tmpVal((int64_t)val_);
|
|
||||||
return pushKV(key, tmpVal);
|
|
||||||
}
|
|
||||||
bool pushKV(const std::string& key, double val_) {
|
|
||||||
UniValue tmpVal(val_);
|
|
||||||
return pushKV(key, tmpVal);
|
|
||||||
}
|
|
||||||
bool pushKVs(const UniValue& obj);
|
bool pushKVs(const UniValue& obj);
|
||||||
|
|
||||||
std::string write(unsigned int prettyIndent = 0,
|
std::string write(unsigned int prettyIndent = 0,
|
||||||
|
@ -185,8 +129,6 @@ public:
|
||||||
}
|
}
|
||||||
bool get_bool() const;
|
bool get_bool() const;
|
||||||
const std::string& get_str() const;
|
const std::string& get_str() const;
|
||||||
auto get_int() const { return getInt<int>(); };
|
|
||||||
auto get_int64() const { return getInt<int64_t>(); };
|
|
||||||
double get_real() const;
|
double get_real() const;
|
||||||
const UniValue& get_obj() const;
|
const UniValue& get_obj() const;
|
||||||
const UniValue& get_array() const;
|
const UniValue& get_array() const;
|
||||||
|
|
|
@ -92,23 +92,30 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
|
||||||
BOOST_CHECK(v1.isNum());
|
BOOST_CHECK(v1.isNum());
|
||||||
BOOST_CHECK_THROW(v1.get_bool(), std::runtime_error);
|
BOOST_CHECK_THROW(v1.get_bool(), std::runtime_error);
|
||||||
|
|
||||||
|
{
|
||||||
|
UniValue v_negative;
|
||||||
|
BOOST_CHECK(v_negative.setNumStr("-1"));
|
||||||
|
BOOST_CHECK_THROW(v_negative.getInt<uint8_t>(), std::runtime_error);
|
||||||
|
BOOST_CHECK_EQUAL(v_negative.getInt<int8_t>(), -1);
|
||||||
|
}
|
||||||
|
|
||||||
UniValue v2;
|
UniValue v2;
|
||||||
BOOST_CHECK(v2.setBool(true));
|
BOOST_CHECK(v2.setBool(true));
|
||||||
BOOST_CHECK_EQUAL(v2.get_bool(), true);
|
BOOST_CHECK_EQUAL(v2.get_bool(), true);
|
||||||
BOOST_CHECK_THROW(v2.get_int(), std::runtime_error);
|
BOOST_CHECK_THROW(v2.getInt<int>(), std::runtime_error);
|
||||||
|
|
||||||
UniValue v3;
|
UniValue v3;
|
||||||
BOOST_CHECK(v3.setNumStr("32482348723847471234"));
|
BOOST_CHECK(v3.setNumStr("32482348723847471234"));
|
||||||
BOOST_CHECK_THROW(v3.get_int64(), std::runtime_error);
|
BOOST_CHECK_THROW(v3.getInt<int64_t>(), std::runtime_error);
|
||||||
BOOST_CHECK(v3.setNumStr("1000"));
|
BOOST_CHECK(v3.setNumStr("1000"));
|
||||||
BOOST_CHECK_EQUAL(v3.get_int64(), 1000);
|
BOOST_CHECK_EQUAL(v3.getInt<int64_t>(), 1000);
|
||||||
|
|
||||||
UniValue v4;
|
UniValue v4;
|
||||||
BOOST_CHECK(v4.setNumStr("2147483648"));
|
BOOST_CHECK(v4.setNumStr("2147483648"));
|
||||||
BOOST_CHECK_EQUAL(v4.get_int64(), 2147483648);
|
BOOST_CHECK_EQUAL(v4.getInt<int64_t>(), 2147483648);
|
||||||
BOOST_CHECK_THROW(v4.get_int(), std::runtime_error);
|
BOOST_CHECK_THROW(v4.getInt<int>(), std::runtime_error);
|
||||||
BOOST_CHECK(v4.setNumStr("1000"));
|
BOOST_CHECK(v4.setNumStr("1000"));
|
||||||
BOOST_CHECK_EQUAL(v4.get_int(), 1000);
|
BOOST_CHECK_EQUAL(v4.getInt<int>(), 1000);
|
||||||
BOOST_CHECK_THROW(v4.get_str(), std::runtime_error);
|
BOOST_CHECK_THROW(v4.get_str(), std::runtime_error);
|
||||||
BOOST_CHECK_EQUAL(v4.get_real(), 1000);
|
BOOST_CHECK_EQUAL(v4.get_real(), 1000);
|
||||||
BOOST_CHECK_THROW(v4.get_array(), std::runtime_error);
|
BOOST_CHECK_THROW(v4.get_array(), std::runtime_error);
|
||||||
|
@ -120,10 +127,10 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
|
||||||
BOOST_CHECK(v5.read("[true, 10]"));
|
BOOST_CHECK(v5.read("[true, 10]"));
|
||||||
BOOST_CHECK_NO_THROW(v5.get_array());
|
BOOST_CHECK_NO_THROW(v5.get_array());
|
||||||
std::vector<UniValue> vals = v5.getValues();
|
std::vector<UniValue> vals = v5.getValues();
|
||||||
BOOST_CHECK_THROW(vals[0].get_int(), std::runtime_error);
|
BOOST_CHECK_THROW(vals[0].getInt<int>(), std::runtime_error);
|
||||||
BOOST_CHECK_EQUAL(vals[0].get_bool(), true);
|
BOOST_CHECK_EQUAL(vals[0].get_bool(), true);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(vals[1].get_int(), 10);
|
BOOST_CHECK_EQUAL(vals[1].getInt<int>(), 10);
|
||||||
BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error);
|
BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue