aboutsummaryrefslogtreecommitdiff
path: root/lib/jsoncpp/src/jsontestrunner/main.cpp
diff options
context:
space:
mode:
authormontellese <montellese@xbmc.org>2011-01-28 14:08:12 +0100
committermontellese <montellese@xbmc.org>2011-04-01 20:35:50 +0200
commit0158bd9ab97f4a4fa8d7770f4137905a3503b224 (patch)
treec457e66ff0e2eb2a7e2121e3e2d7719dfc8c73cc /lib/jsoncpp/src/jsontestrunner/main.cpp
parent97b5e9f770405d37ce0f6ca95f538e80fefe18aa (diff)
JSONRPC: update of jsoncpp library to latest revision
Diffstat (limited to 'lib/jsoncpp/src/jsontestrunner/main.cpp')
-rw-r--r--lib/jsoncpp/src/jsontestrunner/main.cpp88
1 files changed, 62 insertions, 26 deletions
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 <json/json.h>
#include <algorithm> // sort
#include <stdio.h>
@@ -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;
}