|
@@ -40,11 +40,23 @@ static void parse_with_opts_should_handle_empty_strings(void)
|
|
|
{
|
|
|
const char empty_string[] = "";
|
|
|
const char *error_pointer = NULL;
|
|
|
+
|
|
|
TEST_ASSERT_NULL(cJSON_ParseWithOpts(empty_string, NULL, false));
|
|
|
- error_pointer = cJSON_GetErrorPtr();
|
|
|
- TEST_ASSERT_EQUAL_INT(0, error_pointer - empty_string);
|
|
|
+ TEST_ASSERT_EQUAL_PTR(empty_string, cJSON_GetErrorPtr());
|
|
|
+
|
|
|
TEST_ASSERT_NULL(cJSON_ParseWithOpts(empty_string, &error_pointer, false));
|
|
|
- TEST_ASSERT_EQUAL_INT(0, error_pointer - empty_string);
|
|
|
+ TEST_ASSERT_EQUAL_PTR(empty_string, error_pointer);
|
|
|
+ TEST_ASSERT_EQUAL_PTR(NULL, cJSON_GetErrorPtr());
|
|
|
+}
|
|
|
+
|
|
|
+static void parse_with_opts_should_handle_incomplete_json(void)
|
|
|
+{
|
|
|
+ const char json[] = "{ \"name\": ";
|
|
|
+ const char *parse_end = NULL;
|
|
|
+
|
|
|
+ TEST_ASSERT_NULL(cJSON_ParseWithOpts(json, &parse_end, false));
|
|
|
+ TEST_ASSERT_EQUAL_PTR(json + strlen(json), parse_end);
|
|
|
+ TEST_ASSERT_NULL(cJSON_GetErrorPtr());
|
|
|
}
|
|
|
|
|
|
static void parse_with_opts_should_require_null_if_requested(void)
|
|
@@ -65,7 +77,7 @@ static void parse_with_opts_should_return_parse_end(void)
|
|
|
|
|
|
cJSON *item = cJSON_ParseWithOpts(json, &parse_end, false);
|
|
|
TEST_ASSERT_NOT_NULL(item);
|
|
|
- TEST_ASSERT_EQUAL_INT(2, parse_end - json);
|
|
|
+ TEST_ASSERT_EQUAL_PTR(json + 2, parse_end);
|
|
|
cJSON_Delete(item);
|
|
|
}
|
|
|
|
|
@@ -75,6 +87,7 @@ int main(void)
|
|
|
|
|
|
RUN_TEST(parse_with_opts_should_handle_null);
|
|
|
RUN_TEST(parse_with_opts_should_handle_empty_strings);
|
|
|
+ RUN_TEST(parse_with_opts_should_handle_incomplete_json);
|
|
|
RUN_TEST(parse_with_opts_should_require_null_if_requested);
|
|
|
RUN_TEST(parse_with_opts_should_return_parse_end);
|
|
|
|