MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / univalue_object

Function univalue_object

src/univalue/test/object.cpp:268–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268void univalue_object()
269{
270 UniValue obj(UniValue::VOBJ);
271 std::string strKey, strVal;
272 UniValue v;
273
274 strKey = "age";
275 v.setInt(100);
276 obj.pushKV(strKey, v);
277
278 strKey = "first";
279 strVal = "John";
280 obj.pushKV(strKey, strVal);
281
282 strKey = "last";
283 const char* cVal = "Smith";
284 obj.pushKV(strKey, cVal);
285
286 strKey = "distance";
287 obj.pushKV(strKey, int64_t{25});
288
289 strKey = "time";
290 obj.pushKV(strKey, uint64_t{3600});
291
292 strKey = "calories";
293 obj.pushKV(strKey, int{12});
294
295 strKey = "temperature";
296 obj.pushKV(strKey, double{90.012});
297
298 strKey = "moon";
299 obj.pushKV(strKey, true);
300
301 strKey = "spoon";
302 obj.pushKV(strKey, false);
303
304 UniValue obj2(UniValue::VOBJ);
305 obj2.pushKV("cat1", 9000);
306 obj2.pushKV("cat2", 12345);
307
308 obj.pushKVs(obj2);
309
310 BOOST_CHECK_EQUAL(obj.empty(), false);
311 BOOST_CHECK_EQUAL(obj.size(), 11);
312
313 BOOST_CHECK_EQUAL(obj["age"].getValStr(), "100");
314 BOOST_CHECK_EQUAL(obj["first"].getValStr(), "John");
315 BOOST_CHECK_EQUAL(obj["last"].getValStr(), "Smith");
316 BOOST_CHECK_EQUAL(obj["distance"].getValStr(), "25");
317 BOOST_CHECK_EQUAL(obj["time"].getValStr(), "3600");
318 BOOST_CHECK_EQUAL(obj["calories"].getValStr(), "12");
319 BOOST_CHECK_EQUAL(obj["temperature"].getValStr(), "90.012");
320 BOOST_CHECK_EQUAL(obj["moon"].getValStr(), "1");
321 BOOST_CHECK_EQUAL(obj["spoon"].getValStr(), "");
322 BOOST_CHECK_EQUAL(obj["cat1"].getValStr(), "9000");
323 BOOST_CHECK_EQUAL(obj["cat2"].getValStr(), "12345");
324
325 BOOST_CHECK_EQUAL(obj["nyuknyuknyuk"].getValStr(), "");

Callers 1

mainFunction · 0.85

Calls 12

pushKVMethod · 0.80
pushKVsMethod · 0.80
checkObjectMethod · 0.80
getTypeMethod · 0.80
setObjectMethod · 0.80
pushKVEndMethod · 0.80
getObjMapMethod · 0.80
setIntMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
existsMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected