1+ #include < iostream>
12// Copyright 2007-2010 Baptiste Lepilleur
23// Distributed under MIT license, or public domain if desired and
34// recognized in your jurisdiction.
@@ -213,6 +214,31 @@ JSONTEST_FIXTURE(ValueTest, objects) {
213214 JSONTEST_ASSERT_EQUAL (false , did);
214215}
215216
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+ }
216242JSONTEST_FIXTURE (ValueTest, arrays) {
217243 const unsigned int index0 = 0 ;
218244
@@ -1585,8 +1611,9 @@ JSONTEST_FIXTURE(ValueTest, CommentBefore) {
15851611}
15861612
15871613JSONTEST_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 ());
15901617 Json::StreamWriterBuilder b;
15911618 {
15921619 Json::Value root;
@@ -1600,26 +1627,26 @@ JSONTEST_FIXTURE(ValueTest, zeroes) {
16001627 JSONTEST_ASSERT_STRING_EQUAL (binary, root[top].asString ());
16011628 Json::Value removed;
16021629 bool did;
1603- did = root.removeMember (top, top + 3U ,
1630+ did = root.removeMember (top, top + sizeof (top) - 1U ,
16041631 &removed);
16051632 JSONTEST_ASSERT (did);
16061633 JSONTEST_ASSERT_STRING_EQUAL (binary, removed.asString ());
1607- did = root.removeMember (top, top + 3U ,
1634+ did = root.removeMember (top, top + sizeof (top) - 1U ,
16081635 &removed);
16091636 JSONTEST_ASSERT (!did);
16101637 JSONTEST_ASSERT_STRING_EQUAL (binary, removed.asString ()); // still
16111638 }
16121639}
16131640
16141641JSONTEST_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 ()) ;
16181645 {
16191646 Json::Value root;
16201647 root[binary] = " there" ;
16211648 JSONTEST_ASSERT_STRING_EQUAL (" there" , root[binary].asString ());
1622- JSONTEST_ASSERT (!root.isMember (" hi " ));
1649+ JSONTEST_ASSERT (!root.isMember (" h " ));
16231650 JSONTEST_ASSERT (root.isMember (binary));
16241651 JSONTEST_ASSERT_STRING_EQUAL (" there" , root.get (binary, Json::Value::nullRef).asString ());
16251652 Json::Value removed;
@@ -2306,6 +2333,7 @@ int main(int argc, const char* argv[]) {
23062333 JSONTEST_REGISTER_FIXTURE (runner, ValueTest, typeChecksThrowExceptions);
23072334 JSONTEST_REGISTER_FIXTURE (runner, ValueTest, StaticString);
23082335 JSONTEST_REGISTER_FIXTURE (runner, ValueTest, CommentBefore);
2336+ // JSONTEST_REGISTER_FIXTURE(runner, ValueTest, nulls);
23092337 JSONTEST_REGISTER_FIXTURE (runner, ValueTest, zeroes);
23102338 JSONTEST_REGISTER_FIXTURE (runner, ValueTest, zeroesInKeys);
23112339
0 commit comments