Added float Json::Value::asFloat() to obtain a floating point value as a float (avoid lost of precision warning caused by used of asDouble() to initialize a float).

This commit is contained in:
Baptiste Lepilleur
2010-12-24 19:30:06 +00:00
parent fa130ef871
commit b96aed0f3e
4 changed files with 42 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ struct ValueTest : JsonTest::TestCase
Json::Value unsignedInteger_;
Json::Value smallUnsignedInteger_;
Json::Value real_;
Json::Value float_;
Json::Value array1_;
Json::Value object1_;
Json::Value emptyString_;
@@ -43,6 +44,7 @@ struct ValueTest : JsonTest::TestCase
, smallUnsignedInteger_( Json::Value::UInt( Json::Value::maxInt ) )
, unsignedInteger_( 34567890u )
, real_( 1234.56789 )
, float_( 0.00390625f )
, emptyString_( "" )
, string1_( "a" )
, string_( "sometext with space" )
@@ -184,6 +186,11 @@ JSONTEST_FIXTURE( ValueTest, accessArray )
}
JSONTEST_FIXTURE( ValueTest, asFloat )
{
JSONTEST_ASSERT_EQUAL( 0.00390625f, float_.asFloat() ) << "Json::Value::asFloat()";
}
void
ValueTest::checkConstMemberCount( const Json::Value &value, unsigned int expectedCount )
{
@@ -259,5 +266,6 @@ int main( int argc, const char *argv[] )
JSONTEST_REGISTER_FIXTURE( runner, ValueTest, isNull );
JSONTEST_REGISTER_FIXTURE( runner, ValueTest, isNull );
JSONTEST_REGISTER_FIXTURE( runner, ValueTest, accessArray );
JSONTEST_REGISTER_FIXTURE( runner, ValueTest, asFloat );
return runner.runCommandLine( argc, argv );
}