diff --git a/libjson/_internal/Source/JSONDefs.h~ b/libjson/_internal/Source/JSONDefs.h~ deleted file mode 100644 index 3a68fad..0000000 --- a/libjson/_internal/Source/JSONDefs.h~ +++ /dev/null @@ -1,184 +0,0 @@ -#ifndef JSONDEFS_H -#define JSONDEFS_H - -/* - Defines all of the types of functions and various other definitions - that are used in C applications, this is very useful if dynamically loading - the library instead of linking. -*/ - -#include "../../JSONOptions.h" -#include "JSONDefs/Unknown_C.h" -#include "JSONDefs/GNU_C.h" -#include "JSONDefs/Visual_C.h" -#include "JSONDefs/Strings_Defs.h" - -#define __LIBJSON_MAJOR__ 7 -#define __LIBJSON_MINOR__ 6 -#define __LIBJSON_PATCH__ 0 -#define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__) - -#define JSON_NULL '\0' -#define JSON_STRING '\1' -#define JSON_NUMBER '\2' -#define JSON_BOOL '\3' -#define JSON_ARRAY '\4' -#define JSON_NODE '\5' - -#ifdef __cplusplus - #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) - #include "JSONAllocator.h" - #else - #define json_allocator std::allocator - #endif - - #ifdef JSON_STRING_HEADER - #include JSON_STRING_HEADER - #else - typedef std::basic_string, json_allocator > json_string; - #endif -#endif -#define JSON_MAP(x, y) std::map, json_allocator > > - -#ifdef JSON_NO_EXCEPTIONS - #define json_throw(x) - #define json_try - #define json_catch(exception, code) -#else - #define json_throw(x) throw(x) - #define json_try try - #define json_catch(exception, code) catch(exception){ code } -#endif - -#ifdef JSON_STRICT - #ifndef JSON_UNICODE - #error, JSON_UNICODE is required for JSON_STRICT - #endif - #ifdef JSON_COMMENTS - #error, JSON_COMMENTS is required to be off for JSON_STRICT - #endif -#endif - -#ifdef JSON_ISO_STRICT - #ifdef JSON_UNICODE - #error, You can not use unicode under ANSI Strict C++ - #endif -#else - #ifdef __GNUC__ - #ifdef __STRICT_ANSI__ - #warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you - #define JSON_ISO_STRICT - #endif - #endif -#endif - - -#ifdef JSON_NUMBER_TYPE - typedef JSON_NUMBER_TYPE json_number; - #define JSON_FLOAT_THRESHHOLD 0.00001 -#else - #ifdef JSON_LESS_MEMORY - typedef float json_number; - #define JSON_FLOAT_THRESHHOLD 0.00001f - #else - typedef double json_number; - #define JSON_FLOAT_THRESHHOLD 0.00001 - #endif -#endif - - -#ifdef JSON_LESS_MEMORY - /* PACKED and BITS stored in compiler specific headers */ - #define START_MEM_SCOPE { - #define END_MEM_SCOPE } -#else - #define PACKED(x) - #define BITS(x) - #define START_MEM_SCOPE - #define END_MEM_SCOPE -#endif - -#if defined JSON_DEBUG || defined JSON_SAFE - #ifdef JSON_LIBRARY - typedef void (*json_error_callback_t)(const json_char *); - #else - typedef void (*json_error_callback_t)(const json_string &); - #endif -#endif - -#ifdef JSON_INDEX_TYPE - typedef JSON_INDEX_TYPE json_index_t; -#else - typedef unsigned int json_index_t; -#endif - -#ifdef JSON_BOOL_TYPE - typedef JSON_BOOL_TYPE json_bool_t; -#else - typedef int json_bool_t; -#endif - -#ifdef JSON_INT_TYPE - typedef JSON_INT_TYPE json_int_t; -#else - typedef long json_int_t; -#endif - -#define JSONSTREAM_SELF (void*)-1 -typedef void (*json_stream_e_callback_t)(void * identifier); - -typedef void (*json_mutex_callback_t)(void *); -typedef void (*json_free_t)(void *); -#ifndef JSON_LIBRARY - typedef void * (*json_malloc_t)(size_t); - typedef void * (*json_realloc_t)(void *, size_t); -#else - #define JSONNODE void /* so that JSONNODE* is void* */ - typedef JSONNODE** JSONNODE_ITERATOR; - #ifdef JSON_STREAM - #define JSONSTREAM void - typedef void (*json_stream_callback_t)(JSONNODE *, void * identifier); - #endif - typedef void * (*json_malloc_t)(unsigned long); - typedef void * (*json_realloc_t)(void *, unsigned long); -#endif - -#ifdef JSON_DEBUG - #ifdef NDEBUG - #ifdef __GNUC__ - #warning, Have JSON_DEBUG on in a release build - #else - #error, Have JSON_DEBUG on in a release build - #endif - #endif -#else - #ifndef NDEBUG - #ifdef __GNUC__ - #warning, Release build of libjson, but NDEBUG is not on - #else - #error, Release build of libjson, but NDEBUG is not on - #endif - #endif -#endif - -#ifdef JSON_UNIT_TEST - #define JSON_PRIVATE public: - #define JSON_PROTECTED public: -#else - #define JSON_PRIVATE private: - #define JSON_PROTECTED protected: -#endif -#ifdef JSON_STREAM - #ifndef JSON_READ_PRIORITY - #error, JSON_STREAM also requires JSON_READ_PRIORITY - #endif -#endif -#ifdef JSON_VALIDATE - #ifndef JSON_READ_PRIORITY - #error, JSON_VALIDATE also requires JSON_READ_PRIORITY - #endif -#endif - -#define JSON_TEMP_COMMENT_IDENTIFIER JSON_TEXT('#') - -#endif diff --git a/libjson/_internal/Source/NumberToString.h~ b/libjson/_internal/Source/NumberToString.h~ deleted file mode 100644 index c7ceabd..0000000 --- a/libjson/_internal/Source/NumberToString.h~ +++ /dev/null @@ -1,450 +0,0 @@ -#ifndef NUMBERTOSTRING_H -#define NUMBERTOSTRING_H - -#include -#include "JSONDebug.h" -#ifdef JSON_LESS_MEMORY - #include "JSONMemory.h" -#endif -#include "JSONSharedString.h" -#include -#ifdef JSON_STRICT - #include -#endif -template -struct getLenSize{ - char tmp[GETLENSIZE == 16]; // compile time assertion - enum {GETLEN = 41}; -}; - -template<> -struct getLenSize<1>{ - enum {GETLEN = 5}; -}; - -template <> -struct getLenSize<2>{ - enum {GETLEN = 7}; -}; - -template <> -struct getLenSize<4>{ - enum {GETLEN = 12}; -}; - -template <> -struct getLenSize<8>{ - enum {GETLEN = 22}; -}; - -static inline bool _floatsAreEqual(const json_number & one, const json_number & two) json_pure; -static inline bool _floatsAreEqual(const json_number & one, const json_number & two) json_nothrow { - return (one > two) ? (one - two) < JSON_FLOAT_THRESHHOLD : (one - two) > -JSON_FLOAT_THRESHHOLD; -} - -#ifdef JSON_LESS_MEMORY - #define num_str_result s.ptr -#endif - -class NumberToString { -public: - template - static json_string _itoa(T val) json_nothrow { - #ifdef JSON_LESS_MEMORY - json_auto s(getLenSize::GETLEN); - #else - json_char num_str_result[getLenSize::GETLEN]; - #endif - num_str_result[getLenSize::GETLEN - 1] = JSON_TEXT('\0'); //null terminator - json_char * runner = &num_str_result[getLenSize::GETLEN - 2]; - bool negative; - - START_MEM_SCOPE - long value = (long)val; - //first thing, check if it's negative, if so, make it positive - if (value < 0){ - value = -value; - negative = true; - } else { - negative = false; - } - - //create the string - do { - *runner-- = (json_char)(value % 10) + JSON_TEXT('0'); - } while(value /= 10); - END_MEM_SCOPE - - //if it's negative, add the negation - if (negative){ - *runner = JSON_TEXT('-'); - return json_string(runner); - } - return json_string(runner + 1); - } - - #ifndef JSON_LIBRARY - template - static json_string _uitoa(T val) json_nothrow { - #ifdef JSON_LESS_MEMORY - json_auto s(getLenSize::GETLEN); - #else - json_char num_str_result[getLenSize::GETLEN]; - #endif - num_str_result[getLenSize::GETLEN - 1] = JSON_TEXT('\0'); //null terminator - json_char * runner = &num_str_result[getLenSize::GETLEN - 2]; - - //create the string - START_MEM_SCOPE - unsigned long value = (unsigned long)val; - do { - *runner-- = (json_char)(value % 10) + JSON_TEXT('0'); - } while(value /= 10); - END_MEM_SCOPE - - return json_string(runner + 1); - } - #endif - - #ifdef JSON_ISO_STRICT - #define EXTRA_LONG - #define FLOAT_STRING "%f" - #define LFLOAT_STRING L"%f" - #else - #define EXTRA_LONG long - #define FLOAT_STRING "%Lf" - #define LFLOAT_STRING L"%Lf" - #endif - - static json_string _ftoa(json_number value) json_nothrow { - #ifndef JSON_LIBRARY - //ScopeCoverage(_ftoa_coverage, 6); - if (json_unlikely(value >= 0.0 && _floatsAreEqual(value, (json_number)((unsigned EXTRA_LONG long)value)))){ - return _uitoa((unsigned EXTRA_LONG long)value); - } else - #else - //ScopeCoverage(_ftoa_coverage, 5); - #endif - if (json_unlikely(_floatsAreEqual(value, (json_number)((long EXTRA_LONG)value)))){ - return _itoa((long EXTRA_LONG)value); - } - - #ifdef JSON_LESS_MEMORY - json_auto s(64); - #else - json_char num_str_result[64]; - #endif - #ifdef JSON_UNICODE - std::swprintf(num_str_result, 63, LFLOAT_STRING, (EXTRA_LONG double)value); - #else - //Thanks to Salvor Hardin for this Visual C++ fix - #ifdef _MSC_VER - _snprintf_s(num_str_result, 63, 63, FLOAT_STRING, (EXTRA_LONG double)value); //yes, 63 appears twice using _snprintf_s() - #else - std::snprintf(num_str_result, 63, FLOAT_STRING, (EXTRA_LONG double)value); - #endif - #endif - //strip the trailing zeros - for(json_char * pos = &num_str_result[0]; *pos; ++pos){ - if (json_unlikely(*pos == '.')){ //only care about after the decimal - for(json_char * runner = pos + 1; *runner; ++runner){ - if (json_likely(*runner != JSON_TEXT('0'))){ - pos = runner + 1; //have to go to the end 1.0001 - } - } - *pos = JSON_TEXT('\0'); - break; - } - } - return json_string(num_str_result); - } - - #if defined(JSON_SAFE) || defined(JSON_DEBUG) - static bool isNumeric(const json_string & str) json_nothrow { - const json_char * p = str.c_str(); - bool decimal = false; - bool scientific = false; - - #ifdef JSON_STRICT - bool leadingzero = false; - #endif - - //first letter is weird - switch(*p){ - case JSON_TEXT('\0'): - return false; - #ifndef JSON_STRICT - case JSON_TEXT('.'): - decimal = true; - break; - case JSON_TEXT('+'): - #endif - case JSON_TEXT('-'): - switch (*(p + 1)){ - case JSON_TEXT('.'): - case JSON_TEXT('e'): - case JSON_TEXT('E'): - case JSON_TEXT('\0'): - return false; - case JSON_TEXT('0'): - #ifdef JSON_STRICT - switch(*(p + 2)){ - case JSON_TEXT('.'): - case JSON_TEXT('e'): - case JSON_TEXT('E'): - leadingzero = false; - break; - case JSON_TEXT('\0'): - return true; - default: - leadingzero = true; - break; - } - #endif - ++p; - break; - default: - break; - } - break; - case JSON_TEXT('1'): - case JSON_TEXT('2'): - case JSON_TEXT('3'): - case JSON_TEXT('4'): - case JSON_TEXT('5'): - case JSON_TEXT('6'): - case JSON_TEXT('7'): - case JSON_TEXT('8'): - case JSON_TEXT('9'): - break; - case JSON_TEXT('0'): - ++p; - #ifdef JSON_STRICT - leadingzero = true; - #endif - switch(*p){ - case JSON_TEXT('.'): - decimal = true; - break; - case JSON_TEXT('e'): - case JSON_TEXT('E'): - #ifdef JSON_STRICT - leadingzero = false; //not leading, just a zero - #endif - scientific = true; - ++p; - switch(*p){ - case JSON_TEXT('\0'): - return false; - case JSON_TEXT('-'): - case JSON_TEXT('+'): - #ifndef JSON_STRICT - case JSON_TEXT('0'): //cant have a leading zero in scrict - #endif - case JSON_TEXT('1'): - case JSON_TEXT('2'): - case JSON_TEXT('3'): - case JSON_TEXT('4'): - case JSON_TEXT('5'): - case JSON_TEXT('6'): - case JSON_TEXT('7'): - case JSON_TEXT('8'): - case JSON_TEXT('9'): - break; - default: - return false; - } - break; - #ifndef JSON_STRICT - case JSON_TEXT('x'): - return (str.find_first_not_of(JSON_TEXT("0123456789ABCDEFabcdef"), 2) == json_string::npos); - case JSON_TEXT('1'): - case JSON_TEXT('2'): - case JSON_TEXT('3'): - case JSON_TEXT('4'): - case JSON_TEXT('5'): - case JSON_TEXT('6'): - case JSON_TEXT('7'): - return (str.find_first_not_of(JSON_TEXT("01234567"), 1) == json_string::npos); - #endif - case JSON_TEXT('\0'): //just 0 - return true; - default: - return false; - } - break; - default: - return false; - } - ++p; - - //next digits - while (*p){ - switch(*p){ - case JSON_TEXT('.'): - if (json_unlikely(decimal)){ - return false; //multiple decimals - } - - if (json_unlikely(scientific)){ - return false; - } - decimal = true; - break; - case JSON_TEXT('e'): - case JSON_TEXT('E'): - if (json_unlikely(scientific)){ - return false; - } - scientific = true; - ++p; - switch(*p){ - case JSON_TEXT('\0'): - return false; - case JSON_TEXT('-'): - case JSON_TEXT('+'): - if (!isdigit(*(p + 1))){ - return false; - } - - #ifdef JSON_STRICT - if (*(p + 1) == JSON_TEXT('0')){ //no leading zeros on scientific notations - return false; - } - #endif - break; - #ifndef JSON_STRICT - case JSON_TEXT('0'): //cant have a leading zero in scrict - #endif - case JSON_TEXT('1'): - case JSON_TEXT('2'): - case JSON_TEXT('3'): - case JSON_TEXT('4'): - case JSON_TEXT('5'): - case JSON_TEXT('6'): - case JSON_TEXT('7'): - case JSON_TEXT('8'): - case JSON_TEXT('9'): - break; - default: - return false; - } - break; - case JSON_TEXT('0'): - case JSON_TEXT('1'): - case JSON_TEXT('2'): - case JSON_TEXT('3'): - case JSON_TEXT('4'): - case JSON_TEXT('5'): - case JSON_TEXT('6'): - case JSON_TEXT('7'): - case JSON_TEXT('8'): - case JSON_TEXT('9'): - break; - default: - return false; - } - ++p; - } - #ifdef JSON_STRICT - if (leadingzero && !decimal){ - return false; - } - #endif - return true; - } - #endif - - #ifdef JSON_STRICT - //much faster because no octal or hex support - static json_number _atof (const json_char * num){ - json_number sign = (json_number)1.0; - - //sign - if (*num==JSON_TEXT('-')){ - sign = -1.0; - ++num; - } else { - } - - //skip leading zero if one - #if defined(JSON_SAFE) || defined(JSON_DEBUG) - bool _leadingzeros = *num == JSON_TEXT('0'); - bool _leadingdigits = false; - #endif - if (*num == JSON_TEXT('0')){ - ++num; - } - #ifdef JSON_STRICT - else if (json_likely(*num < JSON_TEXT('1') || *num > JSON_TEXT('9'))){ - return std::numeric_limits::signaling_NaN(); - } - #endif - - JSON_ASSERT_SAFE(*num != JSON_TEXT('0'), JSON_TEXT("multiple leading zeros"), return std::numeric_limits::signaling_NaN(); ); - - // Number - json_number n = (json_number)0.0; - if (json_likely(*num >= JSON_TEXT('1') && *num <= JSON_TEXT('9'))){ - #if defined(JSON_SAFE) || defined(JSON_DEBUG) - _leadingdigits = true; - #endif - do { - n = (n * 10.0) + (*num++ - JSON_TEXT('0')); - } while (*num >= JSON_TEXT('0') && *num <= JSON_TEXT('9')); - } else { - JSON_ASSERT_SAFE( - (*num) == JSON_TEXT('.') || //.xxx - (*num) == JSON_TEXT('e') || //0Exxx - (*num) == JSON_TEXT('E') || //0exxx - (*num) == JSON_TEXT('\0') //end of the number, just zero - , JSON_TEXT("first digit not a number, e, period, or terminator"), return std::numeric_limits::signaling_NaN(); ); - } - - // Fractional part - json_number scale = (json_number)0.0; - if (*num == JSON_TEXT('.')) { - JSON_ASSERT_SAFE(_leadingzeros || _leadingdigits, JSON_TEXT("period without leading anything"), return std::numeric_limits::signaling_NaN(); ); - ++num; - for(; *num >= JSON_TEXT('0') && *num <= JSON_TEXT('9');){ - n = (n * 10.0) + (*num++ - JSON_TEXT('0')); - --scale; - }; - } else { - JSON_ASSERT_SAFE(!_leadingzeros || n == 0, JSON_TEXT("leading zero on an int"), return std::numeric_limits::signaling_NaN(); ); - JSON_ASSERT_SAFE( - (*num) == JSON_TEXT('e') || //0Exxx - (*num) == JSON_TEXT('E') || //0exxx - (*num) == JSON_TEXT('\0') //end of the number, just zero - , JSON_TEXT("next char not an e or terminator"), return std::numeric_limits::signaling_NaN(); ); - } - - // Exponent - int subscale = 0, signsubscale = 1; - if (json_unlikely(*num == JSON_TEXT('e') || *num == JSON_TEXT('E'))){ - ++num; - switch(*num){ - case JSON_TEXT('+'): - ++num; - break; - case JSON_TEXT('-'): - signsubscale = -1; - ++num; - JSON_ASSERT_SAFE(*num != JSON_TEXT('0'), JSON_TEXT("negative cant be followed by leading zero even after E"), return std::numeric_limits::signaling_NaN(); ); - break; - default: - break; - } - JSON_ASSERT_SAFE(*num != JSON_TEXT('\0'), JSON_TEXT("no exponent for scientific notation"), return std::numeric_limits::signaling_NaN(); ); - while (*num >= JSON_TEXT('0') && *num <= JSON_TEXT('9')){ - subscale=(subscale * 10) + (*num++ - JSON_TEXT('0')); - } - } - - JSON_ASSERT_SAFE(*num == JSON_TEXT('\0'), JSON_TEXT("done with number, not at terminator"), return std::numeric_limits::signaling_NaN(); ); - return sign * n * pow((json_number)10.0, scale + subscale * signsubscale); // number = +/- number.fraction * 10^+/- exponent - } - #endif -}; - -#endif diff --git a/libjson/_internal/TestSuite/TestString.cpp~ b/libjson/_internal/TestSuite/TestString.cpp~ deleted file mode 100644 index 8b2ec8e..0000000 --- a/libjson/_internal/TestSuite/TestString.cpp~ +++ /dev/null @@ -1,197 +0,0 @@ -#include "TestSuite.h" - -#ifdef JSON_STRING_HEADER - #ifdef JSON_UNICODE - #include "UStringTest.h" - #else - #include "StringTest.h" - #endif -#else - //otherwise it will use the regular STL strings and act as a control - #include "../libjson.h" -#endif - -static void assertConstEmpty(const json_string & s){ - assertEquals(s.length(), 0); - assertTrue(s.empty()); - assertCStringSame(s.c_str(), JSON_TEXT("")); - assertEquals(s, s); - assertEquals(s, JSON_TEXT("")); -} - -static void assertEmpty(json_string & s){ - assertEquals(s.length(), 0); - assertTrue(s.empty()); - assertCStringSame(s.c_str(), JSON_TEXT("")); - assertEquals(s, s); - assertEquals(s, JSON_TEXT("")); - assertConstEmpty(s); -} - -static void assertSame(json_string & s, json_string & m){ - assertEquals(s, m); - assertCStringSame(s.c_str(), m.c_str()); - assertEquals(s.length(), m.length()); - s.swap(m); - assertEquals(s, m); - assertCStringSame(s.c_str(), m.c_str()); - assertEquals(s.length(), m.length()); -} - -static void assertDifferent(json_string & s, json_string & m){ - assertNotEquals(s, m); - assertCStringNotSame(s.c_str(), m.c_str()); -} - -void TestSuite::TestString(void){ - UnitTest::SetPrefix("TestString.cpp - Test String Class"); - { - json_string s; - assertEmpty(s); - } - - { - json_string s; - assertEmpty(s); - json_string m(s); - assertEmpty(m); - assertEmpty(s); - assertSame(s, m); - } - - { - json_string s(JSON_TEXT("hello")); - assertEquals(s.length(), 5); - assertFalse(s.empty()); - assertCStringSame(s.c_str(), JSON_TEXT("hello")); - assertEquals(s, s); - assertEquals(s, JSON_TEXT("hello")); - s.clear(); - assertEmpty(s); - } - - { - json_string s(5, 'h'); - assertEquals(s.length(), 5); - assertFalse(s.empty()); - assertCStringSame(s.c_str(), JSON_TEXT("hhhhh")); - assertEquals(s, s); - assertEquals(s, JSON_TEXT("hhhhh")); - s.clear(); - assertEmpty(s); - } - - { - json_string s(5, 'h'); - json_string m(s); - assertSame(s, m); - } - - { - json_string s(5, 'h'); - json_string m(s); - assertSame(s, m); - s.clear(); - assertEmpty(s); - assertEquals(s.length(), 0); - assertDifferent(s, m); - } - - - { - json_string s(JSON_TEXT("hello")); - json_string m = s; - assertSame(s, m); - m = s.substr(1, 3); - assertEquals(m.length(), 3); - assertEquals(m, JSON_TEXT("ell")); - } - - { - json_string s(JSON_TEXT("hello")); - json_string m = s; - assertSame(s, m); - m = s.substr(1); - assertEquals(m.length(), 4); - assertEquals(m, JSON_TEXT("ello")); - } - - { - json_string s(JSON_TEXT("hello")); - s += JSON_TEXT(" world"); - assertEquals(s.length(), 11); - assertEquals(s, JSON_TEXT("hello world")); - } - - - { - json_string s(JSON_TEXT("hello")); - json_string m = s + JSON_TEXT(" world ") + s; - assertEquals(m.length(), 17); - assertEquals(m, JSON_TEXT("hello world hello")); - } - - { - json_string s(JSON_TEXT("hello")); - s += 'a'; - s += 'a'; - s += 'a'; - s += 'a'; - assertEquals(s.length(), 9); - assertEquals(s, JSON_TEXT("helloaaaa")); - } - - { - json_string s(JSON_TEXT("hello world")); - size_t pos = s.find('w'); - assertEquals(pos, 6); - } - - { - json_string s(JSON_TEXT("hello world")); - size_t pos = s.find('z'); - assertEquals(pos, json_string::npos); - } - - { - json_string s(JSON_TEXT("hello world")); - size_t pos = s.find_first_not_of(JSON_TEXT("helo")); - assertEquals(pos, 5); - } - - { - json_string s(JSON_TEXT("hello world")); - size_t pos = s.find_first_of(JSON_TEXT("ol")); - assertEquals(pos, 2); - } - - { - json_string s(JSON_TEXT("hello world")); - s.erase(s.begin(), s.begin() + 3); - assertEquals(s, JSON_TEXT("lo world")); - } - - { - json_string s(JSON_TEXT("hello world"), 5); - assertEquals(s, JSON_TEXT("hello")); - } - - #ifndef JSON_LIBRARY - #ifndef JSON_STRING_HEADER - { - json_string s(JSON_TEXT("hello world")); - std::wstring wtest(L"hello world"); - std::string stest("hello world"); - assertEquals(libjson::to_std_string(s), stest); - assertEquals(stest, libjson::to_std_string(s)); - assertEquals(libjson::to_std_wstring(s), wtest); - assertEquals(wtest, libjson::to_std_wstring(s)); - - assertEquals(s, libjson::to_json_string(stest)); - assertEquals(libjson::to_json_string(stest), s); - assertEquals(s, libjson::to_json_string(wtest)); - assertEquals(libjson::to_json_string(wtest), s); - } - #endif - #endif -} diff --git a/libjson/_internal/TestSuite/TestSuite.h~ b/libjson/_internal/TestSuite/TestSuite.h~ deleted file mode 100644 index 5ada7dd..0000000 --- a/libjson/_internal/TestSuite/TestSuite.h~ +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef TESTSUITE_H -#define TESTSUITE_H - -#include "UnitTest.h" -#include "../JSONOptions.h" -#include "../libjson.h" -#include "../Source/JSONNode.h" - -#include -using namespace std; - -/* - This class tests libjson's internal working and it's - C++ interface -*/ - -#ifdef JSON_UNICODE - #define assertCStringSame(a, b) assertCStringEqualsW(a, b) - #define assertCStringNotSame(a, b) assertCStringNotEqualsW(a, b) -#else - #define assertCStringSame(a, b) assertCStringEquals(a, b) - #define assertCStringNotSame(a, b) assertCStringNotEquals(a, b) -#endif - - -class TestSuite { -public: - static void TestSelf(void); - static void TestString(void); - static void TestConverters(void); -#ifdef JSON_BINARY - static void TestBase64(void); -#endif - static void TestReferenceCounting(void); - static void TestConstructors(void); - static void TestAssigning(void); - static void TestEquality(void); - static void TestInequality(void); - static void TestChildren(void); - static void TestFunctions(void); - static void TestIterators(void); - static void TestInspectors(void); - static void TestNamespace(void); - static void TestValidator(void); - static void TestStreams(void); -#ifdef JSON_WRITE_PRIORITY - static void TestWriter(void); -#endif -#ifdef JSON_COMMENTS - static void TestComments(void); -#endif -#ifdef JSON_MUTEX_CALLBACKS - static void TestMutex(void); - static void TestThreading(void); -#endif - static void TestSharedString(void); - static void TestFinal(void); - - - - - -#ifdef JSON_LIBRARY - static void testParsingItself(JSONNODE * x){ - #if defined(JSON_WRITE_PRIORITY) && defined(JSON_READ_PRIORITY) - { - json_char * written = json_write(x); - JSONNODE * copy = json_parse(written); - assertTrue(json_equal(x, copy)); - json_delete(copy); - json_free(written); - } - { - json_char * written = json_write_formatted(x); - JSONNODE * copy = json_parse(written); - assertTrue(json_equal(x, copy)); - json_delete(copy); - json_free(written); - } - { - json_char * written = json_write_formatted(x); - json_char * written2 = json_write(x); - json_char * stripped = json_strip_white_space(written); - assertCStringSame(written2, stripped); - json_free(stripped); - json_free(written); - json_free(written2); - } - #endif - { - JSONNODE * copy = json_duplicate(x); - assertTrue(json_equal(x, copy)); - json_delete(copy); - } - } -#else - static void testParsingItself(JSONNode & x){ - #if defined(JSON_WRITE_PRIORITY) && defined(JSON_READ_PRIORITY) - assertEquals(libjson::parse(x.write()), x); - assertEquals(libjson::parse(x.write_formatted()), x); - assertEquals(libjson::strip_white_space(x.write_formatted()), x.write()); - #endif - assertEquals(x, x.duplicate()) - } -#endif -}; - -#endif - diff --git a/libjson/_internal/TestSuite/main.cpp~ b/libjson/_internal/TestSuite/main.cpp~ deleted file mode 100644 index cfe8f32..0000000 --- a/libjson/_internal/TestSuite/main.cpp~ +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include //for malloc, realloc, and free -#include "TestSuite.h" -#include "../libjson.h" - -void DoTests(void); -void DoTests(void){ - TestSuite::TestStreams(); - TestSuite::TestValidator(); - TestSuite::TestString(); - TestSuite::TestConverters(); - #ifdef JSON_BINARY - TestSuite::TestBase64(); - #endif - - TestSuite::TestReferenceCounting(); - TestSuite::TestConstructors(); - TestSuite::TestAssigning(); - TestSuite::TestEquality(); - TestSuite::TestInequality(); - TestSuite::TestChildren(); - TestSuite::TestFunctions(); - TestSuite::TestIterators(); - TestSuite::TestInspectors(); - TestSuite::TestNamespace(); - #ifdef JSON_WRITE_PRIORITY - TestSuite::TestWriter(); - #endif - #ifdef JSON_COMMENTS - TestSuite::TestComments(); - #endif - #ifdef JSON_MUTEX_CALLBACKS - TestSuite::TestMutex(); - TestSuite::TestThreading(); - #endif - TestSuite::TestSharedString(); - TestSuite::TestFinal(); -} - -#ifdef JSON_MEMORY_CALLBACKS - long mallocs = 0; - long reallocs = 0; - long frees = 0; - long bytes = 0; - - //used to check load - size_t maxBytes = 0; - size_t currentBytes = 0; - #ifdef JSON_LIBRARY - #define MEMTYPE unsigned long - #else - #define MEMTYPE size_t - #endif - #include - #include - std::map mem_mapping; - std::vector bytesallocated; - - void * testmal(MEMTYPE siz); - void * testmal(MEMTYPE siz){ - ++mallocs; - bytes += (long)siz; - currentBytes += siz; - if (currentBytes > maxBytes) maxBytes = currentBytes; - bytesallocated.push_back(currentBytes); - - void * res = std::malloc(siz); - mem_mapping[res] = siz; - return res; - } - - void testfree(void * ptr); - void testfree(void * ptr){ - ++frees; - - std::map::iterator i = mem_mapping.find(ptr); - if (i != mem_mapping.end()){ //globals - currentBytes -= mem_mapping[ptr]; - mem_mapping.erase(ptr); - } - - bytesallocated.push_back(currentBytes); - - std::free(ptr); - } - - void * testreal(void * ptr, MEMTYPE siz); - void * testreal(void * ptr, MEMTYPE siz){ - ++reallocs; - - std::map::iterator i = mem_mapping.find(ptr); - if (i != mem_mapping.end()){ //globals - currentBytes -= mem_mapping[ptr]; - mem_mapping.erase(ptr); - } - currentBytes += siz; - if (currentBytes > maxBytes) maxBytes = currentBytes; - bytesallocated.push_back(currentBytes); - - - void * res = std::realloc(ptr, siz); - mem_mapping[res] = siz; - return res; - } - - void doMemTests(void); - void doMemTests(void){ - #ifdef JSON_LIBRARY - json_register_memory_callbacks(testmal, testreal, testfree); - #else - libjson::register_memory_callbacks(testmal, testreal, testfree); - #endif - DoTests(); - echo("mallocs: " << mallocs); - echo("frees: " << frees); - echo("reallocs: " << reallocs); - echo("bytes: " << bytes << " (" << (int)(bytes / 1024) << " KB)"); - echo("max bytes at once: " << maxBytes << " (" << (int)(maxBytes / 1024) << " KB)"); - std::vector::iterator i = bytesallocated.begin(); - std::vector::iterator e = bytesallocated.end(); - size_t bbytes = 0; - for(; i != e; ++i){ - bbytes += *i; - } - bbytes = (size_t)(((double)bbytes) / ((double)bytesallocated.size())); - echo("avg bytes at once: " << bbytes << " (" << (int)(bbytes / 1024) << " KB)"); - echo("still allocated: " << currentBytes << " (" << (int)(currentBytes / 1024) << " KB) (Global variables)"); - assertEquals(mallocs, frees); - } -#endif - -#include "RunTestSuite2.h" - -int main () { - UnitTest::StartTime(); - TestSuite::TestSelf(); - - DoTests(); - - #ifdef JSON_MEMORY_CALLBACKS - doMemTests(); - #endif - - RunTestSuite2::RunTests(); - - UnitTest::SaveTo("out.html"); - - return 0; -} diff --git a/libjson/_internal/TestSuite2/JSONValidator/Resources/validyMacros.h~ b/libjson/_internal/TestSuite2/JSONValidator/Resources/validyMacros.h~ deleted file mode 100644 index 31ccee1..0000000 --- a/libjson/_internal/TestSuite2/JSONValidator/Resources/validyMacros.h~ +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef JSON_TESTSUITE_JSON_VALIDATOR_RESOURCES_VALIDITY_MACROS_H -#define JSON_TESTSUITE_JSON_VALIDATOR_RESOURCES_VALIDITY_MACROS_H - -#include "../../../JSONOptions.h" - -#ifdef JSON_VALIDATE - - #define assertValid(x, method, nextchar)\ - {\ - json_string temp(JSON_TEXT(x));\ - const json_char * ptr = temp.c_str();\ - assertTrue(JSONValidator::method(ptr) && ((*ptr)==JSON_TEXT(nextchar)));\ - } - - #define assertNotValid(x, method, nextchar)\ - {\ - json_string temp(JSON_TEXT(x));\ - const json_char * ptr = temp.c_str();\ - assertTrue(!JSONValidator::method(ptr) || ((*ptr)!=JSON_TEXT(nextchar)));\ - } - - #ifdef JSON_SECURITY_MAX_NEST_LEVEL - #define assertValid_Depth(x, method, nextchar)\ - {\ - json_string temp(JSON_TEXT(x));\ - const json_char * ptr = temp.c_str();\ - assertTrue(JSONValidator::method(ptr, 1) && ((*ptr)==JSON_TEXT(nextchar)));\ - } - - #define assertNotValid_Depth(x, method, nextchar)\ - {\ - json_string temp(JSON_TEXT(x));\ - const json_char * ptr = temp.c_str();\ - assertTrue(!JSONValidator::method(ptr, 1) || ((*ptr)!=JSON_TEXT(nextchar)));\ - } - #else - #define assertValid_Depth(x, method, nextchar) assertValid(x, method, nextchar) - #define assertNotValid_Depth(x, method, nextchar) assertNotValid(x, method, nextchar) - #endif - -#else - #define assertValid(x, method, nextchar) - #define assertNotValid(x, method, nextchar) - #define assertValid_Depth(x, method, nextchar) - #define assertNotValid_Depth(x, method, nextchar) -#endif - -#endif