mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-04-06 02:45:02 +02:00
Fixed bugs in asInt64 and asUInt64.
This commit is contained in:
parent
3c9fdeb859
commit
4f081b50e6
@ -766,7 +766,7 @@ Value::asInt64() const
|
||||
return value_.uint_;
|
||||
case realValue:
|
||||
JSON_ASSERT_MESSAGE( value_.real_ >= minInt64 && value_.real_ <= maxInt64, "Real out of Int64 range" );
|
||||
return Int( value_.real_ );
|
||||
return Int64( value_.real_ );
|
||||
case booleanValue:
|
||||
return value_.bool_ ? 1 : 0;
|
||||
case stringValue:
|
||||
@ -794,7 +794,7 @@ Value::asUInt64() const
|
||||
return value_.uint_;
|
||||
case realValue:
|
||||
JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt64, "Real out of UInt64 range" );
|
||||
return UInt( value_.real_ );
|
||||
return UInt64( value_.real_ );
|
||||
case booleanValue:
|
||||
return value_.bool_ ? 1 : 0;
|
||||
case stringValue:
|
||||
|
@ -427,6 +427,67 @@ JSONTEST_FIXTURE( ValueTest, integers )
|
||||
JSONTEST_ASSERT( double(kuint64max) == val.asDouble());
|
||||
JSONTEST_ASSERT( float(kuint64max) == val.asFloat());
|
||||
#else // ifdef JSON_NO_INT64
|
||||
// 2^40 (signed constructor arg)
|
||||
val = Json::Value(1LL << 40);
|
||||
|
||||
checks = IsCheck();
|
||||
checks.isInt_ = true;
|
||||
checks.isNumeric_ = true;
|
||||
checks.isIntegral_ = true;
|
||||
JSONTEST_ASSERT_PRED( checkIs( val, checks ) );
|
||||
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asInt64());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asLargestInt());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asUInt64());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asLargestUInt());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asDouble());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asFloat());
|
||||
|
||||
// 2^40 (unsigned constructor arg)
|
||||
val = Json::Value(1ULL << 40);
|
||||
|
||||
checks = IsCheck();
|
||||
checks.isUInt_ = true;
|
||||
checks.isNumeric_ = true;
|
||||
checks.isIntegral_ = true;
|
||||
JSONTEST_ASSERT_PRED( checkIs( val, checks ) );
|
||||
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asInt64());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asLargestInt());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asUInt64());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asLargestUInt());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asDouble());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asFloat());
|
||||
|
||||
// 2^40 (floating-point constructor arg)
|
||||
val = Json::Value((1LL << 40) / 1.0);
|
||||
|
||||
checks = IsCheck();
|
||||
checks.isDouble_ = true;
|
||||
checks.isNumeric_ = true;
|
||||
JSONTEST_ASSERT_PRED( checkIs( val, checks ) );
|
||||
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asInt64());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asLargestInt());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asUInt64());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asLargestUInt());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asDouble());
|
||||
JSONTEST_ASSERT( (1LL << 40) == val.asFloat());
|
||||
|
||||
// -2^40
|
||||
val = Json::Value(-(1LL << 40));
|
||||
|
||||
checks = IsCheck();
|
||||
checks.isInt_ = true;
|
||||
checks.isNumeric_ = true;
|
||||
checks.isIntegral_ = true;
|
||||
JSONTEST_ASSERT_PRED( checkIs( val, checks ) );
|
||||
|
||||
JSONTEST_ASSERT( -(1LL << 40) == val.asInt64());
|
||||
JSONTEST_ASSERT( -(1LL << 40) == val.asLargestInt());
|
||||
JSONTEST_ASSERT( -(1LL << 40) == val.asDouble());
|
||||
JSONTEST_ASSERT( -(1LL << 40) == val.asFloat());
|
||||
|
||||
// int64 max
|
||||
val = Json::Value(Json::Int64(kint64max));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user