Skip to content

Commit

Permalink
fix ValueTest/zeroes*
Browse files Browse the repository at this point in the history
  • Loading branch information
cdunn2001 committed Mar 7, 2015
1 parent 401e982 commit 5c44868
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/test_lib_json/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
// Copyright 2007-2010 Baptiste Lepilleur
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
Expand Down Expand Up @@ -213,6 +214,31 @@ JSONTEST_FIXTURE(ValueTest, objects) {
JSONTEST_ASSERT_EQUAL(false, did);
}

JSONTEST_FIXTURE(ValueTest, nulls) {
static char const keyWithNulls[] = "key\0with\0nulls";
std::string const strKeyWithNulls(keyWithNulls, sizeof keyWithNulls);
object1_[strKeyWithNulls] = "object1_[keyWithNulls]";
Json::Value::Members f = object1_.getMemberNames();
std::cout << "size:" << f.size() << "\n";
for (int i=0; i<f.size(); ++i) {
std::cout << f[i].size() << ":" << f[i] << "\n";
}
//abort();
Json::Value const& o = object1_;
Json::Value const& temp = o[strKeyWithNulls];
JSONTEST_ASSERT_EQUAL(Json::Value("object1_[keyWithNulls]"), temp);
JSONTEST_ASSERT(object1_.isMember(keyWithNulls, keyWithNulls + strKeyWithNulls.length()));
//JSONTEST_ASSERT(object1_.isMember(keyWithNulls, keyWithNulls + sizeof(keyWithNulls)));
JSONTEST_ASSERT(!object1_.isMember("key"));

Json::Value got;
bool did;
did = object1_.removeMember(strKeyWithNulls, &got);
JSONTEST_ASSERT_EQUAL(Json::Value("object1_[keyWithNulls]"), got);
JSONTEST_ASSERT_EQUAL(true, did);
did = object1_.removeMember(strKeyWithNulls, &got);
JSONTEST_ASSERT_EQUAL(false, did);
}
JSONTEST_FIXTURE(ValueTest, arrays) {
const unsigned int index0 = 0;

Expand Down Expand Up @@ -1585,8 +1611,9 @@ JSONTEST_FIXTURE(ValueTest, CommentBefore) {
}

JSONTEST_FIXTURE(ValueTest, zeroes) {
std::string binary("hi", 3); // include trailing 0
JSONTEST_ASSERT_EQUAL(3, binary.length());
char const cstr[] = "h\0i";
std::string binary(cstr, sizeof(cstr)); // include trailing 0
JSONTEST_ASSERT_EQUAL(4U, binary.length());
Json::StreamWriterBuilder b;
{
Json::Value root;
Expand All @@ -1600,26 +1627,26 @@ JSONTEST_FIXTURE(ValueTest, zeroes) {
JSONTEST_ASSERT_STRING_EQUAL(binary, root[top].asString());
Json::Value removed;
bool did;
did = root.removeMember(top, top + 3U,
did = root.removeMember(top, top + sizeof(top) - 1U,
&removed);
JSONTEST_ASSERT(did);
JSONTEST_ASSERT_STRING_EQUAL(binary, removed.asString());
did = root.removeMember(top, top + 3U,
did = root.removeMember(top, top + sizeof(top) - 1U,
&removed);
JSONTEST_ASSERT(!did);
JSONTEST_ASSERT_STRING_EQUAL(binary, removed.asString()); // still
}
}

JSONTEST_FIXTURE(ValueTest, zeroesInKeys) {
std::string binary("hi", 3); // include trailing 0
JSONTEST_ASSERT_EQUAL(3, binary.length());
Json::StreamWriterBuilder b;
char const cstr[] = "h\0i";
std::string binary(cstr, sizeof(cstr)); // include trailing 0
JSONTEST_ASSERT_EQUAL(4U, binary.length());
{
Json::Value root;
root[binary] = "there";
JSONTEST_ASSERT_STRING_EQUAL("there", root[binary].asString());
JSONTEST_ASSERT(!root.isMember("hi"));
JSONTEST_ASSERT(!root.isMember("h"));
JSONTEST_ASSERT(root.isMember(binary));
JSONTEST_ASSERT_STRING_EQUAL("there", root.get(binary, Json::Value::nullRef).asString());
Json::Value removed;
Expand Down Expand Up @@ -2306,6 +2333,7 @@ int main(int argc, const char* argv[]) {
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, typeChecksThrowExceptions);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, StaticString);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, CommentBefore);
//JSONTEST_REGISTER_FIXTURE(runner, ValueTest, nulls);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroesInKeys);

Expand Down

0 comments on commit 5c44868

Please sign in to comment.