mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-27 14:14:07 +08:00
cJSON_MakeDuplicateRecursive
This commit is contained in:
parent
e8f56bd194
commit
409c2aaea7
11
cJSON.c
11
cJSON.c
@ -3023,6 +3023,17 @@ CJSON_PUBLIC(cJSON_Context) cJSON_AllowDataAfterJson(cJSON_Context context, cJSO
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CJSON_PUBLIC(cJSON_Context) cJSON_MakeDuplicateRecursive(cJSON_Context context, cJSON_bool recursive)
|
||||||
|
{
|
||||||
|
if (context == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
((internal_context*)context)->duplicate_recursive = recursive;
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
static cJSON_bool compare(const cJSON * const a, const cJSON * const b, const internal_context * const context)
|
static cJSON_bool compare(const cJSON * const a, const cJSON * const b, const internal_context * const context)
|
||||||
{
|
{
|
||||||
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))
|
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))
|
||||||
|
2
cJSON.h
2
cJSON.h
@ -174,6 +174,8 @@ CJSON_PUBLIC(cJSON_Context) cJSON_SetFormat(cJSON_Context context, cJSON_Format
|
|||||||
CJSON_PUBLIC(cJSON_Context) cJSON_MakeCaseSensitive(cJSON_Context context, cJSON_bool case_sensitive);
|
CJSON_PUBLIC(cJSON_Context) cJSON_MakeCaseSensitive(cJSON_Context context, cJSON_bool case_sensitive);
|
||||||
/* Change if data is allowed after the JSON */
|
/* Change if data is allowed after the JSON */
|
||||||
CJSON_PUBLIC(cJSON_Context) cJSON_AllowDataAfterJson(cJSON_Context context, cJSON_bool allow_data_after_json);
|
CJSON_PUBLIC(cJSON_Context) cJSON_AllowDataAfterJson(cJSON_Context context, cJSON_bool allow_data_after_json);
|
||||||
|
/* Change if cJSON_Duplicate copies recursively */
|
||||||
|
CJSON_PUBLIC(cJSON_Context) cJSON_MakeDuplicateRecursive(cJSON_Context context, cJSON_bool recursive);
|
||||||
|
|
||||||
/* Supply malloc and free functions to cJSON globally */
|
/* Supply malloc and free functions to cJSON globally */
|
||||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||||
|
@ -241,6 +241,18 @@ static void allow_data_after_json_should_change_allow_data_after_json(void)
|
|||||||
free(context);
|
free(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void make_duplicate_recursive_should_make_duplicate_recursive(void)
|
||||||
|
{
|
||||||
|
internal_context *context = (internal_context*)cJSON_CreateContext(NULL, NULL);
|
||||||
|
TEST_ASSERT_NOT_NULL(context);
|
||||||
|
|
||||||
|
context = (internal_context*)cJSON_MakeDuplicateRecursive(context, false);
|
||||||
|
TEST_ASSERT_NOT_NULL(context);
|
||||||
|
TEST_ASSERT_FALSE_MESSAGE(context->duplicate_recursive, "Duplicating is not set correctly.");
|
||||||
|
|
||||||
|
free(context);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
@ -260,6 +272,7 @@ int main(void)
|
|||||||
RUN_TEST(set_format_should_set_format);
|
RUN_TEST(set_format_should_set_format);
|
||||||
RUN_TEST(make_case_sensitive_should_change_case_sensitivity);
|
RUN_TEST(make_case_sensitive_should_change_case_sensitivity);
|
||||||
RUN_TEST(allow_data_after_json_should_change_allow_data_after_json);
|
RUN_TEST(allow_data_after_json_should_change_allow_data_after_json);
|
||||||
|
RUN_TEST(make_duplicate_recursive_should_make_duplicate_recursive);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user