mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-17 01:15:59 +01:00
@@ -161,7 +161,7 @@ inline bool Object::has(const std::string& key) const
|
||||
inline bool Object::isArray(const std::string& key) const
|
||||
{
|
||||
ValueMap::const_iterator it = _values.find(key);
|
||||
return it != _values.end() || it->second.type() == typeid(Array::Ptr);
|
||||
return it != _values.end() && it->second.type() == typeid(Array::Ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ inline bool Object::isNull(const std::string& key) const
|
||||
inline bool Object::isObject(const std::string& key) const
|
||||
{
|
||||
ValueMap::const_iterator it = _values.find(key);
|
||||
return it != _values.end() || it->second.type() == typeid(Object::Ptr);
|
||||
return it != _values.end() && it->second.type() == typeid(Object::Ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -366,8 +366,11 @@ void JSONTest::testObjectProperty()
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Object::Ptr));
|
||||
|
||||
|
||||
Object::Ptr object = result.extract<Object::Ptr>();
|
||||
assert (object->isObject("test"));
|
||||
assert (!object->isArray("test"));
|
||||
|
||||
Var test = object->get("test");
|
||||
assert(test.type() == typeid(Object::Ptr));
|
||||
object = test.extract<Object::Ptr>();
|
||||
@@ -379,6 +382,36 @@ void JSONTest::testObjectProperty()
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testObjectArray()
|
||||
{
|
||||
std::string json = "{ \"test\" : { \"test1\" : [1, 2, 3], \"test2\" : 4 } }";
|
||||
Parser parser;
|
||||
Var result;
|
||||
|
||||
try
|
||||
{
|
||||
DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(JSONException& jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Object::Ptr));
|
||||
Object::Ptr object = result.extract<Object::Ptr>();
|
||||
assert(object->isObject("test"));
|
||||
object = object->getObject("test");
|
||||
assert(!object->isObject("test1"));
|
||||
assert(object->isArray("test1"));
|
||||
assert(!object->isObject("test2"));
|
||||
assert(!object->isArray("test2"));
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testEmptyArray()
|
||||
{
|
||||
std::string json = "[]";
|
||||
@@ -833,6 +866,7 @@ CppUnit::Test* JSONTest::suite()
|
||||
CppUnit_addTest(pSuite, JSONTest, testDouble2Property);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDouble3Property);
|
||||
CppUnit_addTest(pSuite, JSONTest, testObjectProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testObjectArray);
|
||||
CppUnit_addTest(pSuite, JSONTest, testEmptyArray);
|
||||
CppUnit_addTest(pSuite, JSONTest, testNestedArray);
|
||||
CppUnit_addTest(pSuite, JSONTest, testNullElement);
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
void testDouble2Property();
|
||||
void testDouble3Property();
|
||||
void testObjectProperty();
|
||||
void testObjectArray();
|
||||
void testEmptyArray();
|
||||
void testNestedArray();
|
||||
void testNullElement();
|
||||
|
||||
Reference in New Issue
Block a user