rippled
Loading...
Searching...
No Matches
Value.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/beast/core/LexicalCast.h>
21#include <xrpl/json/json_errors.h>
22#include <xrpl/json/json_reader.h>
23#include <xrpl/json/json_value.h>
24#include <xrpl/json/json_writer.h>
25
26#include <doctest/doctest.h>
27
28#include <algorithm>
29#include <regex>
30#include <sstream>
31#include <string>
32
33namespace ripple {
34
35TEST_SUITE_BEGIN("json_value");
36
37TEST_CASE("construct and compare Json::StaticString")
38{
39 static constexpr char sample[]{"Contents of a Json::StaticString"};
40
41 static constexpr Json::StaticString test1(sample);
42 char const* addrTest1{test1};
43
44 CHECK(addrTest1 == &sample[0]);
45 CHECK(test1.c_str() == &sample[0]);
46
47 static constexpr Json::StaticString test2{
48 "Contents of a Json::StaticString"};
49 static constexpr Json::StaticString test3{"Another StaticString"};
50
51 CHECK(test1 == test2);
52 CHECK(test1 != test3);
53
54 std::string str{sample};
55 CHECK(str == test2);
56 CHECK(str != test3);
57 CHECK(test2 == str);
58 CHECK(test3 != str);
59}
60
61TEST_CASE("different types")
62{
63 // Exercise ValueType constructor
64 static constexpr Json::StaticString staticStr{"staticStr"};
65
66 auto testCopy = [](Json::ValueType typ) {
67 Json::Value val{typ};
68 Json::Value cpy{val};
69 CHECK(val.type() == typ);
70 CHECK(cpy.type() == typ);
71 return val;
72 };
73 {
74 Json::Value const nullV{testCopy(Json::nullValue)};
75 CHECK(nullV.isNull());
76 CHECK(!nullV.isBool());
77 CHECK(!nullV.isInt());
78 CHECK(!nullV.isUInt());
79 CHECK(!nullV.isIntegral());
80 CHECK(!nullV.isDouble());
81 CHECK(!nullV.isNumeric());
82 CHECK(!nullV.isString());
83 CHECK(!nullV.isArray());
84 CHECK(nullV.isArrayOrNull());
85 CHECK(!nullV.isObject());
86 CHECK(nullV.isObjectOrNull());
87 }
88 {
89 Json::Value const intV{testCopy(Json::intValue)};
90 CHECK(!intV.isNull());
91 CHECK(!intV.isBool());
92 CHECK(intV.isInt());
93 CHECK(!intV.isUInt());
94 CHECK(intV.isIntegral());
95 CHECK(!intV.isDouble());
96 CHECK(intV.isNumeric());
97 CHECK(!intV.isString());
98 CHECK(!intV.isArray());
99 CHECK(!intV.isArrayOrNull());
100 CHECK(!intV.isObject());
101 CHECK(!intV.isObjectOrNull());
102 }
103 {
104 Json::Value const uintV{testCopy(Json::uintValue)};
105 CHECK(!uintV.isNull());
106 CHECK(!uintV.isBool());
107 CHECK(!uintV.isInt());
108 CHECK(uintV.isUInt());
109 CHECK(uintV.isIntegral());
110 CHECK(!uintV.isDouble());
111 CHECK(uintV.isNumeric());
112 CHECK(!uintV.isString());
113 CHECK(!uintV.isArray());
114 CHECK(!uintV.isArrayOrNull());
115 CHECK(!uintV.isObject());
116 CHECK(!uintV.isObjectOrNull());
117 }
118 {
119 Json::Value const realV{testCopy(Json::realValue)};
120 CHECK(!realV.isNull());
121 CHECK(!realV.isBool());
122 CHECK(!realV.isInt());
123 CHECK(!realV.isUInt());
124 CHECK(!realV.isIntegral());
125 CHECK(realV.isDouble());
126 CHECK(realV.isNumeric());
127 CHECK(!realV.isString());
128 CHECK(!realV.isArray());
129 CHECK(!realV.isArrayOrNull());
130 CHECK(!realV.isObject());
131 CHECK(!realV.isObjectOrNull());
132 }
133 {
134 Json::Value const stringV{testCopy(Json::stringValue)};
135 CHECK(!stringV.isNull());
136 CHECK(!stringV.isBool());
137 CHECK(!stringV.isInt());
138 CHECK(!stringV.isUInt());
139 CHECK(!stringV.isIntegral());
140 CHECK(!stringV.isDouble());
141 CHECK(!stringV.isNumeric());
142 CHECK(stringV.isString());
143 CHECK(!stringV.isArray());
144 CHECK(!stringV.isArrayOrNull());
145 CHECK(!stringV.isObject());
146 CHECK(!stringV.isObjectOrNull());
147 }
148 {
149 Json::Value const staticStrV{staticStr};
150 {
151 Json::Value cpy{staticStrV};
152 CHECK(staticStrV.type() == Json::stringValue);
153 CHECK(cpy.type() == Json::stringValue);
154 }
155 CHECK(!staticStrV.isNull());
156 CHECK(!staticStrV.isBool());
157 CHECK(!staticStrV.isInt());
158 CHECK(!staticStrV.isUInt());
159 CHECK(!staticStrV.isIntegral());
160 CHECK(!staticStrV.isDouble());
161 CHECK(!staticStrV.isNumeric());
162 CHECK(staticStrV.isString());
163 CHECK(!staticStrV.isArray());
164 CHECK(!staticStrV.isArrayOrNull());
165 CHECK(!staticStrV.isObject());
166 CHECK(!staticStrV.isObjectOrNull());
167 }
168 {
169 Json::Value const boolV{testCopy(Json::booleanValue)};
170 CHECK(!boolV.isNull());
171 CHECK(boolV.isBool());
172 CHECK(!boolV.isInt());
173 CHECK(!boolV.isUInt());
174 CHECK(boolV.isIntegral());
175 CHECK(!boolV.isDouble());
176 CHECK(boolV.isNumeric());
177 CHECK(!boolV.isString());
178 CHECK(!boolV.isArray());
179 CHECK(!boolV.isArrayOrNull());
180 CHECK(!boolV.isObject());
181 CHECK(!boolV.isObjectOrNull());
182 }
183 {
184 Json::Value const arrayV{testCopy(Json::arrayValue)};
185 CHECK(!arrayV.isNull());
186 CHECK(!arrayV.isBool());
187 CHECK(!arrayV.isInt());
188 CHECK(!arrayV.isUInt());
189 CHECK(!arrayV.isIntegral());
190 CHECK(!arrayV.isDouble());
191 CHECK(!arrayV.isNumeric());
192 CHECK(!arrayV.isString());
193 CHECK(arrayV.isArray());
194 CHECK(arrayV.isArrayOrNull());
195 CHECK(!arrayV.isObject());
196 CHECK(!arrayV.isObjectOrNull());
197 }
198 {
199 Json::Value const objectV{testCopy(Json::objectValue)};
200 CHECK(!objectV.isNull());
201 CHECK(!objectV.isBool());
202 CHECK(!objectV.isInt());
203 CHECK(!objectV.isUInt());
204 CHECK(!objectV.isIntegral());
205 CHECK(!objectV.isDouble());
206 CHECK(!objectV.isNumeric());
207 CHECK(!objectV.isString());
208 CHECK(!objectV.isArray());
209 CHECK(!objectV.isArrayOrNull());
210 CHECK(objectV.isObject());
211 CHECK(objectV.isObjectOrNull());
212 }
213}
214
215TEST_CASE("compare strings")
216{
217 auto doCompare = [&](Json::Value const& lhs,
218 Json::Value const& rhs,
219 bool lhsEqRhs,
220 bool lhsLtRhs,
221 int line) {
222 CAPTURE(line);
223 CHECK((lhs == rhs) == lhsEqRhs);
224 CHECK((lhs != rhs) != lhsEqRhs);
225 CHECK((lhs < rhs) == (!(lhsEqRhs || !lhsLtRhs)));
226 CHECK((lhs <= rhs) == (lhsEqRhs || lhsLtRhs));
227 CHECK((lhs >= rhs) == (lhsEqRhs || !lhsLtRhs));
228 CHECK((lhs > rhs) == (!(lhsEqRhs || lhsLtRhs)));
229 };
230
231 Json::Value const null0;
232 Json::Value const intNeg1{-1};
233 Json::Value const int0{Json::intValue};
234 Json::Value const intPos1{1};
235 Json::Value const uint0{Json::uintValue};
236 Json::Value const uint1{1u};
237 Json::Value const realNeg1{-1.0};
238 Json::Value const real0{Json::realValue};
239 Json::Value const realPos1{1.0};
240 Json::Value const str0{Json::stringValue};
241 Json::Value const str1{"1"};
242 Json::Value const boolF{false};
243 Json::Value const boolT{true};
244 Json::Value const array0{Json::arrayValue};
245 Json::Value const array1{[]() {
246 Json::Value array1;
247 array1[0u] = 1;
248 return array1;
249 }()};
250 Json::Value const obj0{Json::objectValue};
251 Json::Value const obj1{[]() {
252 Json::Value obj1;
253 obj1["one"] = 1;
254 return obj1;
255 }()};
256
257#pragma push_macro("DO_COMPARE")
258 // DO_COMPARE(lhs, rhs, lhsEqualsToRhs lhsLessThanRhs)
259#define DO_COMPARE(lhs, rhs, eq, lt) doCompare(lhs, rhs, eq, lt, __LINE__)
260 DO_COMPARE(null0, Json::Value{}, true, false);
261 DO_COMPARE(null0, intNeg1, false, true);
262 DO_COMPARE(null0, int0, false, true);
263 DO_COMPARE(null0, intPos1, false, true);
264 DO_COMPARE(null0, uint0, false, true);
265 DO_COMPARE(null0, uint1, false, true);
266 DO_COMPARE(null0, realNeg1, false, true);
267 DO_COMPARE(null0, real0, false, true);
268 DO_COMPARE(null0, realPos1, false, true);
269 DO_COMPARE(null0, str0, false, true);
270 DO_COMPARE(null0, str1, false, true);
271 DO_COMPARE(null0, boolF, false, true);
272 DO_COMPARE(null0, boolT, false, true);
273 DO_COMPARE(null0, array0, false, true);
274 DO_COMPARE(null0, array1, false, true);
275 DO_COMPARE(null0, obj0, false, true);
276 DO_COMPARE(null0, obj1, false, true);
277
278 DO_COMPARE(intNeg1, null0, false, false);
279 DO_COMPARE(intNeg1, intNeg1, true, false);
280 DO_COMPARE(intNeg1, int0, false, true);
281 DO_COMPARE(intNeg1, intPos1, false, true);
282 DO_COMPARE(intNeg1, uint0, false, true);
283 DO_COMPARE(intNeg1, uint1, false, true);
284 DO_COMPARE(intNeg1, realNeg1, false, true);
285 DO_COMPARE(intNeg1, real0, false, true);
286 DO_COMPARE(intNeg1, realPos1, false, true);
287 DO_COMPARE(intNeg1, str0, false, true);
288 DO_COMPARE(intNeg1, str1, false, true);
289 DO_COMPARE(intNeg1, boolF, false, true);
290 DO_COMPARE(intNeg1, boolT, false, true);
291 DO_COMPARE(intNeg1, array0, false, true);
292 DO_COMPARE(intNeg1, array1, false, true);
293 DO_COMPARE(intNeg1, obj0, false, true);
294 DO_COMPARE(intNeg1, obj1, false, true);
295
296 DO_COMPARE(int0, null0, false, false);
297 DO_COMPARE(int0, intNeg1, false, false);
298 DO_COMPARE(int0, int0, true, false);
299 DO_COMPARE(int0, intPos1, false, true);
300 DO_COMPARE(int0, uint0, true, false);
301 DO_COMPARE(int0, uint1, false, true);
302 DO_COMPARE(int0, realNeg1, false, true);
303 DO_COMPARE(int0, real0, false, true);
304 DO_COMPARE(int0, realPos1, false, true);
305 DO_COMPARE(int0, str0, false, true);
306 DO_COMPARE(int0, str1, false, true);
307 DO_COMPARE(int0, boolF, false, true);
308 DO_COMPARE(int0, boolT, false, true);
309 DO_COMPARE(int0, array0, false, true);
310 DO_COMPARE(int0, array1, false, true);
311 DO_COMPARE(int0, obj0, false, true);
312 DO_COMPARE(int0, obj1, false, true);
313
314 DO_COMPARE(intPos1, null0, false, false);
315 DO_COMPARE(intPos1, intNeg1, false, false);
316 DO_COMPARE(intPos1, int0, false, false);
317 DO_COMPARE(intPos1, intPos1, true, false);
318 DO_COMPARE(intPos1, uint0, false, false);
319 DO_COMPARE(intPos1, uint1, true, false);
320 DO_COMPARE(intPos1, realNeg1, false, true);
321 DO_COMPARE(intPos1, real0, false, true);
322 DO_COMPARE(intPos1, realPos1, false, true);
323 DO_COMPARE(intPos1, str0, false, true);
324 DO_COMPARE(intPos1, str1, false, true);
325 DO_COMPARE(intPos1, boolF, false, true);
326 DO_COMPARE(intPos1, boolT, false, true);
327 DO_COMPARE(intPos1, array0, false, true);
328 DO_COMPARE(intPos1, array1, false, true);
329 DO_COMPARE(intPos1, obj0, false, true);
330 DO_COMPARE(intPos1, obj1, false, true);
331
332 DO_COMPARE(uint0, null0, false, false);
333 DO_COMPARE(uint0, intNeg1, false, false);
334 DO_COMPARE(uint0, int0, true, false);
335 DO_COMPARE(uint0, intPos1, false, true);
336 DO_COMPARE(uint0, uint0, true, false);
337 DO_COMPARE(uint0, uint1, false, true);
338 DO_COMPARE(uint0, realNeg1, false, true);
339 DO_COMPARE(uint0, real0, false, true);
340 DO_COMPARE(uint0, realPos1, false, true);
341 DO_COMPARE(uint0, str0, false, true);
342 DO_COMPARE(uint0, str1, false, true);
343 DO_COMPARE(uint0, boolF, false, true);
344 DO_COMPARE(uint0, boolT, false, true);
345 DO_COMPARE(uint0, array0, false, true);
346 DO_COMPARE(uint0, array1, false, true);
347 DO_COMPARE(uint0, obj0, false, true);
348 DO_COMPARE(uint0, obj1, false, true);
349
350 DO_COMPARE(uint1, null0, false, false);
351 DO_COMPARE(uint1, intNeg1, false, false);
352 DO_COMPARE(uint1, int0, false, false);
353 DO_COMPARE(uint1, intPos1, true, false);
354 DO_COMPARE(uint1, uint0, false, false);
355 DO_COMPARE(uint1, uint1, true, false);
356 DO_COMPARE(uint1, realNeg1, false, true);
357 DO_COMPARE(uint1, real0, false, true);
358 DO_COMPARE(uint1, realPos1, false, true);
359 DO_COMPARE(uint1, str0, false, true);
360 DO_COMPARE(uint1, str1, false, true);
361 DO_COMPARE(uint1, boolF, false, true);
362 DO_COMPARE(uint1, boolT, false, true);
363 DO_COMPARE(uint1, array0, false, true);
364 DO_COMPARE(uint1, array1, false, true);
365 DO_COMPARE(uint1, obj0, false, true);
366 DO_COMPARE(uint1, obj1, false, true);
367
368 DO_COMPARE(realNeg1, null0, false, false);
369 DO_COMPARE(realNeg1, intNeg1, false, false);
370 DO_COMPARE(realNeg1, int0, false, false);
371 DO_COMPARE(realNeg1, intPos1, false, false);
372 DO_COMPARE(realNeg1, uint0, false, false);
373 DO_COMPARE(realNeg1, uint1, false, false);
374 DO_COMPARE(realNeg1, realNeg1, true, false);
375 DO_COMPARE(realNeg1, real0, false, true);
376 DO_COMPARE(realNeg1, realPos1, false, true);
377 DO_COMPARE(realNeg1, str0, false, true);
378 DO_COMPARE(realNeg1, str1, false, true);
379 DO_COMPARE(realNeg1, boolF, false, true);
380 DO_COMPARE(realNeg1, boolT, false, true);
381 DO_COMPARE(realNeg1, array0, false, true);
382 DO_COMPARE(realNeg1, array1, false, true);
383 DO_COMPARE(realNeg1, obj0, false, true);
384 DO_COMPARE(realNeg1, obj1, false, true);
385
386 DO_COMPARE(real0, null0, false, false);
387 DO_COMPARE(real0, intNeg1, false, false);
388 DO_COMPARE(real0, int0, false, false);
389 DO_COMPARE(real0, intPos1, false, false);
390 DO_COMPARE(real0, uint0, false, false);
391 DO_COMPARE(real0, uint1, false, false);
392 DO_COMPARE(real0, realNeg1, false, false);
393 DO_COMPARE(real0, real0, true, false);
394 DO_COMPARE(real0, realPos1, false, true);
395 DO_COMPARE(real0, str0, false, true);
396 DO_COMPARE(real0, str1, false, true);
397 DO_COMPARE(real0, boolF, false, true);
398 DO_COMPARE(real0, boolT, false, true);
399 DO_COMPARE(real0, array0, false, true);
400 DO_COMPARE(real0, array1, false, true);
401 DO_COMPARE(real0, obj0, false, true);
402 DO_COMPARE(real0, obj1, false, true);
403
404 DO_COMPARE(realPos1, null0, false, false);
405 DO_COMPARE(realPos1, intNeg1, false, false);
406 DO_COMPARE(realPos1, int0, false, false);
407 DO_COMPARE(realPos1, intPos1, false, false);
408 DO_COMPARE(realPos1, uint0, false, false);
409 DO_COMPARE(realPos1, uint1, false, false);
410 DO_COMPARE(realPos1, realNeg1, false, false);
411 DO_COMPARE(realPos1, real0, false, false);
412 DO_COMPARE(realPos1, realPos1, true, false);
413 DO_COMPARE(realPos1, str0, false, true);
414 DO_COMPARE(realPos1, str1, false, true);
415 DO_COMPARE(realPos1, boolF, false, true);
416 DO_COMPARE(realPos1, boolT, false, true);
417 DO_COMPARE(realPos1, array0, false, true);
418 DO_COMPARE(realPos1, array1, false, true);
419 DO_COMPARE(realPos1, obj0, false, true);
420 DO_COMPARE(realPos1, obj1, false, true);
421
422 DO_COMPARE(str0, null0, false, false);
423 DO_COMPARE(str0, intNeg1, false, false);
424 DO_COMPARE(str0, int0, false, false);
425 DO_COMPARE(str0, intPos1, false, false);
426 DO_COMPARE(str0, uint0, false, false);
427 DO_COMPARE(str0, uint1, false, false);
428 DO_COMPARE(str0, realNeg1, false, false);
429 DO_COMPARE(str0, real0, false, false);
430 DO_COMPARE(str0, realPos1, false, false);
431 DO_COMPARE(str0, str0, true, false);
432 DO_COMPARE(str0, str1, false, true);
433 DO_COMPARE(str0, boolF, false, true);
434 DO_COMPARE(str0, boolT, false, true);
435 DO_COMPARE(str0, array0, false, true);
436 DO_COMPARE(str0, array1, false, true);
437 DO_COMPARE(str0, obj0, false, true);
438 DO_COMPARE(str0, obj1, false, true);
439
440 DO_COMPARE(str1, null0, false, false);
441 DO_COMPARE(str1, intNeg1, false, false);
442 DO_COMPARE(str1, int0, false, false);
443 DO_COMPARE(str1, intPos1, false, false);
444 DO_COMPARE(str1, uint0, false, false);
445 DO_COMPARE(str1, uint1, false, false);
446 DO_COMPARE(str1, realNeg1, false, false);
447 DO_COMPARE(str1, real0, false, false);
448 DO_COMPARE(str1, realPos1, false, false);
449 DO_COMPARE(str1, str0, false, false);
450 DO_COMPARE(str1, str1, true, false);
451 DO_COMPARE(str1, boolF, false, true);
452 DO_COMPARE(str1, boolT, false, true);
453 DO_COMPARE(str1, array0, false, true);
454 DO_COMPARE(str1, array1, false, true);
455 DO_COMPARE(str1, obj0, false, true);
456 DO_COMPARE(str1, obj1, false, true);
457
458 DO_COMPARE(boolF, null0, false, false);
459 DO_COMPARE(boolF, intNeg1, false, false);
460 DO_COMPARE(boolF, int0, false, false);
461 DO_COMPARE(boolF, intPos1, false, false);
462 DO_COMPARE(boolF, uint0, false, false);
463 DO_COMPARE(boolF, uint1, false, false);
464 DO_COMPARE(boolF, realNeg1, false, false);
465 DO_COMPARE(boolF, real0, false, false);
466 DO_COMPARE(boolF, realPos1, false, false);
467 DO_COMPARE(boolF, str0, false, false);
468 DO_COMPARE(boolF, str1, false, false);
469 DO_COMPARE(boolF, boolF, true, false);
470 DO_COMPARE(boolF, boolT, false, true);
471 DO_COMPARE(boolF, array0, false, true);
472 DO_COMPARE(boolF, array1, false, true);
473 DO_COMPARE(boolF, obj0, false, true);
474 DO_COMPARE(boolF, obj1, false, true);
475
476 DO_COMPARE(boolT, null0, false, false);
477 DO_COMPARE(boolT, intNeg1, false, false);
478 DO_COMPARE(boolT, int0, false, false);
479 DO_COMPARE(boolT, intPos1, false, false);
480 DO_COMPARE(boolT, uint0, false, false);
481 DO_COMPARE(boolT, uint1, false, false);
482 DO_COMPARE(boolT, realNeg1, false, false);
483 DO_COMPARE(boolT, real0, false, false);
484 DO_COMPARE(boolT, realPos1, false, false);
485 DO_COMPARE(boolT, str0, false, false);
486 DO_COMPARE(boolT, str1, false, false);
487 DO_COMPARE(boolT, boolF, false, false);
488 DO_COMPARE(boolT, boolT, true, false);
489 DO_COMPARE(boolT, array0, false, true);
490 DO_COMPARE(boolT, array1, false, true);
491 DO_COMPARE(boolT, obj0, false, true);
492 DO_COMPARE(boolT, obj1, false, true);
493
494 DO_COMPARE(array0, null0, false, false);
495 DO_COMPARE(array0, intNeg1, false, false);
496 DO_COMPARE(array0, int0, false, false);
497 DO_COMPARE(array0, intPos1, false, false);
498 DO_COMPARE(array0, uint0, false, false);
499 DO_COMPARE(array0, uint1, false, false);
500 DO_COMPARE(array0, realNeg1, false, false);
501 DO_COMPARE(array0, real0, false, false);
502 DO_COMPARE(array0, realPos1, false, false);
503 DO_COMPARE(array0, str0, false, false);
504 DO_COMPARE(array0, str1, false, false);
505 DO_COMPARE(array0, boolF, false, false);
506 DO_COMPARE(array0, boolT, false, false);
507 DO_COMPARE(array0, array0, true, false);
508 DO_COMPARE(array0, array1, false, true);
509 DO_COMPARE(array0, obj0, false, true);
510 DO_COMPARE(array0, obj1, false, true);
511
512 DO_COMPARE(array1, null0, false, false);
513 DO_COMPARE(array1, intNeg1, false, false);
514 DO_COMPARE(array1, int0, false, false);
515 DO_COMPARE(array1, intPos1, false, false);
516 DO_COMPARE(array1, uint0, false, false);
517 DO_COMPARE(array1, uint1, false, false);
518 DO_COMPARE(array1, realNeg1, false, false);
519 DO_COMPARE(array1, real0, false, false);
520 DO_COMPARE(array1, realPos1, false, false);
521 DO_COMPARE(array1, str0, false, false);
522 DO_COMPARE(array1, str1, false, false);
523 DO_COMPARE(array1, boolF, false, false);
524 DO_COMPARE(array1, boolT, false, false);
525 DO_COMPARE(array1, array0, false, false);
526 DO_COMPARE(array1, array1, true, false);
527 DO_COMPARE(array1, obj0, false, true);
528 DO_COMPARE(array1, obj1, false, true);
529
530 DO_COMPARE(obj0, null0, false, false);
531 DO_COMPARE(obj0, intNeg1, false, false);
532 DO_COMPARE(obj0, int0, false, false);
533 DO_COMPARE(obj0, intPos1, false, false);
534 DO_COMPARE(obj0, uint0, false, false);
535 DO_COMPARE(obj0, uint1, false, false);
536 DO_COMPARE(obj0, realNeg1, false, false);
537 DO_COMPARE(obj0, real0, false, false);
538 DO_COMPARE(obj0, realPos1, false, false);
539 DO_COMPARE(obj0, str0, false, false);
540 DO_COMPARE(obj0, str1, false, false);
541 DO_COMPARE(obj0, boolF, false, false);
542 DO_COMPARE(obj0, boolT, false, false);
543 DO_COMPARE(obj0, array0, false, false);
544 DO_COMPARE(obj0, array1, false, false);
545 DO_COMPARE(obj0, obj0, true, false);
546 DO_COMPARE(obj0, obj1, false, true);
547
548 DO_COMPARE(obj1, null0, false, false);
549 DO_COMPARE(obj1, intNeg1, false, false);
550 DO_COMPARE(obj1, int0, false, false);
551 DO_COMPARE(obj1, intPos1, false, false);
552 DO_COMPARE(obj1, uint0, false, false);
553 DO_COMPARE(obj1, uint1, false, false);
554 DO_COMPARE(obj1, realNeg1, false, false);
555 DO_COMPARE(obj1, real0, false, false);
556 DO_COMPARE(obj1, realPos1, false, false);
557 DO_COMPARE(obj1, str0, false, false);
558 DO_COMPARE(obj1, str1, false, false);
559 DO_COMPARE(obj1, boolF, false, false);
560 DO_COMPARE(obj1, boolT, false, false);
561 DO_COMPARE(obj1, array0, false, false);
562 DO_COMPARE(obj1, array1, false, false);
563 DO_COMPARE(obj1, obj0, false, false);
564 DO_COMPARE(obj1, obj1, true, false);
565#undef DO_COMPARE
566#pragma pop_macro("DO_COMPARE")
567}
568
570{
571 CHECK(!Json::Value());
572
573 CHECK(!Json::Value(""));
574
575 CHECK(bool(Json::Value("empty")));
576 CHECK(bool(Json::Value(false)));
577 CHECK(bool(Json::Value(true)));
578 CHECK(bool(Json::Value(0)));
579 CHECK(bool(Json::Value(1)));
580
582 CHECK(!array);
583 array.append(0);
584 CHECK(bool(array));
585
587 CHECK(!object);
588 object[""] = false;
589 CHECK(bool(object));
590}
591
592TEST_CASE("bad json")
593{
594 char const* s(R"({"method":"ledger","params":[{"ledger_index":1e300}]})");
595
596 Json::Value j;
597 Json::Reader r;
598
599 CHECK(r.parse(s, j));
600}
601
602TEST_CASE("edge cases")
603{
604 std::string json;
605
609
610 std::uint32_t a_uint = max_uint - 1978;
611 std::int32_t a_large_int = max_int - 1978;
612 std::int32_t a_small_int = min_int + 1978;
613
614 json = "{\"max_uint\":" + std::to_string(max_uint);
615 json += ",\"max_int\":" + std::to_string(max_int);
616 json += ",\"min_int\":" + std::to_string(min_int);
617 json += ",\"a_uint\":" + std::to_string(a_uint);
618 json += ",\"a_large_int\":" + std::to_string(a_large_int);
619 json += ",\"a_small_int\":" + std::to_string(a_small_int);
620 json += "}";
621
622 Json::Value j1;
623 Json::Reader r1;
624
625 CHECK(r1.parse(json, j1));
626 CHECK(j1["max_uint"].asUInt() == max_uint);
627 CHECK(j1["max_int"].asInt() == max_int);
628 CHECK(j1["min_int"].asInt() == min_int);
629 CHECK(j1["a_uint"].asUInt() == a_uint);
630 CHECK(j1["a_uint"] > a_large_int);
631 CHECK(j1["a_uint"] > a_small_int);
632 CHECK(j1["a_large_int"].asInt() == a_large_int);
633 CHECK(j1["a_large_int"].asUInt() == a_large_int);
634 CHECK(j1["a_large_int"] < a_uint);
635 CHECK(j1["a_small_int"].asInt() == a_small_int);
636 CHECK(j1["a_small_int"] < a_uint);
637
638 json = "{\"overflow\":";
639 json += std::to_string(std::uint64_t(max_uint) + 1);
640 json += "}";
641
642 Json::Value j2;
643 Json::Reader r2;
644
645 CHECK(!r2.parse(json, j2));
646
647 json = "{\"underflow\":";
648 json += std::to_string(std::int64_t(min_int) - 1);
649 json += "}";
650
651 Json::Value j3;
652 Json::Reader r3;
653
654 CHECK(!r3.parse(json, j3));
655
656 Json::Value intString{"4294967296"};
657 CHECK_THROWS_AS(intString.asUInt(), beast::BadLexicalCast);
658
659 intString = "4294967295";
660 CHECK(intString.asUInt() == 4294967295u);
661
662 intString = "0";
663 CHECK(intString.asUInt() == 0);
664
665 intString = "-1";
666 CHECK_THROWS_AS(intString.asUInt(), beast::BadLexicalCast);
667
668 intString = "2147483648";
669 CHECK_THROWS_AS(intString.asInt(), beast::BadLexicalCast);
670
671 intString = "2147483647";
672 CHECK(intString.asInt() == 2147483647);
673
674 intString = "-2147483648";
675 CHECK(intString.asInt() == -2147483648LL); // MSVC wants the LL
676
677 intString = "-2147483649";
678 CHECK_THROWS_AS(intString.asInt(), beast::BadLexicalCast);
679}
680
682{
683 Json::Value v1{2.5};
684 CHECK(v1.isDouble());
685 CHECK(v1.asDouble() == 2.5);
686
687 Json::Value v2 = v1;
688 CHECK(v1.isDouble());
689 CHECK(v1.asDouble() == 2.5);
690 CHECK(v2.isDouble());
691 CHECK(v2.asDouble() == 2.5);
692 CHECK(v1 == v2);
693
694 v1 = v2;
695 CHECK(v1.isDouble());
696 CHECK(v1.asDouble() == 2.5);
697 CHECK(v2.isDouble());
698 CHECK(v2.asDouble() == 2.5);
699 CHECK(v1 == v2);
700}
701
703{
704 Json::Value v1{2.5};
705 CHECK(v1.isDouble());
706 CHECK(v1.asDouble() == 2.5);
707
708 Json::Value v2 = std::move(v1);
709 CHECK(!v1);
710 CHECK(v2.isDouble());
711 CHECK(v2.asDouble() == 2.5);
712 CHECK(v1 != v2);
713
714 v1 = std::move(v2);
715 CHECK(v1.isDouble());
716 CHECK(v1.asDouble() == 2.5);
717 CHECK(!v2);
718 CHECK(v1 != v2);
719}
720
721TEST_CASE("comparisons")
722{
723 Json::Value a, b;
724 auto testEquals = [&](std::string const& name) {
725 CHECK(a == b);
726 CHECK(a <= b);
727 CHECK(a >= b);
728
729 CHECK(!(a != b));
730 CHECK(!(a < b));
731 CHECK(!(a > b));
732
733 CHECK(b == a);
734 CHECK(b <= a);
735 CHECK(b >= a);
736
737 CHECK(!(b != a));
738 CHECK(!(b < a));
739 CHECK(!(b > a));
740 };
741
742 auto testGreaterThan = [&](std::string const& name) {
743 CHECK(!(a == b));
744 CHECK(!(a <= b));
745 CHECK(a >= b);
746
747 CHECK(a != b);
748 CHECK(!(a < b));
749 CHECK(a > b);
750
751 CHECK(!(b == a));
752 CHECK(b <= a);
753 CHECK(!(b >= a));
754
755 CHECK(b != a);
756 CHECK(b < a);
757 CHECK(!(b > a));
758 };
759
760 a["a"] = Json::UInt(0);
761 b["a"] = Json::Int(0);
762 testEquals("zero");
763
764 b["a"] = Json::Int(-1);
765 testGreaterThan("negative");
766
768 Json::UInt bigger = big;
769 bigger++;
770
771 a["a"] = bigger;
772 b["a"] = big;
773 testGreaterThan("big");
774}
775
776TEST_CASE("compact")
777{
778 Json::Value j;
779 Json::Reader r;
780 char const* s("{\"array\":[{\"12\":23},{},null,false,0.5]}");
781
782 auto countLines = [](std::string const& str) {
783 return 1 + std::count_if(str.begin(), str.end(), [](char c) {
784 return c == '\n';
785 });
786 };
787
788 CHECK(r.parse(s, j));
789 {
791 ss << j;
792 CHECK(countLines(ss.str()) > 1);
793 }
794 {
796 ss << Json::Compact(std::move(j));
797 CHECK(countLines(ss.str()) == 1);
798 }
799}
800
801TEST_CASE("conversions")
802{
803 // We have Json::Int, but not Json::Double or Json::Real.
804 // We have Json::Int, Json::Value::Int, and Json::ValueType::intValue.
805 // We have Json::ValueType::realValue but Json::Value::asDouble.
806 // TODO: What's the thinking here?
807 {
808 // null
809 Json::Value val;
810 CHECK(val.isNull());
811 // val.asCString() should trigger an assertion failure
812 CHECK(val.asString() == "");
813 CHECK(val.asInt() == 0);
814 CHECK(val.asUInt() == 0);
815 CHECK(val.asDouble() == 0.0);
816 CHECK(val.asBool() == false);
817
826 }
827 {
828 // int
829 Json::Value val = -1234;
830 CHECK(val.isInt());
831 // val.asCString() should trigger an assertion failure
832 CHECK(val.asString() == "-1234");
833 CHECK(val.asInt() == -1234);
834 CHECK_THROWS_AS(val.asUInt(), Json::error);
835 CHECK(val.asDouble() == -1234.0);
836 CHECK(val.asBool() == true);
837
846 }
847 {
848 // uint
849 Json::Value val = 1234U;
850 CHECK(val.isUInt());
851 // val.asCString() should trigger an assertion failure
852 CHECK(val.asString() == "1234");
853 CHECK(val.asInt() == 1234);
854 CHECK(val.asUInt() == 1234u);
855 CHECK(val.asDouble() == 1234.0);
856 CHECK(val.asBool() == true);
857
866 }
867 {
868 // real
869 Json::Value val = 2.0;
870 CHECK(val.isDouble());
871 // val.asCString() should trigger an assertion failure
872 CHECK(std::regex_match(val.asString(), std::regex("^2\\.0*$")));
873 CHECK(val.asInt() == 2);
874 CHECK(val.asUInt() == 2u);
875 CHECK(val.asDouble() == 2.0);
876 CHECK(val.asBool() == true);
877
886 }
887 {
888 // numeric string
889 Json::Value val = "54321";
890 CHECK(val.isString());
891 CHECK(strcmp(val.asCString(), "54321") == 0);
892 CHECK(val.asString() == "54321");
893 CHECK(val.asInt() == 54321);
894 CHECK(val.asUInt() == 54321u);
895 CHECK_THROWS_AS(val.asDouble(), Json::error);
896 CHECK(val.asBool() == true);
897
906 }
907 {
908 // non-numeric string
910 CHECK(val.isString());
911 CHECK(val.asCString() == nullptr);
912 CHECK(val.asString() == "");
913 CHECK_THROWS_AS(val.asInt(), std::exception);
914 CHECK_THROWS_AS(val.asUInt(), std::exception);
915 CHECK_THROWS_AS(val.asDouble(), std::exception);
916 CHECK(val.asBool() == false);
917
926 }
927 {
928 // bool false
929 Json::Value val = false;
930 CHECK(val.isBool());
931 // val.asCString() should trigger an assertion failure
932 CHECK(val.asString() == "false");
933 CHECK(val.asInt() == 0);
934 CHECK(val.asUInt() == 0);
935 CHECK(val.asDouble() == 0.0);
936 CHECK(val.asBool() == false);
937
946 }
947 {
948 // bool true
949 Json::Value val = true;
950 CHECK(val.isBool());
951 // val.asCString() should trigger an assertion failure
952 CHECK(val.asString() == "true");
953 CHECK(val.asInt() == 1);
954 CHECK(val.asUInt() == 1);
955 CHECK(val.asDouble() == 1.0);
956 CHECK(val.asBool() == true);
957
966 }
967 {
968 // array type
970 CHECK(val.isArray());
971 // val.asCString should trigger an assertion failure
972 CHECK_THROWS_AS(val.asString(), Json::error);
973 CHECK_THROWS_AS(val.asInt(), Json::error);
974 CHECK_THROWS_AS(val.asUInt(), Json::error);
975 CHECK_THROWS_AS(val.asDouble(), Json::error);
976 CHECK(val.asBool() == false); // empty or not
977
986 }
987 {
988 // object type
990 CHECK(val.isObject());
991 // val.asCString should trigger an assertion failure
992 CHECK_THROWS_AS(val.asString(), Json::error);
993 CHECK_THROWS_AS(val.asInt(), Json::error);
994 CHECK_THROWS_AS(val.asUInt(), Json::error);
995 CHECK_THROWS_AS(val.asDouble(), Json::error);
996 CHECK(val.asBool() == false); // empty or not
997
1006 }
1007}
1008
1009TEST_CASE("access members")
1010{
1011 Json::Value val;
1012 CHECK(val.type() == Json::nullValue);
1013 CHECK(val.size() == 0);
1014 CHECK(!val.isValidIndex(0));
1015 CHECK(!val.isMember("key"));
1016 {
1017 Json::Value const constVal = val;
1018 CHECK(constVal[7u].type() == Json::nullValue);
1019 CHECK(!constVal.isMember("key"));
1020 CHECK(constVal["key"].type() == Json::nullValue);
1021 CHECK(constVal.getMemberNames().empty());
1022 CHECK(constVal.get(1u, "default0") == "default0");
1023 CHECK(constVal.get(std::string("not"), "oh") == "oh");
1024 CHECK(constVal.get("missing", "default2") == "default2");
1025 }
1026
1027 val = -7;
1028 CHECK(val.type() == Json::intValue);
1029 CHECK(val.size() == 0);
1030 CHECK(!val.isValidIndex(0));
1031 CHECK(!val.isMember("key"));
1032
1033 val = 42u;
1034 CHECK(val.type() == Json::uintValue);
1035 CHECK(val.size() == 0);
1036 CHECK(!val.isValidIndex(0));
1037 CHECK(!val.isMember("key"));
1038
1039 val = 3.14159;
1040 CHECK(val.type() == Json::realValue);
1041 CHECK(val.size() == 0);
1042 CHECK(!val.isValidIndex(0));
1043 CHECK(!val.isMember("key"));
1044
1045 val = true;
1046 CHECK(val.type() == Json::booleanValue);
1047 CHECK(val.size() == 0);
1048 CHECK(!val.isValidIndex(0));
1049 CHECK(!val.isMember("key"));
1050
1051 val = "string";
1052 CHECK(val.type() == Json::stringValue);
1053 CHECK(val.size() == 0);
1054 CHECK(!val.isValidIndex(0));
1055 CHECK(!val.isMember("key"));
1056
1058 CHECK(val.type() == Json::objectValue);
1059 CHECK(val.size() == 0);
1060 static Json::StaticString const staticThree("three");
1061 val[staticThree] = 3;
1062 val["two"] = 2;
1063 CHECK(val.size() == 2);
1064 CHECK(val.isValidIndex(1));
1065 CHECK(!val.isValidIndex(2));
1066 CHECK(val[staticThree] == 3);
1067 CHECK(val.isMember("two"));
1068 CHECK(val.isMember(staticThree));
1069 CHECK(!val.isMember("key"));
1070 {
1071 Json::Value const constVal = val;
1072 CHECK(constVal["two"] == 2);
1073 CHECK(constVal["four"].type() == Json::nullValue);
1074 CHECK(constVal[staticThree] == 3);
1075 CHECK(constVal.isMember("two"));
1076 CHECK(constVal.isMember(staticThree));
1077 CHECK(!constVal.isMember("key"));
1078 CHECK(val.get(std::string("two"), "backup") == 2);
1079 CHECK(val.get("missing", "default2") == "default2");
1080 }
1081
1083 CHECK(val.type() == Json::arrayValue);
1084 CHECK(val.size() == 0);
1085 val[0u] = "zero";
1086 val[1u] = "one";
1087 CHECK(val.size() == 2);
1088 CHECK(val.isValidIndex(1));
1089 CHECK(!val.isValidIndex(2));
1090 CHECK(val[20u].type() == Json::nullValue);
1091 CHECK(!val.isMember("key"));
1092 {
1093 Json::Value const constVal = val;
1094 CHECK(constVal[0u] == "zero");
1095 CHECK(constVal[2u].type() == Json::nullValue);
1096 CHECK(!constVal.isMember("key"));
1097 CHECK(val.get(1u, "default0") == "one");
1098 CHECK(val.get(3u, "default1") == "default1");
1099 }
1100}
1101
1102TEST_CASE("remove members")
1103{
1104 Json::Value val;
1105 CHECK(val.removeMember(std::string("member")).type() == Json::nullValue);
1106
1108 static Json::StaticString const staticThree("three");
1109 val[staticThree] = 3;
1110 val["two"] = 2;
1111 CHECK(val.size() == 2);
1112
1114 CHECK(val.size() == 2);
1115
1116 CHECK(val.removeMember(staticThree) == 3);
1117 CHECK(val.size() == 1);
1118
1119 CHECK(val.removeMember(staticThree).type() == Json::nullValue);
1120 CHECK(val.size() == 1);
1121
1122 CHECK(val.removeMember(std::string("two")) == 2);
1123 CHECK(val.size() == 0);
1124
1126 CHECK(val.size() == 0);
1127}
1128
1129TEST_CASE("iterator")
1130{
1131 {
1132 // Iterating an array.
1134 arr[0u] = "zero";
1135 arr[1u] = "one";
1136 arr[2u] = "two";
1137 arr[3u] = "three";
1138
1139 Json::ValueIterator const b{arr.begin()};
1140 Json::ValueIterator const e{arr.end()};
1141
1142 Json::ValueIterator i1 = b;
1143 Json::ValueIterator i2 = e;
1144 --i2;
1145
1146 // key(), index(), and memberName() on an object iterator.
1147 CHECK(b != e);
1148 CHECK(!(b == e));
1149 CHECK(i1.key() == 0);
1150 CHECK(i2.key() == 3);
1151 CHECK(i1.index() == 0);
1152 CHECK(i2.index() == 3);
1153 CHECK(std::strcmp(i1.memberName(), "") == 0);
1154 CHECK(std::strcmp(i2.memberName(), "") == 0);
1155
1156 // Pre and post increment and decrement.
1157 *i1++ = "0";
1158 CHECK(*i1 == "one");
1159 *i1 = "1";
1160 ++i1;
1161
1162 *i2-- = "3";
1163 CHECK(*i2 == "two");
1164 CHECK(i1 == i2);
1165 *i2 = "2";
1166 CHECK(*i1 == "2");
1167 }
1168 {
1169 // Iterating a const object.
1170 Json::Value const obj{[]() {
1172 obj["0"] = 0;
1173 obj["1"] = 1;
1174 obj["2"] = 2;
1175 obj["3"] = 3;
1176 return obj;
1177 }()};
1178
1179 Json::ValueConstIterator i1{obj.begin()};
1180 Json::ValueConstIterator i2{obj.end()};
1181 --i2;
1182
1183 // key(), index(), and memberName() on an object iterator.
1184 CHECK(i1 != i2);
1185 CHECK(!(i1 == i2));
1186 CHECK(i1.key() == "0");
1187 CHECK(i2.key() == "3");
1188 CHECK(i1.index() == -1);
1189 CHECK(i2.index() == -1);
1190 CHECK(std::strcmp(i1.memberName(), "0") == 0);
1191 CHECK(std::strcmp(i2.memberName(), "3") == 0);
1192
1193 // Pre and post increment and decrement.
1194 CHECK(*i1++ == 0);
1195 CHECK(*i1 == 1);
1196 ++i1;
1197
1198 CHECK(*i2-- == 3);
1199 CHECK(*i2 == 2);
1200 CHECK(i1 == i2);
1201 CHECK(*i1 == 2);
1202 }
1203 {
1204 // Iterating a non-const null object.
1205 Json::Value nul{};
1206 CHECK(nul.begin() == nul.end());
1207 }
1208 {
1209 // Iterating a const Int.
1210 Json::Value const i{-3};
1211 CHECK(i.begin() == i.end());
1212 }
1213}
1214
1215TEST_CASE("nest limits")
1216{
1217 Json::Reader r;
1218 {
1219 auto nest = [](std::uint32_t depth) -> std::string {
1220 std::string s = "{";
1221 for (std::uint32_t i{1}; i <= depth; ++i)
1222 s += "\"obj\":{";
1223 for (std::uint32_t i{1}; i <= depth; ++i)
1224 s += "}";
1225 s += "}";
1226 return s;
1227 };
1228
1229 {
1230 // Within object nest limit
1231 auto json{nest(std::min(10u, Json::Reader::nest_limit))};
1232 Json::Value j;
1233 CHECK(r.parse(json, j));
1234 }
1235
1236 {
1237 // Exceed object nest limit
1238 auto json{nest(Json::Reader::nest_limit + 1)};
1239 Json::Value j;
1240 CHECK(!r.parse(json, j));
1241 }
1242 }
1243
1244 auto nest = [](std::uint32_t depth) -> std::string {
1245 std::string s = "{";
1246 for (std::uint32_t i{1}; i <= depth; ++i)
1247 s += "\"array\":[{";
1248 for (std::uint32_t i{1}; i <= depth; ++i)
1249 s += "]}";
1250 s += "}";
1251 return s;
1252 };
1253 {
1254 // Exceed array nest limit
1255 auto json{nest(Json::Reader::nest_limit + 1)};
1256 Json::Value j;
1257 CHECK(!r.parse(json, j));
1258 }
1259}
1260
1261TEST_CASE("memory leak")
1262{
1263 // When run with the address sanitizer, this test confirms there is no
1264 // memory leak with the scenarios below.
1265 {
1266 Json::Value a;
1267 a[0u] = 1;
1268 CHECK(a.type() == Json::arrayValue);
1269 CHECK(a[0u].type() == Json::intValue);
1270 a = std::move(a[0u]);
1271 CHECK(a.type() == Json::intValue);
1272 }
1273 {
1274 Json::Value b;
1275 Json::Value temp;
1276 temp["a"] = "Probably avoids the small string optimization";
1277 temp["b"] = "Also probably avoids the small string optimization";
1278 CHECK(temp.type() == Json::objectValue);
1279 b.append(temp);
1280 CHECK(temp.type() == Json::objectValue);
1281 CHECK(b.size() == 1);
1282
1283 b.append(std::move(temp));
1284 CHECK(b.size() == 2);
1285
1286 // Note that the type() == nullValue check is implementation
1287 // specific and not guaranteed to be valid in the future.
1288 CHECK(temp.type() == Json::nullValue);
1289 }
1290}
1291
1293
1294} // namespace ripple
Decorator for streaming out compact json.
Unserialize a JSON document into a Value.
Definition json_reader.h:39
static constexpr unsigned nest_limit
Definition json_reader.h:92
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Lightweight wrapper to tag static string.
Definition json_value.h:63
constexpr char const * c_str() const
Definition json_value.h:76
const iterator for object and array value.
Definition json_value.h:573
Value key() const
Return either the index or the member name of the referenced value as a Value.
char const * memberName() const
Return the member name of the referenced Value.
UInt index() const
Return the index of the referenced Value. -1 if it is not an arrayValue.
Iterator for object and array value.
Definition json_value.h:634
Represents a JSON value.
Definition json_value.h:149
bool isArray() const
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
bool isDouble() const
char const * asCString() const
Int asInt() const
bool isString() const
UInt asUInt() const
Members getMemberNames() const
Return a list of the member names.
ValueType type() const
bool isObject() const
Value removeMember(char const *key)
Remove and return the named member.
bool isValidIndex(UInt index) const
Return true if index < size().
std::string asString() const
Returns the unquoted string value.
bool isBool() const
bool asBool() const
bool isUInt() const
bool isNull() const
isNull() tests to see if this field is null.
bool isMember(char const *key) const
Return true if the object has a member named key.
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
bool isConvertibleTo(ValueType other) const
double asDouble() const
bool isInt() const
T count_if(T... args)
T empty(T... args)
T max(T... args)
T min(T... args)
ValueType
Type of the value held by a Value object.
Definition json_value.h:37
@ booleanValue
bool value
Definition json_value.h:43
@ nullValue
'null' value
Definition json_value.h:38
@ stringValue
UTF-8 string value.
Definition json_value.h:42
@ realValue
double value
Definition json_value.h:41
@ arrayValue
array value (ordered list)
Definition json_value.h:44
@ intValue
signed integer value
Definition json_value.h:39
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
@ uintValue
unsigned integer value
Definition json_value.h:40
int Int
unsigned int UInt
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
TEST_SUITE_END()
TEST_CASE("construct and compare Json::StaticString")
Definition Value.cpp:37
TEST_SUITE_BEGIN("json_value")
T regex_match(T... args)
T str(T... args)
T strcmp(T... args)
Thrown when a conversion is not possible with LexicalCast.
T to_string(T... args)