mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 14:24:35 +01:00
enh(JSON): Add unit test testBasicJson to test basic functionality of the JSON parser. #3331 (#4315)
This commit is contained in:
parent
57bc0bbbb5
commit
4cfa96c94e
@ -1806,6 +1806,43 @@ void JSONTest::testVarConvert()
|
||||
assertTrue(cvt == "[1,2,3]");
|
||||
}
|
||||
|
||||
void JSONTest::testBasicJson()
|
||||
{
|
||||
// Tests basic JSON structure and accessibility of members
|
||||
|
||||
const auto json = R"(
|
||||
{
|
||||
"clientConfig" : "Franky",
|
||||
"arrayMember": [1, "A", 3.5],
|
||||
"objectMember": {
|
||||
"a": 1,
|
||||
"b": "B"
|
||||
}
|
||||
}
|
||||
)";
|
||||
Poco::JSON::Parser jsonParser;
|
||||
Poco::Dynamic::Var jsonObject = jsonParser.parse(json);
|
||||
|
||||
Poco::JSON::Object::Ptr jsonPtr = jsonObject.extract<Poco::JSON::Object::Ptr>();
|
||||
|
||||
assertFalse(jsonPtr->get("clientConfig").isEmpty());
|
||||
const auto testStr = jsonPtr->getValue<std::string>("clientConfig");
|
||||
assertEqual(testStr, "Franky");
|
||||
|
||||
const auto testArr = jsonPtr->getArray("arrayMember");
|
||||
assertFalse(testArr.isNull());
|
||||
assertFalse(testArr->empty());
|
||||
assertEqual(testArr->size(), 3);
|
||||
assertEqual(testArr->getElement<int>(0), 1);
|
||||
assertEqual(testArr->getElement<std::string>(1), "A");
|
||||
|
||||
const auto testObj = jsonPtr->getObject("objectMember");
|
||||
assertFalse(testObj.isNull());
|
||||
assertEqual(testObj->size(), 2);
|
||||
assertEqual(testObj->getValue<int>("a"), 1);
|
||||
assertEqual(testObj->getValue<std::string>("b"), "B");
|
||||
|
||||
}
|
||||
|
||||
void JSONTest::testValidJanssonFiles()
|
||||
{
|
||||
@ -2375,6 +2412,7 @@ CppUnit::Test* JSONTest::suite()
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringifyNaN);
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringifyPreserveOrder);
|
||||
CppUnit_addTest(pSuite, JSONTest, testVarConvert);
|
||||
CppUnit_addTest(pSuite, JSONTest, testBasicJson);
|
||||
CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles);
|
||||
CppUnit_addTest(pSuite, JSONTest, testInvalidJanssonFiles);
|
||||
CppUnit_addTest(pSuite, JSONTest, testInvalidUnicodeJanssonFiles);
|
||||
|
@ -71,6 +71,8 @@ public:
|
||||
void testStringifyPreserveOrder();
|
||||
void testVarConvert();
|
||||
|
||||
void testBasicJson();
|
||||
|
||||
void testValidJanssonFiles();
|
||||
void testInvalidJanssonFiles();
|
||||
void testTemplate();
|
||||
|
Loading…
x
Reference in New Issue
Block a user