1
+ #include < iostream>
1
2
// Copyright 2007-2010 Baptiste Lepilleur
2
3
// Distributed under MIT license, or public domain if desired and
3
4
// recognized in your jurisdiction.
@@ -213,6 +214,31 @@ JSONTEST_FIXTURE(ValueTest, objects) {
213
214
JSONTEST_ASSERT_EQUAL (false , did);
214
215
}
215
216
217
+ JSONTEST_FIXTURE (ValueTest, nulls) {
218
+ static char const keyWithNulls[] = " key\0 with\0 nulls" ;
219
+ std::string const strKeyWithNulls (keyWithNulls, sizeof keyWithNulls);
220
+ object1_[strKeyWithNulls] = " object1_[keyWithNulls]" ;
221
+ Json::Value::Members f = object1_.getMemberNames ();
222
+ std::cout << " size:" << f.size () << " \n " ;
223
+ for (int i=0 ; i<f.size (); ++i) {
224
+ std::cout << f[i].size () << " :" << f[i] << " \n " ;
225
+ }
226
+ // abort();
227
+ Json::Value const & o = object1_;
228
+ Json::Value const & temp = o[strKeyWithNulls];
229
+ JSONTEST_ASSERT_EQUAL (Json::Value (" object1_[keyWithNulls]" ), temp);
230
+ JSONTEST_ASSERT (object1_.isMember (keyWithNulls, keyWithNulls + strKeyWithNulls.length ()));
231
+ // JSONTEST_ASSERT(object1_.isMember(keyWithNulls, keyWithNulls + sizeof(keyWithNulls)));
232
+ JSONTEST_ASSERT (!object1_.isMember (" key" ));
233
+
234
+ Json::Value got;
235
+ bool did;
236
+ did = object1_.removeMember (strKeyWithNulls, &got);
237
+ JSONTEST_ASSERT_EQUAL (Json::Value (" object1_[keyWithNulls]" ), got);
238
+ JSONTEST_ASSERT_EQUAL (true , did);
239
+ did = object1_.removeMember (strKeyWithNulls, &got);
240
+ JSONTEST_ASSERT_EQUAL (false , did);
241
+ }
216
242
JSONTEST_FIXTURE (ValueTest, arrays) {
217
243
const unsigned int index0 = 0 ;
218
244
@@ -1585,8 +1611,9 @@ JSONTEST_FIXTURE(ValueTest, CommentBefore) {
1585
1611
}
1586
1612
1587
1613
JSONTEST_FIXTURE (ValueTest, zeroes) {
1588
- std::string binary (" hi" , 3 ); // include trailing 0
1589
- JSONTEST_ASSERT_EQUAL (3 , binary.length ());
1614
+ char const cstr[] = " h\0 i" ;
1615
+ std::string binary (cstr, sizeof (cstr)); // include trailing 0
1616
+ JSONTEST_ASSERT_EQUAL (4U , binary.length ());
1590
1617
Json::StreamWriterBuilder b;
1591
1618
{
1592
1619
Json::Value root;
@@ -1600,26 +1627,26 @@ JSONTEST_FIXTURE(ValueTest, zeroes) {
1600
1627
JSONTEST_ASSERT_STRING_EQUAL (binary, root[top].asString ());
1601
1628
Json::Value removed;
1602
1629
bool did;
1603
- did = root.removeMember (top, top + 3U ,
1630
+ did = root.removeMember (top, top + sizeof (top) - 1U ,
1604
1631
&removed);
1605
1632
JSONTEST_ASSERT (did);
1606
1633
JSONTEST_ASSERT_STRING_EQUAL (binary, removed.asString ());
1607
- did = root.removeMember (top, top + 3U ,
1634
+ did = root.removeMember (top, top + sizeof (top) - 1U ,
1608
1635
&removed);
1609
1636
JSONTEST_ASSERT (!did);
1610
1637
JSONTEST_ASSERT_STRING_EQUAL (binary, removed.asString ()); // still
1611
1638
}
1612
1639
}
1613
1640
1614
1641
JSONTEST_FIXTURE (ValueTest, zeroesInKeys) {
1615
- std::string binary ( " hi " , 3 ); // include trailing 0
1616
- JSONTEST_ASSERT_EQUAL ( 3 , binary. length ( ));
1617
- Json::StreamWriterBuilder b ;
1642
+ char const cstr[] = " h \0 i " ;
1643
+ std::string binary (cstr, sizeof (cstr )); // include trailing 0
1644
+ JSONTEST_ASSERT_EQUAL ( 4U , binary. length ()) ;
1618
1645
{
1619
1646
Json::Value root;
1620
1647
root[binary] = " there" ;
1621
1648
JSONTEST_ASSERT_STRING_EQUAL (" there" , root[binary].asString ());
1622
- JSONTEST_ASSERT (!root.isMember (" hi " ));
1649
+ JSONTEST_ASSERT (!root.isMember (" h " ));
1623
1650
JSONTEST_ASSERT (root.isMember (binary));
1624
1651
JSONTEST_ASSERT_STRING_EQUAL (" there" , root.get (binary, Json::Value::nullRef).asString ());
1625
1652
Json::Value removed;
@@ -2306,6 +2333,7 @@ int main(int argc, const char* argv[]) {
2306
2333
JSONTEST_REGISTER_FIXTURE (runner, ValueTest, typeChecksThrowExceptions);
2307
2334
JSONTEST_REGISTER_FIXTURE (runner, ValueTest, StaticString);
2308
2335
JSONTEST_REGISTER_FIXTURE (runner, ValueTest, CommentBefore);
2336
+ // JSONTEST_REGISTER_FIXTURE(runner, ValueTest, nulls);
2309
2337
JSONTEST_REGISTER_FIXTURE (runner, ValueTest, zeroes);
2310
2338
JSONTEST_REGISTER_FIXTURE (runner, ValueTest, zeroesInKeys);
2311
2339
0 commit comments