mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-22 16:02:29 +02:00
Fix JSON parsing of large unsigned 64-bit integers
This commit is contained in:
@@ -192,12 +192,42 @@ void JSONTest::testNumberProperty()
|
||||
assert(value == 1969);
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testUnsignedNumberProperty()
|
||||
{
|
||||
// 4294967295 == unsigned(-1)
|
||||
std::string json = "{ \"test\" : 4294967295 }";
|
||||
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>();
|
||||
Var test = object->get("test");
|
||||
assert(test.isInteger());
|
||||
unsigned value = test;
|
||||
assert(value == -1);
|
||||
}
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
|
||||
void JSONTest::testNumber64Property()
|
||||
{
|
||||
std::string json = "{ \"test\" : 5000000000000000 }";
|
||||
std::string json = "{ \"test\" : -5000000000000000 }";
|
||||
Parser parser;
|
||||
Var result;
|
||||
|
||||
@@ -220,10 +250,39 @@ void JSONTest::testNumber64Property()
|
||||
Var test = object->get("test");
|
||||
assert(test.isInteger());
|
||||
Poco::Int64 value = test;
|
||||
assert(value == 5000000000000000);
|
||||
assert(value == -5000000000000000);
|
||||
}
|
||||
|
||||
|
||||
void JSONTest::testUnsignedNumber64Property()
|
||||
{
|
||||
// 18446744073709551615 == UInt64(-1)
|
||||
std::string json = "{ \"test\" : 18446744073709551615 }";
|
||||
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>();
|
||||
Var test = object->get("test");
|
||||
assert(test.isInteger());
|
||||
Poco::UInt64 value = test;
|
||||
assert(value == -1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -962,8 +1021,10 @@ CppUnit::Test* JSONTest::suite()
|
||||
CppUnit_addTest(pSuite, JSONTest, testTrueProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testFalseProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testNumberProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testUnsignedNumberProperty);
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
CppUnit_addTest(pSuite, JSONTest, testNumber64Property);
|
||||
CppUnit_addTest(pSuite, JSONTest, testUnsignedNumber64Property);
|
||||
#endif
|
||||
CppUnit_addTest(pSuite, JSONTest, testStringProperty);
|
||||
CppUnit_addTest(pSuite, JSONTest, testEmptyObject);
|
||||
|
@@ -50,8 +50,10 @@ public:
|
||||
void testTrueProperty();
|
||||
void testFalseProperty();
|
||||
void testNumberProperty();
|
||||
void testUnsignedNumberProperty();
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
void testNumber64Property();
|
||||
void testUnsignedNumber64Property();
|
||||
#endif
|
||||
void testStringProperty();
|
||||
void testEmptyObject();
|
||||
|
Reference in New Issue
Block a user