json test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers assertions.h Source File

assertions.h

00001 // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
00002 // Distributed under MIT license, or public domain if desired and
00003 // recognized in your jurisdiction.
00004 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
00005 
00006 #ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
00007 #define CPPTL_JSON_ASSERTIONS_H_INCLUDED
00008 
00009 #include <stdlib.h>
00010 #include <sstream>
00011 
00012 #if !defined(JSON_IS_AMALGAMATION)
00013 #include "config.h"
00014 #endif // if !defined(JSON_IS_AMALGAMATION)
00015 
00016 /** It should not be possible for a maliciously designed file to
00017  *  cause an abort() or seg-fault, so these macros are used only
00018  *  for pre-condition violations and internal logic errors.
00019  */
00020 #if JSON_USE_EXCEPTION
00021 
00022 // @todo <= add detail about condition in exception
00023 # define JSON_ASSERT(condition)                                                \
00024   {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
00025 
00026 # define JSON_FAIL_MESSAGE(message)                                            \
00027   {                                                                            \
00028     JSONCPP_OSTRINGSTREAM oss; oss << message;                                    \
00029     Json::throwLogicError(oss.str());                                          \
00030     abort();                                                                   \
00031   }
00032 
00033 #else // JSON_USE_EXCEPTION
00034 
00035 # define JSON_ASSERT(condition) assert(condition)
00036 
00037 // The call to assert() will show the failure message in debug builds. In
00038 // release builds we abort, for a core-dump or debugger.
00039 # define JSON_FAIL_MESSAGE(message)                                            \
00040   {                                                                            \
00041     JSONCPP_OSTRINGSTREAM oss; oss << message;                                    \
00042     assert(false && oss.str().c_str());                                        \
00043     abort();                                                                   \
00044   }
00045 
00046 
00047 #endif
00048 
00049 #define JSON_ASSERT_MESSAGE(condition, message)                                \
00050   if (!(condition)) {                                                          \
00051     JSON_FAIL_MESSAGE(message);                                                \
00052   }
00053 
00054 #endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED