| 120 | } |
| 121 | |
| 122 | static cJSON_bool test_generate_test(cJSON *test) |
| 123 | { |
| 124 | cJSON *doc = NULL; |
| 125 | cJSON *patch = NULL; |
| 126 | cJSON *expected = NULL; |
| 127 | cJSON *disabled = NULL; |
| 128 | |
| 129 | cJSON *object = NULL; |
| 130 | cJSON_bool successful = false; |
| 131 | |
| 132 | char *printed_patch = NULL; |
| 133 | |
| 134 | disabled = cJSON_GetObjectItemCaseSensitive(test, "disabled"); |
| 135 | if (cJSON_IsTrue(disabled)) |
| 136 | { |
| 137 | printf("SKIPPED\n"); |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | doc = cJSON_GetObjectItemCaseSensitive(test, "doc"); |
| 142 | TEST_ASSERT_NOT_NULL_MESSAGE(doc, "No \"doc\" in the test."); |
| 143 | |
| 144 | /* Make a working copy of 'doc' */ |
| 145 | object = cJSON_Duplicate(doc, true); |
| 146 | TEST_ASSERT_NOT_NULL(object); |
| 147 | |
| 148 | expected = cJSON_GetObjectItemCaseSensitive(test, "expected"); |
| 149 | if (expected == NULL) |
| 150 | { |
| 151 | cJSON_Delete(object); |
| 152 | /* if there is no expected output, this test doesn't make sense */ |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | patch = cJSONUtils_GeneratePatchesCaseSensitive(doc, expected); |
| 157 | TEST_ASSERT_NOT_NULL_MESSAGE(patch, "Failed to generate patches."); |
| 158 | |
| 159 | printed_patch = cJSON_Print(patch); |
| 160 | printf("%s\n", printed_patch); |
| 161 | free(printed_patch); |
| 162 | |
| 163 | /* apply the generated patch */ |
| 164 | TEST_ASSERT_EQUAL_INT_MESSAGE(0, cJSONUtils_ApplyPatchesCaseSensitive(object, patch), "Failed to apply generated patch."); |
| 165 | |
| 166 | successful = cJSON_Compare(object, expected, true); |
| 167 | |
| 168 | cJSON_Delete(patch); |
| 169 | cJSON_Delete(object); |
| 170 | |
| 171 | if (successful) |
| 172 | { |
| 173 | printf("generated patch: OK\n"); |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | printf("generated patch: FAILED\n"); |
| 178 | } |
| 179 |
no test coverage detected
searching dependent graphs…