@@ -76,6 +76,8 @@ struct ValueTest : JsonTest::TestCase {
76
76
Json::Value float_{0 .00390625f };
77
77
Json::Value array1_;
78
78
Json::Value object1_;
79
+ Json::Value object2_;
80
+ Json::Value object3_;
79
81
Json::Value emptyString_{" " };
80
82
Json::Value string1_{" a" };
81
83
Json::Value string_{" sometext with space" };
@@ -85,6 +87,34 @@ struct ValueTest : JsonTest::TestCase {
85
87
ValueTest () {
86
88
array1_.append (1234 );
87
89
object1_[" id" ] = 1234 ;
90
+
91
+ // object2 with matching values
92
+ object2_[" null" ] = Json::nullValue;
93
+ object2_[" bool" ] = true ;
94
+ object2_[" int" ] = Json::Int{Json::Value::maxInt};
95
+ object2_[" int64" ] = Json::Int64{Json::Value::maxInt64};
96
+ object2_[" uint" ] = Json::UInt{Json::Value::maxUInt};
97
+ object2_[" uint64" ] = Json::UInt64 {Json::Value::maxUInt64};
98
+ object2_[" integral" ] = 1234 ;
99
+ object2_[" double" ] = 1234.56789 ;
100
+ object2_[" numeric" ] = 0 .12345f ;
101
+ object2_[" string" ] = " string" ;
102
+ object2_[" array" ] = Json::arrayValue;
103
+ object2_[" object" ] = Json::objectValue;
104
+
105
+ // object3 with not matching values
106
+ object3_[" object" ] = Json::nullValue;
107
+ object3_[" null" ] = true ;
108
+ object3_[" bool" ] = Json::Int{Json::Value::maxInt};
109
+ object3_[" int" ] = " not_an_int" ;
110
+ object3_[" int64" ] = " not_an_int64" ;
111
+ object3_[" uint" ] = " not_an_uint" ;
112
+ object3_[" uin64" ] = " not_an_uint64" ;
113
+ object3_[" integral" ] = 1234.56789 ;
114
+ object3_[" double" ] = false ;
115
+ object3_[" numeric" ] = " string" ;
116
+ object3_[" string" ] = Json::arrayValue;
117
+ object3_[" array" ] = Json::objectValue;
88
118
}
89
119
90
120
struct IsCheck {
@@ -234,6 +264,62 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, objects) {
234
264
const Json::Value* stringFoundUnknownId = object1_.find (stringUnknownIdKey);
235
265
JSONTEST_ASSERT_EQUAL (nullptr , stringFoundUnknownId);
236
266
267
+ // Access through find<Type>()
268
+ const Json::Value* nullFound = object2_.findNull (" null" );
269
+ JSONTEST_ASSERT (nullFound != nullptr );
270
+ JSONTEST_ASSERT_EQUAL (Json::nullValue, *nullFound);
271
+ JSONTEST_ASSERT (object3_.findNull (" null" ) == nullptr );
272
+
273
+ const Json::Value* boolFound = object2_.findBool (" bool" );
274
+ JSONTEST_ASSERT (boolFound != nullptr );
275
+ JSONTEST_ASSERT_EQUAL (true , *boolFound);
276
+ JSONTEST_ASSERT (object3_.findBool (" bool" ) == nullptr );
277
+
278
+ const Json::Value* intFound = object2_.findInt (" int" );
279
+ JSONTEST_ASSERT (intFound != nullptr );
280
+ JSONTEST_ASSERT_EQUAL (Json::Int{Json::Value::maxInt}, *intFound);
281
+ JSONTEST_ASSERT (object3_.findInt (" int" ) == nullptr );
282
+
283
+ const Json::Value* int64Found = object2_.findInt64 (" int64" );
284
+ JSONTEST_ASSERT (int64Found != nullptr );
285
+ JSONTEST_ASSERT_EQUAL (Json::Int64{Json::Value::maxInt64}, *int64Found);
286
+ JSONTEST_ASSERT (object3_.findInt64 (" int64" ) == nullptr );
287
+
288
+ const Json::Value* uintFound = object2_.findUInt (" uint" );
289
+ JSONTEST_ASSERT (uintFound != nullptr );
290
+ JSONTEST_ASSERT_EQUAL (Json::UInt{Json::Value::maxUInt}, *uintFound);
291
+ JSONTEST_ASSERT (object3_.findUInt (" uint" ) == nullptr );
292
+
293
+ const Json::Value* uint64Found = object2_.findUInt64 (" uint64" );
294
+ JSONTEST_ASSERT (uint64Found != nullptr );
295
+ JSONTEST_ASSERT_EQUAL (Json::UInt64 {Json::Value::maxUInt64}, *uint64Found);
296
+ JSONTEST_ASSERT (object3_.findUInt64 (" uint64" ) == nullptr );
297
+
298
+ const Json::Value* integralFound = object2_.findIntegral (" integral" );
299
+ JSONTEST_ASSERT (integralFound != nullptr );
300
+ JSONTEST_ASSERT_EQUAL (1234 , *integralFound);
301
+ JSONTEST_ASSERT (object3_.findIntegral (" integral" ) == nullptr );
302
+
303
+ const Json::Value* doubleFound = object2_.findDouble (" double" );
304
+ JSONTEST_ASSERT (doubleFound != nullptr );
305
+ JSONTEST_ASSERT_EQUAL (1234.56789 , *doubleFound);
306
+ JSONTEST_ASSERT (object3_.findDouble (" double" ) == nullptr );
307
+
308
+ const Json::Value* numericFound = object2_.findNumeric (" numeric" );
309
+ JSONTEST_ASSERT (numericFound != nullptr );
310
+ JSONTEST_ASSERT_EQUAL (0 .12345f , *numericFound);
311
+ JSONTEST_ASSERT (object3_.findNumeric (" numeric" ) == nullptr );
312
+
313
+ const Json::Value* stringFound = object2_.findString (" string" );
314
+ JSONTEST_ASSERT (stringFound != nullptr );
315
+ JSONTEST_ASSERT_EQUAL (std::string{" string" }, *stringFound);
316
+ JSONTEST_ASSERT (object3_.findString (" string" ) == nullptr );
317
+
318
+ const Json::Value* arrayFound = object2_.findArray (" array" );
319
+ JSONTEST_ASSERT (arrayFound != nullptr );
320
+ JSONTEST_ASSERT_EQUAL (Json::arrayValue, *arrayFound);
321
+ JSONTEST_ASSERT (object3_.findArray (" array" ) == nullptr );
322
+
237
323
// Access through demand()
238
324
const char yetAnotherIdKey[] = " yet another id" ;
239
325
const Json::Value* foundYetAnotherId =
0 commit comments