mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-16 18:56:52 +02:00
Copy JSON from SandBox to trunk
This commit is contained in:
807
JSON/testsuite/src/JSONTest.cpp
Normal file
807
JSON/testsuite/src/JSONTest.cpp
Normal file
@@ -0,0 +1,807 @@
|
||||
#include <set>
|
||||
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "Poco/JSON/Parser.h"
|
||||
#include "Poco/JSON/Query.h"
|
||||
#include "Poco/JSON/JSONException.h"
|
||||
#include "Poco/JSON/Stringifier.h"
|
||||
#include "Poco/JSON/DefaultHandler.h"
|
||||
//#include "Poco/Util/JSONConfiguration.h"
|
||||
#include "Poco/JSON/Template.h"
|
||||
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/Glob.h"
|
||||
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "CppUnit/TestRunner.h"
|
||||
|
||||
class JSONTest : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
JSONTest(const std::string& name): CppUnit::TestCase("JSON")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void testNullProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : null }";
|
||||
Poco::JSON::Parser parser;
|
||||
|
||||
Poco::DynamicAny result;
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
assert(object->isNull("test"));
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.isEmpty());
|
||||
}
|
||||
|
||||
void testTrueProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : true }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.type() == typeid(bool));
|
||||
bool value = test;
|
||||
assert(value);
|
||||
}
|
||||
|
||||
void testFalseProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : false }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.type() == typeid(bool));
|
||||
bool value = test;
|
||||
assert(!value);
|
||||
}
|
||||
|
||||
void testNumberProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : 1969 }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.isInteger());
|
||||
int value = test;
|
||||
assert(value == 1969);
|
||||
}
|
||||
|
||||
void testStringProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : \"value\" }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.isString());
|
||||
std::string value = test;
|
||||
assert(value.compare("value") == 0);
|
||||
}
|
||||
|
||||
void testEmptyObject()
|
||||
{
|
||||
std::string json = "{}";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
assert(object->size() == 0);
|
||||
}
|
||||
|
||||
void testDoubleProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : 123.45 }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.isNumeric());
|
||||
double value = test;
|
||||
assert(value == 123.45);
|
||||
}
|
||||
|
||||
void testDouble2Property()
|
||||
{
|
||||
std::string json = "{ \"test\" : 12e34 }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.isNumeric());
|
||||
double value = test;
|
||||
assert(value == 12e34);
|
||||
}
|
||||
|
||||
void testDouble3Property()
|
||||
{
|
||||
std::string json = "{ \"test\" : 12e-34 }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.isNumeric());
|
||||
double value = test;
|
||||
assert(value == 12e-34);
|
||||
}
|
||||
|
||||
void testObjectProperty()
|
||||
{
|
||||
std::string json = "{ \"test\" : { \"property\" : \"value\" } }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::DynamicAny test = object->get("test");
|
||||
assert(test.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
object = test.extract<Poco::JSON::Object::Ptr>();
|
||||
|
||||
test = object->get("property");
|
||||
assert(test.isString());
|
||||
std::string value = test;
|
||||
assert(value.compare("value") == 0);
|
||||
}
|
||||
|
||||
void testEmptyArray()
|
||||
{
|
||||
std::string json = "[]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
assert(array->size() == 0);
|
||||
}
|
||||
|
||||
void testNestedArray()
|
||||
{
|
||||
std::string json = "[[[[]]]]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
assert(array->size() == 1);
|
||||
}
|
||||
|
||||
void testNullElement()
|
||||
{
|
||||
std::string json = "[ null ]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
assert(array->isNull(0));
|
||||
Poco::DynamicAny test = array->get(0);
|
||||
assert(test.isEmpty());
|
||||
}
|
||||
|
||||
void testTrueElement()
|
||||
{
|
||||
std::string json = "[ true ]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
Poco::DynamicAny test = array->get(0);
|
||||
assert(test.type() == typeid(bool));
|
||||
bool value = test;
|
||||
assert(value);
|
||||
}
|
||||
|
||||
void testFalseElement()
|
||||
{
|
||||
std::string json = "[ false ]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
Poco::DynamicAny test = array->get(0);
|
||||
assert(test.type() == typeid(bool));
|
||||
bool value = test;
|
||||
assert(!value);
|
||||
}
|
||||
|
||||
void testNumberElement()
|
||||
{
|
||||
std::string json = "[ 1969 ]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
Poco::DynamicAny test = array->get(0);
|
||||
assert(test.isInteger());
|
||||
int value = test;
|
||||
assert(value == 1969);
|
||||
}
|
||||
|
||||
void testStringElement()
|
||||
{
|
||||
std::string json = "[ \"value\" ]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
Poco::DynamicAny test = array->get(0);
|
||||
assert(test.isString());
|
||||
std::string value = test;
|
||||
assert(value.compare("value") == 0);
|
||||
}
|
||||
|
||||
void testEmptyObjectElement()
|
||||
{
|
||||
std::string json = "[{}]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
Poco::JSON::Object::Ptr object = array->getObject(0);
|
||||
assert(object->size() == 0);
|
||||
}
|
||||
|
||||
void testDoubleElement()
|
||||
{
|
||||
std::string json = "[ 123.45 ]";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Array::Ptr));
|
||||
|
||||
Poco::JSON::Array::Ptr array = result.extract<Poco::JSON::Array::Ptr>();
|
||||
Poco::DynamicAny test = array->get(0);
|
||||
assert(test.isNumeric());
|
||||
double value = test;
|
||||
assert(value == 123.45);
|
||||
}
|
||||
|
||||
void testOptValue()
|
||||
{
|
||||
std::string json = "{ }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
|
||||
int n = object->optValue("test", 123);
|
||||
assert(n == 123);
|
||||
}
|
||||
|
||||
void testQuery()
|
||||
{
|
||||
std::string json = "{ \"name\" : \"Franky\", \"children\" : [ \"Jonas\", \"Ellen\" ] }";
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(json);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
assert(result.type() == typeid(Poco::JSON::Object::Ptr));
|
||||
|
||||
Poco::JSON::Query query(result);
|
||||
|
||||
std::string firstChild = query.findValue("children[0]", "");
|
||||
assert(firstChild.compare("Jonas") == 0);
|
||||
}
|
||||
|
||||
void testValidJanssonFiles()
|
||||
{
|
||||
Poco::Path pathPattern("/home/bronx/Development/mqweb/JSON/testsuite/testfiles/valid/*");
|
||||
std::set<std::string> paths;
|
||||
Poco::Glob::glob(pathPattern, paths);
|
||||
|
||||
for(std::set<std::string>::iterator it = paths.begin(); it != paths.end(); ++it)
|
||||
{
|
||||
Poco::Path filePath(*it, "input");
|
||||
|
||||
if ( filePath.isFile() )
|
||||
{
|
||||
Poco::File inputFile(filePath);
|
||||
if ( inputFile.exists() )
|
||||
{
|
||||
Poco::FileInputStream fis(filePath.toString());
|
||||
std::cout << filePath.toString() << std::endl;
|
||||
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(fis);
|
||||
result = handler.result();
|
||||
std::cout << "Ok!" << std::endl;
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
// We shouldn't get here.
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testInvalidJanssonFiles()
|
||||
{
|
||||
Poco::Path pathPattern("/home/bronx/Development/mqweb/JSON/testsuite/testfiles/invalid/*");
|
||||
std::set<std::string> paths;
|
||||
Poco::Glob::glob(pathPattern, paths);
|
||||
|
||||
for(std::set<std::string>::iterator it = paths.begin(); it != paths.end(); ++it)
|
||||
{
|
||||
Poco::Path filePath(*it, "input");
|
||||
|
||||
if ( filePath.isFile() )
|
||||
{
|
||||
Poco::File inputFile(filePath);
|
||||
if ( inputFile.exists() )
|
||||
{
|
||||
Poco::FileInputStream fis(filePath.toString());
|
||||
std::cout << filePath.toString() << std::endl;
|
||||
|
||||
Poco::JSON::Parser parser;
|
||||
Poco::DynamicAny result;
|
||||
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(fis);
|
||||
result = handler.result();
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << "Exception!!! " << jsone.message() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
void testConfiguration()
|
||||
{
|
||||
Poco::JSON::Configuration config;
|
||||
|
||||
std::string json = "{ \"config\" : "
|
||||
" { \"prop1\" : \"value1\", "
|
||||
" \"prop2\" : 10, "
|
||||
" \"prop3\" : [ \"element1\", \"element2\" ], "
|
||||
" \"prop4\" : { \"prop5\" : false, "
|
||||
" \"prop6\" : null } "
|
||||
"}"
|
||||
"}";
|
||||
|
||||
std::istringstream iss(json);
|
||||
try
|
||||
{
|
||||
config.load(iss);
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
std::string property1 = config.getString("config.prop1");
|
||||
assert(property1.compare("value1") == 0);
|
||||
|
||||
int property2 = config.getInt("config.prop2");
|
||||
assert(property2 == 10);
|
||||
|
||||
int nonExistingProperty = config.getInt("config.prop7", 5);
|
||||
assert(nonExistingProperty == 5);
|
||||
|
||||
std::string arrProperty = config.getString("config.prop3[1]");
|
||||
assert(arrProperty.compare("element2") == 0);
|
||||
|
||||
bool property35 = config.getBool("config.prop4.prop5");
|
||||
assert(! property35);
|
||||
|
||||
try
|
||||
{
|
||||
config.getString("propertyUnknown");
|
||||
assert(true);
|
||||
}
|
||||
catch(Poco::NotFoundException nfe)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
void testTemplate()
|
||||
{
|
||||
Poco::JSON::Template tpl;
|
||||
tpl.parse("Hello world! From <?= person.name ?>\n<?if person.toOld ?>You're to old<?endif?>\n");
|
||||
|
||||
Poco::JSON::Object::Ptr data = new Poco::JSON::Object();
|
||||
Poco::JSON::Object::Ptr person = new Poco::JSON::Object();
|
||||
data->set("person", person);
|
||||
person->set("name", "Franky");
|
||||
person->set("toOld", true);
|
||||
tpl.render(data, std::cout);
|
||||
}
|
||||
|
||||
void testItunes()
|
||||
{
|
||||
Poco::FileInputStream fis("/home/bronx/Development/search.json");
|
||||
Poco::JSON::Parser parser;
|
||||
try
|
||||
{
|
||||
Poco::JSON::DefaultHandler handler;
|
||||
parser.setHandler(&handler);
|
||||
parser.parse(fis);
|
||||
}
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << jsone.message();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static CppUnit::Test* suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("JSONTest");
|
||||
|
||||
CppUnit_addTest(pSuite, JSONTest, testNullProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testTrueProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testFalseProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testNumberProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testEmptyObject);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDoubleProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDouble2Property);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDouble3Property);
|
||||
CppUnit_addTest(pSuite, JSONTest, testObjectProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testEmptyArray);
|
||||
CppUnit_addTest(pSuite, JSONTest, testNestedArray);
|
||||
CppUnit_addTest(pSuite, JSONTest, testNullElement);
|
||||
CppUnit_addTest(pSuite, JSONTest, testTrueElement);
|
||||
CppUnit_addTest(pSuite, JSONTest, testFalseElement);
|
||||
CppUnit_addTest(pSuite, JSONTest, testNumberElement);
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringElement);
|
||||
CppUnit_addTest(pSuite, JSONTest, testEmptyObjectElement);
|
||||
CppUnit_addTest(pSuite, JSONTest, testDoubleElement);
|
||||
CppUnit_addTest(pSuite, JSONTest, testOptValue);
|
||||
CppUnit_addTest(pSuite, JSONTest, testQuery);
|
||||
//CppUnit_addTest(pSuite, JSONTest, testValidJanssonFiles);
|
||||
//CppUnit_addTest(pSuite, JSONTest, testInvalidJanssonFiles);
|
||||
|
||||
//CppUnit_addTest(pSuite, JSONTest, testConfiguration);
|
||||
CppUnit_addTest(pSuite, JSONTest, testTemplate);
|
||||
|
||||
//CppUnit_addTest(pSuite, JSONTest, testItunes);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
};
|
||||
|
||||
CppUnitMain(JSONTest)
|
@@ -0,0 +1 @@
|
||||
["<22><><EFBFBD> <-- encoded surrogate half"]
|
@@ -0,0 +1 @@
|
||||
["\<5C>"]
|
@@ -0,0 +1 @@
|
||||
[<5B>]
|
@@ -0,0 +1 @@
|
||||
[123<32>]
|
@@ -0,0 +1 @@
|
||||
["\u<>"]
|
@@ -0,0 +1 @@
|
||||
[1e1<65>]
|
@@ -0,0 +1 @@
|
||||
[a<>]
|
@@ -0,0 +1 @@
|
||||
[0<>]
|
@@ -0,0 +1 @@
|
||||
[1e<31>]
|
@@ -0,0 +1 @@
|
||||
["<22> <-- invalid UTF-8"]
|
@@ -0,0 +1 @@
|
||||
<EFBFBD>
|
@@ -0,0 +1 @@
|
||||
["<22>"]
|
@@ -0,0 +1 @@
|
||||
["<22><><EFBFBD><EFBFBD>"]
|
@@ -0,0 +1 @@
|
||||
["<22><><EFBFBD> <-- overlong encoding"]
|
@@ -0,0 +1 @@
|
||||
["<22><><EFBFBD><EFBFBD> <-- overlong encoding"]
|
@@ -0,0 +1 @@
|
||||
["<22>"]
|
@@ -0,0 +1 @@
|
||||
["<22>"]
|
@@ -0,0 +1 @@
|
||||
["<22><> <-- truncated UTF-8"]
|
1
JSON/testsuite/testfiles/invalid/apostrophe/input
Normal file
1
JSON/testsuite/testfiles/invalid/apostrophe/input
Normal file
@@ -0,0 +1 @@
|
||||
['
|
@@ -0,0 +1 @@
|
||||
aå
|
1
JSON/testsuite/testfiles/invalid/brace-comma/input
Normal file
1
JSON/testsuite/testfiles/invalid/brace-comma/input
Normal file
@@ -0,0 +1 @@
|
||||
{,
|
1
JSON/testsuite/testfiles/invalid/bracket-comma/input
Normal file
1
JSON/testsuite/testfiles/invalid/bracket-comma/input
Normal file
@@ -0,0 +1 @@
|
||||
[,
|
1
JSON/testsuite/testfiles/invalid/bracket-one-comma/input
Normal file
1
JSON/testsuite/testfiles/invalid/bracket-one-comma/input
Normal file
@@ -0,0 +1 @@
|
||||
[1,
|
0
JSON/testsuite/testfiles/invalid/empty/input
Normal file
0
JSON/testsuite/testfiles/invalid/empty/input
Normal file
@@ -0,0 +1 @@
|
||||
["\u0000 (null byte not allowed)"]
|
@@ -0,0 +1 @@
|
||||
[1,]
|
@@ -0,0 +1,6 @@
|
||||
[1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
]
|
@@ -0,0 +1,2 @@
|
||||
[1,2,3]
|
||||
foo
|
@@ -0,0 +1 @@
|
||||
[1,2,3]foo
|
@@ -0,0 +1 @@
|
||||
[012]
|
1
JSON/testsuite/testfiles/invalid/invalid-escape/input
Normal file
1
JSON/testsuite/testfiles/invalid/invalid-escape/input
Normal file
@@ -0,0 +1 @@
|
||||
["\a <-- invalid escape"]
|
@@ -0,0 +1 @@
|
||||
[troo
|
@@ -0,0 +1 @@
|
||||
[-123foo]
|
@@ -0,0 +1 @@
|
||||
[-123.123foo]
|
@@ -0,0 +1 @@
|
||||
["\uD888\u3210 (first surrogate and invalid second surrogate)"]
|
1
JSON/testsuite/testfiles/invalid/lone-open-brace/input
Normal file
1
JSON/testsuite/testfiles/invalid/lone-open-brace/input
Normal file
@@ -0,0 +1 @@
|
||||
{
|
1
JSON/testsuite/testfiles/invalid/lone-open-bracket/input
Normal file
1
JSON/testsuite/testfiles/invalid/lone-open-bracket/input
Normal file
@@ -0,0 +1 @@
|
||||
[
|
@@ -0,0 +1 @@
|
||||
["\uDFAA (second surrogate on it's own)"]
|
@@ -0,0 +1 @@
|
||||
[-foo]
|
@@ -0,0 +1 @@
|
||||
[-012]
|
BIN
JSON/testsuite/testfiles/invalid/null-byte-in-string/input
Normal file
BIN
JSON/testsuite/testfiles/invalid/null-byte-in-string/input
Normal file
Binary file not shown.
BIN
JSON/testsuite/testfiles/invalid/null-byte-outside-string/input
Normal file
BIN
JSON/testsuite/testfiles/invalid/null-byte-outside-string/input
Normal file
Binary file not shown.
1
JSON/testsuite/testfiles/invalid/null/input
Normal file
1
JSON/testsuite/testfiles/invalid/null/input
Normal file
@@ -0,0 +1 @@
|
||||
null
|
@@ -0,0 +1 @@
|
||||
{'a'
|
@@ -0,0 +1 @@
|
||||
{"a":"a" 123}
|
@@ -0,0 +1 @@
|
||||
[{}
|
1
JSON/testsuite/testfiles/invalid/object-no-colon/input
Normal file
1
JSON/testsuite/testfiles/invalid/object-no-colon/input
Normal file
@@ -0,0 +1 @@
|
||||
{"a"
|
1
JSON/testsuite/testfiles/invalid/object-no-value/input
Normal file
1
JSON/testsuite/testfiles/invalid/object-no-value/input
Normal file
@@ -0,0 +1 @@
|
||||
{"a":
|
@@ -0,0 +1 @@
|
||||
{"a":"a
|
@@ -0,0 +1 @@
|
||||
[1ea]
|
@@ -0,0 +1 @@
|
||||
[-123123e100000]
|
@@ -0,0 +1 @@
|
||||
[123123e100000]
|
@@ -0,0 +1 @@
|
||||
[1e]
|
@@ -0,0 +1 @@
|
||||
[1.]
|
@@ -0,0 +1 @@
|
||||
[" <-- tab character"]
|
@@ -0,0 +1 @@
|
||||
[-123123123123123123123123123123]
|
@@ -0,0 +1 @@
|
||||
[123123123123123123123123123123]
|
@@ -0,0 +1 @@
|
||||
["\uDADA (first surrogate without the second)"]
|
@@ -0,0 +1 @@
|
||||
å
|
@@ -0,0 +1 @@
|
||||
[{
|
@@ -0,0 +1 @@
|
||||
["a"
|
@@ -0,0 +1 @@
|
||||
{"
|
1
JSON/testsuite/testfiles/invalid/unterminated-key/input
Normal file
1
JSON/testsuite/testfiles/invalid/unterminated-key/input
Normal file
@@ -0,0 +1 @@
|
||||
{"a
|
@@ -0,0 +1 @@
|
||||
{[
|
@@ -0,0 +1 @@
|
||||
["a
|
5
JSON/testsuite/testfiles/valid/complex-array/input
Normal file
5
JSON/testsuite/testfiles/valid/complex-array/input
Normal file
@@ -0,0 +1,5 @@
|
||||
[1,2,3,4,
|
||||
"a", "b", "c",
|
||||
{"foo": "bar", "core": "dump"},
|
||||
true, false, true, true, null, false
|
||||
]
|
1
JSON/testsuite/testfiles/valid/empty-array/input
Normal file
1
JSON/testsuite/testfiles/valid/empty-array/input
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
@@ -0,0 +1 @@
|
||||
[{}]
|
1
JSON/testsuite/testfiles/valid/empty-object/input
Normal file
1
JSON/testsuite/testfiles/valid/empty-object/input
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
1
JSON/testsuite/testfiles/valid/empty-string/input
Normal file
1
JSON/testsuite/testfiles/valid/empty-string/input
Normal file
@@ -0,0 +1 @@
|
||||
[""]
|
@@ -0,0 +1 @@
|
||||
["\u0012 escaped control character"]
|
1
JSON/testsuite/testfiles/valid/false/input
Normal file
1
JSON/testsuite/testfiles/valid/false/input
Normal file
@@ -0,0 +1 @@
|
||||
[false]
|
1
JSON/testsuite/testfiles/valid/negative-int/input
Normal file
1
JSON/testsuite/testfiles/valid/negative-int/input
Normal file
@@ -0,0 +1 @@
|
||||
[-123]
|
1
JSON/testsuite/testfiles/valid/negative-one/input
Normal file
1
JSON/testsuite/testfiles/valid/negative-one/input
Normal file
@@ -0,0 +1 @@
|
||||
[-1]
|
1
JSON/testsuite/testfiles/valid/negative-zero/input
Normal file
1
JSON/testsuite/testfiles/valid/negative-zero/input
Normal file
@@ -0,0 +1 @@
|
||||
[-0]
|
1
JSON/testsuite/testfiles/valid/null/input
Normal file
1
JSON/testsuite/testfiles/valid/null/input
Normal file
@@ -0,0 +1 @@
|
||||
[null]
|
1
JSON/testsuite/testfiles/valid/one-byte-utf-8/input
Normal file
1
JSON/testsuite/testfiles/valid/one-byte-utf-8/input
Normal file
@@ -0,0 +1 @@
|
||||
["\u002c one-byte UTF-8"]
|
@@ -0,0 +1 @@
|
||||
[1E-2]
|
@@ -0,0 +1 @@
|
||||
[1E+2]
|
1
JSON/testsuite/testfiles/valid/real-capital-e/input
Normal file
1
JSON/testsuite/testfiles/valid/real-capital-e/input
Normal file
@@ -0,0 +1 @@
|
||||
[1E22]
|
1
JSON/testsuite/testfiles/valid/real-exponent/input
Normal file
1
JSON/testsuite/testfiles/valid/real-exponent/input
Normal file
@@ -0,0 +1 @@
|
||||
[123e45]
|
@@ -0,0 +1 @@
|
||||
[123.456e78]
|
@@ -0,0 +1 @@
|
||||
[1e-2]
|
@@ -0,0 +1 @@
|
||||
[1e+2]
|
1
JSON/testsuite/testfiles/valid/real-underflow/input
Normal file
1
JSON/testsuite/testfiles/valid/real-underflow/input
Normal file
@@ -0,0 +1 @@
|
||||
[123e-10000000]
|
1
JSON/testsuite/testfiles/valid/short-string/input
Normal file
1
JSON/testsuite/testfiles/valid/short-string/input
Normal file
@@ -0,0 +1 @@
|
||||
["a"]
|
1
JSON/testsuite/testfiles/valid/simple-ascii-string/input
Normal file
1
JSON/testsuite/testfiles/valid/simple-ascii-string/input
Normal file
@@ -0,0 +1 @@
|
||||
["abcdefghijklmnopqrstuvwxyz1234567890 "]
|
1
JSON/testsuite/testfiles/valid/simple-int-0/input
Normal file
1
JSON/testsuite/testfiles/valid/simple-int-0/input
Normal file
@@ -0,0 +1 @@
|
||||
[0]
|
1
JSON/testsuite/testfiles/valid/simple-int-1/input
Normal file
1
JSON/testsuite/testfiles/valid/simple-int-1/input
Normal file
@@ -0,0 +1 @@
|
||||
[1]
|
1
JSON/testsuite/testfiles/valid/simple-int-123/input
Normal file
1
JSON/testsuite/testfiles/valid/simple-int-123/input
Normal file
@@ -0,0 +1 @@
|
||||
[123]
|
1
JSON/testsuite/testfiles/valid/simple-object/input
Normal file
1
JSON/testsuite/testfiles/valid/simple-object/input
Normal file
@@ -0,0 +1 @@
|
||||
{"a":[]}
|
1
JSON/testsuite/testfiles/valid/simple-real/input
Normal file
1
JSON/testsuite/testfiles/valid/simple-real/input
Normal file
@@ -0,0 +1 @@
|
||||
[123.456789]
|
1
JSON/testsuite/testfiles/valid/string-escapes/input
Normal file
1
JSON/testsuite/testfiles/valid/string-escapes/input
Normal file
@@ -0,0 +1 @@
|
||||
["\"\\\/\b\f\n\r\t"]
|
1
JSON/testsuite/testfiles/valid/three-byte-utf-8/input
Normal file
1
JSON/testsuite/testfiles/valid/three-byte-utf-8/input
Normal file
@@ -0,0 +1 @@
|
||||
["\u0821 three-byte UTF-8"]
|
1
JSON/testsuite/testfiles/valid/true/input
Normal file
1
JSON/testsuite/testfiles/valid/true/input
Normal file
@@ -0,0 +1 @@
|
||||
[true]
|
1
JSON/testsuite/testfiles/valid/two-byte-utf-8/input
Normal file
1
JSON/testsuite/testfiles/valid/two-byte-utf-8/input
Normal file
@@ -0,0 +1 @@
|
||||
["\u0123 two-byte UTF-8"]
|
1
JSON/testsuite/testfiles/valid/utf-8-string/input
Normal file
1
JSON/testsuite/testfiles/valid/utf-8-string/input
Normal file
@@ -0,0 +1 @@
|
||||
["€þıœəßð some utf-8 ĸʒ×ŋµåäö𝄞"]
|
@@ -0,0 +1 @@
|
||||
["\uD834\uDD1E surrogate, four-byte UTF-8"]
|
Reference in New Issue
Block a user