parse_array: Use parsebuffer

This commit is contained in:
Max Bruckner
2017-03-14 10:27:57 +01:00
parent fd0320cf54
commit 033a542532
3 changed files with 79 additions and 30 deletions

View File

@@ -46,13 +46,23 @@ static void assert_is_array(cJSON *array_item)
static void assert_not_array(const char *json)
{
TEST_ASSERT_NULL(parse_array(item, (const unsigned char*)json, &error_pointer, &global_hooks));
parse_buffer buffer;
buffer.content = (const unsigned char*)json;
buffer.length = strlen(json) + sizeof("");
buffer.offset = 0;
TEST_ASSERT_NULL(parse_array(item, &buffer, &error_pointer, &global_hooks));
assert_is_invalid(item);
}
static void assert_parse_array(const char *json)
{
TEST_ASSERT_NOT_NULL(parse_array(item, (const unsigned char*)json, &error_pointer, &global_hooks));
parse_buffer buffer;
buffer.content = (const unsigned char*)json;
buffer.length = strlen(json) + sizeof("");
buffer.offset = 0;
TEST_ASSERT_NOT_NULL(parse_array(item, &buffer, &error_pointer, &global_hooks));
assert_is_array(item);
}

View File

@@ -35,6 +35,11 @@ static void assert_print_array(const char * const expected, const char * const i
printbuffer formatted_buffer;
printbuffer unformatted_buffer;
parse_buffer parsebuffer;
parsebuffer.content = (const unsigned char*)input;
parsebuffer.length = strlen(input) + sizeof("");
parsebuffer.offset = 0;
/* buffer for formatted printing */
formatted_buffer.buffer = printed_formatted;
formatted_buffer.length = sizeof(printed_formatted);
@@ -48,7 +53,7 @@ static void assert_print_array(const char * const expected, const char * const i
unformatted_buffer.noalloc = true;
memset(item, 0, sizeof(item));
TEST_ASSERT_NOT_NULL_MESSAGE(parse_array(item, (const unsigned char*)input, &error_pointer, &global_hooks), "Failed to parse array.");
TEST_ASSERT_NOT_NULL_MESSAGE(parse_array(item, &parsebuffer, &error_pointer, &global_hooks), "Failed to parse array.");
TEST_ASSERT_TRUE_MESSAGE(print_array(item, 0, false, &unformatted_buffer, &global_hooks), "Failed to print unformatted string.");
TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted array is not correct.");