summaryrefslogtreecommitdiff
path: root/support/cJSON-master/tests/misc_utils_tests.c
diff options
context:
space:
mode:
authorlijie <[email protected]>2018-12-18 14:13:02 +0800
committerlijie <[email protected]>2018-12-18 14:13:02 +0800
commita4abef91b597f226f918f506e7ff591a77f3b126 (patch)
treeb16c769bb9ec312b832b28d7315110f7daecc631 /support/cJSON-master/tests/misc_utils_tests.c
parentfc99454ea9bce35065e34b28815f8cf417b37804 (diff)
修改包含cjson头文件形式,添加mrl的cjson源码v2.0.0
Diffstat (limited to 'support/cJSON-master/tests/misc_utils_tests.c')
-rw-r--r--support/cJSON-master/tests/misc_utils_tests.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/support/cJSON-master/tests/misc_utils_tests.c b/support/cJSON-master/tests/misc_utils_tests.c
new file mode 100644
index 0000000..7d300bc
--- /dev/null
+++ b/support/cJSON-master/tests/misc_utils_tests.c
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "unity/examples/unity_config.h"
+#include "unity/src/unity.h"
+#include "common.h"
+#include "../cJSON_Utils.h"
+
+static void cjson_utils_functions_shouldnt_crash_with_null_pointers(void)
+{
+ cJSON *item = cJSON_CreateString("item");
+ TEST_ASSERT_NOT_NULL(item);
+
+ TEST_ASSERT_NULL(cJSONUtils_GetPointer(item, NULL));
+ TEST_ASSERT_NULL(cJSONUtils_GetPointer(NULL, "pointer"));
+ TEST_ASSERT_NULL(cJSONUtils_GetPointerCaseSensitive(NULL, "pointer"));
+ TEST_ASSERT_NULL(cJSONUtils_GetPointerCaseSensitive(item, NULL));
+ TEST_ASSERT_NULL(cJSONUtils_GeneratePatches(item, NULL));
+ TEST_ASSERT_NULL(cJSONUtils_GeneratePatches(NULL, item));
+ TEST_ASSERT_NULL(cJSONUtils_GeneratePatchesCaseSensitive(item, NULL));
+ TEST_ASSERT_NULL(cJSONUtils_GeneratePatchesCaseSensitive(NULL, item));
+ cJSONUtils_AddPatchToArray(item, "path", "add", NULL);
+ cJSONUtils_AddPatchToArray(item, "path", NULL, item);
+ cJSONUtils_AddPatchToArray(item, NULL, "add", item);
+ cJSONUtils_AddPatchToArray(NULL, "path", "add", item);
+ cJSONUtils_ApplyPatches(item, NULL);
+ cJSONUtils_ApplyPatches(NULL, item);
+ cJSONUtils_ApplyPatchesCaseSensitive(item, NULL);
+ cJSONUtils_ApplyPatchesCaseSensitive(NULL, item);
+ TEST_ASSERT_NULL(cJSONUtils_MergePatch(item, NULL));
+ item = cJSON_CreateString("item");
+ TEST_ASSERT_NULL(cJSONUtils_MergePatchCaseSensitive(item, NULL));
+ item = cJSON_CreateString("item");
+ /* these calls are actually valid */
+ /* cJSONUtils_MergePatch(NULL, item); */
+ /* cJSONUtils_MergePatchCaseSensitive(NULL, item);*/
+ /* cJSONUtils_GenerateMergePatch(item, NULL); */
+ /* cJSONUtils_GenerateMergePatch(NULL, item); */
+ /* cJSONUtils_GenerateMergePatchCaseSensitive(item, NULL); */
+ /* cJSONUtils_GenerateMergePatchCaseSensitive(NULL, item); */
+
+ TEST_ASSERT_NULL(cJSONUtils_FindPointerFromObjectTo(item, NULL));
+ TEST_ASSERT_NULL(cJSONUtils_FindPointerFromObjectTo(NULL, item));
+ cJSONUtils_SortObject(NULL);
+ cJSONUtils_SortObjectCaseSensitive(NULL);
+
+ cJSON_Delete(item);
+}
+
+int main(void)
+{
+ UNITY_BEGIN();
+
+ RUN_TEST(cjson_utils_functions_shouldnt_crash_with_null_pointers);
+
+ return UNITY_END();
+}