mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 21:50:47 +01:00
few JSON fixes and tests
This commit is contained in:
@@ -342,6 +342,83 @@ void JSONTest::testEmptyObject()
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testComplexObject()
|
||||
{
|
||||
std::string json =
|
||||
"{"
|
||||
"\"id\": 1,"
|
||||
"\"jsonrpc\": \"2.0\","
|
||||
"\"total\": 1,"
|
||||
"\"result\": ["
|
||||
"{"
|
||||
"\"id\": 1,"
|
||||
"\"guid\": \"67acfb26-17eb-4a75-bdbd-f0669b7d8f73\","
|
||||
"\"picture\": \"http://placehold.it/32x32\","
|
||||
"\"age\": 40,"
|
||||
"\"name\": \"Angelina Crossman\","
|
||||
"\"gender\": \"female\","
|
||||
"\"company\": \"Raylog\","
|
||||
"\"phone\": \"892-470-2803\","
|
||||
"\"email\": \"angelina@raylog.com\","
|
||||
"\"address\": \"20726, CostaMesa, Horatio Streets\","
|
||||
"\"about\": \"Consectetuer suscipit volutpat eros dolor euismod, "
|
||||
"et dignissim in feugiat sed, ea tation exerci quis. Consectetuer, "
|
||||
"dolor dolore ad vero ullamcorper, tincidunt facilisis at in facilisi, "
|
||||
"iusto illum illum. Autem nibh, sed elit consequat volutpat tation, "
|
||||
"nisl lorem lorem sed tation, facilisis dolore. Augue odio molestie, "
|
||||
"dolor zzril nostrud aliquam sed, wisi dolor et ut iusto, ea. Magna "
|
||||
"ex qui facilisi, hendrerit quis in eros ut, zzril nibh dolore nisl "
|
||||
"suscipit, vulputate elit ut lobortis exerci, nulla dolore eros at "
|
||||
"aliquam, ullamcorper vero ad iusto. Adipiscing, nisl eros exerci "
|
||||
"nisl vel, erat in luptatum in duis, iusto.\","
|
||||
"\"registered\": \"2008-04-09T11:13:17 +05:00\","
|
||||
"\"tags\": ["
|
||||
"\"ut\","
|
||||
"\"accumsan\","
|
||||
"\"feugait\","
|
||||
"\"ex\","
|
||||
"\"odio\","
|
||||
"\"consequat\","
|
||||
"\"delenit\""
|
||||
"],"
|
||||
"\"friends\": ["
|
||||
"{"
|
||||
"\"id\": 1,"
|
||||
"\"name\": \"Hailey Hardman\""
|
||||
"},"
|
||||
"{"
|
||||
"\"id\": 2,"
|
||||
"\"name\": \"Bailey Oldridge\""
|
||||
"},"
|
||||
"{"
|
||||
"\"id\": 3,"
|
||||
"\"name\": \"Makayla Campbell\""
|
||||
"}"
|
||||
"]"
|
||||
"}"
|
||||
"]"
|
||||
"}";
|
||||
|
||||
Parser parser;
|
||||
Var result;
|
||||
|
||||
try
|
||||
{
|
||||
ParseHandler 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));
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testDoubleProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : 123.45 }";
|
||||
@@ -1273,14 +1350,17 @@ void JSONTest::testInvalidUnicodeJanssonFiles()
|
||||
void JSONTest::testTemplate()
|
||||
{
|
||||
Template tpl;
|
||||
tpl.parse("Hello world! From <?= person.name ?>\n<?if person.toOld ?>You're too old<?endif?>\n");
|
||||
tpl.parse("Hello world! From <?= person.name?>.\n<?if person.tooOld?>You're too old.<?endif?>");
|
||||
|
||||
Object::Ptr data = new Object();
|
||||
Object::Ptr person = new Object();
|
||||
data->set("person", person);
|
||||
person->set("name", "Franky");
|
||||
person->set("toOld", true);
|
||||
tpl.render(data, std::cout);
|
||||
person->set("tooOld", true);
|
||||
std::ostringstream ostr;
|
||||
tpl.render(data, ostr);
|
||||
std::cout << ostr.str();
|
||||
assert (ostr.str() == "Hello world! From Franky.\nYou're too old.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1363,6 +1443,7 @@ CppUnit::Test* JSONTest::suite()
|
||||
#endif
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testEmptyObject);
|
||||
CppUnit_addTest(pSuite, JSONTest, testComplexObject);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDoubleProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDouble2Property);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDouble3Property);
|
||||
|
||||
Reference in New Issue
Block a user