├── src ├── plugin.def ├── libjson │ ├── ._JSONOptions.h │ ├── Documentation.pdf │ ├── _internal │ │ ├── Source │ │ │ ├── ._JSONDefs │ │ │ ├── ._JSONDebug.h │ │ │ ├── ._JSONDefs.h │ │ │ ├── ._JSONNode.h │ │ │ ├── ._JSONStats.h │ │ │ ├── ._libjson.cpp │ │ │ ├── ._JSONChildren.h │ │ │ ├── ._JSONDebug.cpp │ │ │ ├── ._JSONGlobals.h │ │ │ ├── ._JSONMemory.cpp │ │ │ ├── ._JSONMemory.h │ │ │ ├── ._JSONNode.cpp │ │ │ ├── ._JSONPreparse.h │ │ │ ├── ._JSONStream.cpp │ │ │ ├── ._JSONStream.h │ │ │ ├── ._JSONWorker.cpp │ │ │ ├── ._JSONWorker.h │ │ │ ├── ._JSONWriter.cpp │ │ │ ├── ._JSON_Base64.h │ │ │ ├── ._JSONAllocator.h │ │ │ ├── ._JSONChildren.cpp │ │ │ ├── ._JSONMemoryPool.h │ │ │ ├── ._JSONPreparse.cpp │ │ │ ├── ._JSONSingleton.h │ │ │ ├── ._JSONValidator.h │ │ │ ├── ._NumberToString.h │ │ │ ├── JSONDefs │ │ │ │ ├── ._GNU_C.h │ │ │ │ ├── ._Visual_C.h │ │ │ │ ├── ._Unknown_C.h │ │ │ │ ├── ._Strings_Defs.h │ │ │ │ ├── Unknown_C.h │ │ │ │ ├── Visual_C.h │ │ │ │ ├── Strings_Defs.h │ │ │ │ └── GNU_C.h │ │ │ ├── ._JSONAllocator.cpp │ │ │ ├── ._JSONIterators.cpp │ │ │ ├── ._JSONNode_Mutex.cpp │ │ │ ├── ._JSONSharedString.h │ │ │ ├── ._internalJSONNode.h │ │ │ ├── ._internalJSONNode.cpp │ │ │ ├── JSONAllocator.cpp │ │ │ ├── JSONSingleton.h │ │ │ ├── JSONPreparse.h │ │ │ ├── JSON_Base64.h │ │ │ ├── JSONDebug.cpp │ │ │ ├── JSONMemoryPool.h │ │ │ ├── JSONValidator.h │ │ │ ├── JSONDebug.h │ │ │ ├── JSONAllocator.h │ │ │ ├── JSONStream.h │ │ │ ├── JSONWorker.h │ │ │ ├── JSONStats.h │ │ │ ├── JSONGlobals.h │ │ │ ├── JSONChildren.cpp │ │ │ ├── JSONStream.cpp │ │ │ ├── JSONDefs.h │ │ │ └── JSONDefs.h~ │ │ ├── Dependencies │ │ │ ├── ._mempool++ │ │ │ ├── ._libbase64++ │ │ │ ├── mempool++ │ │ │ │ └── ._mempool.h │ │ │ └── libbase64++ │ │ │ │ └── ._libbase64++.h │ │ ├── TestSuite │ │ │ ├── TestSuite.xcodeproj │ │ │ │ ├── ._xcuserdata │ │ │ │ ├── ._wallace.mode1v3 │ │ │ │ ├── ._wallace.pbxuser │ │ │ │ ├── ._project.xcworkspace │ │ │ │ ├── project.xcworkspace │ │ │ │ │ ├── ._xcuserdata │ │ │ │ │ ├── xcuserdata │ │ │ │ │ │ ├── ._wallace.xcuserdatad │ │ │ │ │ │ └── wallace.xcuserdatad │ │ │ │ │ │ │ └── WorkspaceSettings.xcsettings │ │ │ │ │ └── contents.xcworkspacedata │ │ │ │ └── xcuserdata │ │ │ │ │ ├── ._wallace.xcuserdatad │ │ │ │ │ └── wallace.xcuserdatad │ │ │ │ │ ├── ._xcdebugger │ │ │ │ │ ├── ._xcschemes │ │ │ │ │ ├── xcschemes │ │ │ │ │ ├── ._TestSuite.xcscheme │ │ │ │ │ ├── ._xcschememanagement.plist │ │ │ │ │ ├── xcschememanagement.plist │ │ │ │ │ └── TestSuite.xcscheme │ │ │ │ │ └── xcdebugger │ │ │ │ │ └── Breakpoints.xcbkptlist │ │ │ ├── RunTestSuite2.h │ │ │ ├── Checklist.txt │ │ │ ├── TestBinary.cpp │ │ │ ├── Benchmark │ │ │ │ └── makefile │ │ │ ├── TestSuite2Creator.php │ │ │ ├── TestInequality.cpp │ │ │ ├── TestSuite.cpp │ │ │ ├── TestEquality.cpp │ │ │ ├── TestSuite.1 │ │ │ ├── TestSuite.h~ │ │ │ ├── TestSuite.h │ │ │ ├── TestCtors.cpp │ │ │ ├── TestRefCounting.cpp │ │ │ ├── main.cpp~ │ │ │ ├── main.cpp │ │ │ ├── TestAssign.cpp │ │ │ ├── TestString.cpp │ │ │ └── TestString.cpp~ │ │ └── TestSuite2 │ │ │ ├── JSONValidator │ │ │ ├── isValidArray.h │ │ │ ├── isValidObject.h │ │ │ ├── isValidNamedObject.h │ │ │ ├── isValidPartialRoot.h │ │ │ ├── isValidArray.cpp │ │ │ ├── isValidObject.cpp │ │ │ ├── isValidNamedObject.cpp │ │ │ ├── isValidPartialRoot.cpp │ │ │ ├── securityTest.h │ │ │ ├── isValidRoot.h │ │ │ ├── isValidMember.h │ │ │ ├── isValidString.h │ │ │ ├── isValidNumber.h │ │ │ ├── securityTest.cpp │ │ │ ├── Resources │ │ │ │ ├── validyMacros.h~ │ │ │ │ └── validyMacros.h │ │ │ ├── isValidRoot.cpp │ │ │ ├── isValidString.cpp │ │ │ └── isValidMember.cpp │ │ │ ├── JSON_Base64 │ │ │ ├── json_decode64.h │ │ │ ├── json_encode64.h │ │ │ ├── json_decode64.cpp │ │ │ └── json_encode64.cpp │ │ │ ├── NumberToString │ │ │ ├── getLenSize.h │ │ │ ├── _ftoa.h │ │ │ ├── _itoa.h │ │ │ ├── _areFloatsEqual.h │ │ │ ├── _uitoa.h │ │ │ ├── getLenSize.cpp │ │ │ ├── _atof.h │ │ │ ├── isNumeric.h │ │ │ ├── _areFloatsEqual.cpp │ │ │ ├── _ftoa.cpp │ │ │ ├── _uitoa.cpp │ │ │ └── _itoa.cpp │ │ │ ├── JSONGlobals │ │ │ ├── jsonSingleton.h │ │ │ └── jsonSingleton.cpp │ │ │ ├── JSONDebug │ │ │ ├── JSON_FAIL.h │ │ │ ├── JSON_FAIL_SAFE.h │ │ │ ├── JSON_ASSERT.h │ │ │ ├── JSON_ASSERT_SAFE.h │ │ │ ├── JSON_FAIL.cpp │ │ │ ├── JSON_FAIL_SAFE.cpp │ │ │ ├── JSON_ASSERT.cpp │ │ │ └── JSON_ASSERT_SAFE.cpp │ │ │ └── BaseTest.h │ ├── libjson.vcxproj.user │ ├── JSONOptions.h │ └── License.txt ├── Util.h ├── Server.h ├── Server.cpp ├── Platform.cpp ├── AMXUtil.h ├── Platform.h ├── SDK │ ├── amx │ │ └── sclinux.h │ └── plugincommon.h ├── Util.cpp ├── JSONParser.h ├── Makefile ├── plugin.cpp ├── SAMPSON.sln ├── SAMPSON.vcxproj.filters └── AMXUtil.cpp ├── pawn.json ├── test.pwn ├── .gitignore ├── LICENSE ├── pawno └── include │ └── a_json.inc └── README.md /src/plugin.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | Supports 3 | Load 4 | Unload 5 | AmxLoad 6 | AmxUnload 7 | -------------------------------------------------------------------------------- /src/libjson/._JSONOptions.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/._JSONOptions.h -------------------------------------------------------------------------------- /src/libjson/Documentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/Documentation.pdf -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONDefs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONDefs -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONDebug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONDebug.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONDefs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONDefs.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONNode.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONNode.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONStats.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONStats.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._libjson.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._libjson.cpp -------------------------------------------------------------------------------- /src/Util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Util 4 | { 5 | public: 6 | static char* ReadFile(const char szPath[]); 7 | 8 | }; 9 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONChildren.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONChildren.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONDebug.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONDebug.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONGlobals.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONGlobals.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONMemory.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONMemory.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONMemory.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONMemory.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONNode.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONNode.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONPreparse.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONPreparse.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONStream.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONStream.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONStream.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONStream.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONWorker.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONWorker.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONWorker.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONWorker.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONWriter.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONWriter.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSON_Base64.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSON_Base64.h -------------------------------------------------------------------------------- /src/libjson/_internal/Dependencies/._mempool++: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Dependencies/._mempool++ -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONAllocator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONAllocator.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONChildren.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONChildren.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONMemoryPool.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONMemoryPool.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONPreparse.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONPreparse.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONSingleton.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONSingleton.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONValidator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONValidator.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._NumberToString.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._NumberToString.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/._GNU_C.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/JSONDefs/._GNU_C.h -------------------------------------------------------------------------------- /src/libjson/_internal/Dependencies/._libbase64++: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Dependencies/._libbase64++ -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONAllocator.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONAllocator.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONIterators.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONIterators.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONNode_Mutex.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONNode_Mutex.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._JSONSharedString.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._JSONSharedString.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._internalJSONNode.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._internalJSONNode.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/._Visual_C.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/JSONDefs/._Visual_C.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/._internalJSONNode.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/._internalJSONNode.cpp -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/._Unknown_C.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/JSONDefs/._Unknown_C.h -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/._Strings_Defs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Source/JSONDefs/._Strings_Defs.h -------------------------------------------------------------------------------- /src/libjson/_internal/Dependencies/mempool++/._mempool.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Dependencies/mempool++/._mempool.h -------------------------------------------------------------------------------- /src/Server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Server 4 | { 5 | public: 6 | static bool GetScriptfilesPath(char pBuf[], const char szAppend[] = nullptr); 7 | }; 8 | -------------------------------------------------------------------------------- /src/libjson/_internal/Dependencies/libbase64++/._libbase64++.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/Dependencies/libbase64++/._libbase64++.h -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._xcuserdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._xcuserdata -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._wallace.mode1v3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._wallace.mode1v3 -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._wallace.pbxuser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._wallace.pbxuser -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._project.xcworkspace: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/._project.xcworkspace -------------------------------------------------------------------------------- /src/libjson/libjson.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/RunTestSuite2.h: -------------------------------------------------------------------------------- 1 | #ifndef RUN_TEST_SUITE2_H 2 | #define RUN_TEST_SUITE2_H 3 | 4 | class RunTestSuite2 { 5 | public: 6 | static void RunTests(void); 7 | }; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/project.xcworkspace/._xcuserdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/project.xcworkspace/._xcuserdata -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/._wallace.xcuserdatad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/._wallace.xcuserdatad -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/._xcdebugger: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/._xcdebugger -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/._xcschemes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/._xcschemes -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidArray.h 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidObject.h 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/project.xcworkspace/xcuserdata/._wallace.xcuserdatad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/project.xcworkspace/xcuserdata/._wallace.xcuserdatad -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidNamedObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidNamedObject.h 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidPartialRoot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidPartialRoot.h 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/._TestSuite.xcscheme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/._TestSuite.xcscheme -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/._xcschememanagement.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hual/SAMPSON/HEAD/src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/._xcschememanagement.plist -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidArray.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidArray.cpp 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "isValidArray.h" 11 | 12 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidObject.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidObject.cpp 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "isValidObject.h" 11 | 12 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidNamedObject.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidNamedObject.cpp 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "isValidNamedObject.h" 11 | 12 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidPartialRoot.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * isValidPartialRoot.cpp 3 | * TestSuite 4 | * 5 | * Created by Jonathan Wallace on 11/13/11. 6 | * Copyright 2011 StreamWIDE. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "isValidPartialRoot.h" 11 | 12 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSON_Base64/json_decode64.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_BASE64__JSON_DECODE64_H 2 | #define JSON_TESTSUITE_JSON_BASE64__JSON_DECODE64_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSON_Base64__json_decode64 : public BaseTest { 7 | public: 8 | testJSON_Base64__json_decode64(const std::string & name) : BaseTest(name){} 9 | void testNotBase64(void); 10 | }; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "JSONAllocator.h" 2 | 3 | #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) 4 | #include "JSONMemory.h" 5 | 6 | void * JSONAllocatorRelayer::alloc(size_t bytes) json_nothrow { 7 | return JSONMemory::json_malloc(bytes); 8 | } 9 | 10 | void JSONAllocatorRelayer::dealloc(void * ptr) json_nothrow { 11 | JSONMemory::json_free(ptr); 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/getLenSize.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_NUMBER_TO_STRING__GET_LEN_SIZE_H 2 | #define JSON_TESTSUITE_NUMBER_TO_STRING__GET_LEN_SIZE_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testNumberToString__getLenSize : public BaseTest { 7 | public: 8 | testNumberToString__getLenSize(const std::string & name) : BaseTest(name){} 9 | void testStruct(void); 10 | }; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/securityTest.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_VALIDATOR__SECURITY_TEST_H 2 | #define JSON_TESTSUITE_JSON_VALIDATOR__SECURITY_TEST_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONValidator__securityTest : public BaseTest { 7 | public: 8 | testJSONValidator__securityTest(const std::string & name) : BaseTest(name){} 9 | void testsecurity(void); 10 | }; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /pawn.json: -------------------------------------------------------------------------------- 1 | { 2 | "include_path": "pawno/include", 3 | "user": "Hual", 4 | "repo": "SAMPSON", 5 | "entry": "test.pwn", 6 | "output": "test.amx", 7 | "dependencies": ["sampctl/samp-stdlib"], 8 | "resources": [ 9 | { 10 | "name": "SAMPSON.dll", 11 | "platform": "windows", 12 | "archive": false 13 | }, 14 | { 15 | "name": "SAMPSON.so", 16 | "platform": "linux", 17 | "archive": false 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_ftoa.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_NUMBER_TO_STRING__FTOA_H 2 | #define JSON_TESTSUITE_NUMBER_TO_STRING__FTOA_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testNumberToString__ftoa : public BaseTest { 7 | public: 8 | testNumberToString__ftoa(const std::string & name) : BaseTest(name){} 9 | void testRandomNumbers(void); 10 | void testSpecializedInts(void); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONGlobals/jsonSingleton.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_GLOBALS__JSON_SINGLETON_H 2 | #define JSON_TESTSUITE_JSON_GLOBALS__JSON_SINGLETON_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONGlobals__jsonSingleton : public BaseTest { 7 | public: 8 | testJSONGlobals__jsonSingleton(const std::string & name) : BaseTest(name){} 9 | void testValue(void); 10 | void testNoValue(void); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSON_Base64/json_encode64.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_BASE64__JSON_ENCODE64_H 2 | #define JSON_TESTSUITE_JSON_BASE64__JSON_ENCODE64_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSON_Base64__json_encode64 : public BaseTest { 7 | public: 8 | testJSON_Base64__json_encode64(const std::string & name) : BaseTest(name){} 9 | void testReverseEachOther(void); 10 | void testAllChars(void); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/Checklist.txt: -------------------------------------------------------------------------------- 1 | Update LIBJSON_VERSION values and values in makefile too 2 | Strip all trailing white space 3 | Run test in XCode using all options on 4 | Export Documentation to PDF 5 | Delete build folders 6 | Run all tests on Mac 7 | Run all tests on Linux 8 | Run test in VC++ using all options on (if possible) 9 | Run benchmark to assert options are all the default 10 | Remove Hidden Finder files 11 | Zip TestSuite 12 | Zip on Linux 13 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_FAIL.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_DEBUG__JSON_FAIL_H 2 | #define JSON_TESTSUITE_JSON_DEBUG__JSON_FAIL_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONDebug_JSON_FAIL : public BaseTest { 7 | public: 8 | testJSONDebug_JSON_FAIL(const std::string & name) : BaseTest(name){} 9 | virtual void setUp(const std::string & methodName); 10 | virtual void tearDown(void); 11 | void testFail(void); 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidRoot.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_ROOT_H 2 | #define JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_ROOT_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONValidator__isValidRoot : public BaseTest { 7 | public: 8 | testJSONValidator__isValidRoot(const std::string & name) : BaseTest(name){} 9 | void testRoots(void); 10 | void testNotRoots(void); 11 | void testSuddenEnd(void); 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_FAIL_SAFE.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_DEBUG__JSON_FAIL_SAFE_H 2 | #define JSON_TESTSUITE_JSON_DEBUG__JSON_FAIL_SAFE_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONDebug_JSON_FAIL_SAFE : public BaseTest { 7 | public: 8 | testJSONDebug_JSON_FAIL_SAFE(const std::string & name) : BaseTest(name){} 9 | virtual void setUp(const std::string & methodName); 10 | virtual void tearDown(void); 11 | void testFail(void); 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_itoa.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_NUMBER_TO_STRING__ITOA_H 2 | #define JSON_TESTSUITE_NUMBER_TO_STRING__ITOA_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testNumberToString__itoa : public BaseTest { 7 | public: 8 | testNumberToString__itoa(const std::string & name) : BaseTest(name){} 9 | void testChar(void); 10 | void testShort(void); 11 | void testInt(void); 12 | void testLong(void); 13 | void testLongLong(void); 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_areFloatsEqual.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_NUMBER_TO_STRING__ARE_FLOATS_EQUAL_H 2 | #define JSON_TESTSUITE_NUMBER_TO_STRING__ARE_FLOATS_EQUAL_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testNumberToString__areFloatsEqual : public BaseTest { 7 | public: 8 | testNumberToString__areFloatsEqual(const std::string & name) : BaseTest(name){} 9 | void testEqual(void); 10 | void testNotEqual(void); 11 | void testCloseEnough(void); 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_uitoa.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_NUMBER_TO_STRING__UITOA_H 2 | #define JSON_TESTSUITE_NUMBER_TO_STRING__UITOA_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testNumberToString__uitoa : public BaseTest { 7 | public: 8 | testNumberToString__uitoa(const std::string & name) : BaseTest(name){} 9 | void testChar(void); 10 | void testShort(void); 11 | void testInt(void); 12 | void testLong(void); 13 | void testLongLong(void); 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_ASSERT.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_DEBUG__JSON_ASSERT_H 2 | #define JSON_TESTSUITE_JSON_DEBUG__JSON_ASSERT_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONDebug_JSON_ASSERT : public BaseTest { 7 | public: 8 | testJSONDebug_JSON_ASSERT(const std::string & name) : BaseTest(name){} 9 | virtual void setUp(const std::string & methodName); 10 | virtual void tearDown(void); 11 | void testPass(void); 12 | void testFail(void); 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /test.pwn: -------------------------------------------------------------------------------- 1 | // generated by "sampctl package generate" 2 | 3 | #include "pawno/include/a_json.inc" 4 | 5 | 6 | 7 | main() { 8 | new dummy_data[128], foo[8], JSONNode:response; 9 | format(dummy_data, sizeof(dummy_data), "{ \"foo\": \"bar\", \"testing\": true, \"count\": 123 }"); 10 | 11 | response = json_parse_string(dummy_data); 12 | 13 | json_get_string(response, foo, sizeof(foo), "foo"); 14 | 15 | printf("%s %d %i", foo, json_get_bool(response, "testing"), json_get_int(response, "count")); 16 | } 17 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_ASSERT_SAFE.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_DEBUG__JSON_ASSERT_SAFE_H 2 | #define JSON_TESTSUITE_JSON_DEBUG__JSON_ASSERT_SAFE_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONDebug_JSON_ASSERT_SAFE : public BaseTest { 7 | public: 8 | testJSONDebug_JSON_ASSERT_SAFE(const std::string & name) : BaseTest(name){} 9 | virtual void setUp(const std::string & methodName); 10 | virtual void tearDown(void); 11 | void testPass(void); 12 | void testFail(void); 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSON_Base64/json_decode64.cpp: -------------------------------------------------------------------------------- 1 | #include "json_decode64.h" 2 | #include "../../Source/JSON_Base64.h" 3 | 4 | void testJSON_Base64__json_decode64::testNotBase64(void){ 5 | #if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) 6 | #ifdef JSON_SAFE 7 | assertEquals(JSONBase64::json_decode64(JSON_TEXT("123!abc")), ""); 8 | assertEquals(JSONBase64::json_decode64(JSON_TEXT("123=abc")), ""); 9 | assertEquals(JSONBase64::json_decode64(JSON_TEXT("123abc===")), ""); 10 | #endif 11 | #endif 12 | } 13 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/project.xcworkspace/xcuserdata/wallace.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/getLenSize.cpp: -------------------------------------------------------------------------------- 1 | #include "getLenSize.h" 2 | #include "../../Source/NumberToString.h" 3 | 4 | 5 | /** 6 | * Make sure the specialized template returns the right 7 | * number of bytes required 8 | */ 9 | void testNumberToString__getLenSize::testStruct(void){ 10 | assertEquals(getLenSize<1>::GETLEN, 5); 11 | assertEquals(getLenSize<2>::GETLEN, 7); 12 | assertEquals(getLenSize<4>::GETLEN, 12); 13 | assertEquals(getLenSize<8>::GETLEN, 22); 14 | assertEquals(getLenSize<16>::GETLEN, 41); 15 | } 16 | -------------------------------------------------------------------------------- /src/Server.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Server.h" 4 | #include "Platform.h" 5 | #include "AMXUtil.h" 6 | 7 | #define S_SCRIPTFILES_PATH (PATH_SEPARATOR "scriptfiles" PATH_SEPARATOR) 8 | 9 | bool Server::GetScriptfilesPath(char pBuf[], const char szAppend[]) 10 | { 11 | if (Platform::GetExecutablePath(pBuf) == nullptr) { 12 | return false; 13 | } 14 | 15 | std::strcat(pBuf, S_SCRIPTFILES_PATH); 16 | 17 | if (szAppend != nullptr) { 18 | std::strcat(pBuf, szAppend); 19 | } 20 | 21 | return true; 22 | } 23 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidMember.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_MEMBER_H 2 | #define JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_MEMBER_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONValidator__isValidMember : public BaseTest { 7 | public: 8 | testJSONValidator__isValidMember(const std::string & name) : BaseTest(name){} 9 | void testMembers(void); 10 | void testStrict(void); 11 | void testNotStrict(void); 12 | void testNotMembers(void); 13 | void testSuddenEnd(void); 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidString.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_STRING_H 2 | #define JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_STRING_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONValidator__isValidString : public BaseTest { 7 | public: 8 | testJSONValidator__isValidString(const std::string & name) : BaseTest(name){} 9 | void testNormal(void); 10 | void testUnicode(void); 11 | void testStrict(void); 12 | void testNotStrict(void); 13 | void testNotString(void); 14 | void testSuddenEnd(void); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # 31 | # Package only files 32 | # 33 | 34 | # Compiled Bytecode, precompiled output and assembly 35 | *.amx 36 | *.lst 37 | *.asm 38 | 39 | # Vendor directory for dependencies 40 | dependencies/ 41 | 42 | # Dependency versions lockfile 43 | pawn.lock 44 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONSingleton.h: -------------------------------------------------------------------------------- 1 | #ifndef JSONSINGLETON_H 2 | #define JSONSINGLETON_H 3 | 4 | template class JSONSingleton { 5 | public: 6 | static inline T get(void){ 7 | return get_singleton() -> ptr; 8 | } 9 | static inline void set(T p){ 10 | get_singleton() -> ptr = p; 11 | } 12 | private: 13 | inline JSONSingleton() : ptr(NULL) { } 14 | JSONSingleton(const JSONSingleton &); 15 | JSONSingleton operator = (const JSONSingleton &); 16 | static inline JSONSingleton * get_singleton(void){ 17 | static JSONSingleton instance; 18 | return &instance; 19 | } 20 | T ptr; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TestSuite.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 8DD76F620486A84900D96B5E 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/libjson/JSONOptions.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_OPTIONS_H 2 | #define JSON_OPTIONS_H 3 | 4 | #define JSON_LIBRARY 5 | #define JSON_ISO_STRICT 6 | #define JSON_SAFE 7 | #define JSON_STDERROR 8 | //#define JSON_UNICODE 9 | #define JSON_REF_COUNT 10 | #define JSON_ITERATORS 11 | #define JSON_WRITE_PRIORITY MED 12 | #define JSON_READ_PRIORITY HIGH 13 | #define JSON_ESCAPE_WRITES 14 | #define JSON_CASE_INSENSITIVE_FUNCTIONS 15 | #define JSON_BOOL_TYPE char 16 | #define JSON_NUMBER_TYPE float 17 | #define JSON_CASTABLE 18 | #define JSON_SECURITY_MAX_NEST_LEVEL 128 19 | #define JSON_SECURITY_MAX_STRING_LENGTH 33554432 20 | #define JSON_SECURITY_MAX_STREAM_OBJECTS 128 21 | #define JSON_NO_EXCEPTIONS 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/BaseTest.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_BASETEST_H 2 | #define JSON_TESTSUITE_BASETEST_H 3 | 4 | #include "../TestSuite/UnitTest.h" 5 | #include 6 | 7 | class libjson_CodeCoverage; 8 | 9 | class BaseTest { 10 | public: 11 | BaseTest(const std::string & name) : _name(name), coverage(0) {} 12 | virtual ~BaseTest(void){}; 13 | virtual void setUp(const std::string & methodName){ UnitTest::SetPrefix(_name + "::" + methodName); } 14 | virtual void tearDown(void){} 15 | protected: 16 | const std::string _name; 17 | libjson_CodeCoverage * coverage; 18 | private: 19 | BaseTest(const BaseTest &); 20 | BaseTest & operator=(const BaseTest &); 21 | }; 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_atof.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_NUMBER_TO_STRING__ATOF_H 2 | #define JSON_TESTSUITE_NUMBER_TO_STRING__ATOF_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testNumberToString__atof : public BaseTest { 7 | public: 8 | testNumberToString__atof(const std::string & name); 9 | virtual ~testNumberToString__atof(); 10 | void testPositive(void); 11 | void testNegative(void); 12 | void testPositive_ScientificNotation(void); 13 | void testNegative_ScientificNotation(void); 14 | void testPositive_SignedScientificNotation(void); 15 | void testNegative_SignedScientificNotation(void); 16 | void testStrict(void); 17 | void testNotNumbers(void); 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/Unknown_C.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_UNKNOWN_C_HEADER 2 | #define JSON_UNKNOWN_C_HEADER 3 | 4 | #if !defined(__GNUC__) && !defined(_MSC_VER) 5 | 6 | #define json_deprecated(method, warning) method 7 | 8 | #define json_nothrow 9 | #define json_throws(x) 10 | #define json_pure json_nothrow 11 | #define json_read_priority 12 | #define json_write_priority 13 | #define json_malloc_attr json_nothrow 14 | #define json_hot 15 | #define json_cold 16 | #define json_likely(x) x 17 | #define json_unlikely(x) x 18 | 19 | #ifdef JSON_LESS_MEMORY 20 | #define PACKED(x) :x 21 | #define BITS(x) :x 22 | #endif 23 | 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/Visual_C.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_VISUAL_C_HEADER 2 | #define JSON_VISUAL_C_HEADER 3 | 4 | #ifdef _MSC_VER 5 | 6 | #define json_deprecated(method, warning) __declspec(deprecated(warning)) method 7 | 8 | #define json_nothrow 9 | #define json_throws(x) 10 | #define json_pure json_nothrow 11 | #define json_read_priority 12 | #define json_write_priority 13 | #define json_malloc_attr json_nothrow 14 | #define json_hot 15 | #define json_cold 16 | #define json_likely(x) x 17 | #define json_unlikely(x) x 18 | 19 | #ifdef JSON_LESS_MEMORY 20 | #define PACKED(x) :x 21 | #define BITS(x) :x 22 | #endif 23 | 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/isNumeric.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_NUMBER_TO_STRING__IS_NUMERIC_H 2 | #define JSON_TESTSUITE_NUMBER_TO_STRING__IS_NUMERIC_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testNumberToString__isNumeric : public BaseTest { 7 | public: 8 | testNumberToString__isNumeric(const std::string & name); 9 | virtual ~testNumberToString__isNumeric(); 10 | void testPositive(void); 11 | void testNegative(void); 12 | void testPositive_ScientificNotation(void); 13 | void testNegative_ScientificNotation(void); 14 | void testPositive_SignedScientificNotation(void); 15 | void testNegative_SignedScientificNotation(void); 16 | void testStrict(void); 17 | void testNotStrict(void); 18 | void testNotNumbers(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidNumber.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_NUMBER_H 2 | #define JSON_TESTSUITE_JSON_VALIDATOR__IS_VALID_NUMBER_H 3 | 4 | #include "../BaseTest.h" 5 | 6 | class testJSONValidator__isValidNumber : public BaseTest { 7 | public: 8 | testJSONValidator__isValidNumber(const std::string & name) : BaseTest(name){} 9 | void testPositive(void); 10 | void testNegative(void); 11 | void testPositive_ScientificNotation(void); 12 | void testNegative_ScientificNotation(void); 13 | void testPositive_SignedScientificNotation(void); 14 | void testNegative_SignedScientificNotation(void); 15 | void testStrict(void); 16 | void testNotStrict(void); 17 | void testNotNumbers(void); 18 | void testSuddenEnd(void); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONGlobals/jsonSingleton.cpp: -------------------------------------------------------------------------------- 1 | #include "jsonSingleton.h" 2 | #include "../../Source/JSONGlobals.h" 3 | 4 | json_global_decl(std::string, WITHVALUE, "myvalue"); 5 | json_global_decl(std::string, WITHOUTVALUE, ); 6 | 7 | void testJSONGlobals__jsonSingleton::testValue(void){ 8 | std::string * p1 = &jsonSingletonWITHVALUE::getValue(); 9 | std::string * p2 = &json_global(WITHVALUE); 10 | assertEquals(p1, p2); 11 | assertEquals(json_global(WITHVALUE), "myvalue"); 12 | assertEquals(jsonSingletonWITHVALUE::getValue(), "myvalue"); 13 | } 14 | 15 | void testJSONGlobals__jsonSingleton::testNoValue(void){ 16 | std::string * p1 = &jsonSingletonWITHOUTVALUE::getValue(); 17 | std::string * p2 = &json_global(WITHOUTVALUE); 18 | assertEquals(p1, p2); 19 | assertEquals(json_global(WITHOUTVALUE), ""); 20 | assertEquals(jsonSingletonWITHOUTVALUE::getValue(), ""); 21 | } 22 | -------------------------------------------------------------------------------- /src/Platform.cpp: -------------------------------------------------------------------------------- 1 | #include "Platform.h" 2 | 3 | #include 4 | 5 | Platform::JSONError Platform::Error = Platform::JSONError::JSON_ERROR_NONE; 6 | int Platform::SecondaryError = 0; 7 | 8 | char* Platform::GetExecutablePath(char pBuf[], const size_t sSize) 9 | { 10 | return ::_getcwd(pBuf, sSize); 11 | } 12 | 13 | CALLBACK_RETURN Platform::GetLastError(CALLBACK_PARAMS) 14 | { 15 | return Error; 16 | } 17 | 18 | CALLBACK_RETURN Platform::GetLastErrorSecondary(CALLBACK_PARAMS) 19 | { 20 | return SecondaryError; 21 | } 22 | 23 | CALLBACK_RETURN Platform::GetErrorSecondaryString(CALLBACK_PARAMS) 24 | { 25 | cell *out_addr = 0; 26 | amx_GetAddr(pAmx, pParams[2], &out_addr); 27 | char* pString = std::strerror(pParams[1]); 28 | 29 | if (pString == nullptr) 30 | return 0; 31 | 32 | amx_SetString(out_addr, pString, pParams[4], 0, pParams[3]); 33 | 34 | return 1; 35 | } 36 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/securityTest.cpp: -------------------------------------------------------------------------------- 1 | #include "securityTest.h" 2 | #include "Resources/validyMacros.h" 3 | #include "../../Source/JSONValidator.h" 4 | 5 | void testJSONValidator__securityTest::testsecurity(void){ 6 | #ifdef JSON_SECURITY_MAX_NEST_LEVEL 7 | #if (JSON_SECURITY_MAX_NEST_LEVEL != 128) 8 | #error, test suite only wants a nest security level of 100 9 | #endif 10 | { 11 | json_string json(JSON_TEXT("{")); 12 | for(unsigned int i = 0; i < 127; ++i){ 13 | json += JSON_TEXT("\"n\":{"); 14 | } 15 | json += json_string(128, '}'); 16 | assertTrue(JSONValidator::isValidRoot(json.c_str())); 17 | } 18 | { 19 | json_string json(JSON_TEXT("{")); 20 | for(unsigned int i = 0; i < 128; ++i){ 21 | json += JSON_TEXT("\"n\":{"); 22 | } 23 | json += json_string(129, '}'); 24 | assertFalse(JSONValidator::isValidRoot(json.c_str())); 25 | } 26 | #endif 27 | } 28 | -------------------------------------------------------------------------------- /src/AMXUtil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define CALLBACK_RETURN cell AMX_NATIVE_CALL 4 | #define CALLBACK_PARAMS AMX* pAmx, cell* pParams 5 | 6 | typedef void(*logprintf_t)(char* format, ...); 7 | 8 | #include 9 | #include 10 | 11 | struct PAWNArray 12 | { 13 | cell* address; 14 | size_t length; 15 | }; 16 | 17 | class AMXUtil 18 | { 19 | public: 20 | static cell Invoke(const char* szFunction, const char* szFormat, ...); 21 | static void SetAMXFunctions(void* pFunctionData); 22 | static char* GetStringFromCell(AMX* pAmx, cell cellString); 23 | static inline const std::list& GetAMXList() { return m_lAMX; }; 24 | static inline void AddAMX(AMX* pAmx) { m_lAMX.push_back(pAmx); }; 25 | static inline void RemoveAMX(AMX* pAmx) { m_lAMX.remove(pAmx); }; 26 | static inline void SetPrintFunction(logprintf_t func) { Printf = func; }; 27 | 28 | static logprintf_t Printf; 29 | 30 | private: 31 | static std::list m_lAMX; 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/Strings_Defs.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGS_DEFS_HEADER 2 | #define STRINGS_DEFS_HEADER 3 | 4 | #include "../../../JSONOptions.h" 5 | 6 | #ifdef JSON_UNICODE 7 | #define json_char wchar_t 8 | #define json_uchar wchar_t 9 | #ifdef __cplusplus 10 | #include /* need wide characters */ 11 | #ifndef JSON_STRING_HEADER 12 | #include 13 | #endif 14 | #else 15 | #include /* need wide characters */ 16 | #endif 17 | #define JSON_TEXT(s) L ## s 18 | #define json_strlen wcslen 19 | #define json_strcmp wcscmp 20 | #else 21 | #define json_char char 22 | #define json_uchar unsigned char 23 | #ifdef __cplusplus 24 | #ifndef JSON_STRING_HEADER 25 | #include 26 | #endif 27 | #else 28 | #include /* still need it for strlen and such */ 29 | #endif 30 | #define JSON_TEXT(s) s 31 | #define json_strlen strlen 32 | #define json_strcmp strcmp 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/Platform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if (defined WIN32 || defined _WIN32) 7 | #define PATH_SEPARATOR "\\" 8 | 9 | #include 10 | #include 11 | #else 12 | #define PATH_SEPARATOR "/" 13 | #define _getcwd getcwd 14 | 15 | #include 16 | #include 17 | #endif 18 | 19 | #include "AMXUtil.h" 20 | 21 | class Platform 22 | { 23 | public: 24 | enum JSONError : int { 25 | JSON_ERROR_NONE = 0, 26 | JSON_ERROR_SCRIPTFILES_PATH_NOT_FOUND = 1, 27 | JSON_ERROR_FAILED_READING_FILE = 2, 28 | JSON_ERROR_INVALID_JSON_PATH = 3 29 | }; 30 | 31 | static char* GetExecutablePath(char pBuf[], size_t sSize = FILENAME_MAX); 32 | 33 | static CALLBACK_RETURN GetLastError(CALLBACK_PARAMS); 34 | static CALLBACK_RETURN GetLastErrorSecondary(CALLBACK_PARAMS); 35 | static CALLBACK_RETURN GetErrorSecondaryString(CALLBACK_PARAMS); 36 | 37 | static JSONError Error; 38 | static int SecondaryError; 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /src/SDK/amx/sclinux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Things needed to compile under linux. 3 | * 4 | * Should be reworked totally to use GNU's 'configure' 5 | */ 6 | #ifndef SCLINUX_H 7 | #define SCLINUX_H 8 | 9 | #define stricmp(a,b) strcasecmp(a,b) 10 | #define strnicmp(a,b,c) strncasecmp(a,b,c) 11 | 12 | /* 13 | * WinWorld wants '\'. Unices do not. 14 | */ 15 | #define DIRECTORY_SEP_CHAR '/' 16 | #define DIRECTORY_SEP_STR "/" 17 | 18 | /* 19 | * SC assumes that a computer is Little Endian unless told otherwise. It uses 20 | * (and defines) the macros BYTE_ORDER and BIG_ENDIAN. 21 | * For Linux, we must overrule these settings with those defined in glibc. 22 | */ 23 | #if !defined __BYTE_ORDER 24 | # include 25 | #endif 26 | 27 | #if defined __OpenBSD__ || defined __FreeBSD__ 28 | # define __BYTE_ORDER BYTE_ORDER 29 | # define __LITTLE_ENDIAN LITTLE_ENDIAN 30 | # define __BIG_ENDIAN BIG_ENDIAN 31 | #endif 32 | 33 | #if !defined __BYTE_ORDER 34 | # error "Can't figure computer byte order (__BYTE_ORDER macro not found)" 35 | #endif 36 | 37 | #endif /* SCLINUX_H */ 38 | -------------------------------------------------------------------------------- /src/Util.cpp: -------------------------------------------------------------------------------- 1 | #include "Util.h" 2 | 3 | #include 4 | 5 | #include "Platform.h" 6 | #include "AMXUtil.h" 7 | 8 | char* Util::ReadFile(const char szPath[]) 9 | { 10 | FILE* pFile = nullptr; 11 | char* pResult = nullptr; 12 | long lFileSize = 0L; 13 | size_t bytesRead = 0U; 14 | 15 | if ((pFile = std::fopen(szPath, "rb")) == nullptr) { 16 | Platform::SecondaryError = errno; 17 | return nullptr; 18 | } 19 | 20 | if (std::fseek(pFile, 0, SEEK_END) != 0) { 21 | Platform::SecondaryError = errno; 22 | std::fclose(pFile); 23 | return nullptr; 24 | } 25 | 26 | if ((lFileSize = std::ftell(pFile)) == -1L) { 27 | Platform::SecondaryError = errno; 28 | std::fclose(pFile); 29 | return nullptr; 30 | } 31 | 32 | std::rewind(pFile); 33 | 34 | pResult = new char[lFileSize + 1]; 35 | if ((bytesRead = std::fread(pResult, sizeof(char), lFileSize, pFile)) != lFileSize) { 36 | std::fclose(pFile); 37 | return nullptr; 38 | } 39 | 40 | std::fclose(pFile); 41 | 42 | pResult[bytesRead] = 0; 43 | return pResult; 44 | } 45 | -------------------------------------------------------------------------------- /src/JSONParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "AMXUtil.h" 9 | 10 | class JSONParser 11 | { 12 | public: 13 | static CALLBACK_RETURN ParseFile(CALLBACK_PARAMS); 14 | static CALLBACK_RETURN ParseString(CALLBACK_PARAMS); 15 | static CALLBACK_RETURN Close(CALLBACK_PARAMS); 16 | static CALLBACK_RETURN GetType(CALLBACK_PARAMS); 17 | static CALLBACK_RETURN GetNode(CALLBACK_PARAMS); 18 | static CALLBACK_RETURN GetString(CALLBACK_PARAMS); 19 | static CALLBACK_RETURN GetBool(CALLBACK_PARAMS); 20 | static CALLBACK_RETURN GetInt(CALLBACK_PARAMS); 21 | static CALLBACK_RETURN GetFloat(CALLBACK_PARAMS); 22 | static CALLBACK_RETURN GetArray(CALLBACK_PARAMS); 23 | static CALLBACK_RETURN GetArraySize(CALLBACK_PARAMS); 24 | static CALLBACK_RETURN GetArrayElement(CALLBACK_PARAMS); 25 | static CALLBACK_RETURN GetName(CALLBACK_PARAMS); 26 | 27 | private: 28 | static JSONNODE* json_get_recursive(JSONNODE* pRootNode, char* szPath, const char cDelim); 29 | 30 | }; 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Nikola Yanakiev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | GXX=g++ 2 | CFLAGS=-fPIC -fpermissive -c -w -std=c++11 -ISDK/ -Ilibjson/ 3 | BFLAGS=-fshort-wchar -shared 4 | FLAGS=-DLINUX -D__LINUX__ -DNDEBUG -v -g0 -m32 -O2 5 | BUILDDIR=build 6 | BUILDFILE=SAMPSON.so 7 | 8 | all: 9 | @echo '====================== Build started =======================' 10 | mkdir -p $(BUILDDIR) 11 | cd libjson; make SHARED=0 12 | @echo '====================== Compiling SDK =======================' 13 | $(GXX) $(FLAGS) $(CFLAGS) SDK/*.cpp 14 | @echo '===================== Compiling plugin =====================' 15 | $(GXX) $(FLAGS) $(CFLAGS) *.cpp 16 | @echo '====================== Building plugin =====================' 17 | $(GXX) $(FLAGS) $(BFLAGS) -o $(BUILDDIR)/$(BUILDFILE) *.o -Wl,--whole-archive libjson/libjson.a -Wl,--no-whole-archive 18 | @echo '====================== Build finished ======================' 19 | rm *.o 20 | @echo '====================== Clean finished ======================' 21 | 22 | clean: 23 | @echo '====================== Clean started =======================' 24 | cd libjson; make clean 25 | rm *.o 26 | @echo '====================== Clean finished ======================' 27 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONPreparse.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBJSON_GUARD_PREPARSE_H 2 | #define LIBJSON_GUARD_PREPARSE_H 3 | 4 | #include "JSONDebug.h" 5 | #include "JSONNode.h" 6 | 7 | #if (defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)) 8 | 9 | #ifdef JSON_COMMENTS 10 | #define COMMENT_PARAM(name) ,const json_string & name 11 | #else 12 | #define COMMENT_PARAM(name) 13 | #endif 14 | 15 | class JSONPreparse { 16 | public: 17 | static JSONNode isValidNumber(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority; 18 | static JSONNode isValidMember(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority; 19 | static json_string isValidString(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority; 20 | static void isValidNamedObject(json_string::const_iterator & ptr, json_string::const_iterator & end, JSONNode & parent COMMENT_PARAM(comment)) json_read_priority; 21 | static JSONNode isValidObject(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority; 22 | static JSONNode isValidArray(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority; 23 | static JSONNode isValidRoot(const json_string & json) json_throws(std::invalid_argument) json_read_priority; 24 | }; 25 | 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSON_Base64.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBJSON_GUARD_BASE64_H 2 | #define LIBJSON_GUARD_BASE64_H 3 | 4 | #include "JSONDebug.h" 5 | #if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) //if this is not needed, don't waste space compiling it 6 | 7 | #include "../Dependencies/libbase64++/libbase64++.h" 8 | 9 | class JSONBase64 { 10 | public: 11 | inline static json_string json_encode64(const unsigned char * binary, size_t bytes) json_nothrow json_cold; 12 | inline static std::string json_decode64(const json_string & encoded) json_nothrow json_cold; 13 | private: 14 | JSONBase64(void); 15 | }; 16 | 17 | json_string JSONBase64::json_encode64(const unsigned char * binary, size_t bytes) json_nothrow { 18 | #if defined JSON_DEBUG || defined JSON_SAFE 19 | return libbase64::encode(binary, bytes); 20 | #else 21 | return libbase64::encode(binary, bytes); 22 | #endif 23 | } 24 | 25 | std::string JSONBase64::json_decode64(const json_string & encoded) json_nothrow { 26 | #if defined JSON_DEBUG || defined JSON_SAFE 27 | return libbase64::decode(encoded); 28 | #else 29 | return libbase64::decode(encoded); 30 | #endif 31 | } 32 | 33 | 34 | #endif 35 | #endif 36 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 19 | 20 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDebug.cpp: -------------------------------------------------------------------------------- 1 | #include "JSONDebug.h" 2 | #ifdef JSON_DEBUG 3 | 4 | #ifdef JSON_STDERROR 5 | #include //need std::cerr 6 | #else 7 | #include "JSONSingleton.h" 8 | //otherwise, use a callback to tell the end user what happened 9 | json_error_callback_t JSONDebug::register_callback(json_error_callback_t callback) json_nothrow { 10 | json_error_callback_t res = JSONSingleton::get(); 11 | JSONSingleton::set(callback); 12 | return res; 13 | } 14 | #endif 15 | 16 | //Something went wrong or an assert failed 17 | void JSONDebug::_JSON_FAIL(const json_string & msg) json_nothrow { 18 | #ifdef JSON_STDERROR //no callback, just use stderror 19 | #ifndef JSON_UNICODE 20 | std::cerr << msg << std::endl; 21 | #else 22 | std::cerr << std::string(msg.begin(), msg.end()) << std::endl; 23 | #endif 24 | #else 25 | if (json_error_callback_t ErrorCallback = JSONSingleton::get()){ //only do anything if the callback is registered 26 | #ifdef JSON_LIBRARY 27 | ErrorCallback(msg.c_str()); 28 | #else 29 | ErrorCallback(msg); 30 | #endif 31 | } 32 | #endif 33 | } 34 | 35 | //asserts that condition is true, more useful than cassert because it lets you keep going 36 | void JSONDebug::_JSON_ASSERT(bool condition, const json_string & msg) json_nothrow { 37 | if (json_unlikely(!condition)){ 38 | _JSON_FAIL(msg); 39 | } 40 | } 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONMemoryPool.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBJSON_GUARD_MEMORY_POOL_H 2 | #define LIBJSON_GUARD_MEMORY_POOL_H 3 | 4 | #ifdef JSON_MEMORY_POOL 5 | 6 | #include "../Dependencies/mempool++/mempool.h" 7 | 8 | //this macro expands to the number of bytes a pool gets based on block size and number of 32s of the total pool it gets 9 | #define jsonPoolPart(bytes_per_block, thirty_seconds_of_mem) bytes_per_block, ((thirty_seconds_of_mem * JSON_MEMORY_POOL / 32) / bytes_per_block) 10 | 11 | #ifdef JSON_PREPARSE 12 | #define NODEPOOL jsonPoolPart(sizeof(JSONNode), 1) 13 | #define INTERNALNODEPOOL jsonPoolPart(sizeof(internalJSONNode), 3) 14 | #define MEMPOOL_1 jsonPoolPart(8, 2) 15 | #define MEMPOOL_2 jsonPoolPart(16, 2) 16 | #define MEMPOOL_3 jsonPoolPart(32, 2) 17 | #define MEMPOOL_4 jsonPoolPart(64, 2) 18 | #define MEMPOOL_5 jsonPoolPart(128, 3) 19 | #define MEMPOOL_6 jsonPoolPart(256, 4) 20 | #define MEMPOOL_7 jsonPoolPart(512, 5) 21 | #define MEMPOOL_8 jsonPoolPart(4096, 8) 22 | #else 23 | #define NODEPOOL jsonPoolPart(sizeof(JSONNode), 2) 24 | #define INTERNALNODEPOOL jsonPoolPart(sizeof(internalJSONNode), 7) 25 | #define MEMPOOL_1 jsonPoolPart(8, 1) 26 | #define MEMPOOL_2 jsonPoolPart(16, 1) 27 | #define MEMPOOL_3 jsonPoolPart(32, 1) 28 | #define MEMPOOL_4 jsonPoolPart(64, 1) 29 | #define MEMPOOL_5 jsonPoolPart(128, 3) 30 | #define MEMPOOL_6 jsonPoolPart(256, 3) 31 | #define MEMPOOL_7 jsonPoolPart(512, 5) 32 | #define MEMPOOL_8 jsonPoolPart(4096, 8) 33 | #endif 34 | 35 | #endif 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONValidator.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_VALIDATOR_H 2 | #define JSON_VALIDATOR_H 3 | 4 | #include "JSONDebug.h" 5 | 6 | #ifdef JSON_VALIDATE 7 | 8 | #ifdef JSON_SECURITY_MAX_NEST_LEVEL 9 | #define DEPTH_PARAM ,size_t depth_param 10 | #define DEPTH_ARG(arg) ,arg 11 | #define INC_DEPTH()\ 12 | if (++depth_param > JSON_SECURITY_MAX_NEST_LEVEL){\ 13 | JSON_FAIL(JSON_TEXT("Exceeded JSON_SECURITY_MAX_NEST_LEVEL"));\ 14 | return false;\ 15 | } 16 | #else 17 | #define DEPTH_PARAM 18 | #define DEPTH_ARG(arg) 19 | #define INC_DEPTH() (void)0 20 | #endif 21 | 22 | class JSONValidator { 23 | public: 24 | static bool isValidNumber(const json_char * & ptr) json_nothrow json_read_priority; 25 | static bool isValidMember(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority; 26 | static bool isValidString(const json_char * & ptr) json_nothrow json_read_priority; 27 | static bool isValidNamedObject(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority; 28 | static bool isValidObject(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority; 29 | static bool isValidArray(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority; 30 | static bool isValidRoot(const json_char * json) json_nothrow json_read_priority; 31 | #ifdef JSON_STREAM 32 | static bool isValidPartialRoot(const json_char * json) json_nothrow json_read_priority; 33 | #endif 34 | private: 35 | JSONValidator(void); 36 | }; 37 | 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/libjson/License.txt: -------------------------------------------------------------------------------- 1 | This license is also available in Documentation.pdf 2 | 3 | Copyright 2010 Jonathan Wallace. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | THIS SOFTWARE IS PROVIDED BY JONATHAN WALLACE ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JONATHAN WALLACE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | 13 | The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Jonathan Wallace. -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_FAIL.cpp: -------------------------------------------------------------------------------- 1 | #include "JSON_FAIL.h" 2 | #include "../../Source/JSONDebug.h" 3 | 4 | #if defined JSON_DEBUG 5 | #ifndef JSON_STDERROR 6 | static json_string last; 7 | #ifdef JSON_LIBRARY 8 | static void callback(const json_char * p){ last = p; } 9 | #else 10 | static void callback(const json_string & p){ last = p; } 11 | #endif 12 | #endif 13 | #endif 14 | 15 | const json_string fail_constf = JSON_TEXT("fail"); //should pass the same pointer all the way through, no copies 16 | const json_string null_constf = JSON_TEXT(""); 17 | #if defined JSON_DEBUG || defined JSON_SAFE 18 | json_error_callback_t origCallbackf = NULL; 19 | #endif 20 | 21 | void testJSONDebug_JSON_FAIL::setUp(const std::string & methodName){ 22 | BaseTest::setUp(methodName); 23 | #if defined JSON_DEBUG 24 | #ifndef JSON_STDERROR 25 | origCallbackf = JSONDebug::register_callback(callback); //check that the callback was called 26 | last = null_constf; 27 | #endif 28 | #endif 29 | } 30 | 31 | void testJSONDebug_JSON_FAIL::tearDown(void){ 32 | BaseTest::tearDown(); 33 | #if defined JSON_DEBUG 34 | #ifndef JSON_STDERROR 35 | JSONDebug::register_callback(origCallbackf); //check that the callback was called 36 | #endif 37 | #endif 38 | } 39 | 40 | 41 | /** 42 | * Make sure fails do call the callback 43 | */ 44 | void testJSONDebug_JSON_FAIL::testFail(void){ 45 | #if defined JSON_DEBUG 46 | #ifndef JSON_STDERROR 47 | JSON_FAIL(fail_constf); 48 | assertEquals(last, fail_constf); //make sure the callback was actually called 49 | #endif 50 | #endif 51 | } 52 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDebug.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBJSON_GUARD_DEBUG_H 2 | #define LIBJSON_GUARD_DEBUG_H 3 | 4 | #include "JSONDefs.h" 5 | #include "JSONStats.h" 6 | 7 | #ifdef JSON_DEBUG 8 | #ifdef JSON_SAFE 9 | #define JSON_ASSERT_SAFE(condition, msg, code)\ 10 | {\ 11 | if (json_unlikely(!(condition))){\ 12 | JSON_FAIL(msg);\ 13 | code\ 14 | }\ 15 | } 16 | #define JSON_FAIL_SAFE(msg, code)\ 17 | {\ 18 | JSON_FAIL(msg);\ 19 | code\ 20 | } 21 | #else 22 | #define JSON_ASSERT_SAFE(condition, msg, code) JSON_ASSERT(condition, msg) 23 | #define JSON_FAIL_SAFE(msg, code) JSON_FAIL(msg) 24 | #endif 25 | 26 | #define JSON_FAIL(msg) JSONDebug::_JSON_FAIL(msg) 27 | #define JSON_ASSERT(bo, msg) JSONDebug::_JSON_ASSERT(bo, msg) 28 | 29 | class JSONDebug { 30 | public: 31 | #ifndef JSON_STDERROR 32 | static json_error_callback_t register_callback(json_error_callback_t callback) json_nothrow json_cold; 33 | #endif 34 | static void _JSON_FAIL(const json_string & msg) json_nothrow json_cold; 35 | static void _JSON_ASSERT(bool condition, const json_string & msg) json_nothrow json_cold; 36 | }; 37 | #else 38 | #ifdef JSON_SAFE 39 | #define JSON_ASSERT_SAFE(condition, msg, code)\ 40 | {\ 41 | if (json_unlikely(!(condition))){\ 42 | code\ 43 | }\ 44 | } 45 | #define JSON_FAIL_SAFE(msg, code)\ 46 | {\ 47 | code\ 48 | } 49 | #else 50 | #define JSON_ASSERT_SAFE(condition, msg, code) 51 | #define JSON_FAIL_SAFE(msg, code) 52 | #endif 53 | 54 | #define JSON_ASSERT(condition, msg) 55 | #define JSON_FAIL(msg) 56 | #endif 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/Resources/validyMacros.h~: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_VALIDATOR_RESOURCES_VALIDITY_MACROS_H 2 | #define JSON_TESTSUITE_JSON_VALIDATOR_RESOURCES_VALIDITY_MACROS_H 3 | 4 | #include "../../../JSONOptions.h" 5 | 6 | #ifdef JSON_VALIDATE 7 | 8 | #define assertValid(x, method, nextchar)\ 9 | {\ 10 | json_string temp(JSON_TEXT(x));\ 11 | const json_char * ptr = temp.c_str();\ 12 | assertTrue(JSONValidator::method(ptr) && ((*ptr)==JSON_TEXT(nextchar)));\ 13 | } 14 | 15 | #define assertNotValid(x, method, nextchar)\ 16 | {\ 17 | json_string temp(JSON_TEXT(x));\ 18 | const json_char * ptr = temp.c_str();\ 19 | assertTrue(!JSONValidator::method(ptr) || ((*ptr)!=JSON_TEXT(nextchar)));\ 20 | } 21 | 22 | #ifdef JSON_SECURITY_MAX_NEST_LEVEL 23 | #define assertValid_Depth(x, method, nextchar)\ 24 | {\ 25 | json_string temp(JSON_TEXT(x));\ 26 | const json_char * ptr = temp.c_str();\ 27 | assertTrue(JSONValidator::method(ptr, 1) && ((*ptr)==JSON_TEXT(nextchar)));\ 28 | } 29 | 30 | #define assertNotValid_Depth(x, method, nextchar)\ 31 | {\ 32 | json_string temp(JSON_TEXT(x));\ 33 | const json_char * ptr = temp.c_str();\ 34 | assertTrue(!JSONValidator::method(ptr, 1) || ((*ptr)!=JSON_TEXT(nextchar)));\ 35 | } 36 | #else 37 | #define assertValid_Depth(x, method, nextchar) assertValid(x, method, nextchar) 38 | #define assertNotValid_Depth(x, method, nextchar) assertNotValid(x, method, nextchar) 39 | #endif 40 | 41 | #else 42 | #define assertValid(x, method, nextchar) 43 | #define assertNotValid(x, method, nextchar) 44 | #define assertValid_Depth(x, method, nextchar) 45 | #define assertNotValid_Depth(x, method, nextchar) 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/Resources/validyMacros.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TESTSUITE_JSON_VALIDATOR_RESOURCES_VALIDITY_MACROS_H 2 | #define JSON_TESTSUITE_JSON_VALIDATOR_RESOURCES_VALIDITY_MACROS_H 3 | 4 | #include "../../../../JSONOptions.h" 5 | 6 | #ifdef JSON_VALIDATE 7 | 8 | #define assertValid(x, method, nextchar)\ 9 | {\ 10 | json_string temp(JSON_TEXT(x));\ 11 | const json_char * ptr = temp.c_str();\ 12 | assertTrue(JSONValidator::method(ptr) && ((*ptr)==JSON_TEXT(nextchar)));\ 13 | } 14 | 15 | #define assertNotValid(x, method, nextchar)\ 16 | {\ 17 | json_string temp(JSON_TEXT(x));\ 18 | const json_char * ptr = temp.c_str();\ 19 | assertTrue(!JSONValidator::method(ptr) || ((*ptr)!=JSON_TEXT(nextchar)));\ 20 | } 21 | 22 | #ifdef JSON_SECURITY_MAX_NEST_LEVEL 23 | #define assertValid_Depth(x, method, nextchar)\ 24 | {\ 25 | json_string temp(JSON_TEXT(x));\ 26 | const json_char * ptr = temp.c_str();\ 27 | assertTrue(JSONValidator::method(ptr, 1) && ((*ptr)==JSON_TEXT(nextchar)));\ 28 | } 29 | 30 | #define assertNotValid_Depth(x, method, nextchar)\ 31 | {\ 32 | json_string temp(JSON_TEXT(x));\ 33 | const json_char * ptr = temp.c_str();\ 34 | assertTrue(!JSONValidator::method(ptr, 1) || ((*ptr)!=JSON_TEXT(nextchar)));\ 35 | } 36 | #else 37 | #define assertValid_Depth(x, method, nextchar) assertValid(x, method, nextchar) 38 | #define assertNotValid_Depth(x, method, nextchar) assertNotValid(x, method, nextchar) 39 | #endif 40 | 41 | #else 42 | #define assertValid(x, method, nextchar) 43 | #define assertNotValid(x, method, nextchar) 44 | #define assertValid_Depth(x, method, nextchar) 45 | #define assertNotValid_Depth(x, method, nextchar) 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidRoot.cpp: -------------------------------------------------------------------------------- 1 | #include "isValidRoot.h" 2 | #include "Resources/validyMacros.h" 3 | #include "../../Source/JSONValidator.h" 4 | 5 | void testJSONValidator__isValidRoot::testRoots(void){ 6 | #ifdef JSON_VALIDATE 7 | assertTrue(JSONValidator::isValidRoot(JSON_TEXT("{}"))); 8 | assertTrue(JSONValidator::isValidRoot(JSON_TEXT("[]"))); 9 | assertTrue(JSONValidator::isValidRoot(JSON_TEXT("[\"stuff\"]"))); 10 | #endif 11 | } 12 | 13 | void testJSONValidator__isValidRoot::testNotRoots(void){ 14 | #ifdef JSON_VALIDATE 15 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("{]"))); 16 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("[}"))); 17 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("{}aoe"))); 18 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("[]aoe"))); 19 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("aoe"))); 20 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT(""))); 21 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("[\"stuff\":{},]"))); 22 | #endif 23 | } 24 | 25 | void testJSONValidator__isValidRoot::testSuddenEnd(void){ 26 | #ifdef JSON_VALIDATE 27 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT(""))); 28 | 29 | //--- void testJSONValidator__isValidRoot::testRoots(void){ 30 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("{"))); 31 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("["))); 32 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("[\"stuff"))); 33 | 34 | //---void testJSONValidator__isValidRoot::testNotRoots(void){ 35 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("{}aoe"))); 36 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("[]aoe"))); 37 | assertFalse(JSONValidator::isValidRoot(JSON_TEXT("aoe"))); 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_areFloatsEqual.cpp: -------------------------------------------------------------------------------- 1 | #include "_areFloatsEqual.h" 2 | #include "../../Source/NumberToString.h" 3 | 4 | 5 | /** 6 | * Tests that numbers that are actually equal are identified that way 7 | */ 8 | void testNumberToString__areFloatsEqual::testEqual(void){ 9 | assertTrue(_floatsAreEqual( 0.0, 0.0)); 10 | assertTrue(_floatsAreEqual( 1.0, 1.0)); 11 | assertTrue(_floatsAreEqual( 1.1, 1.1)); 12 | assertTrue(_floatsAreEqual(-1.0, -1.0)); 13 | assertTrue(_floatsAreEqual( 0.1, 0.1)); 14 | assertTrue(_floatsAreEqual(-0.1, -0.1)); 15 | } 16 | 17 | 18 | /** 19 | * Make sure that numbers that are very different are identified as not equal 20 | */ 21 | void testNumberToString__areFloatsEqual::testNotEqual(void){ 22 | assertFalse(_floatsAreEqual( 1.0, -1.0)); 23 | assertFalse(_floatsAreEqual( 1.0, 0.0)); 24 | assertFalse(_floatsAreEqual(-1.0, -.0)); 25 | assertFalse(_floatsAreEqual( 0.1, 0.0)); 26 | assertFalse(_floatsAreEqual(-0.1, 0.0)); 27 | assertFalse(_floatsAreEqual(1.0, 1.0001)); 28 | assertFalse(_floatsAreEqual(1.0001, 1.0)); 29 | } 30 | 31 | 32 | /** 33 | * Make sure numbers that are different, but within the threshold of 34 | * floats/doubles being equal are identified as equal 35 | */ 36 | void testNumberToString__areFloatsEqual::testCloseEnough(void){ 37 | //check the exact threshold 38 | assertFalse(_floatsAreEqual( 0.0, JSON_FLOAT_THRESHHOLD)); 39 | assertFalse(_floatsAreEqual( 0.0, -JSON_FLOAT_THRESHHOLD)); 40 | 41 | //check things beneath that threashold 42 | assertTrue(_floatsAreEqual(0.0, JSON_FLOAT_THRESHHOLD / 2)); 43 | assertTrue(_floatsAreEqual(0.0, JSON_FLOAT_THRESHHOLD / -2)); 44 | assertTrue(_floatsAreEqual(-0.1, -0.1)); 45 | assertTrue(_floatsAreEqual(1.000000001, 1.0)); 46 | assertTrue(_floatsAreEqual(1.0, 1.000000001)); 47 | } 48 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestBinary.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | #include "../Source/JSON_Base64.h" 3 | 4 | #if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) 5 | void TestSuite::TestBase64(void){ 6 | UnitTest::SetPrefix("TestBinary.cpp - Base 64"); 7 | 8 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"A", 1)), "A"); 9 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"AB", 2)), "AB"); 10 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABC", 3)), "ABC"); 11 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCD", 4)), "ABCD"); 12 | #ifdef JSON_SAFE 13 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"", 0)), ""); 14 | assertEquals(JSONBase64::json_decode64(JSON_TEXT("123!abc")), ""); 15 | assertEquals(JSONBase64::json_decode64(JSON_TEXT("123=abc")), ""); 16 | assertEquals(JSONBase64::json_decode64(JSON_TEXT("123abc===")), ""); 17 | #endif 18 | 19 | unsigned char temp[255]; 20 | for(unsigned int i = 0; i < 255; ++i){ 21 | temp[i] = (unsigned char)i; 22 | } 23 | json_string ts = JSONBase64::json_encode64(temp, 255); 24 | std::string rs = JSONBase64::json_decode64(ts); 25 | assertEquals(rs.size(), 255); 26 | assertEquals(memcmp(rs.data(), temp, 255), 0); 27 | 28 | #if defined(JSON_LIBRARY) && defined(JSON_EXPOSE_BASE64) 29 | json_char * test = json_encode64(temp, 255); 30 | assertNotNull(test); 31 | unsigned long _size; 32 | void * bin = json_decode64(test, & _size); 33 | assertNotNull(bin); 34 | assertEquals(_size, 255); 35 | assertEquals(memcmp(bin, temp, 255), 0); 36 | json_free(test); 37 | json_free(bin); 38 | #endif 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_FAIL_SAFE.cpp: -------------------------------------------------------------------------------- 1 | #include "JSON_FAIL_SAFE.h" 2 | #include "../../Source/JSONDebug.h" 3 | 4 | #if defined JSON_DEBUG 5 | #ifndef JSON_STDERROR 6 | static json_string last; 7 | #ifdef JSON_LIBRARY 8 | static void callback(const json_char * p){ last = p; } 9 | #else 10 | static void callback(const json_string & p){ last = p; } 11 | #endif 12 | #endif 13 | #endif 14 | 15 | const json_string fail_constfs = JSON_TEXT("fail"); //should pass the same pointer all the way through, no copies 16 | const json_string null_constfs = JSON_TEXT(""); 17 | #if defined JSON_DEBUG || defined JSON_SAFE 18 | json_error_callback_t origCallbackfs = NULL; 19 | #endif 20 | 21 | void testJSONDebug_JSON_FAIL_SAFE::setUp(const std::string & methodName){ 22 | BaseTest::setUp(methodName); 23 | #if defined JSON_DEBUG 24 | #ifndef JSON_STDERROR 25 | origCallbackfs = JSONDebug::register_callback(callback); //check that the callback was called 26 | last = null_constfs; 27 | #endif 28 | #endif 29 | } 30 | 31 | void testJSONDebug_JSON_FAIL_SAFE::tearDown(void){ 32 | BaseTest::tearDown(); 33 | #if defined JSON_DEBUG 34 | #ifndef JSON_STDERROR 35 | JSONDebug::register_callback(origCallbackfs); //check that the callback was called 36 | #endif 37 | #endif 38 | } 39 | 40 | 41 | /** 42 | * Make sure fails do call the callback and run extra code 43 | */ 44 | void testJSONDebug_JSON_FAIL_SAFE::testFail(void){ 45 | int i = 0; 46 | JSON_FAIL_SAFE(fail_constfs, i = 1;); 47 | #if defined(JSON_SAFE) 48 | assertEquals(i, 1); //safe caught the code 49 | #else 50 | assertEquals(i, 0); //fell through because no safety catch 51 | #endif 52 | 53 | #if defined JSON_DEBUG 54 | #ifndef JSON_STDERROR 55 | assertEquals(last, fail_constfs); //make sure the callback was actually called 56 | #endif 57 | #endif 58 | } 59 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/Benchmark/makefile: -------------------------------------------------------------------------------- 1 | OS=$(shell uname) 2 | ifeq ($(OS), Darwin) 3 | fastflag = -fast 4 | else 5 | fastflag = -O3 6 | endif 7 | 8 | single: 9 | g++ main.cpp \ 10 | ../../Source/internalJSONNode.cpp \ 11 | ../../Source/JSONChildren.cpp ../../Source/JSONDebug.cpp \ 12 | ../../Source/JSONIterators.cpp ../../Source/JSONMemory.cpp \ 13 | ../../Source/JSONNode_Mutex.cpp ../../Source/JSONNode.cpp \ 14 | ../../Source/JSONWorker.cpp ../../Source/JSONWriter.cpp \ 15 | ../../Source/libjson.cpp ../../Source/JSONValidator.cpp \ 16 | ../../Source/JSONStream.cpp ../../Source/JSONAllocator.cpp \ 17 | ../../Source/JSONPreparse.cpp \ 18 | -Wfatal-errors -DNDEBUG $(fastflag) -ffast-math -fexpensive-optimizations -o testapp 19 | 20 | debug: 21 | g++ main.cpp \ 22 | ../../Source/internalJSONNode.cpp \ 23 | ../../Source/JSONChildren.cpp ../../Source/JSONDebug.cpp \ 24 | ../../Source/JSONIterators.cpp ../../Source/JSONMemory.cpp \ 25 | ../../Source/JSONNode_Mutex.cpp ../../Source/JSONNode.cpp \ 26 | ../../Source/JSONWorker.cpp ../../Source/JSONWriter.cpp \ 27 | ../../Source/libjson.cpp ../../Source/JSONValidator.cpp \ 28 | ../../Source/JSONStream.cpp ../../Source/JSONAllocator.cpp \ 29 | ../../Source/JSONPreparse.cpp \ 30 | -Wfatal-errors -DJSON_DEBUG -o testapp 31 | 32 | small: 33 | g++ main.cpp \ 34 | ../../Source/internalJSONNode.cpp \ 35 | ../../Source/JSONChildren.cpp ../../Source/JSONDebug.cpp \ 36 | ../../Source/JSONIterators.cpp ../../Source/JSONMemory.cpp \ 37 | ../../Source/JSONNode_Mutex.cpp ../../Source/JSONNode.cpp \ 38 | ../../Source/JSONWorker.cpp ../../Source/JSONWriter.cpp \ 39 | ../../Source/libjson.cpp ../../Source/JSONValidator.cpp \ 40 | ../../Source/JSONStream.cpp ../../Source/JSONAllocator.cpp \ 41 | ../../Source/JSONPreparse.cpp \ 42 | -Wfatal-errors -DNDEBUG -Os -ffast-math -DJSON_LESS_MEMORY -o testapp 43 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_ASSERT.cpp: -------------------------------------------------------------------------------- 1 | #include "JSON_ASSERT.h" 2 | #include "../../Source/JSONDebug.h" 3 | 4 | #if defined JSON_DEBUG 5 | #ifndef JSON_STDERROR 6 | static json_string last; 7 | #ifdef JSON_LIBRARY 8 | static void callback(const json_char * p){ last = p; } 9 | #else 10 | static void callback(const json_string & p){ last = p; } 11 | #endif 12 | #endif 13 | #endif 14 | 15 | const json_string fail_consta = JSON_TEXT("fail"); //should pass the same pointer all the way through, no copies 16 | const json_string null_consta = JSON_TEXT(""); 17 | #if defined JSON_DEBUG || defined JSON_SAFE 18 | json_error_callback_t origCallbacka = NULL; 19 | #endif 20 | 21 | void testJSONDebug_JSON_ASSERT::setUp(const std::string & methodName){ 22 | BaseTest::setUp(methodName); 23 | #if defined JSON_DEBUG 24 | #ifndef JSON_STDERROR 25 | origCallbacka = JSONDebug::register_callback(callback); //check that the callback was called 26 | last = null_consta; 27 | #endif 28 | #endif 29 | } 30 | 31 | void testJSONDebug_JSON_ASSERT::tearDown(void){ 32 | BaseTest::tearDown(); 33 | #if defined JSON_DEBUG 34 | #ifndef JSON_STDERROR 35 | JSONDebug::register_callback(origCallbacka); //check that the callback was called 36 | #endif 37 | #endif 38 | } 39 | 40 | 41 | /** 42 | * Make sure asserts that pass do not call the callback or run extra code 43 | */ 44 | void testJSONDebug_JSON_ASSERT::testPass(void){ 45 | #if defined JSON_DEBUG 46 | #ifndef JSON_STDERROR 47 | JSON_ASSERT(1 == 1, fail_consta); 48 | assertEquals(last, null_consta); //make sure the callback was not called 49 | #endif 50 | #endif 51 | } 52 | 53 | 54 | /** 55 | * Make sure asserts that fail do call the callback and run extra code 56 | */ 57 | void testJSONDebug_JSON_ASSERT::testFail(void){ 58 | #if defined JSON_DEBUG 59 | #ifndef JSON_STDERROR 60 | JSON_ASSERT(1 == 0, fail_consta); 61 | assertEquals(last, fail_consta); //make sure the callback was actually called 62 | #endif 63 | #endif 64 | } 65 | -------------------------------------------------------------------------------- /src/plugin.cpp: -------------------------------------------------------------------------------- 1 | #define PLUGIN_VERSION "0.2.0" 2 | 3 | #include 4 | #include 5 | 6 | #include "AMXUtil.h" 7 | #include "JSONParser.h" 8 | #include "Platform.h" 9 | 10 | PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() 11 | { 12 | return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES; 13 | } 14 | 15 | PLUGIN_EXPORT bool PLUGIN_CALL Load(void** ppData) 16 | { 17 | AMXUtil::SetAMXFunctions(ppData[PLUGIN_DATA_AMX_EXPORTS]); 18 | AMXUtil::SetPrintFunction((logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF]); 19 | AMXUtil::Printf("============== SAMPSON v" PLUGIN_VERSION " by King_Hual loaded =============="); 20 | return 1; 21 | } 22 | 23 | PLUGIN_EXPORT void PLUGIN_CALL Unload() 24 | { 25 | AMXUtil::Printf("============= SAMPSON v" PLUGIN_VERSION " by King_Hual unloaded ============="); 26 | } 27 | 28 | AMX_NATIVE_INFO PluginNatives[] = 29 | { 30 | { "json_parse_file", JSONParser::ParseFile }, 31 | { "json_parse_string", JSONParser::ParseString }, 32 | { "json_close", JSONParser::Close }, 33 | { "json_get_string", JSONParser::GetString }, 34 | { "json_get_type", JSONParser::GetType }, 35 | { "json_get_node", JSONParser::GetNode }, 36 | { "json_get_bool", JSONParser::GetBool }, 37 | { "json_get_int", JSONParser::GetInt }, 38 | { "json_get_float", JSONParser::GetFloat }, 39 | { "json_get_array", JSONParser::GetArray }, 40 | { "json_array_count", JSONParser::GetArraySize }, 41 | { "json_array_at", JSONParser::GetArrayElement }, 42 | { "json_get_name", JSONParser::GetName }, 43 | { "json_get_last_error", Platform::GetLastError }, 44 | { "json_get_last_error_extra", Platform::GetLastErrorSecondary }, 45 | { "json_get_error_extra_string", Platform::GetErrorSecondaryString }, 46 | { 0, 0 } 47 | }; 48 | 49 | PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX* pAmx) 50 | { 51 | AMXUtil::AddAMX(pAmx); 52 | return amx_Register(pAmx, PluginNatives, -1); 53 | } 54 | 55 | PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX* pAmx) 56 | { 57 | AMXUtil::RemoveAMX(pAmx); 58 | return AMX_ERR_NONE; 59 | } 60 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_ftoa.cpp: -------------------------------------------------------------------------------- 1 | #include "_ftoa.h" 2 | #include "../../Source/NumberToString.h" 3 | 4 | 5 | /** 6 | * Test that the float to string function works 7 | */ 8 | void testNumberToString__ftoa::testRandomNumbers(void){ 9 | //random numbers to varying precision 10 | assertEquals(NumberToString::_ftoa((json_number) 1.2), JSON_TEXT( "1.2")); 11 | assertEquals(NumberToString::_ftoa((json_number) -1.2), JSON_TEXT( "-1.2")); 12 | assertEquals(NumberToString::_ftoa((json_number) 1.02), JSON_TEXT( "1.02")); 13 | assertEquals(NumberToString::_ftoa((json_number) -1.02), JSON_TEXT( "-1.02")); 14 | assertEquals(NumberToString::_ftoa((json_number) 1.002), JSON_TEXT( "1.002")); 15 | assertEquals(NumberToString::_ftoa((json_number) -1.002), JSON_TEXT( "-1.002")); 16 | assertEquals(NumberToString::_ftoa((json_number) 3.1415), JSON_TEXT( "3.1415")); 17 | assertEquals(NumberToString::_ftoa((json_number) -3.1415), JSON_TEXT( "-3.1415")); 18 | } 19 | 20 | 21 | /** 22 | * This function reverts to one of the int functions in case of an int because 23 | * they are faster. This tests that. 24 | */ 25 | void testNumberToString__ftoa::testSpecializedInts(void){ 26 | assertEquals(NumberToString::_ftoa((json_number) 1.0), JSON_TEXT( "1")); 27 | assertEquals(NumberToString::_ftoa((json_number) 10.0), JSON_TEXT( "10")); 28 | assertEquals(NumberToString::_ftoa((json_number) -1.0), JSON_TEXT( "-1")); 29 | assertEquals(NumberToString::_ftoa((json_number)-10.0), JSON_TEXT("-10")); 30 | assertEquals(NumberToString::_ftoa((json_number) 0.0), JSON_TEXT( "0")); 31 | assertEquals(NumberToString::_ftoa((json_number) -0.0), JSON_TEXT( "0")); 32 | 33 | //close enough to an int 34 | assertEquals(NumberToString::_ftoa((json_number) 1.000000001), JSON_TEXT( "1")); 35 | assertEquals(NumberToString::_ftoa((json_number) -1.000000001), JSON_TEXT( "-1")); 36 | assertEquals(NumberToString::_ftoa((json_number) 0.000000001), JSON_TEXT( "0")); 37 | assertEquals(NumberToString::_ftoa((json_number) -0.000000001), JSON_TEXT( "0")); 38 | } 39 | -------------------------------------------------------------------------------- /src/SAMPSON.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2006 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SAMPSON", "SAMPSON.vcxproj", "{9851555C-5434-492F-B7C5-D34662049A9B}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA} = {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "statLibJson", "libjson\libjson.vcxproj", "{153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Release|Win32 = Release|Win32 17 | small|Win32 = small|Win32 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {9851555C-5434-492F-B7C5-D34662049A9B}.Debug|Win32.ActiveCfg = Debug|Win32 21 | {9851555C-5434-492F-B7C5-D34662049A9B}.Debug|Win32.Build.0 = Debug|Win32 22 | {9851555C-5434-492F-B7C5-D34662049A9B}.Release|Win32.ActiveCfg = Release|Win32 23 | {9851555C-5434-492F-B7C5-D34662049A9B}.Release|Win32.Build.0 = Release|Win32 24 | {9851555C-5434-492F-B7C5-D34662049A9B}.small|Win32.ActiveCfg = small|Win32 25 | {9851555C-5434-492F-B7C5-D34662049A9B}.small|Win32.Build.0 = small|Win32 26 | {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA}.Debug|Win32.Build.0 = Debug|Win32 28 | {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA}.Release|Win32.ActiveCfg = Release|Win32 29 | {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA}.Release|Win32.Build.0 = Release|Win32 30 | {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA}.small|Win32.ActiveCfg = small|Win32 31 | {153A6FE5-40A9-4C31-B0C2-1C68D2E37BEA}.small|Win32.Build.0 = small|Win32 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(ExtensibilityGlobals) = postSolution 37 | SolutionGuid = {D4E3A2D9-F0D0-4974-AE4F-48A3EEFDD36D} 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /src/SAMPSON.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {e5281bb1-e316-4946-a1c1-54df799c43da} 6 | 7 | 8 | {f9f51206-ec41-41d6-a853-43fe09b12feb} 9 | 10 | 11 | {ec3110fd-019c-42d4-9ddb-280b7fc3fba1} 12 | 13 | 14 | 15 | 16 | SDK 17 | 18 | 19 | Plugin 20 | 21 | 22 | Plugin 23 | 24 | 25 | Plugin 26 | 27 | 28 | 29 | Plugin 30 | 31 | 32 | Plugin 33 | 34 | 35 | 36 | 37 | Plugin 38 | 39 | 40 | 41 | 42 | SDK 43 | 44 | 45 | SDK\amx 46 | 47 | 48 | SDK\amx 49 | 50 | 51 | Plugin 52 | 53 | 54 | Plugin 55 | 56 | 57 | 58 | Plugin 59 | 60 | 61 | Plugin 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/AMXUtil.cpp: -------------------------------------------------------------------------------- 1 | #include "AMXUtil.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | extern void* pAMXFunctions; 8 | 9 | logprintf_t AMXUtil::Printf; 10 | std::list AMXUtil::m_lAMX; 11 | 12 | cell AMXUtil::Invoke(const char* szFunction, const char* szFormat, ...) 13 | { 14 | cell iReturnValue = 1; 15 | std::vector returnValues(m_lAMX.size(), 1); 16 | size_t idx = 0; 17 | va_list argPtr; 18 | 19 | for (std::list::iterator it = m_lAMX.begin(); it != m_lAMX.end(); ++it, ++idx) { 20 | AMX* pAmx = *it; 21 | int iFuncIdx; 22 | 23 | if (amx_FindPublic(pAmx, szFunction, &iFuncIdx) != 0) { 24 | continue; 25 | } 26 | 27 | cell addresses[16]; 28 | unsigned int addrIdx = 0; 29 | 30 | if (szFormat) { 31 | va_start(argPtr, szFormat); 32 | 33 | for (unsigned int i = 0; i < strlen(szFormat); ++i) { 34 | if (szFormat[i] == 'i') { 35 | amx_Push(pAmx, va_arg(argPtr, int)); 36 | } 37 | else if (szFormat[i] == 's') { 38 | amx_PushString(pAmx, &addresses[addrIdx++], NULL, va_arg(argPtr, char*), false, false); 39 | } 40 | else if (szFormat[i] == 'a') { 41 | cell iAmxAddr, *pPhysAddr; 42 | 43 | PAWNArray array = va_arg(argPtr, PAWNArray); 44 | amx_Allot(pAmx, array.length, &iAmxAddr, &pPhysAddr); 45 | memcpy(pPhysAddr, array.address, array.length * sizeof(cell)); 46 | amx_Push(pAmx, iAmxAddr); 47 | 48 | } 49 | } 50 | 51 | va_end(argPtr); 52 | } 53 | 54 | amx_Exec(pAmx, &returnValues[idx], iFuncIdx); 55 | 56 | if (!returnValues[idx]) { 57 | iReturnValue = 0; 58 | } 59 | 60 | for (unsigned int i = 0; i < addrIdx; ++i) { 61 | amx_Release(pAmx, addresses[i]); 62 | } 63 | 64 | } 65 | 66 | return iReturnValue; 67 | } 68 | 69 | void AMXUtil::SetAMXFunctions(void* pFunctionData) 70 | { 71 | pAMXFunctions = pFunctionData; 72 | } 73 | 74 | char* AMXUtil::GetStringFromCell(AMX* pAmx, cell cellString) 75 | { 76 | cell* pAddr = 0; 77 | int iLen = 0; 78 | char* pStr; 79 | 80 | amx_GetAddr(pAmx, cellString, &pAddr); 81 | amx_StrLen(pAddr, &iLen); 82 | ++iLen; 83 | pStr = new char[iLen]; 84 | amx_GetString(pStr, pAddr, 0, iLen); 85 | return pStr; 86 | } 87 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs/GNU_C.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_GNU_C_HEADER 2 | #define JSON_GUN_C_HEADER 3 | 4 | #ifdef __GNUC__ 5 | 6 | #define json_deprecated(method, warning) method __attribute__((deprecated)) 7 | 8 | #if (__GNUC__ >= 3) 9 | #define JSON_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 10 | #else 11 | #define JSON_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) 12 | #endif 13 | 14 | #if (JSON_GCC_VERSION >= 40300) 15 | #define json_hot __attribute__ ((hot)) 16 | #define json_cold __attribute__ ((cold)) 17 | #define json_pure json_nothrow __attribute__ ((pure, hot)) 18 | #define json_malloc_attr json_nothrow __attribute__ ((malloc, hot)) 19 | 20 | /* Can do priorities */ 21 | #if (JSON_WRITE_PRIORITY == HIGH) 22 | #define json_write_priority __attribute__ ((hot)) 23 | #elif (JSON_WRITE_PRIORITY == LOW) 24 | #define json_write_priority __attribute__ ((cold)) 25 | #else 26 | #define json_write_priority 27 | #endif 28 | 29 | #if (JSON_READ_PRIORITY == HIGH) 30 | #define json_read_priority __attribute__ ((hot)) 31 | #elif (JSON_READ_PRIORITY == LOW) 32 | #define json_read_priority __attribute__ ((cold)) 33 | #else 34 | #define json_read_priority 35 | #endif 36 | 37 | #define json_likely(x) __builtin_expect((long)((bool)(x)),1) 38 | #define json_unlikely(x) __builtin_expect((long)((bool)(x)),0) 39 | #else 40 | #if (JSON_GCC_VERSION >= 29600) 41 | #define json_pure json_nothrow __attribute__ ((pure)) 42 | #define json_likely(x) __builtin_expect((long)((bool)(x)),1) 43 | #define json_unlikely(x) __builtin_expect((long)((bool)(x)),0) 44 | #else 45 | #define json_pure json_nothrow 46 | #define json_likely(x) x 47 | #define json_unlikely(x) x 48 | #endif 49 | 50 | #define json_malloc_attr json_nothrow __attribute__ ((malloc)) 51 | #define json_write_priority 52 | #define json_read_priority 53 | #define json_hot 54 | #define json_cold 55 | #endif 56 | 57 | #define json_nothrow throw() 58 | #define json_throws(x) throw(x) 59 | 60 | #ifdef JSON_LESS_MEMORY 61 | #define PACKED(x) :x __attribute__ ((packed)) 62 | #define BITS(x) :x 63 | #endif 64 | 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONDebug/JSON_ASSERT_SAFE.cpp: -------------------------------------------------------------------------------- 1 | #include "JSON_ASSERT_SAFE.h" 2 | #include "../../Source/JSONDebug.h" 3 | 4 | #if defined JSON_DEBUG 5 | #ifndef JSON_STDERROR 6 | static json_string last; 7 | #ifdef JSON_LIBRARY 8 | static void callback(const json_char * p){ last = p; } 9 | #else 10 | static void callback(const json_string & p){ last = p; } 11 | #endif 12 | #endif 13 | #endif 14 | 15 | const json_string fail_const = JSON_TEXT("fail"); //should pass the same pointer all the way through, no copies 16 | const json_string null_const = JSON_TEXT(""); 17 | #if defined JSON_DEBUG || defined JSON_SAFE 18 | json_error_callback_t origCallback = NULL; 19 | #endif 20 | 21 | void testJSONDebug_JSON_ASSERT_SAFE::setUp(const std::string & methodName){ 22 | BaseTest::setUp(methodName); 23 | #if defined JSON_DEBUG 24 | #ifndef JSON_STDERROR 25 | origCallback = JSONDebug::register_callback(callback); //check that the callback was called 26 | last = null_const; 27 | #endif 28 | #endif 29 | } 30 | 31 | void testJSONDebug_JSON_ASSERT_SAFE::tearDown(void){ 32 | BaseTest::tearDown(); 33 | #if defined JSON_DEBUG 34 | #ifndef JSON_STDERROR 35 | JSONDebug::register_callback(origCallback); //check that the callback was called 36 | #endif 37 | #endif 38 | } 39 | 40 | 41 | /** 42 | * Make sure asserts that pass do not call the callback or run extra code 43 | */ 44 | void testJSONDebug_JSON_ASSERT_SAFE::testPass(void){ 45 | int i = 0; 46 | JSON_ASSERT_SAFE(1 == 1, fail_const, i = 1;); 47 | assertEquals(i, 0); 48 | 49 | #if defined JSON_DEBUG 50 | #ifndef JSON_STDERROR 51 | assertEquals(last, null_const); //make sure the callback was not called 52 | #endif 53 | #endif 54 | } 55 | 56 | 57 | /** 58 | * Make sure asserts that fail do call the callback and run extra code 59 | */ 60 | void testJSONDebug_JSON_ASSERT_SAFE::testFail(void){ 61 | int i = 0; 62 | JSON_ASSERT_SAFE(1 == 0, fail_const, i = 1;); 63 | #if defined(JSON_SAFE) 64 | assertEquals(i, 1); //safe caught the code 65 | #else 66 | assertEquals(i, 0); //fell through because no safety catch 67 | #endif 68 | 69 | #if defined JSON_DEBUG 70 | #ifndef JSON_STDERROR 71 | assertEquals(last, fail_const); //make sure the callback was actually called 72 | #endif 73 | #endif 74 | } 75 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite2Creator.php: -------------------------------------------------------------------------------- 1 | 7 | 8 | #if !defined JSON_DEFAULT_DELIMITER 9 | #define JSON_DEFAULT_DELIMITER '/' 10 | #endif 11 | 12 | #define JSON_NULL 0 13 | #define JSON_STRING 1 14 | #define JSON_NUMBER 2 15 | #define JSON_BOOL 3 16 | #define JSON_ARRAY 4 17 | #define JSON_NODE 5 18 | 19 | #define JSON_ERROR_NONE 0 20 | #define JSON_ERROR_JSON_ERROR_SCRIPTFILES_PATH_NOT_FOUND 1 21 | #define JSON_ERROR_FAILED_READING_FILE 2 22 | #define JSON_ERROR_INVALID_JSON_PATH 3 23 | 24 | native JSONNode:json_parse_file(const file_path[]); 25 | native JSONNode:json_parse_string(const string[]); 26 | native json_close(JSONNode:node); 27 | native json_get_type(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER); 28 | native JSONNode:json_get_node(JSONNode:node, const path[], const path_delim = JSON_DEFAULT_DELIMITER); 29 | native bool:json_get_bool(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER); 30 | native json_get_int(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER); 31 | native Float:json_get_float(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER); 32 | native json_get_string(JSONNode:node, dst[], const len = sizeof(dst), const path[] = '\0', const bool:packed = false, const path_delim = JSON_DEFAULT_DELIMITER); 33 | native json_get_name(JSONNode:node, dst[], const len = sizeof(dst), const bool:packed = false); 34 | 35 | native JSONArray:json_get_array(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER); 36 | native json_array_count(JSONArray:array); 37 | native JSONNode:json_array_at(JSONArray:array, const index); 38 | 39 | native json_get_last_error(); 40 | native json_get_last_error_extra(); 41 | native json_get_error_extra_string(errno, dst[] , const len = sizeof(dst)); 42 | 43 | stock json_get_error_string(errno, dst[], const len = sizeof(dst)) 44 | { 45 | switch (errno) 46 | { 47 | case JSON_ERROR_NONE: 48 | { 49 | strcat(dst, "None", len); 50 | } 51 | case JSON_ERROR_JSON_ERROR_SCRIPTFILES_PATH_NOT_FOUND: 52 | { 53 | strcat(dst, "Could not get scriptfiles path", len); 54 | } 55 | case JSON_ERROR_FAILED_READING_FILE: 56 | { 57 | strcat(dst, "Could not read input file.", len); 58 | } 59 | case JSON_ERROR_INVALID_JSON_PATH: 60 | { 61 | strcat(dst, "Invalid JSON path given. Node does not exist.", len); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestInequality.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | 3 | void TestSuite::TestInequality(void){ 4 | UnitTest::SetPrefix("TestInequality.cpp - Inequality"); 5 | #ifdef JSON_LIBRARY 6 | JSONNODE * test1 = json_new(JSON_NODE); 7 | JSONNODE * test2 = json_new(JSON_NODE); 8 | json_set_a(test1, JSON_TEXT("hello")); 9 | json_set_a(test2, JSON_TEXT("world")); 10 | assertFalse(json_equal(test1, test2)); 11 | 12 | json_set_i(test2,13); 13 | assertFalse(json_equal(test1, test2)); 14 | 15 | json_set_f(test2, 13.5f); 16 | assertFalse(json_equal(test1, test2)); 17 | 18 | json_set_b(test2, true); 19 | assertFalse(json_equal(test1, test2)); 20 | 21 | json_set_b(test2, false); 22 | assertFalse(json_equal(test1, test2)); 23 | 24 | json_nullify(test2); 25 | assertFalse(json_equal(test1, test2)); 26 | json_delete(test1); 27 | json_delete(test2); 28 | #else 29 | JSONNode test1; 30 | JSONNode test2; 31 | test1 = JSON_TEXT("hello"); 32 | test2 = JSON_TEXT("world"); 33 | assertNotEquals(test1, test2); 34 | assertNotEquals(test1, JSON_TEXT("hi")); 35 | assertNotEquals(test2, 13.5f); 36 | assertNotEquals(test2, 14); 37 | assertNotEquals(test2, true); 38 | assertNotEquals(test2, false); 39 | 40 | test2 = 13; 41 | assertNotEquals(test1, test2); 42 | assertNotEquals(test2, 13.5f); 43 | assertNotEquals(test2, 14); 44 | assertNotEquals(test2, true); 45 | assertNotEquals(test2, false); 46 | assertNotEquals(test2, JSON_TEXT("13")); //not the same type 47 | 48 | test2 = 13.5f; 49 | assertNotEquals(test1, test2); 50 | assertNotEquals(test2, 13); 51 | assertNotEquals(test2, 14); 52 | assertNotEquals(test2, true); 53 | assertNotEquals(test2, false); 54 | assertNotEquals(test2, JSON_TEXT("13.5")); //not the same type 55 | 56 | test2 = true; 57 | assertNotEquals(test1, test2); 58 | assertNotEquals(test2, 13.5f); 59 | assertNotEquals(test2, 14); 60 | assertNotEquals(test2, false); 61 | assertNotEquals(test2, JSON_TEXT("true")); //not the same type 62 | 63 | test2 = false; 64 | assertNotEquals(test1, test2); 65 | assertNotEquals(test2, 13.5f); 66 | assertNotEquals(test2, 14); 67 | assertNotEquals(test2, true); 68 | assertNotEquals(test2, JSON_TEXT("false")); //not the same type 69 | 70 | test2.nullify(); 71 | assertNotEquals(test1, test2); 72 | assertNotEquals(test2, 13.5f); 73 | assertNotEquals(test2, 14); 74 | assertNotEquals(test2, true); 75 | assertNotEquals(test2, false); 76 | assertNotEquals(test2, "null"); //not the same type 77 | #endif 78 | } 79 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSON_Base64/json_encode64.cpp: -------------------------------------------------------------------------------- 1 | #include "json_encode64.h" 2 | #include "../../Source/JSON_Base64.h" 3 | 4 | /** 5 | * Make sure that these two function reverse each other 6 | */ 7 | void testJSON_Base64__json_encode64::testReverseEachOther(void){ 8 | #if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) 9 | #ifdef JSON_SAFE 10 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"", 0)), ""); 11 | #endif 12 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"A", 1)), "A"); 13 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"AB", 2)), "AB"); 14 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABC", 3)), "ABC"); 15 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCD", 4)), "ABCD"); 16 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDE", 5)), "ABCDE"); 17 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEF", 6)), "ABCDEF"); 18 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEFG", 7)), "ABCDEFG"); 19 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEFGH", 8)), "ABCDEFGH"); 20 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEFGHI", 9)), "ABCDEFGHI"); 21 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEFGHIJ", 10)), "ABCDEFGHIJ"); 22 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEFGHIJK", 11)), "ABCDEFGHIJK"); 23 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEFGHIJKL", 12)), "ABCDEFGHIJKL"); 24 | assertEquals(JSONBase64::json_decode64(JSONBase64::json_encode64((unsigned char *)"ABCDEFGHIJKLM", 13)), "ABCDEFGHIJKLM"); 25 | #endif 26 | } 27 | 28 | /** 29 | * Make sure all characters work in the code 30 | */ 31 | void testJSON_Base64__json_encode64::testAllChars(void){ 32 | #if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) 33 | 34 | //create a binary chunk of data to use with every char 35 | unsigned char temp[255]; 36 | for(unsigned int i = 0; i < 255; ++i){ 37 | temp[i] = (unsigned char)i; 38 | } 39 | 40 | //loop through all of the lengths 41 | for(unsigned int length = 1; length < 255; ++length){ 42 | json_string ts = JSONBase64::json_encode64(temp, length); 43 | std::string rs = JSONBase64::json_decode64(ts); 44 | assertEquals(rs.size(), length); 45 | assertEquals(memcmp(rs.data(), temp, length), 0); 46 | } 47 | #endif 48 | } 49 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_ALLOCATOR_H 2 | #define JSON_ALLOCATOR_H 3 | 4 | #include "JSONStats.h" 5 | #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) 6 | 7 | #include 8 | 9 | //need these for the json_nothrow 10 | #include "JSONDefs/Visual_C.h" 11 | #include "JSONDefs/GNU_C.h" 12 | #include "JSONDefs/Unknown_C.h" 13 | 14 | class JSONAllocatorRelayer { 15 | public: 16 | static void * alloc(size_t bytes) json_nothrow json_hot; 17 | static void dealloc(void * ptr) json_nothrow json_hot; 18 | }; 19 | 20 | template class json_allocator; 21 | 22 | // specialize for void: 23 | template <> class json_allocator { 24 | public: 25 | typedef void* pointer; 26 | typedef const void* const_pointer; 27 | // reference to void members are impossible. 28 | typedef void value_type; 29 | template struct rebind { typedef json_allocator other; }; 30 | }; 31 | 32 | template class json_allocator { 33 | public: 34 | typedef size_t size_type; 35 | typedef ptrdiff_t difference_type; 36 | typedef T* pointer; 37 | typedef const T* const_pointer; 38 | typedef T& reference; 39 | typedef const T& const_reference; 40 | typedef T value_type; 41 | template struct rebind { typedef json_allocator other; }; 42 | 43 | //LIBJSON_OBJECT(json_allocator); 44 | 45 | inline json_allocator() json_nothrow { 46 | //LIBJSON_CTOR; 47 | } 48 | inline json_allocator(const json_allocator&) json_nothrow { 49 | //LIBJSON_COPY_CTOR; 50 | } 51 | template inline json_allocator(const json_allocator&) json_nothrow { 52 | //LIBJSON_COPY_CTOR; 53 | } 54 | inline ~json_allocator() json_nothrow { 55 | //LIBJSON_DTOR; 56 | } 57 | 58 | inline pointer address(reference x) const { return &x; } 59 | inline const_pointer address(const_reference x) const { return &x; } 60 | 61 | inline pointer allocate(size_type n, json_allocator::const_pointer = 0) json_hot { 62 | return (pointer)JSONAllocatorRelayer::alloc(n * sizeof(T)); 63 | } 64 | inline void deallocate(pointer p, size_type) json_hot { 65 | JSONAllocatorRelayer::dealloc(p); 66 | } 67 | 68 | inline size_type max_size() const json_nothrow { return 0xEFFFFFFF; } 69 | 70 | inline void construct(pointer p, const T& val){ 71 | new(p)T(val); 72 | }; 73 | inline void destroy(pointer p){ 74 | ((T*)p) -> ~T(); 75 | } 76 | }; 77 | 78 | template inline bool operator==(const json_allocator&, const json_allocator&) json_nothrow { return true; } 79 | template inline bool operator!=(const json_allocator&, const json_allocator&) json_nothrow { return false; } 80 | 81 | #endif 82 | #endif 83 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONStream.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBJSON_GUARD_STREAM_H 2 | #define LIBJSON_GUARD_STREAM_H 3 | 4 | #include "JSONDebug.h" 5 | 6 | #ifdef JSON_STREAM 7 | 8 | #ifdef JSON_LESS_MEMORY 9 | #ifdef __GNUC__ 10 | #pragma pack(push, 1) 11 | #elif _MSC_VER 12 | #pragma pack(push, JSONStream_pack, 1) 13 | #endif 14 | #endif 15 | 16 | #ifdef JSON_MEMORY_CALLBACKS 17 | #include "JSONMemory.h" 18 | #endif 19 | 20 | #ifndef JSON_LIBRARY 21 | class JSONNode; //foreward declaration 22 | typedef void (*json_stream_callback_t)(JSONNode &, void *); 23 | #endif 24 | 25 | class JSONStream { 26 | public: 27 | LIBJSON_OBJECT(JSONStream); 28 | JSONStream(json_stream_callback_t call_p, json_stream_e_callback_t call_e = NULL, void * callbackIdentifier = JSONSTREAM_SELF) json_nothrow; 29 | JSONStream(const JSONStream & orig) json_nothrow; 30 | JSONStream & operator =(const JSONStream & orig) json_nothrow; 31 | ~JSONStream(void) json_nothrow { LIBJSON_DTOR; } 32 | #ifdef JSON_LIBRARY 33 | JSONStream & operator << (const json_char * str) json_nothrow; 34 | #else 35 | JSONStream & operator << (const json_string & str) json_nothrow; 36 | #endif 37 | 38 | static void deleteJSONStream(JSONStream * stream) json_nothrow { 39 | #ifdef JSON_MEMORY_CALLBACKS 40 | stream -> ~JSONStream(); 41 | libjson_free(stream); 42 | #else 43 | delete stream; 44 | #endif 45 | } 46 | 47 | static JSONStream * newJSONStream(json_stream_callback_t callback, json_stream_e_callback_t call_e, void * callbackIdentifier) json_nothrow { 48 | #ifdef JSON_MEMORY_CALLBACKS 49 | return new(json_malloc(1)) JSONStream(callback, call_e, callbackIdentifier); 50 | #else 51 | return new JSONStream(callback, call_e, callbackIdentifier); 52 | #endif 53 | } 54 | 55 | inline void reset() json_nothrow { 56 | state = true; 57 | buffer.clear(); 58 | } 59 | JSON_PRIVATE 60 | inline void * getIdentifier(void) json_nothrow { 61 | if (callback_identifier == JSONSTREAM_SELF){ 62 | return (void*)this; 63 | } 64 | return callback_identifier; 65 | } 66 | 67 | #if (JSON_READ_PRIORITY == HIGH) && (!(defined(JSON_LESS_MEMORY))) 68 | template 69 | static size_t FindNextRelevant(const json_string & value_t, const size_t pos) json_nothrow json_read_priority; 70 | #else 71 | static size_t FindNextRelevant(json_char ch, const json_string & value_t, const size_t pos) json_nothrow json_read_priority; 72 | #endif 73 | 74 | void parse(void) json_nothrow; 75 | json_string buffer; 76 | json_stream_callback_t call; 77 | json_stream_e_callback_t err_call; 78 | void * callback_identifier; 79 | bool state BITS(1); 80 | }; 81 | 82 | #ifdef JSON_LESS_MEMORY 83 | #ifdef __GNUC__ 84 | #pragma pack(pop) 85 | #elif _MSC_VER 86 | #pragma pack(pop, JSONStream_pack) 87 | #endif 88 | #endif 89 | 90 | #endif 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/TestSuite.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 38 | 39 | 45 | 46 | 47 | 48 | 49 | 50 | 55 | 56 | 62 | 63 | 64 | 65 | 67 | 68 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | #include "../Source/JSONNode.h" 3 | 4 | #ifndef JSON_STDERROR 5 | #ifdef JSON_DEBUG 6 | #ifdef JSON_LIBRARY 7 | static void callback(const json_char * msg_c){ 8 | json_string msg(msg_c); 9 | #else 10 | static void callback(const json_string & msg){ 11 | #endif 12 | #ifdef JSON_STRING_HEADER 13 | echo("callback triggered, but can't display string"); 14 | #else 15 | #ifdef JSON_UNICODE 16 | const std::string res = std::string(msg.begin(), msg.end()); 17 | echo(res); 18 | #else 19 | echo(msg); 20 | #endif 21 | #endif 22 | } 23 | #endif 24 | #endif 25 | 26 | void TestSuite::TestSelf(void){ 27 | UnitTest::SetPrefix("TestSuite.cpp - Self Test"); 28 | #ifndef JSON_STDERROR 29 | #ifdef JSON_DEBUG 30 | #ifdef JSON_LIBRARY 31 | json_register_debug_callback(callback); 32 | #else 33 | libjson::register_debug_callback(callback); 34 | #endif 35 | #endif 36 | #endif 37 | assertUnitTest(); 38 | 39 | #if defined(JSON_SAFE) && ! defined(JSON_LIBRARY) 40 | bool temp = false; 41 | JSON_ASSERT_SAFE(true, JSON_TEXT(""), temp = true;); 42 | assertFalse(temp); 43 | JSON_ASSERT_SAFE(false, JSON_TEXT(""), temp = true;); 44 | assertTrue(temp); 45 | 46 | temp = false; 47 | JSON_FAIL_SAFE(JSON_TEXT(""), temp = true;); 48 | assertTrue(temp); 49 | #endif 50 | 51 | echo("If this fails, then edit JSON_INDEX_TYPE in JSONOptions.h"); 52 | assertLessThanEqualTo(sizeof(json_index_t), sizeof(void*)); 53 | } 54 | 55 | //makes sure that libjson didn't leak memory somewhere 56 | void TestSuite::TestFinal(void){ 57 | #ifdef JSON_UNIT_TEST 58 | UnitTest::SetPrefix("TestSuite.cpp - Memory Leak"); 59 | echo("Node allocations: " << JSONNode::getNodeAllocationCount()); 60 | echo("Node deallocations: " << JSONNode::getNodeDeallocationCount()); 61 | assertEquals(JSONNode::getNodeAllocationCount(), JSONNode::getNodeDeallocationCount()); 62 | 63 | echo("internal allocations: " << JSONNode::getInternalAllocationCount()); 64 | echo("internal deallocations: " << JSONNode::getInternalDeallocationCount()); 65 | assertEquals(JSONNode::getInternalAllocationCount(), JSONNode::getInternalDeallocationCount()); 66 | 67 | echo("children allocations: " << JSONNode::getChildrenAllocationCount()); 68 | echo("children deallocations: " << JSONNode::getChildrenDeallocationCount()); 69 | assertEquals(JSONNode::getChildrenAllocationCount(), JSONNode::getChildrenDeallocationCount()); 70 | 71 | #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) 72 | echo("stl allocations: " << JSONAllocatorRelayer::getAllocationCount()); 73 | echo("stl deallocations: " << JSONAllocatorRelayer::getDeallocationCount()); 74 | echo("stl bytes: " << JSONAllocatorRelayer::getAllocationByteCount()); 75 | assertEquals(JSONAllocatorRelayer::getAllocationCount(), JSONAllocatorRelayer::getDeallocationCount()); 76 | #endif 77 | #endif 78 | } 79 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestEquality.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | #include "../Source/JSONNode.h" 3 | 4 | void TestSuite::TestEquality(void){ 5 | UnitTest::SetPrefix("TestEquality.cpp - Equality"); 6 | #ifdef JSON_LIBRARY 7 | JSONNODE * test1 = json_new(JSON_NODE); 8 | JSONNODE * test2 = json_new(JSON_NODE); 9 | assertTrue(json_equal(test1, test2)); 10 | 11 | //check literally the same internal pointer 12 | json_set_n(test2, test1); 13 | #ifdef JSON_UNIT_TEST 14 | #ifdef JSON_REF_COUNT 15 | assertEquals(((JSONNode*)test1) -> internal, ((JSONNode*)test2) -> internal); 16 | #else 17 | assertNotEquals(((JSONNode*)test1) -> internal, ((JSONNode*)test2) -> internal); 18 | #endif 19 | #endif 20 | assertTrue(json_equal(test1, test2)); 21 | 22 | json_set_a(test1, JSON_TEXT("hello")); 23 | json_set_a(test2, JSON_TEXT("hello")); 24 | assertTrue(json_equal(test1, test2)); 25 | 26 | json_set_f(test1, 13.5f); 27 | json_set_f(test2, 13.5f); 28 | assertTrue(json_equal(test1, test2)); 29 | 30 | json_set_i(test1, 13); 31 | json_set_f(test2, 13.0f); 32 | assertTrue(json_equal(test1, test2)); 33 | 34 | json_set_b(test1, true); 35 | json_set_b(test2, (int)true); 36 | assertTrue(json_equal(test1, test2)); 37 | 38 | json_set_b(test1, false); 39 | json_set_b(test2, (int)false); 40 | assertTrue(json_equal(test1, test2)); 41 | 42 | json_nullify(test1); 43 | json_nullify(test2); 44 | assertTrue(json_equal(test1, test2)); 45 | JSONNODE * test3 = json_new(JSON_NULL); 46 | assertTrue(json_equal(test1, test3)); 47 | assertTrue(json_equal(test3, test3)); 48 | 49 | json_delete(test1); 50 | json_delete(test2); 51 | json_delete(test3); 52 | #else 53 | JSONNode test1; 54 | JSONNode test2; 55 | assertEquals(test1, test2); 56 | 57 | //check literally the same internal pointer 58 | test2 = test1; 59 | #ifdef JSON_UNIT_TEST 60 | #ifdef JSON_REF_COUNT 61 | assertEquals(test1.internal, test2.internal); 62 | #else 63 | assertNotEquals(test1.internal, test2.internal); 64 | #endif 65 | #endif 66 | assertEquals(test1, test2); 67 | 68 | test1 = JSON_TEXT("hello"); 69 | test2 = JSON_TEXT("hello"); 70 | assertEquals(test1, JSON_TEXT("hello")); 71 | assertEquals(test1, test2); 72 | 73 | test1 = 13.5f; 74 | test2 = 13.5f; 75 | assertEquals(test1, 13.5f); 76 | assertEquals(test1, test2); 77 | 78 | test1 = 13; 79 | test2 = 13.0f; 80 | assertEquals(test1, 13.0f); 81 | assertEquals(test1, 13); 82 | assertEquals(test1, test2); 83 | 84 | test1 = true; 85 | test2 = true; 86 | assertEquals(test1, true); 87 | assertEquals(test1, test2); 88 | 89 | test1 = false; 90 | test2 = false; 91 | assertEquals(test1, false); 92 | assertEquals(test1, test2); 93 | 94 | test1.nullify(); 95 | test2.nullify(); 96 | assertEquals(test1, test2); 97 | JSONNode test3 = JSONNode(JSON_NULL); 98 | assertEquals(test1, test3); 99 | assertEquals(test2, test3); 100 | #endif 101 | } 102 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONWorker.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_WORKER_H 2 | #define JSON_WORKER_H 3 | 4 | #include "JSONNode.h" 5 | #include "JSONSharedString.h" 6 | 7 | class JSONWorker { 8 | public: 9 | static json_string RemoveWhiteSpaceAndComments(const json_string & value_t, bool escapeQuotes) json_nothrow json_read_priority; 10 | static json_char * RemoveWhiteSpaceAndCommentsC(const json_string & value_t, bool escapeQuotes) json_nothrow json_read_priority; 11 | 12 | #ifdef JSON_READ_PRIORITY 13 | static JSONNode parse(const json_string & json) json_throws(std::invalid_argument) json_read_priority; 14 | static JSONNode parse_unformatted(const json_string & json) json_throws(std::invalid_argument) json_read_priority; 15 | 16 | static JSONNode _parse_unformatted(const json_char * json, const json_char * const end) json_throws(std::invalid_argument) json_read_priority; 17 | 18 | static json_char * RemoveWhiteSpace(const json_string & value_t, size_t & len, bool escapeQuotes) json_nothrow json_read_priority; 19 | 20 | static void DoArray(const internalJSONNode * parent, const json_string & value_t) json_nothrow json_read_priority; 21 | static void DoNode(const internalJSONNode * parent, const json_string & value_t) json_nothrow json_read_priority; 22 | 23 | #ifdef JSON_LESS_MEMORY 24 | #define NAME_ENCODED this, true 25 | #define STRING_ENCODED this, false 26 | static json_string FixString(const json_string & value_t, const internalJSONNode * flag, bool which) json_nothrow json_read_priority; 27 | #else 28 | #define NAME_ENCODED _name_encoded 29 | #define STRING_ENCODED _string_encoded 30 | static json_string FixString(const json_string & value_t, bool & flag) json_nothrow json_read_priority; 31 | #endif 32 | #endif 33 | 34 | #if defined(JSON_READ_PRIORITY) || defined(JSON_STREAM) 35 | #if (JSON_READ_PRIORITY == HIGH) && (!(defined(JSON_LESS_MEMORY))) 36 | template 37 | static size_t FindNextRelevant(const json_string & value_t, const size_t pos) json_nothrow json_read_priority; 38 | #else 39 | static size_t FindNextRelevant(json_char ch, const json_string & value_t, const size_t pos) json_nothrow json_read_priority; 40 | #endif 41 | #endif 42 | static void UnfixString(const json_string & value_t, bool flag, json_string & res) json_nothrow; 43 | JSON_PRIVATE 44 | #ifdef JSON_READ_PRIORITY 45 | static json_char Hex(const json_char * & pos) json_nothrow; 46 | static json_uchar UTF8(const json_char * & pos, const json_char * const end) json_nothrow; 47 | #endif 48 | #ifdef JSON_ESCAPE_WRITES 49 | static json_string toUTF8(json_uchar p) json_nothrow; 50 | #endif 51 | #ifdef JSON_UNICODE 52 | static void UTF(const json_char * & pos, json_string & result, const json_char * const end) json_nothrow; 53 | #ifdef JSON_ESCAPE_WRITES 54 | static json_string toSurrogatePair(json_uchar pos) json_nothrow; 55 | #endif 56 | #endif 57 | #ifdef JSON_READ_PRIORITY 58 | static void SpecialChar(const json_char * & pos, const json_char * const end, json_string & res) json_nothrow; 59 | static void NewNode(const internalJSONNode * parent, const json_string & name, const json_string & value, bool array) json_nothrow; 60 | #endif 61 | private: 62 | JSONWorker(void); 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 9/3/10 \" DATE 7 | .Dt TestSuite 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm TestSuite, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.h~: -------------------------------------------------------------------------------- 1 | #ifndef TESTSUITE_H 2 | #define TESTSUITE_H 3 | 4 | #include "UnitTest.h" 5 | #include "../JSONOptions.h" 6 | #include "../libjson.h" 7 | #include "../Source/JSONNode.h" 8 | 9 | #include 10 | using namespace std; 11 | 12 | /* 13 | This class tests libjson's internal working and it's 14 | C++ interface 15 | */ 16 | 17 | #ifdef JSON_UNICODE 18 | #define assertCStringSame(a, b) assertCStringEqualsW(a, b) 19 | #define assertCStringNotSame(a, b) assertCStringNotEqualsW(a, b) 20 | #else 21 | #define assertCStringSame(a, b) assertCStringEquals(a, b) 22 | #define assertCStringNotSame(a, b) assertCStringNotEquals(a, b) 23 | #endif 24 | 25 | 26 | class TestSuite { 27 | public: 28 | static void TestSelf(void); 29 | static void TestString(void); 30 | static void TestConverters(void); 31 | #ifdef JSON_BINARY 32 | static void TestBase64(void); 33 | #endif 34 | static void TestReferenceCounting(void); 35 | static void TestConstructors(void); 36 | static void TestAssigning(void); 37 | static void TestEquality(void); 38 | static void TestInequality(void); 39 | static void TestChildren(void); 40 | static void TestFunctions(void); 41 | static void TestIterators(void); 42 | static void TestInspectors(void); 43 | static void TestNamespace(void); 44 | static void TestValidator(void); 45 | static void TestStreams(void); 46 | #ifdef JSON_WRITE_PRIORITY 47 | static void TestWriter(void); 48 | #endif 49 | #ifdef JSON_COMMENTS 50 | static void TestComments(void); 51 | #endif 52 | #ifdef JSON_MUTEX_CALLBACKS 53 | static void TestMutex(void); 54 | static void TestThreading(void); 55 | #endif 56 | static void TestSharedString(void); 57 | static void TestFinal(void); 58 | 59 | 60 | 61 | 62 | 63 | #ifdef JSON_LIBRARY 64 | static void testParsingItself(JSONNODE * x){ 65 | #if defined(JSON_WRITE_PRIORITY) && defined(JSON_READ_PRIORITY) 66 | { 67 | json_char * written = json_write(x); 68 | JSONNODE * copy = json_parse(written); 69 | assertTrue(json_equal(x, copy)); 70 | json_delete(copy); 71 | json_free(written); 72 | } 73 | { 74 | json_char * written = json_write_formatted(x); 75 | JSONNODE * copy = json_parse(written); 76 | assertTrue(json_equal(x, copy)); 77 | json_delete(copy); 78 | json_free(written); 79 | } 80 | { 81 | json_char * written = json_write_formatted(x); 82 | json_char * written2 = json_write(x); 83 | json_char * stripped = json_strip_white_space(written); 84 | assertCStringSame(written2, stripped); 85 | json_free(stripped); 86 | json_free(written); 87 | json_free(written2); 88 | } 89 | #endif 90 | { 91 | JSONNODE * copy = json_duplicate(x); 92 | assertTrue(json_equal(x, copy)); 93 | json_delete(copy); 94 | } 95 | } 96 | #else 97 | static void testParsingItself(JSONNode & x){ 98 | #if defined(JSON_WRITE_PRIORITY) && defined(JSON_READ_PRIORITY) 99 | assertEquals(libjson::parse(x.write()), x); 100 | assertEquals(libjson::parse(x.write_formatted()), x); 101 | assertEquals(libjson::strip_white_space(x.write_formatted()), x.write()); 102 | #endif 103 | assertEquals(x, x.duplicate()) 104 | } 105 | #endif 106 | }; 107 | 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestSuite.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTSUITE_H 2 | #define TESTSUITE_H 3 | 4 | #include "UnitTest.h" 5 | #include "../../JSONOptions.h" 6 | #include "../../libjson.h" 7 | #include "../Source/JSONNode.h" 8 | 9 | #include 10 | using namespace std; 11 | 12 | /* 13 | This class tests libjson's internal working and it's 14 | C++ interface 15 | */ 16 | 17 | #ifdef JSON_UNICODE 18 | #define assertCStringSame(a, b) assertCStringEqualsW(a, b) 19 | #define assertCStringNotSame(a, b) assertCStringNotEqualsW(a, b) 20 | #else 21 | #define assertCStringSame(a, b) assertCStringEquals(a, b) 22 | #define assertCStringNotSame(a, b) assertCStringNotEquals(a, b) 23 | #endif 24 | 25 | 26 | class TestSuite { 27 | public: 28 | static void TestSelf(void); 29 | static void TestString(void); 30 | static void TestConverters(void); 31 | #ifdef JSON_BINARY 32 | static void TestBase64(void); 33 | #endif 34 | static void TestReferenceCounting(void); 35 | static void TestConstructors(void); 36 | static void TestAssigning(void); 37 | static void TestEquality(void); 38 | static void TestInequality(void); 39 | static void TestChildren(void); 40 | static void TestFunctions(void); 41 | static void TestIterators(void); 42 | static void TestInspectors(void); 43 | static void TestNamespace(void); 44 | static void TestValidator(void); 45 | static void TestStreams(void); 46 | #ifdef JSON_WRITE_PRIORITY 47 | static void TestWriter(void); 48 | #endif 49 | #ifdef JSON_COMMENTS 50 | static void TestComments(void); 51 | #endif 52 | #ifdef JSON_MUTEX_CALLBACKS 53 | static void TestMutex(void); 54 | static void TestThreading(void); 55 | #endif 56 | static void TestSharedString(void); 57 | static void TestFinal(void); 58 | 59 | 60 | 61 | 62 | 63 | #ifdef JSON_LIBRARY 64 | static void testParsingItself(JSONNODE * x){ 65 | #if defined(JSON_WRITE_PRIORITY) && defined(JSON_READ_PRIORITY) 66 | { 67 | json_char * written = json_write(x); 68 | JSONNODE * copy = json_parse(written); 69 | assertTrue(json_equal(x, copy)); 70 | json_delete(copy); 71 | json_free(written); 72 | } 73 | { 74 | json_char * written = json_write_formatted(x); 75 | JSONNODE * copy = json_parse(written); 76 | assertTrue(json_equal(x, copy)); 77 | json_delete(copy); 78 | json_free(written); 79 | } 80 | { 81 | json_char * written = json_write_formatted(x); 82 | json_char * written2 = json_write(x); 83 | json_char * stripped = json_strip_white_space(written); 84 | assertCStringSame(written2, stripped); 85 | json_free(stripped); 86 | json_free(written); 87 | json_free(written2); 88 | } 89 | #endif 90 | { 91 | JSONNODE * copy = json_duplicate(x); 92 | assertTrue(json_equal(x, copy)); 93 | json_delete(copy); 94 | } 95 | } 96 | #else 97 | static void testParsingItself(JSONNode & x){ 98 | #if defined(JSON_WRITE_PRIORITY) && defined(JSON_READ_PRIORITY) 99 | assertEquals(libjson::parse(x.write()), x); 100 | assertEquals(libjson::parse(x.write_formatted()), x); 101 | assertEquals(libjson::strip_white_space(x.write_formatted()), x.write()); 102 | #endif 103 | assertEquals(x, x.duplicate()) 104 | } 105 | #endif 106 | }; 107 | 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONStats.h: -------------------------------------------------------------------------------- 1 | #ifndef TestSuite_JSONStats_h 2 | #define TestSuite_JSONStats_h 3 | 4 | #include "../../JSONOptions.h" 5 | 6 | #if defined(JSON_UNIT_TEST) || defined(JSON_DEBUG) 7 | #define LIBJSON_OBJECT(name)\ 8 | static size_t & getCtorCounter(void){\ 9 | static size_t count = 0;\ 10 | static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\ 11 | return count;\ 12 | }\ 13 | static size_t & getCopyCtorCounter(void){\ 14 | static size_t count = 0;\ 15 | static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\ 16 | return count;\ 17 | }\ 18 | static size_t & getAssignmentCounter(void){\ 19 | static size_t count = 0;\ 20 | static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\ 21 | return count;\ 22 | }\ 23 | static size_t & getDtorCounter(void){\ 24 | static size_t count = 0;\ 25 | static int i = JSONStats::setCallbacks(getCtorCounter, getCopyCtorCounter, getAssignmentCounter, getDtorCounter, #name);\ 26 | return count;\ 27 | } 28 | #define LIBJSON_CTOR getCtorCounter() += 1 29 | #define LIBJSON_COPY_CTOR getCopyCtorCounter() += 1 30 | #define LIBJSON_ASSIGNMENT getAssignmentCounter() += 1 31 | #define LIBJSON_DTOR getDtorCounter() += 1 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | class JSONStats { 38 | public: 39 | ~JSONStats(void){ 40 | std::map & mymap = getMapper(); 41 | std::map::iterator b = mymap.begin(); 42 | std::map::iterator e = mymap.end(); 43 | std::cout << "Counters for libjson:" << std::endl; 44 | for(; b != e; ++b){ 45 | std::cout << " " << b -> second -> _name << std::endl; 46 | std::cout << " Constructor: " << b -> second -> _cTor() << std::endl; 47 | std::cout << " Copy Constructor: " << b -> second -> _ccTor() << std::endl; 48 | std::cout << " Assignment: " << b -> second -> _assign() << std::endl; 49 | std::cout << " Destructor: " << b -> second -> _dTor() << std::endl; 50 | delete b -> second; 51 | } 52 | } 53 | 54 | typedef size_t & (*getCounter_m)(void); 55 | struct objectStructure { 56 | objectStructure(getCounter_m cTor, getCounter_m ccTor, getCounter_m assign, getCounter_m dTor, const std::string & name): 57 | _cTor(cTor), _ccTor(ccTor), _assign(assign), _dTor(dTor), _name(name){} 58 | std::string _name; 59 | getCounter_m _cTor; 60 | getCounter_m _ccTor; 61 | getCounter_m _assign; 62 | getCounter_m _dTor; 63 | }; 64 | static int setCallbacks(getCounter_m cTor, getCounter_m ccTor, getCounter_m assign, getCounter_m dtor, const std::string & name){ 65 | getMapper()[cTor] = new objectStructure (cTor, ccTor, assign, dtor, name); 66 | return 0; 67 | } 68 | 69 | static std::map & getMapper(void) { 70 | static std::map mymap; 71 | return mymap; 72 | } 73 | }; 74 | #else 75 | #define LIBJSON_OBJECT(name) 76 | #define LIBJSON_CTOR (void)0 77 | #define LIBJSON_DTOR (void)0 78 | #define LIBJSON_COPY_CTOR (void)0 79 | #define LIBJSON_ASSIGNMENT (void)0 80 | typedef int JSONStats; 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONGlobals.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_GLOBALS_H 2 | #define JSON_GLOBALS_H 3 | 4 | #include "JSONDefs.h" 5 | 6 | /* 7 | * The use of singletons for globals makes globals not 8 | * actually be initialized until it is first needed, this 9 | * makes the library faster to load, and have a smaller 10 | * memory footprint 11 | */ 12 | 13 | #define json_global_decl(TYPE, NAME, VALUE) \ 14 | class jsonSingleton ## NAME { \ 15 | public: \ 16 | inline static TYPE & getValue() json_nothrow { \ 17 | static jsonSingleton ## NAME single; \ 18 | return single.val; \ 19 | } \ 20 | protected: \ 21 | inline jsonSingleton ## NAME() json_nothrow : val(VALUE) {} \ 22 | TYPE val; \ 23 | } 24 | 25 | #define json_global_decl_strconfig(TYPE, NAME, VALUE) \ 26 | class jsonSingleton ## NAME { \ 27 | public: \ 28 | inline static TYPE & getValue() json_nothrow { \ 29 | static jsonSingleton ## NAME single; \ 30 | return single.val; \ 31 | } \ 32 | protected: \ 33 | inline jsonSingleton ## NAME() json_nothrow { \ 34 | const std::string tmp = std::string(VALUE); \ 35 | val = json_string(tmp.begin(), tmp.end()); \ 36 | } \ 37 | TYPE val; \ 38 | } 39 | 40 | #define json_global(NAME) jsonSingleton ## NAME::getValue() 41 | 42 | #include 43 | json_global_decl(json_string, EMPTY_JSON_STRING, ); 44 | json_global_decl(std::string, EMPTY_STD_STRING, ); 45 | 46 | json_global_decl(json_string, CONST_TRUE, JSON_TEXT("true")); 47 | json_global_decl(json_string, CONST_FALSE, JSON_TEXT("false")); 48 | json_global_decl(json_string, CONST_NULL, JSON_TEXT("null")); 49 | 50 | #ifndef JSON_NEWLINE 51 | json_global_decl(json_string, NEW_LINE, JSON_TEXT("\n")); 52 | #else 53 | json_global_decl_strconfig(json_string, NEW_LINE, JSON_NEWLINE); 54 | #endif 55 | 56 | #ifdef JSON_WRITE_BASH_COMMENTS 57 | json_global_decl(json_string, SINGLELINE_COMMENT, JSON_TEXT("#")); 58 | #else 59 | json_global_decl(json_string, SINGLELINE_COMMENT, JSON_TEXT("//")); 60 | #endif 61 | 62 | #ifdef JSON_INDENT 63 | json_global_decl_strconfig(json_string, INDENT, JSON_INDENT); 64 | #endif 65 | 66 | #ifdef JSON_MUTEX_CALLBACKS 67 | #include 68 | json_global_decl(JSON_MAP(void *, unsigned int), MUTEX_MANAGER, ); 69 | json_global_decl(JSON_MAP(int, JSON_MAP(void *, unsigned int) ), THREAD_LOCKS, ); 70 | #endif 71 | 72 | #ifdef JSON_LIBRARY 73 | #ifdef JSON_MEMORY_MANAGE 74 | #include "JSONMemory.h" 75 | json_global_decl(auto_expand, STRING_HANDLER, ); 76 | json_global_decl(auto_expand_node, NODE_HANDLER, ); 77 | #ifdef JSON_STREAM 78 | json_global_decl(auto_expand_stream, STREAM_HANDLER, ); 79 | #endif 80 | #endif 81 | #endif 82 | 83 | //These are common error responses 84 | json_global_decl(json_string, ERROR_TOO_LONG, JSON_TEXT("Exceeding JSON_SECURITY_MAX_STRING_LENGTH")); 85 | json_global_decl(json_string, ERROR_UNKNOWN_LITERAL, JSON_TEXT("Unknown JSON literal: ")); 86 | json_global_decl(json_string, ERROR_NON_CONTAINER, JSON_TEXT("Calling container method on non-container: ")); 87 | json_global_decl(json_string, ERROR_NON_ITERATABLE, JSON_TEXT("Calling iterator method on non-iteratable: ")); 88 | json_global_decl(json_string, ERROR_NULL_IN_CHILDREN, JSON_TEXT("a null pointer within the children")); 89 | json_global_decl(json_string, ERROR_UNDEFINED, JSON_TEXT("Undefined results: ")); 90 | json_global_decl(json_string, ERROR_LOWER_RANGE, JSON_TEXT(" is outside the lower range of ")); 91 | json_global_decl(json_string, ERROR_UPPER_RANGE, JSON_TEXT(" is outside the upper range of ")); 92 | json_global_decl(json_string, ERROR_NOT_BASE64, JSON_TEXT("Not base64")); 93 | json_global_decl(json_string, ERROR_OUT_OF_MEMORY, JSON_TEXT("Out of memory")); 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/JSONValidator/isValidMember.cpp: -------------------------------------------------------------------------------- 1 | #include "isValidMember.h" 2 | #include "Resources/validyMacros.h" 3 | #include "../../Source/JSONValidator.h" 4 | 5 | /* 6 | * 7 | * !!! ATTENTION !!! 8 | * 9 | * libjson currently has three number parsing methods, they are being merged 10 | * behind the scenes, but all three interfaces must be consistent, so every set 11 | * of numbers need to be tested in all three spots 12 | * 13 | * JSONValidator/isValidMember *this file* 14 | * * Soon to come actual parser * 15 | */ 16 | 17 | 18 | /** 19 | * This tests the three valid members that is not string, number, or container 20 | */ 21 | void testJSONValidator__isValidMember::testMembers(void){ 22 | #ifdef JSON_VALIDATE 23 | assertValid_Depth("true,", isValidMember, ','); 24 | assertValid_Depth("false,", isValidMember, ','); 25 | assertValid_Depth("null,", isValidMember, ','); 26 | #endif 27 | } 28 | 29 | 30 | /** 31 | * This tests that json's case sensitive rules are to be obeyed 32 | */ 33 | void testJSONValidator__isValidMember::testStrict(void){ 34 | #ifdef JSON_VALIDATE 35 | #ifdef JSON_STRICT 36 | assertNotValid_Depth("TRUE,", isValidMember, ','); 37 | assertNotValid_Depth("FALSE,", isValidMember, ','); 38 | assertNotValid_Depth("NULL,", isValidMember, ','); 39 | assertNotValid_Depth(",", isValidMember, ','); //also accepted as null usually 40 | #endif 41 | #endif 42 | } 43 | 44 | 45 | /** 46 | * This tests that json's case sensitive rules are not obeyed normally 47 | */ 48 | void testJSONValidator__isValidMember::testNotStrict(void){ 49 | #ifdef JSON_VALIDATE 50 | #ifndef JSON_STRICT 51 | assertValid_Depth("TRUE,", isValidMember, ','); 52 | assertValid_Depth("FALSE,", isValidMember, ','); 53 | assertValid_Depth("NULL,", isValidMember, ','); 54 | assertValid_Depth(",", isValidMember, ','); //also accepted as null usually 55 | #endif 56 | #endif 57 | } 58 | 59 | 60 | /** 61 | * This tests that non member values are not allowed 62 | */ 63 | void testJSONValidator__isValidMember::testNotMembers(void){ 64 | #ifdef JSON_VALIDATE 65 | assertNotValid_Depth("tru,", isValidMember, ','); 66 | assertNotValid_Depth("fals,", isValidMember, ','); 67 | assertNotValid_Depth("nul,", isValidMember, ','); 68 | assertNotValid_Depth("", isValidMember, ','); //needs a comma after it because of how the pipeline works 69 | assertNotValid_Depth("xxx,", isValidMember, ','); 70 | assertNotValid_Depth("nonsense,", isValidMember, ','); 71 | #endif 72 | } 73 | 74 | 75 | /** 76 | * This tests that for all cases, if the string suddely ends, it recovers 77 | */ 78 | void testJSONValidator__isValidMember::testSuddenEnd(void){ 79 | #ifdef JSON_VALIDATE 80 | assertNotValid_Depth("", isValidMember, ','); 81 | 82 | //--- void testJSONValidator__isValidMember::testSuddenEnd(void){ 83 | assertNotValid_Depth("true", isValidMember, ','); 84 | assertNotValid_Depth("false", isValidMember, ','); 85 | assertNotValid_Depth("null", isValidMember, ','); 86 | 87 | //strict stuff 88 | assertNotValid_Depth("TRUE", isValidMember, ','); 89 | assertNotValid_Depth("FALSE", isValidMember, ','); 90 | assertNotValid_Depth("NULL", isValidMember, ','); 91 | 92 | //--- void testJSONValidator__isValidMember::testNotMembers(void){ 93 | assertNotValid_Depth("tru", isValidMember, ','); 94 | assertNotValid_Depth("fals", isValidMember, ','); 95 | assertNotValid_Depth("nul", isValidMember, ','); 96 | assertNotValid_Depth("", isValidMember, ','); //needs a comma after it because of how the pipeline works 97 | assertNotValid_Depth("xxx", isValidMember, ','); 98 | assertNotValid_Depth("nonsense", isValidMember, ','); 99 | assertNotValid_Depth("1234", isValidMember, ','); 100 | #endif 101 | } 102 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONChildren.cpp: -------------------------------------------------------------------------------- 1 | #include "JSONChildren.h" 2 | #include "JSONNode.h" 3 | 4 | /* 5 | * reserves a certain number of bytes, in memory saving mode it creates a special 6 | * type of child container that will not autoshrink 7 | */ 8 | void jsonChildren::reserve2(jsonChildren *& mine, json_index_t amount) json_nothrow { 9 | if (mine -> array != 0){ 10 | if (mine -> mycapacity < amount){ 11 | mine -> inc(amount - mine -> mycapacity); 12 | #ifdef JSON_LESS_MEMORY 13 | mine = jsonChildren_Reserved::newChildren_Reserved(mine, amount); 14 | #endif 15 | } 16 | } else { 17 | mine -> reserve(amount); 18 | } 19 | } 20 | 21 | void jsonChildren::inc(void) json_nothrow { 22 | JSON_ASSERT(this != 0, JSON_TEXT("Children is null inc")); 23 | if (json_unlikely(mysize == mycapacity)){ //it's full 24 | if (json_unlikely(mycapacity == 0)){ //the array hasn't been created yet 25 | JSON_ASSERT(!array, JSON_TEXT("Expanding a 0 capacity array, but not null")); 26 | #ifdef JSON_LESS_MEMORY 27 | array = json_malloc(1); 28 | mycapacity = 1; 29 | #else 30 | array = json_malloc(8); //8 seems average for JSON, and it's only 64 bytes 31 | mycapacity = 8; 32 | #endif 33 | } else { 34 | #ifdef JSON_LESS_MEMORY 35 | mycapacity += 1; //increment the size of the array 36 | #else 37 | mycapacity <<= 1; //double the size of the array 38 | #endif 39 | array = json_realloc(array, mycapacity); 40 | } 41 | } 42 | } 43 | 44 | 45 | void jsonChildren::inc(json_index_t amount) json_nothrow { 46 | JSON_ASSERT(this != 0, JSON_TEXT("Children is null inc(amount)")); 47 | if (json_unlikely(amount == 0)) return; 48 | if (json_likely(mysize + amount >= mycapacity)){ //it's full 49 | if (json_unlikely(mycapacity == 0)){ //the array hasn't been created yet 50 | JSON_ASSERT(!array, JSON_TEXT("Expanding a 0 capacity array, but not null")); 51 | #ifdef JSON_LESS_MEMORY 52 | array = json_malloc(amount); 53 | mycapacity = amount; 54 | #else 55 | array = json_malloc(amount > 8 ? amount : 8); //8 seems average for JSON, and it's only 64 bytes 56 | mycapacity = amount > 8 ? amount : 8; 57 | #endif 58 | } else { 59 | #ifdef JSON_LESS_MEMORY 60 | mycapacity = mysize + amount; //increment the size of the array 61 | #else 62 | while(mysize + amount > mycapacity){ 63 | mycapacity <<= 1; //double the size of the array 64 | } 65 | #endif 66 | array = json_realloc(array, mycapacity); 67 | } 68 | } 69 | } 70 | 71 | //actually deletes everything within the vector, this is safe to do on an empty or even a null array 72 | void jsonChildren::deleteAll(void) json_nothrow { 73 | JSON_ASSERT(this != 0, JSON_TEXT("Children is null deleteAll")); 74 | json_foreach(this, runner){ 75 | JSON_ASSERT(*runner != JSON_TEXT('\0'), JSON_TEXT("a null pointer within the children")); 76 | JSONNode::deleteJSONNode(*runner); //this is why I can't do forward declaration 77 | } 78 | } 79 | 80 | void jsonChildren::doerase(JSONNode ** position, json_index_t number) json_nothrow { 81 | JSON_ASSERT(this != 0, JSON_TEXT("Children is null doerase")); 82 | JSON_ASSERT(array != 0, JSON_TEXT("erasing something from a null array 2")); 83 | JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array 2")); 84 | JSON_ASSERT(position + number <= array + mysize, JSON_TEXT("erasing out of bounds 2")); 85 | if (position + number >= array + mysize){ 86 | mysize = (json_index_t)(position - array); 87 | #ifndef JSON_ISO_STRICT 88 | JSON_ASSERT((long long)position - (long long)array >= 0, JSON_TEXT("doing negative allocation")); 89 | #endif 90 | } else { 91 | std::memmove(position, position + number, (mysize - (position - array) - number) * sizeof(JSONNode *)); 92 | mysize -= number; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/SDK/plugincommon.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------- 2 | // 3 | // SA-MP Multiplayer Modification For GTA:SA 4 | // Copyright 2004-2009 SA-MP Team 5 | // 6 | //---------------------------------------------------------- 7 | 8 | #pragma once 9 | 10 | //---------------------------------------------------------- 11 | 12 | #define SAMP_PLUGIN_VERSION 0x0200 13 | 14 | //---------------------------------------------------------- 15 | 16 | #ifdef __cplusplus 17 | #define PLUGIN_EXTERN_C extern "C" 18 | #else 19 | #define PLUGIN_EXTERN_C 20 | #endif 21 | 22 | #if defined(__LINUX__) || defined(__FreeBSD__) || defined(__OpenBSD__) 23 | #ifndef __GNUC__ 24 | #pragma message "Warning: Not using a GNU compiler." 25 | #endif 26 | #define PLUGIN_CALL 27 | #ifndef SAMPSVR 28 | // Compile code with -fvisibility=hidden to hide non-exported functions. 29 | #define PLUGIN_EXPORT PLUGIN_EXTERN_C __attribute__((visibility("default"))) 30 | #else 31 | #define PLUGIN_EXPORT PLUGIN_EXTERN_C 32 | #endif 33 | #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 34 | #ifndef _MSC_VER 35 | #pragma message "Warning: Not using a VC++ compiler." 36 | #endif 37 | #define PLUGIN_CALL __stdcall 38 | #define PLUGIN_EXPORT PLUGIN_EXTERN_C 39 | #else 40 | #error "You must define one of WIN32, LINUX or FREEBSD" 41 | #endif 42 | 43 | //---------------------------------------------------------- 44 | 45 | enum SUPPORTS_FLAGS 46 | { 47 | SUPPORTS_VERSION = SAMP_PLUGIN_VERSION, 48 | SUPPORTS_VERSION_MASK = 0xffff, 49 | SUPPORTS_AMX_NATIVES = 0x10000, 50 | SUPPORTS_PROCESS_TICK = 0x20000 51 | }; 52 | 53 | //---------------------------------------------------------- 54 | 55 | enum PLUGIN_DATA_TYPE 56 | { 57 | // For some debugging 58 | PLUGIN_DATA_LOGPRINTF = 0x00, // void (*logprintf)(char* format, ...) 59 | 60 | // AMX 61 | PLUGIN_DATA_AMX_EXPORTS = 0x10, // void* AmxFunctionTable[] (see PLUGIN_AMX_EXPORT) 62 | PLUGIN_DATA_CALLPUBLIC_FS = 0x11, // int (*AmxCallPublicFilterScript)(char *szFunctionName) 63 | PLUGIN_DATA_CALLPUBLIC_GM = 0x12, // int (*AmxCallPublicGameMode)(char *szFunctionName) 64 | 65 | }; 66 | 67 | //---------------------------------------------------------- 68 | 69 | enum PLUGIN_AMX_EXPORT 70 | { 71 | PLUGIN_AMX_EXPORT_Align16 = 0, 72 | PLUGIN_AMX_EXPORT_Align32 = 1, 73 | PLUGIN_AMX_EXPORT_Align64 = 2, 74 | PLUGIN_AMX_EXPORT_Allot = 3, 75 | PLUGIN_AMX_EXPORT_Callback = 4, 76 | PLUGIN_AMX_EXPORT_Cleanup = 5, 77 | PLUGIN_AMX_EXPORT_Clone = 6, 78 | PLUGIN_AMX_EXPORT_Exec = 7, 79 | PLUGIN_AMX_EXPORT_FindNative = 8, 80 | PLUGIN_AMX_EXPORT_FindPublic = 9, 81 | PLUGIN_AMX_EXPORT_FindPubVar = 10, 82 | PLUGIN_AMX_EXPORT_FindTagId = 11, 83 | PLUGIN_AMX_EXPORT_Flags = 12, 84 | PLUGIN_AMX_EXPORT_GetAddr = 13, 85 | PLUGIN_AMX_EXPORT_GetNative = 14, 86 | PLUGIN_AMX_EXPORT_GetPublic = 15, 87 | PLUGIN_AMX_EXPORT_GetPubVar = 16, 88 | PLUGIN_AMX_EXPORT_GetString = 17, 89 | PLUGIN_AMX_EXPORT_GetTag = 18, 90 | PLUGIN_AMX_EXPORT_GetUserData = 19, 91 | PLUGIN_AMX_EXPORT_Init = 20, 92 | PLUGIN_AMX_EXPORT_InitJIT = 21, 93 | PLUGIN_AMX_EXPORT_MemInfo = 22, 94 | PLUGIN_AMX_EXPORT_NameLength = 23, 95 | PLUGIN_AMX_EXPORT_NativeInfo = 24, 96 | PLUGIN_AMX_EXPORT_NumNatives = 25, 97 | PLUGIN_AMX_EXPORT_NumPublics = 26, 98 | PLUGIN_AMX_EXPORT_NumPubVars = 27, 99 | PLUGIN_AMX_EXPORT_NumTags = 28, 100 | PLUGIN_AMX_EXPORT_Push = 29, 101 | PLUGIN_AMX_EXPORT_PushArray = 30, 102 | PLUGIN_AMX_EXPORT_PushString = 31, 103 | PLUGIN_AMX_EXPORT_RaiseError = 32, 104 | PLUGIN_AMX_EXPORT_Register = 33, 105 | PLUGIN_AMX_EXPORT_Release = 34, 106 | PLUGIN_AMX_EXPORT_SetCallback = 35, 107 | PLUGIN_AMX_EXPORT_SetDebugHook = 36, 108 | PLUGIN_AMX_EXPORT_SetString = 37, 109 | PLUGIN_AMX_EXPORT_SetUserData = 38, 110 | PLUGIN_AMX_EXPORT_StrLen = 39, 111 | PLUGIN_AMX_EXPORT_UTF8Check = 40, 112 | PLUGIN_AMX_EXPORT_UTF8Get = 41, 113 | PLUGIN_AMX_EXPORT_UTF8Len = 42, 114 | PLUGIN_AMX_EXPORT_UTF8Put = 43, 115 | }; 116 | 117 | //---------------------------------------------------------- 118 | // EOF 119 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestCtors.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | #include "../Source/JSONNode.h" 3 | 4 | void TestSuite::TestConstructors(void){ 5 | UnitTest::SetPrefix("TestCtor.cpp - Constructors"); 6 | #ifdef JSON_LIBRARY 7 | JSONNODE * test = json_new(JSON_NULL); 8 | assertEquals(json_type(test), JSON_NULL); 9 | json_delete(test); 10 | 11 | test = json_new_a(JSON_TEXT("hello"), JSON_TEXT("world")); 12 | json_char * res = json_as_string(test); 13 | assertCStringSame(res, JSON_TEXT("world")); 14 | json_free(res); 15 | res = json_name(test); 16 | assertCStringSame(res, JSON_TEXT("hello")); 17 | json_free(res); 18 | assertEquals(json_type(test), JSON_STRING); 19 | json_delete(test); 20 | 21 | test = json_new_i(JSON_TEXT("hello"), 15); 22 | #ifdef JSON_CASTABLE 23 | res = json_as_string(test); 24 | assertCStringSame(res, JSON_TEXT("15")); 25 | json_free(res); 26 | #endif 27 | assertEquals_Primitive(json_as_int(test), 15); 28 | assertEquals_Primitive(json_as_float(test), 15.0f); 29 | res = json_name(test); 30 | assertCStringSame(res, JSON_TEXT("hello")); 31 | json_free(res); 32 | assertEquals(json_type(test), JSON_NUMBER); 33 | json_delete(test); 34 | 35 | test = json_new_f(JSON_TEXT("hello"), 15.5f); 36 | assertEquals_Primitive(json_as_int(test), 15); 37 | assertEquals_Primitive(json_as_float(test), 15.5f); 38 | #ifdef JSON_CASTABLE 39 | res = json_as_string(test); 40 | assertCStringSame(res, JSON_TEXT("15.5")); 41 | json_free(res); 42 | #endif 43 | res = json_name(test); 44 | assertCStringSame(res, JSON_TEXT("hello")); 45 | json_free(res); 46 | assertEquals(json_type(test), JSON_NUMBER); 47 | json_delete(test); 48 | 49 | test = json_new_b(JSON_TEXT("hello"), (int)true); 50 | #ifdef JSON_CASTABLE 51 | res = json_as_string(test); 52 | assertCStringSame(res, JSON_TEXT("true")); 53 | json_free(res); 54 | #endif 55 | assertEquals(json_as_bool(test), (int)true); 56 | res = json_name(test); 57 | assertCStringSame(res, JSON_TEXT("hello")); 58 | json_free(res); 59 | assertEquals(json_type(test), JSON_BOOL); 60 | 61 | JSONNODE * cpy = json_copy(test); 62 | assertTrue(json_equal(cpy, test)); 63 | json_delete(cpy); 64 | 65 | json_delete(test); 66 | #else 67 | JSONNode test = JSONNode(JSON_NULL); 68 | assertEquals(test.type(), JSON_NULL); 69 | 70 | test = JSONNode(JSON_TEXT("hello"), JSON_TEXT("world")); 71 | assertEquals(test, JSON_TEXT("world")); 72 | assertEquals(test.as_string(), JSON_TEXT("world")); 73 | assertEquals(test.name(), JSON_TEXT("hello")); 74 | assertEquals(test.type(), JSON_STRING); 75 | 76 | test = JSONNode(JSON_TEXT("hello"), 15); 77 | assertEquals(test, 15); 78 | #ifdef JSON_CASTABLE 79 | assertEquals(test.as_string(), JSON_TEXT("15")); 80 | #endif 81 | assertEquals(test.as_int(), 15); 82 | assertEquals(test.as_float(), 15.0f); 83 | assertEquals(test.name(), JSON_TEXT("hello")); 84 | assertEquals(test.type(), JSON_NUMBER); 85 | 86 | test = JSONNode(JSON_TEXT("hello"), 15.5f); 87 | assertEquals(test, 15.5f); 88 | assertEquals(test.as_int(), 15); 89 | assertEquals(test.as_float(), 15.5f); 90 | #ifdef JSON_CASTABLE 91 | assertEquals(test.as_string(), JSON_TEXT("15.5")); 92 | #endif 93 | assertEquals(test.name(), JSON_TEXT("hello")); 94 | assertEquals(test.type(), JSON_NUMBER); 95 | 96 | test = JSONNode(JSON_TEXT("hello"), true); 97 | assertEquals(test, true); 98 | #ifdef JSON_CASTABLE 99 | assertEquals(test.as_string(), JSON_TEXT("true")); 100 | #endif 101 | assertEquals(test.as_bool(), true); 102 | assertEquals(test.name(), JSON_TEXT("hello")); 103 | assertEquals(test.type(), JSON_BOOL); 104 | 105 | test = JSONNode(json_string(JSON_TEXT("hello")), JSON_TEXT('\0')); 106 | assertEquals(test, 0); 107 | #ifdef JSON_CASTABLE 108 | assertEquals(test.as_string(), JSON_TEXT("0")); 109 | #endif 110 | assertEquals(test.as_int(), 0); 111 | assertEquals(test.as_float(), 0.0f); 112 | assertEquals(test.name(), JSON_TEXT("hello")); 113 | assertEquals(test.type(), JSON_NUMBER); 114 | #endif 115 | } 116 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_uitoa.cpp: -------------------------------------------------------------------------------- 1 | #include "_uitoa.h" 2 | #include "../../Source/NumberToString.h" 3 | 4 | 5 | /** 6 | * Test converting a char value into a string 7 | */ 8 | void testNumberToString__uitoa::testChar(void){ 9 | #ifndef JSON_LIBRARY 10 | assertEquals(sizeof(unsigned char), 1); 11 | assertEquals(NumberToString::_uitoa((unsigned char)255), JSON_TEXT("255")); 12 | assertEquals(NumberToString::_uitoa((unsigned char)127), JSON_TEXT("127")); 13 | assertEquals(NumberToString::_uitoa((unsigned char)15), JSON_TEXT("15")); 14 | assertEquals(NumberToString::_uitoa((unsigned char)0), JSON_TEXT("0")); 15 | #endif 16 | } 17 | 18 | 19 | /** 20 | * Test converting a short value into a string 21 | */ 22 | void testNumberToString__uitoa::testShort(void){ 23 | #ifndef JSON_LIBRARY 24 | assertEquals(sizeof(unsigned short), 2); 25 | assertEquals(NumberToString::_uitoa((unsigned short)65535), JSON_TEXT("65535")); 26 | assertEquals(NumberToString::_uitoa((unsigned short)32767), JSON_TEXT("32767")); 27 | assertEquals(NumberToString::_uitoa((unsigned short)127), JSON_TEXT("127")); 28 | assertEquals(NumberToString::_uitoa((unsigned short)15), JSON_TEXT("15")); 29 | assertEquals(NumberToString::_uitoa((unsigned short)0), JSON_TEXT("0")); 30 | #endif 31 | } 32 | 33 | 34 | /** 35 | * Test converting a int value into a string 36 | */ 37 | void testNumberToString__uitoa::testInt(void){ 38 | #ifndef JSON_LIBRARY 39 | assertEquals(sizeof(unsigned int), 4); 40 | assertEquals(NumberToString::_uitoa((unsigned int)4294967295u), JSON_TEXT("4294967295")); 41 | assertEquals(NumberToString::_uitoa((unsigned int)2147483647), JSON_TEXT("2147483647")); 42 | assertEquals(NumberToString::_uitoa((unsigned int)32767), JSON_TEXT("32767")); 43 | assertEquals(NumberToString::_uitoa((unsigned int)127), JSON_TEXT("127")); 44 | assertEquals(NumberToString::_uitoa((unsigned int)15), JSON_TEXT("15")); 45 | assertEquals(NumberToString::_uitoa((unsigned int)0), JSON_TEXT("0")); 46 | #endif 47 | } 48 | 49 | 50 | /** 51 | * Test converting a long value into a string 52 | */ 53 | void testNumberToString__uitoa::testLong(void){ 54 | #ifndef JSON_LIBRARY 55 | #ifdef TEST_LONG_EXTREMES 56 | if (sizeof(unsigned long) >= 8){ 57 | assertEquals(NumberToString::_uitoa((unsigned long)18446744073709551615UL), JSON_TEXT("18446744073709551615")); 58 | assertEquals(NumberToString::_uitoa((unsigned long)9223372036854775807L), JSON_TEXT("9223372036854775807")); 59 | } 60 | #endif 61 | assertEquals(NumberToString::_uitoa((unsigned long)2147483647), JSON_TEXT("2147483647")); 62 | assertEquals(NumberToString::_uitoa((unsigned long)32767), JSON_TEXT("32767")); 63 | assertEquals(NumberToString::_uitoa((unsigned long)127), JSON_TEXT("127")); 64 | assertEquals(NumberToString::_uitoa((unsigned long)15), JSON_TEXT("15")); 65 | assertEquals(NumberToString::_uitoa((unsigned long)0), JSON_TEXT("0")); 66 | #endif 67 | } 68 | 69 | 70 | /** 71 | * Test converting a long long value into a string 72 | */ 73 | void testNumberToString__uitoa::testLongLong(void){ 74 | #ifndef JSON_LIBRARY 75 | #ifndef JSON_ISO_STRICT 76 | #ifdef TEST_LONG_EXTREMES 77 | if (sizeof(unsigned long long) >= 8){ 78 | assertEquals(NumberToString::_uitoa((unsigned long long)18446744073709551615UL), JSON_TEXT("18446744073709551615")); 79 | assertEquals(NumberToString::_uitoa((unsigned long long)9223372036854775807L), JSON_TEXT("9223372036854775807")); 80 | assertEquals(NumberToString::_uitoa((unsigned long long)-9223372036854775807L), JSON_TEXT("-9223372036854775807")); 81 | } 82 | #endif 83 | assertEquals(NumberToString::_uitoa((unsigned long long)2147483647), JSON_TEXT("2147483647")); 84 | assertEquals(NumberToString::_uitoa((unsigned long long)32767), JSON_TEXT("32767")); 85 | assertEquals(NumberToString::_uitoa((unsigned long long)127), JSON_TEXT("127")); 86 | assertEquals(NumberToString::_uitoa((unsigned long long)15), JSON_TEXT("15")); 87 | assertEquals(NumberToString::_uitoa((unsigned long long)0), JSON_TEXT("0")); 88 | #endif 89 | #endif 90 | } 91 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestRefCounting.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | 3 | void TestSuite::TestReferenceCounting(void){ 4 | UnitTest::SetPrefix("TestRefCounting.cpp - Reference Counting"); 5 | #ifdef JSON_LIBRARY 6 | #else 7 | JSONNode test1; 8 | #ifdef JSON_UNIT_TEST 9 | assertNotNull(test1.internal); 10 | #ifdef JSON_REF_COUNT 11 | assertEquals(test1.internal -> refcount, 1); 12 | #endif 13 | #endif 14 | 15 | //copy ctor, should simply increment the reference counter 16 | JSONNode test2 = JSONNode(test1); 17 | #ifdef JSON_REF_COUNT 18 | #ifdef JSON_UNIT_TEST 19 | assertEquals(test1.internal, test2.internal); 20 | #endif 21 | assertEquals(test1, test2); 22 | #ifdef JSON_UNIT_TEST 23 | assertEquals(test1.internal -> refcount, 2); 24 | #endif 25 | #else 26 | #ifdef JSON_UNIT_TEST 27 | assertNotEquals(test1.internal, test2.internal); 28 | #endif 29 | assertEquals(test1, test2); 30 | #endif 31 | 32 | //assignment operator, should simply increment the reference counter 33 | JSONNode test3 = test2; 34 | #ifdef JSON_UNIT_TEST 35 | #ifdef JSON_REF_COUNT 36 | assertEquals(test1.internal, test3.internal); 37 | assertEquals(test2.internal, test3.internal); 38 | assertEquals(test1.internal -> refcount, 3); 39 | #else 40 | assertNotEquals(test1.internal, test3.internal); 41 | assertNotEquals(test2.internal, test3.internal); 42 | #endif 43 | #endif 44 | 45 | //assigning something, it should copy now 46 | test2 = "hello"; 47 | #ifdef JSON_UNIT_TEST 48 | #ifdef JSON_REF_COUNT 49 | assertEquals(test1.internal, test3.internal); 50 | assertNotEquals(test2.internal, test3.internal); 51 | assertEquals(test1.internal -> refcount, 2); 52 | assertEquals(test2.internal -> refcount, 1); 53 | #else 54 | assertNotEquals(test1.internal, test3.internal); 55 | assertNotEquals(test2.internal, test3.internal); 56 | #endif 57 | #endif 58 | 59 | //assigning something, it should copy now 60 | test1 = 15; 61 | #ifdef JSON_UNIT_TEST 62 | assertNotEquals(test1.internal, test3.internal); 63 | #ifdef JSON_REF_COUNT 64 | assertEquals(test1.internal -> refcount, 1); 65 | assertEquals(test3.internal -> refcount, 1); 66 | #endif 67 | #endif 68 | 69 | test1 = test2; 70 | #ifdef JSON_REF_COUNT 71 | #ifdef JSON_UNIT_TEST 72 | assertEquals(test1.internal, test2.internal); 73 | assertEquals(test1.internal -> refcount, 2); 74 | #endif 75 | #else 76 | #ifdef JSON_UNIT_TEST 77 | assertNotEquals(test1.internal, test2.internal); 78 | #endif 79 | assertEquals(test1, test2); 80 | #endif 81 | 82 | test1.set_name(JSON_TEXT("hello world")); 83 | #ifdef JSON_UNIT_TEST 84 | assertNotEquals(test1.internal, test2.internal); 85 | #ifdef JSON_REF_COUNT 86 | assertEquals(test1.internal -> refcount, 1); 87 | assertEquals(test1.internal -> refcount, 1); 88 | #endif 89 | #endif 90 | 91 | //test tree copying and partial tree copying 92 | UnitTest::SetPrefix("TestRefCounting.cpp - Partial Copy"); 93 | test1 = JSONNode(JSON_NODE); 94 | test1.push_back(JSONNode(JSON_NODE)); 95 | test1.push_back(JSONNode(JSON_TEXT(""), 5)); 96 | assertEquals(test1.size(), 2); 97 | test2 = test1; 98 | #ifdef JSON_UNIT_TEST 99 | #ifdef JSON_REF_COUNT 100 | assertEquals(test1.internal -> refcount, 2); 101 | assertEquals(test1.internal, test2.internal); 102 | #else 103 | assertNotEquals(test1.internal, test2.internal); 104 | #endif 105 | #endif 106 | #ifdef JSON_READ_PRIORITY 107 | assertEquals(test1, libjson::parse(JSON_TEXT("{\"\":{},\"\":5}"))); 108 | assertEquals(test1, test1); 109 | assertEquals(libjson::parse(JSON_TEXT("{\"\":{},\"\":5}")), libjson::parse(JSON_TEXT("{\"\":{},\"\":5}"))); 110 | TestSuite::testParsingItself(test1); 111 | #endif 112 | 113 | test2[1] = 15; 114 | assertEquals(test1[1], 5); 115 | assertEquals(test2[1], 15); 116 | test1 = test2; 117 | #ifdef JSON_UNIT_TEST 118 | #ifdef JSON_REF_COUNT 119 | assertEquals(test1.internal, test2.internal); 120 | #else 121 | assertNotEquals(test1.internal, test2.internal); 122 | #endif 123 | #endif 124 | test1[0].push_back(JSONNode(JSON_TEXT(""), 1)); 125 | test1[0].push_back(JSONNode(JSON_TEXT(""), 2)); 126 | assertEquals(test1[0].size(), 2); 127 | assertEquals(test2[0].size(), 0); 128 | TestSuite::testParsingItself(test1); 129 | TestSuite::testParsingItself(test2); 130 | #endif 131 | } 132 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/main.cpp~: -------------------------------------------------------------------------------- 1 | #include 2 | #include //for malloc, realloc, and free 3 | #include "TestSuite.h" 4 | #include "../libjson.h" 5 | 6 | void DoTests(void); 7 | void DoTests(void){ 8 | TestSuite::TestStreams(); 9 | TestSuite::TestValidator(); 10 | TestSuite::TestString(); 11 | TestSuite::TestConverters(); 12 | #ifdef JSON_BINARY 13 | TestSuite::TestBase64(); 14 | #endif 15 | 16 | TestSuite::TestReferenceCounting(); 17 | TestSuite::TestConstructors(); 18 | TestSuite::TestAssigning(); 19 | TestSuite::TestEquality(); 20 | TestSuite::TestInequality(); 21 | TestSuite::TestChildren(); 22 | TestSuite::TestFunctions(); 23 | TestSuite::TestIterators(); 24 | TestSuite::TestInspectors(); 25 | TestSuite::TestNamespace(); 26 | #ifdef JSON_WRITE_PRIORITY 27 | TestSuite::TestWriter(); 28 | #endif 29 | #ifdef JSON_COMMENTS 30 | TestSuite::TestComments(); 31 | #endif 32 | #ifdef JSON_MUTEX_CALLBACKS 33 | TestSuite::TestMutex(); 34 | TestSuite::TestThreading(); 35 | #endif 36 | TestSuite::TestSharedString(); 37 | TestSuite::TestFinal(); 38 | } 39 | 40 | #ifdef JSON_MEMORY_CALLBACKS 41 | long mallocs = 0; 42 | long reallocs = 0; 43 | long frees = 0; 44 | long bytes = 0; 45 | 46 | //used to check load 47 | size_t maxBytes = 0; 48 | size_t currentBytes = 0; 49 | #ifdef JSON_LIBRARY 50 | #define MEMTYPE unsigned long 51 | #else 52 | #define MEMTYPE size_t 53 | #endif 54 | #include 55 | #include 56 | std::map mem_mapping; 57 | std::vector bytesallocated; 58 | 59 | void * testmal(MEMTYPE siz); 60 | void * testmal(MEMTYPE siz){ 61 | ++mallocs; 62 | bytes += (long)siz; 63 | currentBytes += siz; 64 | if (currentBytes > maxBytes) maxBytes = currentBytes; 65 | bytesallocated.push_back(currentBytes); 66 | 67 | void * res = std::malloc(siz); 68 | mem_mapping[res] = siz; 69 | return res; 70 | } 71 | 72 | void testfree(void * ptr); 73 | void testfree(void * ptr){ 74 | ++frees; 75 | 76 | std::map::iterator i = mem_mapping.find(ptr); 77 | if (i != mem_mapping.end()){ //globals 78 | currentBytes -= mem_mapping[ptr]; 79 | mem_mapping.erase(ptr); 80 | } 81 | 82 | bytesallocated.push_back(currentBytes); 83 | 84 | std::free(ptr); 85 | } 86 | 87 | void * testreal(void * ptr, MEMTYPE siz); 88 | void * testreal(void * ptr, MEMTYPE siz){ 89 | ++reallocs; 90 | 91 | std::map::iterator i = mem_mapping.find(ptr); 92 | if (i != mem_mapping.end()){ //globals 93 | currentBytes -= mem_mapping[ptr]; 94 | mem_mapping.erase(ptr); 95 | } 96 | currentBytes += siz; 97 | if (currentBytes > maxBytes) maxBytes = currentBytes; 98 | bytesallocated.push_back(currentBytes); 99 | 100 | 101 | void * res = std::realloc(ptr, siz); 102 | mem_mapping[res] = siz; 103 | return res; 104 | } 105 | 106 | void doMemTests(void); 107 | void doMemTests(void){ 108 | #ifdef JSON_LIBRARY 109 | json_register_memory_callbacks(testmal, testreal, testfree); 110 | #else 111 | libjson::register_memory_callbacks(testmal, testreal, testfree); 112 | #endif 113 | DoTests(); 114 | echo("mallocs: " << mallocs); 115 | echo("frees: " << frees); 116 | echo("reallocs: " << reallocs); 117 | echo("bytes: " << bytes << " (" << (int)(bytes / 1024) << " KB)"); 118 | echo("max bytes at once: " << maxBytes << " (" << (int)(maxBytes / 1024) << " KB)"); 119 | std::vector::iterator i = bytesallocated.begin(); 120 | std::vector::iterator e = bytesallocated.end(); 121 | size_t bbytes = 0; 122 | for(; i != e; ++i){ 123 | bbytes += *i; 124 | } 125 | bbytes = (size_t)(((double)bbytes) / ((double)bytesallocated.size())); 126 | echo("avg bytes at once: " << bbytes << " (" << (int)(bbytes / 1024) << " KB)"); 127 | echo("still allocated: " << currentBytes << " (" << (int)(currentBytes / 1024) << " KB) (Global variables)"); 128 | assertEquals(mallocs, frees); 129 | } 130 | #endif 131 | 132 | #include "RunTestSuite2.h" 133 | 134 | int main () { 135 | UnitTest::StartTime(); 136 | TestSuite::TestSelf(); 137 | 138 | DoTests(); 139 | 140 | #ifdef JSON_MEMORY_CALLBACKS 141 | doMemTests(); 142 | #endif 143 | 144 | RunTestSuite2::RunTests(); 145 | 146 | UnitTest::SaveTo("out.html"); 147 | 148 | return 0; 149 | } 150 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include //for malloc, realloc, and free 3 | #include "TestSuite.h" 4 | #include "../../libjson.h" 5 | 6 | void DoTests(void); 7 | void DoTests(void){ 8 | TestSuite::TestStreams(); 9 | TestSuite::TestValidator(); 10 | TestSuite::TestString(); 11 | TestSuite::TestConverters(); 12 | #ifdef JSON_BINARY 13 | TestSuite::TestBase64(); 14 | #endif 15 | 16 | TestSuite::TestReferenceCounting(); 17 | TestSuite::TestConstructors(); 18 | TestSuite::TestAssigning(); 19 | TestSuite::TestEquality(); 20 | TestSuite::TestInequality(); 21 | TestSuite::TestChildren(); 22 | TestSuite::TestFunctions(); 23 | TestSuite::TestIterators(); 24 | TestSuite::TestInspectors(); 25 | TestSuite::TestNamespace(); 26 | #ifdef JSON_WRITE_PRIORITY 27 | TestSuite::TestWriter(); 28 | #endif 29 | #ifdef JSON_COMMENTS 30 | TestSuite::TestComments(); 31 | #endif 32 | #ifdef JSON_MUTEX_CALLBACKS 33 | TestSuite::TestMutex(); 34 | TestSuite::TestThreading(); 35 | #endif 36 | TestSuite::TestSharedString(); 37 | TestSuite::TestFinal(); 38 | } 39 | 40 | #ifdef JSON_MEMORY_CALLBACKS 41 | long mallocs = 0; 42 | long reallocs = 0; 43 | long frees = 0; 44 | long bytes = 0; 45 | 46 | //used to check load 47 | size_t maxBytes = 0; 48 | size_t currentBytes = 0; 49 | #ifdef JSON_LIBRARY 50 | #define MEMTYPE unsigned long 51 | #else 52 | #define MEMTYPE size_t 53 | #endif 54 | #include 55 | #include 56 | std::map mem_mapping; 57 | std::vector bytesallocated; 58 | 59 | void * testmal(MEMTYPE siz); 60 | void * testmal(MEMTYPE siz){ 61 | ++mallocs; 62 | bytes += (long)siz; 63 | currentBytes += siz; 64 | if (currentBytes > maxBytes) maxBytes = currentBytes; 65 | bytesallocated.push_back(currentBytes); 66 | 67 | void * res = std::malloc(siz); 68 | mem_mapping[res] = siz; 69 | return res; 70 | } 71 | 72 | void testfree(void * ptr); 73 | void testfree(void * ptr){ 74 | ++frees; 75 | 76 | std::map::iterator i = mem_mapping.find(ptr); 77 | if (i != mem_mapping.end()){ //globals 78 | currentBytes -= mem_mapping[ptr]; 79 | mem_mapping.erase(ptr); 80 | } 81 | 82 | bytesallocated.push_back(currentBytes); 83 | 84 | std::free(ptr); 85 | } 86 | 87 | void * testreal(void * ptr, MEMTYPE siz); 88 | void * testreal(void * ptr, MEMTYPE siz){ 89 | ++reallocs; 90 | 91 | std::map::iterator i = mem_mapping.find(ptr); 92 | if (i != mem_mapping.end()){ //globals 93 | currentBytes -= mem_mapping[ptr]; 94 | mem_mapping.erase(ptr); 95 | } 96 | currentBytes += siz; 97 | if (currentBytes > maxBytes) maxBytes = currentBytes; 98 | bytesallocated.push_back(currentBytes); 99 | 100 | 101 | void * res = std::realloc(ptr, siz); 102 | mem_mapping[res] = siz; 103 | return res; 104 | } 105 | 106 | void doMemTests(void); 107 | void doMemTests(void){ 108 | #ifdef JSON_LIBRARY 109 | json_register_memory_callbacks(testmal, testreal, testfree); 110 | #else 111 | libjson::register_memory_callbacks(testmal, testreal, testfree); 112 | #endif 113 | DoTests(); 114 | echo("mallocs: " << mallocs); 115 | echo("frees: " << frees); 116 | echo("reallocs: " << reallocs); 117 | echo("bytes: " << bytes << " (" << (int)(bytes / 1024) << " KB)"); 118 | echo("max bytes at once: " << maxBytes << " (" << (int)(maxBytes / 1024) << " KB)"); 119 | std::vector::iterator i = bytesallocated.begin(); 120 | std::vector::iterator e = bytesallocated.end(); 121 | size_t bbytes = 0; 122 | for(; i != e; ++i){ 123 | bbytes += *i; 124 | } 125 | bbytes = (size_t)(((double)bbytes) / ((double)bytesallocated.size())); 126 | echo("avg bytes at once: " << bbytes << " (" << (int)(bbytes / 1024) << " KB)"); 127 | echo("still allocated: " << currentBytes << " (" << (int)(currentBytes / 1024) << " KB) (Global variables)"); 128 | assertEquals(mallocs, frees); 129 | } 130 | #endif 131 | 132 | #include "RunTestSuite2.h" 133 | 134 | int main () { 135 | UnitTest::StartTime(); 136 | TestSuite::TestSelf(); 137 | 138 | DoTests(); 139 | 140 | #ifdef JSON_MEMORY_CALLBACKS 141 | doMemTests(); 142 | #endif 143 | 144 | RunTestSuite2::RunTests(); 145 | 146 | UnitTest::SaveTo("out.html"); 147 | 148 | return 0; 149 | } 150 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONStream.cpp: -------------------------------------------------------------------------------- 1 | #include "JSONStream.h" 2 | 3 | #ifdef JSON_STREAM 4 | #include "JSONWorker.h" 5 | #include "JSONValidator.h" 6 | 7 | 8 | JSONStream::JSONStream(json_stream_callback_t call_p, json_stream_e_callback_t call_e, void * callbackIdentifier) json_nothrow : state(true), call(call_p), err_call(call_e), buffer(), callback_identifier(callbackIdentifier) { 9 | LIBJSON_CTOR; 10 | } 11 | 12 | JSONStream::JSONStream(const JSONStream & orig) json_nothrow : state(orig.state), call(orig.call), err_call(orig.err_call), buffer(orig.buffer), callback_identifier(orig.callback_identifier){ 13 | LIBJSON_COPY_CTOR; 14 | } 15 | 16 | JSONStream & JSONStream::operator =(const JSONStream & orig) json_nothrow { 17 | LIBJSON_ASSIGNMENT; 18 | err_call = orig.err_call; 19 | call = orig.call; 20 | state = orig.state; 21 | buffer = orig.buffer; 22 | callback_identifier = orig.callback_identifier; 23 | return *this; 24 | } 25 | 26 | #ifdef JSON_LIBRARY 27 | JSONStream & JSONStream::operator << (const json_char * str) json_nothrow { 28 | #else 29 | JSONStream & JSONStream::operator << (const json_string & str) json_nothrow { 30 | #endif 31 | if (state){ 32 | buffer += str; 33 | parse(); 34 | } 35 | return *this; 36 | } 37 | 38 | 39 | #define QUOTECASE_STREAM()\ 40 | case JSON_TEXT('\"'):\ 41 | while (*(++p) != JSON_TEXT('\"')){\ 42 | if (json_unlikely(*p == JSON_TEXT('\0'))) return json_string::npos;\ 43 | }\ 44 | break; 45 | 46 | 47 | #define NULLCASE_STREAM()\ 48 | case JSON_TEXT('\0'):\ 49 | return json_string::npos;\ 50 | 51 | 52 | #define BRACKET_STREAM(left, right)\ 53 | case left: {\ 54 | size_t brac = 1;\ 55 | while (brac){\ 56 | switch (*(++p)){\ 57 | case right:\ 58 | --brac;\ 59 | break;\ 60 | case left:\ 61 | ++brac;\ 62 | break;\ 63 | QUOTECASE_STREAM()\ 64 | NULLCASE_STREAM()\ 65 | }\ 66 | }\ 67 | break;}\ 68 | case right:\ 69 | return json_string::npos; 70 | 71 | #if (JSON_READ_PRIORITY == HIGH) && (!(defined(JSON_LESS_MEMORY))) 72 | #define STREAM_FIND_NEXT_RELEVANT(ch, vt, po) FindNextRelevant(vt, po) 73 | template 74 | size_t JSONStream::FindNextRelevant(const json_string & value_t, const size_t pos) json_nothrow { 75 | #else 76 | #define STREAM_FIND_NEXT_RELEVANT(ch, vt, po) FindNextRelevant(ch, vt, po) 77 | size_t JSONStream::FindNextRelevant(json_char ch, const json_string & value_t, const size_t pos) json_nothrow { 78 | #endif 79 | const json_char * start = value_t.c_str(); 80 | for (const json_char * p = start + pos; *p; ++p){ 81 | if (json_unlikely(*p == ch)) return p - start; 82 | switch (*p){ 83 | BRACKET_STREAM(JSON_TEXT('['), JSON_TEXT(']')) 84 | BRACKET_STREAM(JSON_TEXT('{'), JSON_TEXT('}')) 85 | QUOTECASE_STREAM() 86 | } 87 | }; 88 | return json_string::npos; 89 | } 90 | 91 | void JSONStream::parse(void) json_nothrow { 92 | #ifdef JSON_SECURITY_MAX_STREAM_OBJECTS 93 | size_t objects = 0; 94 | #endif 95 | for(;;){ 96 | size_t pos = buffer.find_first_of(JSON_TEXT("{[")); 97 | if (json_likely(pos != json_string::npos)){ 98 | size_t end = (buffer[pos] == JSON_TEXT('[')) ? STREAM_FIND_NEXT_RELEVANT(JSON_TEXT(']'), buffer, pos + 1) : STREAM_FIND_NEXT_RELEVANT(JSON_TEXT('}'), buffer, pos + 1); 99 | if (end != json_string::npos){ 100 | #ifdef JSON_SECURITY_MAX_STREAM_OBJECTS 101 | if (++objects > JSON_SECURITY_MAX_STREAM_OBJECTS){ 102 | JSON_FAIL(JSON_TEXT("Maximum number of json objects for a stream at once has been reached")); 103 | if (err_call) err_call(getIdentifier()); 104 | state = false; 105 | return; 106 | } 107 | #endif 108 | START_MEM_SCOPE 109 | JSONNode temp(JSONWorker::parse(buffer.substr(pos, end - pos + 1))); 110 | #ifndef JSON_LIBRARY 111 | call(temp, getIdentifier()); 112 | #else 113 | call(&temp, getIdentifier()); 114 | #endif 115 | END_MEM_SCOPE 116 | json_string::iterator beginning = buffer.begin(); 117 | buffer.erase(beginning, beginning + end); 118 | continue; //parse(); //parse the next object too 119 | } 120 | #ifdef JSON_SAFE 121 | else { 122 | //verify that what's in there is at least valid so far 123 | #ifndef JSON_VALIDATE 124 | #error In order to use safe mode and streams, JSON_VALIDATE needs to be defined 125 | #endif 126 | 127 | json_auto s; 128 | size_t len; 129 | s.set(JSONWorker::RemoveWhiteSpace(json_string(buffer.c_str() + pos), len, false)); 130 | 131 | 132 | if (!JSONValidator::isValidPartialRoot(s.ptr)){ 133 | if (err_call) err_call(getIdentifier()); 134 | state = false; 135 | } 136 | } 137 | #endif 138 | } 139 | break; 140 | } 141 | } 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestAssign.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | #include "../Source/JSONNode.h" 3 | 4 | void TestSuite::TestAssigning(void){ 5 | UnitTest::SetPrefix("TestAssign.cpp - Assigning"); 6 | #ifdef JSON_LIBRARY 7 | //check names 8 | JSONNODE * test1 = json_new(JSON_NODE); 9 | json_set_name(test1, JSON_TEXT("hello world")); 10 | json_char * res = json_name(test1); 11 | assertCStringSame(res, JSON_TEXT("hello world")); 12 | json_free(res); 13 | 14 | //check strings 15 | json_set_a(test1, JSON_TEXT("Hello world")); 16 | assertEquals(json_type(test1), JSON_STRING); 17 | res = json_as_string(test1); 18 | assertCStringSame(res, JSON_TEXT("Hello world")); 19 | json_free(res); 20 | 21 | //check ints 22 | json_set_i(test1, 13); 23 | assertEquals(json_type(test1), JSON_NUMBER); 24 | res = json_as_string(test1); 25 | #ifdef JSON_CASTABLE 26 | assertCStringSame(res, JSON_TEXT("13")); 27 | #endif 28 | json_free(res); 29 | assertEquals(json_as_int(test1), 13); 30 | assertEquals(json_as_float(test1), 13.0f); 31 | 32 | //check doubles work 33 | json_set_f(test1, 13.7f); 34 | assertEquals(json_type(test1), JSON_NUMBER); 35 | res = json_as_string(test1); 36 | #ifdef JSON_CASTABLE 37 | assertCStringSame(res, JSON_TEXT("13.7")); 38 | #endif 39 | json_free(res); 40 | assertEquals(json_as_int(test1), 13); 41 | assertEquals(json_as_float(test1), 13.7f); 42 | 43 | //test making sure stripping the trailing period works 44 | json_set_f(test1, 13.0f); 45 | assertEquals(json_type(test1), JSON_NUMBER); 46 | res = json_as_string(test1); 47 | #ifdef JSON_CASTABLE 48 | assertCStringSame(res, JSON_TEXT("13")); 49 | #endif 50 | json_free(res); 51 | assertEquals(json_as_int(test1), 13); 52 | assertEquals(json_as_float(test1), 13.0f); 53 | 54 | //check boolean 55 | json_set_b(test1, (int)true); 56 | assertEquals(json_type(test1), JSON_BOOL); 57 | res = json_as_string(test1); 58 | #ifdef JSON_CASTABLE 59 | assertCStringSame(res, JSON_TEXT("true")); 60 | #endif 61 | json_free(res); 62 | assertEquals(json_as_bool(test1), true); 63 | 64 | //check boolean 65 | json_set_b(test1, false); 66 | assertEquals(json_type(test1), JSON_BOOL); 67 | res = json_as_string(test1); 68 | #ifdef JSON_CASTABLE 69 | assertCStringSame(res, JSON_TEXT("false")); 70 | #endif 71 | json_free(res); 72 | assertEquals(json_as_bool(test1), false); 73 | 74 | //check null 75 | json_nullify(test1); 76 | assertEquals(json_type(test1), JSON_NULL); 77 | res = json_as_string(test1); 78 | #ifdef JSON_CASTABLE 79 | assertCStringSame(res, JSON_TEXT("null")); 80 | #endif 81 | json_free(res); 82 | 83 | json_delete(test1); 84 | 85 | #else 86 | //check names 87 | JSONNode test1; 88 | test1.set_name(JSON_TEXT("hello world")); 89 | assertEquals(test1.name(), JSON_TEXT("hello world")); 90 | 91 | //check strings 92 | test1 = JSON_TEXT("Hello world"); 93 | assertEquals(test1.type(), JSON_STRING); 94 | assertEquals(test1.as_string(), JSON_TEXT("Hello world")); 95 | 96 | //test chars 97 | test1 = JSON_TEXT('\0'); 98 | assertEquals(test1.type(), JSON_NUMBER); 99 | #ifdef JSON_CASTABLE 100 | assertEquals(test1.as_string(), JSON_TEXT("0")); 101 | #endif 102 | assertEquals(test1.as_int(), 0); 103 | assertEquals(test1.as_float(), 0.0f); 104 | 105 | //check ints 106 | test1 = 13; 107 | assertEquals(test1.type(), JSON_NUMBER); 108 | #ifdef JSON_CASTABLE 109 | assertEquals(test1.as_string(), JSON_TEXT("13")); 110 | #endif 111 | assertEquals(test1.as_int(), 13); 112 | assertEquals(test1.as_float(), 13.0f); 113 | 114 | //check doubles work 115 | test1 = 13.7f; 116 | assertEquals(test1.type(), JSON_NUMBER); 117 | #ifdef JSON_CASTABLE 118 | assertEquals(test1.as_string(), JSON_TEXT("13.7")); 119 | #endif 120 | assertEquals(test1.as_int(), 13); 121 | assertEquals(test1.as_float(), 13.7f); 122 | 123 | //test making sure stripping hte trailing period works 124 | test1 = 13.0f; 125 | assertEquals(test1.type(), JSON_NUMBER); 126 | #ifdef JSON_CASTABLE 127 | assertEquals(test1.as_string(), JSON_TEXT("13")); 128 | #endif 129 | assertEquals(test1.as_int(), 13); 130 | assertEquals(test1.as_float(), 13.0f); 131 | 132 | //check boolean 133 | test1 = true; 134 | assertEquals(test1.type(), JSON_BOOL); 135 | #ifdef JSON_CASTABLE 136 | assertEquals(test1.as_string(), JSON_TEXT("true")); 137 | #endif 138 | assertEquals(test1.as_bool(), true); 139 | 140 | //check boolean 141 | test1 = false; 142 | assertEquals(test1.type(), JSON_BOOL); 143 | #ifdef JSON_CASTABLE 144 | assertEquals(test1.as_string(), JSON_TEXT("false")); 145 | #endif 146 | assertEquals(test1.as_bool(), false); 147 | 148 | //check null 149 | test1.nullify(); 150 | assertEquals(test1.type(), JSON_NULL); 151 | #ifdef JSON_CASTABLE 152 | assertEquals(test1.as_string(), JSON_TEXT("null")); 153 | #endif 154 | #endif 155 | } 156 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SAMPSON 2 | ======= 3 | 4 | SAMPSON - A JSON plugin for SA-MP 5 | 6 | ### Why? 7 | I decided to build this plugin as a fellow member of the SA-MP community was having issues with DJSON. DJSON is also outdated and does not conform to various JSON standards. It caches to disk, has a large memory footprint, and uses SQL for... JSON storage. It seemed wrong to me, so I decided to build my own plugin. 8 | 9 | ### Features: 10 | The plugin currently features a JSON parser for files located in your 'scriptfiles' directory. It's compliant to the JSON standards and can parse strings, numbers, booleans and arrays. 11 | 12 | ### Documentation: 13 | I'll be doing tutorials on the usage of this plugin, and a Wiki for all the functions. But for now, I'll just dump the functions with basic information about them here: 14 | 15 | You can define a node delimiter by defining JSON_DEFAULT_DELIMITER to a char; Default delimiter is 16 | ``` 17 | #define JSON_DEFAULT_DELIMITER '/' 18 | ``` 19 | --- 20 | 21 | ##### `json_parse_file` 22 | ``` 23 | native JSONNode:json_parse_file(const file_path[]) 24 | ``` 25 | >Function: Reads a file, parses it, and stores it in memory for further parsing. 26 | >Returns: A handle to the root node. 27 | 28 | ##### `json_parse_string` 29 | ``` 30 | native JSONNode:json_parse_string(const string[]) 31 | ``` 32 | >Function: Parses a string and stores it in memory for further parsing. 33 | >Returns: A handle to the root node. 34 | 35 | ##### `json_close` 36 | ``` 37 | native json_close(JSONNode:node) 38 | ``` 39 | >Function: Closes a JSON file with root node 'node' and frees all memory associated with it. 40 | >Returns: 1 on success, 0 on failure. 41 | 42 | ##### `json_get_type` 43 | ``` 44 | native json_get_type(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER) 45 | ``` 46 | >Function: Gets the type of a node's value. 47 | >Returns: An integer representing the node's value type. See below for type definitions. 48 | 49 | ``` 50 | JSON_NULL 51 | JSON_STRING 52 | JSON_NUMBER 53 | JSON_BOOL 54 | JSON_ARRAY 55 | JSON_NODE 56 | ``` 57 | ##### `json_get_node` 58 | ``` 59 | native JSONNode:json_get_node(JSONNode:node, const path[], const path_delim = JSON_DEFAULT_DELIMITER) 60 | ``` 61 | >Function: Gets the node at some path using 'node' as a root node. 62 | >Returns: The node on success, 0 if the node doesn't exist. 63 | 64 | ##### `json_get_bool` 65 | ``` 66 | native bool:json_get_bool(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER) 67 | ``` 68 | >Function: Gets the value of some path using 'node' as a root node as a boolean. 69 | >Returns: The value of the specified path's key as a boolean. 70 | 71 | ##### `json_get_int` 72 | ``` 73 | native json_get_int(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER) 74 | ``` 75 | >Function: Gets the value of some path using 'node' as a root node as an integer. 76 | >Returns: The value of the specified path's key as an integer. 77 | 78 | ##### `json_get_float` 79 | ``` 80 | native Float:json_get_float(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER) 81 | ``` 82 | >Function: Gets the value of some path using 'node' as a root node as a float. 83 | >Returns: The value of the specified path's key as a float. 84 | 85 | ##### `json_get_string` 86 | ``` 87 | native json_get_string(JSONNode:node, dst[], const len = sizeof(dst), const path[] = '\0', const bool:packed = false, const path_delim = JSON_DEFAULT_DELIMITER) 88 | ``` 89 | >Function: Gets the value of some path using 'node' as a root node as a string and writes it to 'dst'. 90 | >Returns: 1. 91 | 92 | ##### `json_get_name` 93 | ``` 94 | native json_get_name(JSONNode:node, dst[], const len = sizeof(dst), const bool:packed = false) 95 | ``` 96 | 97 | >Function: Gets the name (key) of some path using 'node' as a root node and writes it to 'dst'. 98 | >Returns: 1 if the node has a name (key) associated with it, 0 if it doesn't. 99 | 100 | ##### `json_get_array` 101 | ``` 102 | native JSONArray:json_get_array(JSONNode:node, const path[] = '\0', const path_delim = JSON_DEFAULT_DELIMITER) 103 | ``` 104 | >Function: Gets the value of some path using 'node' as a root node as an array. 105 | >Returns: A JSON array type which is used for array functions. 106 | 107 | ##### `json_array_count` 108 | ``` 109 | native json_array_count(JSONArray:array) 110 | ``` 111 | >Function: Gets the amount of elements 'array' contains. 112 | >Returns: An integer representing the amount of elements 'array' contains. 113 | 114 | ##### `json_array_at` 115 | ``` 116 | native JSONNode:json_array_at(JSONArray:array, const index) 117 | ``` 118 | >Function: Gets the element at 'index' in 'array' as a node. 119 | >Returns: The element as a JSON node. 120 | 121 | ### Installation 122 | Download the [release archive](https://github.com/Hual/SAMPSON/releases) and place its contents into your server folder. Open your configuration file and add 'SAMPSON' ('SAMPSON.so' on Linux) to your 'plugins' line. 123 | 124 | ### Building from source 125 | 1. Download the source code from the link provided above. 126 | 2. On Windows, open the 'SAMPSON.sln' file in Visual Studio, select 'Release' build target and then build it. 127 | 3. On Linux, run 'make' in the 'src' folder. The built plugin should be found in the 'build' folder. 128 | 129 | 130 | ### Credits 131 | - The SA-MP team - SA-MP, SA-MP plugin SDK 132 | - Djole1337 - Testing support, Linux build support 133 | 134 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs.h: -------------------------------------------------------------------------------- 1 | #ifndef JSONDEFS_H 2 | #define JSONDEFS_H 3 | 4 | /* 5 | Defines all of the types of functions and various other definitions 6 | that are used in C applications, this is very useful if dynamically loading 7 | the library instead of linking. 8 | */ 9 | 10 | #include "../../JSONOptions.h" 11 | #include "JSONDefs/Unknown_C.h" 12 | #include "JSONDefs/GNU_C.h" 13 | #include "JSONDefs/Visual_C.h" 14 | #include "JSONDefs/Strings_Defs.h" 15 | 16 | #define __LIBJSON_MAJOR__ 7 17 | #define __LIBJSON_MINOR__ 6 18 | #define __LIBJSON_PATCH__ 1 19 | #define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__) 20 | 21 | #define JSON_NULL '\0' 22 | #define JSON_STRING '\1' 23 | #define JSON_NUMBER '\2' 24 | #define JSON_BOOL '\3' 25 | #define JSON_ARRAY '\4' 26 | #define JSON_NODE '\5' 27 | 28 | #ifdef __cplusplus 29 | #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) 30 | #include "JSONAllocator.h" 31 | #else 32 | #define json_allocator std::allocator 33 | #endif 34 | 35 | #ifdef JSON_STRING_HEADER 36 | #include JSON_STRING_HEADER 37 | #else 38 | typedef std::basic_string, json_allocator > json_string; 39 | #endif 40 | #endif 41 | #define JSON_MAP(x, y) std::map, json_allocator > > 42 | 43 | #ifdef JSON_NO_EXCEPTIONS 44 | #define json_throw(x) 45 | #define json_try 46 | #define json_catch(exception, code) 47 | #else 48 | #define json_throw(x) throw(x) 49 | #define json_try try 50 | #define json_catch(exception, code) catch(exception){ code } 51 | #endif 52 | 53 | #ifdef JSON_STRICT 54 | #ifndef JSON_UNICODE 55 | #error, JSON_UNICODE is required for JSON_STRICT 56 | #endif 57 | #ifdef JSON_COMMENTS 58 | #error, JSON_COMMENTS is required to be off for JSON_STRICT 59 | #endif 60 | #endif 61 | 62 | #ifdef JSON_ISO_STRICT 63 | #ifdef JSON_UNICODE 64 | #error, You can not use unicode under ANSI Strict C++ 65 | #endif 66 | #else 67 | #ifdef __GNUC__ 68 | #ifdef __STRICT_ANSI__ 69 | #warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you 70 | #define JSON_ISO_STRICT 71 | #endif 72 | #endif 73 | #endif 74 | 75 | 76 | #ifdef JSON_NUMBER_TYPE 77 | typedef JSON_NUMBER_TYPE json_number; 78 | #define JSON_FLOAT_THRESHHOLD 0.00001 79 | #else 80 | #ifdef JSON_LESS_MEMORY 81 | typedef float json_number; 82 | #define JSON_FLOAT_THRESHHOLD 0.00001f 83 | #else 84 | typedef double json_number; 85 | #define JSON_FLOAT_THRESHHOLD 0.00001 86 | #endif 87 | #endif 88 | 89 | 90 | #ifdef JSON_LESS_MEMORY 91 | /* PACKED and BITS stored in compiler specific headers */ 92 | #define START_MEM_SCOPE { 93 | #define END_MEM_SCOPE } 94 | #else 95 | #define PACKED(x) 96 | #define BITS(x) 97 | #define START_MEM_SCOPE 98 | #define END_MEM_SCOPE 99 | #endif 100 | 101 | #if defined JSON_DEBUG || defined JSON_SAFE 102 | #ifdef JSON_LIBRARY 103 | typedef void (*json_error_callback_t)(const json_char *); 104 | #else 105 | typedef void (*json_error_callback_t)(const json_string &); 106 | #endif 107 | #endif 108 | 109 | #ifdef JSON_INDEX_TYPE 110 | typedef JSON_INDEX_TYPE json_index_t; 111 | #else 112 | typedef unsigned int json_index_t; 113 | #endif 114 | 115 | #ifdef JSON_BOOL_TYPE 116 | typedef JSON_BOOL_TYPE json_bool_t; 117 | #else 118 | typedef int json_bool_t; 119 | #endif 120 | 121 | #ifdef JSON_INT_TYPE 122 | typedef JSON_INT_TYPE json_int_t; 123 | #else 124 | typedef long json_int_t; 125 | #endif 126 | 127 | #define JSONSTREAM_SELF (void*)-1 128 | typedef void (*json_stream_e_callback_t)(void * identifier); 129 | 130 | typedef void (*json_mutex_callback_t)(void *); 131 | typedef void (*json_free_t)(void *); 132 | #ifndef JSON_LIBRARY 133 | typedef void * (*json_malloc_t)(size_t); 134 | typedef void * (*json_realloc_t)(void *, size_t); 135 | #else 136 | #define JSONNODE void /* so that JSONNODE* is void* */ 137 | typedef JSONNODE** JSONNODE_ITERATOR; 138 | #ifdef JSON_STREAM 139 | #define JSONSTREAM void 140 | typedef void (*json_stream_callback_t)(JSONNODE *, void * identifier); 141 | #endif 142 | typedef void * (*json_malloc_t)(unsigned long); 143 | typedef void * (*json_realloc_t)(void *, unsigned long); 144 | #endif 145 | 146 | #ifdef JSON_DEBUG 147 | #ifdef NDEBUG 148 | #ifdef __GNUC__ 149 | #warning, Have JSON_DEBUG on in a release build 150 | #else 151 | #error, Have JSON_DEBUG on in a release build 152 | #endif 153 | #endif 154 | #else 155 | #ifndef NDEBUG 156 | #ifdef __GNUC__ 157 | #warning, Release build of libjson, but NDEBUG is not on 158 | #else 159 | #error, Release build of libjson, but NDEBUG is not on 160 | #endif 161 | #endif 162 | #endif 163 | 164 | #ifdef JSON_UNIT_TEST 165 | #define JSON_PRIVATE public: 166 | #define JSON_PROTECTED public: 167 | #else 168 | #define JSON_PRIVATE private: 169 | #define JSON_PROTECTED protected: 170 | #endif 171 | #ifdef JSON_STREAM 172 | #ifndef JSON_READ_PRIORITY 173 | #error, JSON_STREAM also requires JSON_READ_PRIORITY 174 | #endif 175 | #endif 176 | #ifdef JSON_VALIDATE 177 | #ifndef JSON_READ_PRIORITY 178 | #error, JSON_VALIDATE also requires JSON_READ_PRIORITY 179 | #endif 180 | #endif 181 | 182 | #define JSON_TEMP_COMMENT_IDENTIFIER JSON_TEXT('#') 183 | 184 | #endif 185 | -------------------------------------------------------------------------------- /src/libjson/_internal/Source/JSONDefs.h~: -------------------------------------------------------------------------------- 1 | #ifndef JSONDEFS_H 2 | #define JSONDEFS_H 3 | 4 | /* 5 | Defines all of the types of functions and various other definitions 6 | that are used in C applications, this is very useful if dynamically loading 7 | the library instead of linking. 8 | */ 9 | 10 | #include "../../JSONOptions.h" 11 | #include "JSONDefs/Unknown_C.h" 12 | #include "JSONDefs/GNU_C.h" 13 | #include "JSONDefs/Visual_C.h" 14 | #include "JSONDefs/Strings_Defs.h" 15 | 16 | #define __LIBJSON_MAJOR__ 7 17 | #define __LIBJSON_MINOR__ 6 18 | #define __LIBJSON_PATCH__ 0 19 | #define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__) 20 | 21 | #define JSON_NULL '\0' 22 | #define JSON_STRING '\1' 23 | #define JSON_NUMBER '\2' 24 | #define JSON_BOOL '\3' 25 | #define JSON_ARRAY '\4' 26 | #define JSON_NODE '\5' 27 | 28 | #ifdef __cplusplus 29 | #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) 30 | #include "JSONAllocator.h" 31 | #else 32 | #define json_allocator std::allocator 33 | #endif 34 | 35 | #ifdef JSON_STRING_HEADER 36 | #include JSON_STRING_HEADER 37 | #else 38 | typedef std::basic_string, json_allocator > json_string; 39 | #endif 40 | #endif 41 | #define JSON_MAP(x, y) std::map, json_allocator > > 42 | 43 | #ifdef JSON_NO_EXCEPTIONS 44 | #define json_throw(x) 45 | #define json_try 46 | #define json_catch(exception, code) 47 | #else 48 | #define json_throw(x) throw(x) 49 | #define json_try try 50 | #define json_catch(exception, code) catch(exception){ code } 51 | #endif 52 | 53 | #ifdef JSON_STRICT 54 | #ifndef JSON_UNICODE 55 | #error, JSON_UNICODE is required for JSON_STRICT 56 | #endif 57 | #ifdef JSON_COMMENTS 58 | #error, JSON_COMMENTS is required to be off for JSON_STRICT 59 | #endif 60 | #endif 61 | 62 | #ifdef JSON_ISO_STRICT 63 | #ifdef JSON_UNICODE 64 | #error, You can not use unicode under ANSI Strict C++ 65 | #endif 66 | #else 67 | #ifdef __GNUC__ 68 | #ifdef __STRICT_ANSI__ 69 | #warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you 70 | #define JSON_ISO_STRICT 71 | #endif 72 | #endif 73 | #endif 74 | 75 | 76 | #ifdef JSON_NUMBER_TYPE 77 | typedef JSON_NUMBER_TYPE json_number; 78 | #define JSON_FLOAT_THRESHHOLD 0.00001 79 | #else 80 | #ifdef JSON_LESS_MEMORY 81 | typedef float json_number; 82 | #define JSON_FLOAT_THRESHHOLD 0.00001f 83 | #else 84 | typedef double json_number; 85 | #define JSON_FLOAT_THRESHHOLD 0.00001 86 | #endif 87 | #endif 88 | 89 | 90 | #ifdef JSON_LESS_MEMORY 91 | /* PACKED and BITS stored in compiler specific headers */ 92 | #define START_MEM_SCOPE { 93 | #define END_MEM_SCOPE } 94 | #else 95 | #define PACKED(x) 96 | #define BITS(x) 97 | #define START_MEM_SCOPE 98 | #define END_MEM_SCOPE 99 | #endif 100 | 101 | #if defined JSON_DEBUG || defined JSON_SAFE 102 | #ifdef JSON_LIBRARY 103 | typedef void (*json_error_callback_t)(const json_char *); 104 | #else 105 | typedef void (*json_error_callback_t)(const json_string &); 106 | #endif 107 | #endif 108 | 109 | #ifdef JSON_INDEX_TYPE 110 | typedef JSON_INDEX_TYPE json_index_t; 111 | #else 112 | typedef unsigned int json_index_t; 113 | #endif 114 | 115 | #ifdef JSON_BOOL_TYPE 116 | typedef JSON_BOOL_TYPE json_bool_t; 117 | #else 118 | typedef int json_bool_t; 119 | #endif 120 | 121 | #ifdef JSON_INT_TYPE 122 | typedef JSON_INT_TYPE json_int_t; 123 | #else 124 | typedef long json_int_t; 125 | #endif 126 | 127 | #define JSONSTREAM_SELF (void*)-1 128 | typedef void (*json_stream_e_callback_t)(void * identifier); 129 | 130 | typedef void (*json_mutex_callback_t)(void *); 131 | typedef void (*json_free_t)(void *); 132 | #ifndef JSON_LIBRARY 133 | typedef void * (*json_malloc_t)(size_t); 134 | typedef void * (*json_realloc_t)(void *, size_t); 135 | #else 136 | #define JSONNODE void /* so that JSONNODE* is void* */ 137 | typedef JSONNODE** JSONNODE_ITERATOR; 138 | #ifdef JSON_STREAM 139 | #define JSONSTREAM void 140 | typedef void (*json_stream_callback_t)(JSONNODE *, void * identifier); 141 | #endif 142 | typedef void * (*json_malloc_t)(unsigned long); 143 | typedef void * (*json_realloc_t)(void *, unsigned long); 144 | #endif 145 | 146 | #ifdef JSON_DEBUG 147 | #ifdef NDEBUG 148 | #ifdef __GNUC__ 149 | #warning, Have JSON_DEBUG on in a release build 150 | #else 151 | #error, Have JSON_DEBUG on in a release build 152 | #endif 153 | #endif 154 | #else 155 | #ifndef NDEBUG 156 | #ifdef __GNUC__ 157 | #warning, Release build of libjson, but NDEBUG is not on 158 | #else 159 | #error, Release build of libjson, but NDEBUG is not on 160 | #endif 161 | #endif 162 | #endif 163 | 164 | #ifdef JSON_UNIT_TEST 165 | #define JSON_PRIVATE public: 166 | #define JSON_PROTECTED public: 167 | #else 168 | #define JSON_PRIVATE private: 169 | #define JSON_PROTECTED protected: 170 | #endif 171 | #ifdef JSON_STREAM 172 | #ifndef JSON_READ_PRIORITY 173 | #error, JSON_STREAM also requires JSON_READ_PRIORITY 174 | #endif 175 | #endif 176 | #ifdef JSON_VALIDATE 177 | #ifndef JSON_READ_PRIORITY 178 | #error, JSON_VALIDATE also requires JSON_READ_PRIORITY 179 | #endif 180 | #endif 181 | 182 | #define JSON_TEMP_COMMENT_IDENTIFIER JSON_TEXT('#') 183 | 184 | #endif 185 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite2/NumberToString/_itoa.cpp: -------------------------------------------------------------------------------- 1 | #include "_itoa.h" 2 | #include "../../Source/NumberToString.h" 3 | 4 | 5 | /** 6 | * Test converting a char value into a string 7 | */ 8 | void testNumberToString__itoa::testChar(void){ 9 | //GetScopeCoverage(_itoa, true); 10 | assertEquals(sizeof(char), 1); 11 | assertEquals(NumberToString::_itoa((char)127), JSON_TEXT("127")); 12 | assertEquals(NumberToString::_itoa((char)15), JSON_TEXT("15")); 13 | assertEquals(NumberToString::_itoa((char)0), JSON_TEXT("0")); 14 | assertEquals(NumberToString::_itoa((char)-0), JSON_TEXT("0")); 15 | assertEquals(NumberToString::_itoa((char)-15), JSON_TEXT("-15")); 16 | assertEquals(NumberToString::_itoa((char)-127), JSON_TEXT("-127")); 17 | //AssertScopeCoverage(_itoa); 18 | } 19 | 20 | 21 | /** 22 | * Test converting a short value into a string 23 | */ 24 | void testNumberToString__itoa::testShort(void){ 25 | //GetScopeCoverage(_itoa, true); 26 | assertEquals(sizeof(short), 2); 27 | assertEquals(NumberToString::_itoa((short)32767), JSON_TEXT("32767")); 28 | assertEquals(NumberToString::_itoa((short)127), JSON_TEXT("127")); 29 | assertEquals(NumberToString::_itoa((short)15), JSON_TEXT("15")); 30 | assertEquals(NumberToString::_itoa((short)0), JSON_TEXT("0")); 31 | assertEquals(NumberToString::_itoa((short)-0), JSON_TEXT("0")); 32 | assertEquals(NumberToString::_itoa((short)-15), JSON_TEXT("-15")); 33 | assertEquals(NumberToString::_itoa((short)-127), JSON_TEXT("-127")); 34 | assertEquals(NumberToString::_itoa((short)-32767), JSON_TEXT("-32767")); 35 | //AssertScopeCoverage(_itoa); 36 | } 37 | 38 | 39 | /** 40 | * Test converting an int value into a string 41 | */ 42 | void testNumberToString__itoa::testInt(void){ 43 | //GetScopeCoverage(_itoa, true); 44 | assertEquals(sizeof(int), 4); 45 | assertEquals(NumberToString::_itoa((int)2147483647), JSON_TEXT("2147483647")); 46 | assertEquals(NumberToString::_itoa((int)32767), JSON_TEXT("32767")); 47 | assertEquals(NumberToString::_itoa((int)127), JSON_TEXT("127")); 48 | assertEquals(NumberToString::_itoa((int)15), JSON_TEXT("15")); 49 | assertEquals(NumberToString::_itoa((int)0), JSON_TEXT("0")); 50 | assertEquals(NumberToString::_itoa((int)-0), JSON_TEXT("0")); 51 | assertEquals(NumberToString::_itoa((int)-15), JSON_TEXT("-15")); 52 | assertEquals(NumberToString::_itoa((int)-127), JSON_TEXT("-127")); 53 | assertEquals(NumberToString::_itoa((int)-32767), JSON_TEXT("-32767")); 54 | assertEquals(NumberToString::_itoa((int)-2147483647), JSON_TEXT("-2147483647")); 55 | //AssertScopeCoverage(_itoa); 56 | } 57 | 58 | 59 | /** 60 | * Test converting a long value into a string 61 | */ 62 | void testNumberToString__itoa::testLong(void){ 63 | //GetScopeCoverage(_itoa, true); 64 | #ifdef TEST_LONG_EXTREMES 65 | if (sizeof(long) >= 8){ 66 | assertEquals(NumberToString::_itoa((long)9223372036854775807L), JSON_TEXT("9223372036854775807")); 67 | assertEquals(NumberToString::_itoa((long)-9223372036854775807L), JSON_TEXT("-9223372036854775807")); 68 | } 69 | #endif 70 | assertEquals(NumberToString::_itoa((long)2147483647), JSON_TEXT("2147483647")); 71 | assertEquals(NumberToString::_itoa((long)32767), JSON_TEXT("32767")); 72 | assertEquals(NumberToString::_itoa((long)127), JSON_TEXT("127")); 73 | assertEquals(NumberToString::_itoa((long)15), JSON_TEXT("15")); 74 | assertEquals(NumberToString::_itoa((long)0), JSON_TEXT("0")); 75 | assertEquals(NumberToString::_itoa((long)-0), JSON_TEXT("0")); 76 | assertEquals(NumberToString::_itoa((long)-15), JSON_TEXT("-15")); 77 | assertEquals(NumberToString::_itoa((long)-127), JSON_TEXT("-127")); 78 | assertEquals(NumberToString::_itoa((long)-32767), JSON_TEXT("-32767")); 79 | assertEquals(NumberToString::_itoa((long)-2147483647), JSON_TEXT("-2147483647")); 80 | //AssertScopeCoverage(_itoa); 81 | } 82 | 83 | 84 | /** 85 | * Test converting a long long value into a string 86 | */ 87 | void testNumberToString__itoa::testLongLong(void){ 88 | #ifndef JSON_ISO_STRICT 89 | //GetScopeCoverage(_itoa, true); 90 | #ifdef TEST_LONG_EXTREMES 91 | if (sizeof(long long) >= 8){ 92 | assertEquals(NumberToString::_itoa((long long)9223372036854775807L), JSON_TEXT("9223372036854775807")); 93 | assertEquals(NumberToString::_itoa((long long)-9223372036854775807L), JSON_TEXT("-9223372036854775807")); 94 | } 95 | #endif 96 | assertEquals(NumberToString::_itoa((long long)2147483647), JSON_TEXT("2147483647")); 97 | assertEquals(NumberToString::_itoa((long long)32767), JSON_TEXT("32767")); 98 | assertEquals(NumberToString::_itoa((long long)127), JSON_TEXT("127")); 99 | assertEquals(NumberToString::_itoa((long long)15), JSON_TEXT("15")); 100 | assertEquals(NumberToString::_itoa((long long)0), JSON_TEXT("0")); 101 | assertEquals(NumberToString::_itoa((long long)-0), JSON_TEXT("0")); 102 | assertEquals(NumberToString::_itoa((long long)-15), JSON_TEXT("-15")); 103 | assertEquals(NumberToString::_itoa((long long)-127), JSON_TEXT("-127")); 104 | assertEquals(NumberToString::_itoa((long long)-32767), JSON_TEXT("-32767")); 105 | assertEquals(NumberToString::_itoa((long long)-2147483647), JSON_TEXT("-2147483647")); 106 | //AssertScopeCoverage(_itoa); 107 | #endif 108 | } 109 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestString.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | 3 | #ifdef JSON_STRING_HEADER 4 | #ifdef JSON_UNICODE 5 | #include "UStringTest.h" 6 | #else 7 | #include "StringTest.h" 8 | #endif 9 | #else 10 | //otherwise it will use the regular STL strings and act as a control 11 | #include "../../libjson.h" 12 | #endif 13 | 14 | static void assertConstEmpty(const json_string & s){ 15 | assertEquals(s.length(), 0); 16 | assertTrue(s.empty()); 17 | assertCStringSame(s.c_str(), JSON_TEXT("")); 18 | assertEquals(s, s); 19 | assertEquals(s, JSON_TEXT("")); 20 | } 21 | 22 | static void assertEmpty(json_string & s){ 23 | assertEquals(s.length(), 0); 24 | assertTrue(s.empty()); 25 | assertCStringSame(s.c_str(), JSON_TEXT("")); 26 | assertEquals(s, s); 27 | assertEquals(s, JSON_TEXT("")); 28 | assertConstEmpty(s); 29 | } 30 | 31 | static void assertSame(json_string & s, json_string & m){ 32 | assertEquals(s, m); 33 | assertCStringSame(s.c_str(), m.c_str()); 34 | assertEquals(s.length(), m.length()); 35 | s.swap(m); 36 | assertEquals(s, m); 37 | assertCStringSame(s.c_str(), m.c_str()); 38 | assertEquals(s.length(), m.length()); 39 | } 40 | 41 | static void assertDifferent(json_string & s, json_string & m){ 42 | assertNotEquals(s, m); 43 | assertCStringNotSame(s.c_str(), m.c_str()); 44 | } 45 | 46 | void TestSuite::TestString(void){ 47 | UnitTest::SetPrefix("TestString.cpp - Test String Class"); 48 | { 49 | json_string s; 50 | assertEmpty(s); 51 | } 52 | 53 | { 54 | json_string s; 55 | assertEmpty(s); 56 | json_string m(s); 57 | assertEmpty(m); 58 | assertEmpty(s); 59 | assertSame(s, m); 60 | } 61 | 62 | { 63 | json_string s(JSON_TEXT("hello")); 64 | assertEquals(s.length(), 5); 65 | assertFalse(s.empty()); 66 | assertCStringSame(s.c_str(), JSON_TEXT("hello")); 67 | assertEquals(s, s); 68 | assertEquals(s, JSON_TEXT("hello")); 69 | s.clear(); 70 | assertEmpty(s); 71 | } 72 | 73 | { 74 | json_string s(5, 'h'); 75 | assertEquals(s.length(), 5); 76 | assertFalse(s.empty()); 77 | assertCStringSame(s.c_str(), JSON_TEXT("hhhhh")); 78 | assertEquals(s, s); 79 | assertEquals(s, JSON_TEXT("hhhhh")); 80 | s.clear(); 81 | assertEmpty(s); 82 | } 83 | 84 | { 85 | json_string s(5, 'h'); 86 | json_string m(s); 87 | assertSame(s, m); 88 | } 89 | 90 | { 91 | json_string s(5, 'h'); 92 | json_string m(s); 93 | assertSame(s, m); 94 | s.clear(); 95 | assertEmpty(s); 96 | assertEquals(s.length(), 0); 97 | assertDifferent(s, m); 98 | } 99 | 100 | 101 | { 102 | json_string s(JSON_TEXT("hello")); 103 | json_string m = s; 104 | assertSame(s, m); 105 | m = s.substr(1, 3); 106 | assertEquals(m.length(), 3); 107 | assertEquals(m, JSON_TEXT("ell")); 108 | } 109 | 110 | { 111 | json_string s(JSON_TEXT("hello")); 112 | json_string m = s; 113 | assertSame(s, m); 114 | m = s.substr(1); 115 | assertEquals(m.length(), 4); 116 | assertEquals(m, JSON_TEXT("ello")); 117 | } 118 | 119 | { 120 | json_string s(JSON_TEXT("hello")); 121 | s += JSON_TEXT(" world"); 122 | assertEquals(s.length(), 11); 123 | assertEquals(s, JSON_TEXT("hello world")); 124 | } 125 | 126 | 127 | { 128 | json_string s(JSON_TEXT("hello")); 129 | json_string m = s + JSON_TEXT(" world ") + s; 130 | assertEquals(m.length(), 17); 131 | assertEquals(m, JSON_TEXT("hello world hello")); 132 | } 133 | 134 | { 135 | json_string s(JSON_TEXT("hello")); 136 | s += 'a'; 137 | s += 'a'; 138 | s += 'a'; 139 | s += 'a'; 140 | assertEquals(s.length(), 9); 141 | assertEquals(s, JSON_TEXT("helloaaaa")); 142 | } 143 | 144 | { 145 | json_string s(JSON_TEXT("hello world")); 146 | size_t pos = s.find('w'); 147 | assertEquals(pos, 6); 148 | } 149 | 150 | { 151 | json_string s(JSON_TEXT("hello world")); 152 | size_t pos = s.find('z'); 153 | assertEquals(pos, json_string::npos); 154 | } 155 | 156 | { 157 | json_string s(JSON_TEXT("hello world")); 158 | size_t pos = s.find_first_not_of(JSON_TEXT("helo")); 159 | assertEquals(pos, 5); 160 | } 161 | 162 | { 163 | json_string s(JSON_TEXT("hello world")); 164 | size_t pos = s.find_first_of(JSON_TEXT("ol")); 165 | assertEquals(pos, 2); 166 | } 167 | 168 | { 169 | json_string s(JSON_TEXT("hello world")); 170 | s.erase(s.begin(), s.begin() + 3); 171 | assertEquals(s, JSON_TEXT("lo world")); 172 | } 173 | 174 | { 175 | json_string s(JSON_TEXT("hello world"), 5); 176 | assertEquals(s, JSON_TEXT("hello")); 177 | } 178 | 179 | #ifndef JSON_LIBRARY 180 | #ifndef JSON_STRING_HEADER 181 | { 182 | json_string s(JSON_TEXT("hello world")); 183 | std::wstring wtest(L"hello world"); 184 | std::string stest("hello world"); 185 | assertEquals(libjson::to_std_string(s), stest); 186 | assertEquals(stest, libjson::to_std_string(s)); 187 | assertEquals(libjson::to_std_wstring(s), wtest); 188 | assertEquals(wtest, libjson::to_std_wstring(s)); 189 | 190 | assertEquals(s, libjson::to_json_string(stest)); 191 | assertEquals(libjson::to_json_string(stest), s); 192 | assertEquals(s, libjson::to_json_string(wtest)); 193 | assertEquals(libjson::to_json_string(wtest), s); 194 | } 195 | #endif 196 | #endif 197 | } 198 | -------------------------------------------------------------------------------- /src/libjson/_internal/TestSuite/TestString.cpp~: -------------------------------------------------------------------------------- 1 | #include "TestSuite.h" 2 | 3 | #ifdef JSON_STRING_HEADER 4 | #ifdef JSON_UNICODE 5 | #include "UStringTest.h" 6 | #else 7 | #include "StringTest.h" 8 | #endif 9 | #else 10 | //otherwise it will use the regular STL strings and act as a control 11 | #include "../libjson.h" 12 | #endif 13 | 14 | static void assertConstEmpty(const json_string & s){ 15 | assertEquals(s.length(), 0); 16 | assertTrue(s.empty()); 17 | assertCStringSame(s.c_str(), JSON_TEXT("")); 18 | assertEquals(s, s); 19 | assertEquals(s, JSON_TEXT("")); 20 | } 21 | 22 | static void assertEmpty(json_string & s){ 23 | assertEquals(s.length(), 0); 24 | assertTrue(s.empty()); 25 | assertCStringSame(s.c_str(), JSON_TEXT("")); 26 | assertEquals(s, s); 27 | assertEquals(s, JSON_TEXT("")); 28 | assertConstEmpty(s); 29 | } 30 | 31 | static void assertSame(json_string & s, json_string & m){ 32 | assertEquals(s, m); 33 | assertCStringSame(s.c_str(), m.c_str()); 34 | assertEquals(s.length(), m.length()); 35 | s.swap(m); 36 | assertEquals(s, m); 37 | assertCStringSame(s.c_str(), m.c_str()); 38 | assertEquals(s.length(), m.length()); 39 | } 40 | 41 | static void assertDifferent(json_string & s, json_string & m){ 42 | assertNotEquals(s, m); 43 | assertCStringNotSame(s.c_str(), m.c_str()); 44 | } 45 | 46 | void TestSuite::TestString(void){ 47 | UnitTest::SetPrefix("TestString.cpp - Test String Class"); 48 | { 49 | json_string s; 50 | assertEmpty(s); 51 | } 52 | 53 | { 54 | json_string s; 55 | assertEmpty(s); 56 | json_string m(s); 57 | assertEmpty(m); 58 | assertEmpty(s); 59 | assertSame(s, m); 60 | } 61 | 62 | { 63 | json_string s(JSON_TEXT("hello")); 64 | assertEquals(s.length(), 5); 65 | assertFalse(s.empty()); 66 | assertCStringSame(s.c_str(), JSON_TEXT("hello")); 67 | assertEquals(s, s); 68 | assertEquals(s, JSON_TEXT("hello")); 69 | s.clear(); 70 | assertEmpty(s); 71 | } 72 | 73 | { 74 | json_string s(5, 'h'); 75 | assertEquals(s.length(), 5); 76 | assertFalse(s.empty()); 77 | assertCStringSame(s.c_str(), JSON_TEXT("hhhhh")); 78 | assertEquals(s, s); 79 | assertEquals(s, JSON_TEXT("hhhhh")); 80 | s.clear(); 81 | assertEmpty(s); 82 | } 83 | 84 | { 85 | json_string s(5, 'h'); 86 | json_string m(s); 87 | assertSame(s, m); 88 | } 89 | 90 | { 91 | json_string s(5, 'h'); 92 | json_string m(s); 93 | assertSame(s, m); 94 | s.clear(); 95 | assertEmpty(s); 96 | assertEquals(s.length(), 0); 97 | assertDifferent(s, m); 98 | } 99 | 100 | 101 | { 102 | json_string s(JSON_TEXT("hello")); 103 | json_string m = s; 104 | assertSame(s, m); 105 | m = s.substr(1, 3); 106 | assertEquals(m.length(), 3); 107 | assertEquals(m, JSON_TEXT("ell")); 108 | } 109 | 110 | { 111 | json_string s(JSON_TEXT("hello")); 112 | json_string m = s; 113 | assertSame(s, m); 114 | m = s.substr(1); 115 | assertEquals(m.length(), 4); 116 | assertEquals(m, JSON_TEXT("ello")); 117 | } 118 | 119 | { 120 | json_string s(JSON_TEXT("hello")); 121 | s += JSON_TEXT(" world"); 122 | assertEquals(s.length(), 11); 123 | assertEquals(s, JSON_TEXT("hello world")); 124 | } 125 | 126 | 127 | { 128 | json_string s(JSON_TEXT("hello")); 129 | json_string m = s + JSON_TEXT(" world ") + s; 130 | assertEquals(m.length(), 17); 131 | assertEquals(m, JSON_TEXT("hello world hello")); 132 | } 133 | 134 | { 135 | json_string s(JSON_TEXT("hello")); 136 | s += 'a'; 137 | s += 'a'; 138 | s += 'a'; 139 | s += 'a'; 140 | assertEquals(s.length(), 9); 141 | assertEquals(s, JSON_TEXT("helloaaaa")); 142 | } 143 | 144 | { 145 | json_string s(JSON_TEXT("hello world")); 146 | size_t pos = s.find('w'); 147 | assertEquals(pos, 6); 148 | } 149 | 150 | { 151 | json_string s(JSON_TEXT("hello world")); 152 | size_t pos = s.find('z'); 153 | assertEquals(pos, json_string::npos); 154 | } 155 | 156 | { 157 | json_string s(JSON_TEXT("hello world")); 158 | size_t pos = s.find_first_not_of(JSON_TEXT("helo")); 159 | assertEquals(pos, 5); 160 | } 161 | 162 | { 163 | json_string s(JSON_TEXT("hello world")); 164 | size_t pos = s.find_first_of(JSON_TEXT("ol")); 165 | assertEquals(pos, 2); 166 | } 167 | 168 | { 169 | json_string s(JSON_TEXT("hello world")); 170 | s.erase(s.begin(), s.begin() + 3); 171 | assertEquals(s, JSON_TEXT("lo world")); 172 | } 173 | 174 | { 175 | json_string s(JSON_TEXT("hello world"), 5); 176 | assertEquals(s, JSON_TEXT("hello")); 177 | } 178 | 179 | #ifndef JSON_LIBRARY 180 | #ifndef JSON_STRING_HEADER 181 | { 182 | json_string s(JSON_TEXT("hello world")); 183 | std::wstring wtest(L"hello world"); 184 | std::string stest("hello world"); 185 | assertEquals(libjson::to_std_string(s), stest); 186 | assertEquals(stest, libjson::to_std_string(s)); 187 | assertEquals(libjson::to_std_wstring(s), wtest); 188 | assertEquals(wtest, libjson::to_std_wstring(s)); 189 | 190 | assertEquals(s, libjson::to_json_string(stest)); 191 | assertEquals(libjson::to_json_string(stest), s); 192 | assertEquals(s, libjson::to_json_string(wtest)); 193 | assertEquals(libjson::to_json_string(wtest), s); 194 | } 195 | #endif 196 | #endif 197 | } 198 | --------------------------------------------------------------------------------