ソースを参照

cJSON_MakeDuplicateRecursive

Max Bruckner 7 年 前
コミット
409c2aaea7
3 ファイル変更26 行追加0 行削除
  1. 11 0
      cJSON.c
  2. 2 0
      cJSON.h
  3. 13 0
      tests/context_tests.c

+ 11 - 0
cJSON.c

@@ -3023,6 +3023,17 @@ CJSON_PUBLIC(cJSON_Context) cJSON_AllowDataAfterJson(cJSON_Context context, cJSO
     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)
 {
     if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))

+ 2 - 0
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);
 /* Change if data is allowed after the 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 */
 CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);

+ 13 - 0
tests/context_tests.c

@@ -241,6 +241,18 @@ static void allow_data_after_json_should_change_allow_data_after_json(void)
     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)
 {
     UNITY_BEGIN();
@@ -260,6 +272,7 @@ int main(void)
     RUN_TEST(set_format_should_set_format);
     RUN_TEST(make_case_sensitive_should_change_case_sensitivity);
     RUN_TEST(allow_data_after_json_should_change_allow_data_after_json);
+    RUN_TEST(make_duplicate_recursive_should_make_duplicate_recursive);
 
     return UNITY_END();
 }