mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
misc_utils_tests: call all utils function with NULL pointers
This commit is contained in:
parent
93227319f0
commit
18ad8a8770
@ -84,7 +84,8 @@ if(ENABLE_CJSON_TEST)
|
|||||||
|
|
||||||
set (cjson_utils_tests
|
set (cjson_utils_tests
|
||||||
json_patch_tests
|
json_patch_tests
|
||||||
old_utils_tests)
|
old_utils_tests
|
||||||
|
misc_utils_tests)
|
||||||
|
|
||||||
foreach (cjson_utils_test ${cjson_utils_tests})
|
foreach (cjson_utils_test ${cjson_utils_tests})
|
||||||
add_executable("${cjson_utils_test}" "${cjson_utils_test}.c")
|
add_executable("${cjson_utils_test}" "${cjson_utils_test}.c")
|
||||||
|
80
tests/misc_utils_tests.c
Normal file
80
tests/misc_utils_tests.c
Normal file
@ -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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user