From 0158bd9ab97f4a4fa8d7770f4137905a3503b224 Mon Sep 17 00:00:00 2001 From: montellese Date: Fri, 28 Jan 2011 14:08:12 +0100 Subject: JSONRPC: update of jsoncpp library to latest revision --- lib/jsoncpp/src/jsontestrunner/main.cpp | 88 +++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 26 deletions(-) (limited to 'lib/jsoncpp/src/jsontestrunner/main.cpp') diff --git a/lib/jsoncpp/src/jsontestrunner/main.cpp b/lib/jsoncpp/src/jsontestrunner/main.cpp index 231ee0c44d..2da3ede9ea 100644 --- a/lib/jsoncpp/src/jsontestrunner/main.cpp +++ b/lib/jsoncpp/src/jsontestrunner/main.cpp @@ -1,3 +1,12 @@ +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +/* This executable is used for testing parser/writer using real JSON files. + */ + + #include #include // sort #include @@ -35,10 +44,10 @@ printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." ) fprintf( fout, "%s=null\n", path.c_str() ); break; case Json::intValue: - fprintf( fout, "%s=%d\n", path.c_str(), value.asInt() ); + fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestInt() ).c_str() ); break; case Json::uintValue: - fprintf( fout, "%s=%u\n", path.c_str(), value.asUInt() ); + fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestUInt() ).c_str() ); break; case Json::realValue: fprintf( fout, "%s=%.16g\n", path.c_str(), value.asDouble() ); @@ -148,6 +157,19 @@ removeSuffix( const std::string &path, return path.substr( 0, path.length() - extension.length() ); } + +static void +printConfig() +{ + // Print the configuration used to compile JsonCpp +#if defined(JSON_NO_INT64) + printf( "JSON_NO_INT64=1\n" ); +#else + printf( "JSON_NO_INT64=0\n" ); +#endif +} + + static int printUsage( const char *argv[] ) { @@ -175,6 +197,12 @@ parseCommandLine( int argc, const char *argv[], ++index; } + if ( std::string(argv[1]) == "--json-config" ) + { + printConfig(); + return 3; + } + if ( index == argc || index + 1 < argc ) { return printUsage( argv ); @@ -196,37 +224,45 @@ int main( int argc, const char *argv[] ) return exitCode; } - std::string input = readInputTestFile( path.c_str() ); - if ( input.empty() ) + try { - printf( "Failed to read input or empty input: %s\n", path.c_str() ); - return 3; - } + std::string input = readInputTestFile( path.c_str() ); + if ( input.empty() ) + { + printf( "Failed to read input or empty input: %s\n", path.c_str() ); + return 3; + } - std::string basePath = removeSuffix( argv[1], ".json" ); - if ( !parseOnly && basePath.empty() ) - { - printf( "Bad input path. Path does not end with '.expected':\n%s\n", path.c_str() ); - return 3; - } + std::string basePath = removeSuffix( argv[1], ".json" ); + if ( !parseOnly && basePath.empty() ) + { + printf( "Bad input path. Path does not end with '.expected':\n%s\n", path.c_str() ); + return 3; + } - std::string actualPath = basePath + ".actual"; - std::string rewritePath = basePath + ".rewrite"; - std::string rewriteActualPath = basePath + ".actual-rewrite"; + std::string actualPath = basePath + ".actual"; + std::string rewritePath = basePath + ".rewrite"; + std::string rewriteActualPath = basePath + ".actual-rewrite"; - Json::Value root; - exitCode = parseAndSaveValueTree( input, actualPath, "input", root, features, parseOnly ); - if ( exitCode == 0 && !parseOnly ) - { - std::string rewrite; - exitCode = rewriteValueTree( rewritePath, root, rewrite ); - if ( exitCode == 0 ) + Json::Value root; + exitCode = parseAndSaveValueTree( input, actualPath, "input", root, features, parseOnly ); + if ( exitCode == 0 && !parseOnly ) { - Json::Value rewriteRoot; - exitCode = parseAndSaveValueTree( rewrite, rewriteActualPath, - "rewrite", rewriteRoot, features, parseOnly ); + std::string rewrite; + exitCode = rewriteValueTree( rewritePath, root, rewrite ); + if ( exitCode == 0 ) + { + Json::Value rewriteRoot; + exitCode = parseAndSaveValueTree( rewrite, rewriteActualPath, + "rewrite", rewriteRoot, features, parseOnly ); + } } } + catch ( const std::exception &e ) + { + printf( "Unhandled exception:\n%s\n", e.what() ); + exitCode = 1; + } return exitCode; } -- cgit v1.2.3