MCPcopy Index your code
hub / github.com/DaveGamble/cJSON / test_apply_patch

Function test_apply_patch

tests/json_patch_tests.c:49–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49static cJSON_bool test_apply_patch(const cJSON * const test)
50{
51 cJSON *doc = NULL;
52 cJSON *patch = NULL;
53 cJSON *expected = NULL;
54 cJSON *error_element = NULL;
55 cJSON *comment = NULL;
56 cJSON *disabled = NULL;
57
58 cJSON *object = NULL;
59 cJSON_bool successful = false;
60
61 /* extract all the data out of the test */
62 comment = cJSON_GetObjectItemCaseSensitive(test, "comment");
63 if (cJSON_IsString(comment))
64 {
65 printf("Testing \"%s\"\n", comment->valuestring);
66 }
67 else
68 {
69 printf("Testing unknown\n");
70 }
71
72 disabled = cJSON_GetObjectItemCaseSensitive(test, "disabled");
73 if (cJSON_IsTrue(disabled))
74 {
75 printf("SKIPPED\n");
76 return true;
77 }
78
79 doc = cJSON_GetObjectItemCaseSensitive(test, "doc");
80 TEST_ASSERT_NOT_NULL_MESSAGE(doc, "No \"doc\" in the test.");
81 patch = cJSON_GetObjectItemCaseSensitive(test, "patch");
82 TEST_ASSERT_NOT_NULL_MESSAGE(patch, "No \"patch\"in the test.");
83 /* Make a working copy of 'doc' */
84 object = cJSON_Duplicate(doc, true);
85 TEST_ASSERT_NOT_NULL(object);
86
87 expected = cJSON_GetObjectItemCaseSensitive(test, "expected");
88 error_element = cJSON_GetObjectItemCaseSensitive(test, "error");
89 if (error_element != NULL)
90 {
91 /* excepting an error */
92 TEST_ASSERT_TRUE_MESSAGE(0 != cJSONUtils_ApplyPatchesCaseSensitive(object, patch), "Test didn't fail as it's supposed to.");
93
94 successful = true;
95 }
96 else
97 {
98 /* apply the patch */
99 TEST_ASSERT_EQUAL_INT_MESSAGE(0, cJSONUtils_ApplyPatchesCaseSensitive(object, patch), "Failed to apply patches.");
100 successful = true;
101
102 if (expected != NULL)
103 {
104 successful = cJSON_Compare(object, expected, true);
105 }
106 }

Calls 7

cJSON_IsStringFunction · 0.85
cJSON_IsTrueFunction · 0.85
cJSON_DuplicateFunction · 0.85
cJSON_CompareFunction · 0.85
cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…