parser: Construct error pointer from buffer offset

This commit is contained in:
Max Bruckner
2017-03-21 21:41:37 +01:00
parent c837177a56
commit 2683589d93
8 changed files with 49 additions and 72 deletions

View File

@@ -30,8 +30,6 @@
static cJSON item[1];
static const unsigned char *error_pointer = NULL;
static void assert_is_array(cJSON *array_item)
{
TEST_ASSERT_NOT_NULL_MESSAGE(array_item, "Item is NULL.");
@@ -51,7 +49,7 @@ static void assert_not_array(const char *json)
buffer.length = strlen(json) + sizeof("");
buffer.offset = 0;
TEST_ASSERT_FALSE(parse_array(item, &buffer, &error_pointer, &global_hooks));
TEST_ASSERT_FALSE(parse_array(item, &buffer, &global_hooks));
assert_is_invalid(item);
}
@@ -62,7 +60,7 @@ static void assert_parse_array(const char *json)
buffer.length = strlen(json) + sizeof("");
buffer.offset = 0;
TEST_ASSERT_TRUE(parse_array(item, &buffer, &error_pointer, &global_hooks));
TEST_ASSERT_TRUE(parse_array(item, &buffer, &global_hooks));
assert_is_array(item);
}

View File

@@ -30,8 +30,6 @@
static cJSON item[1];
static const unsigned char *error_pointer = NULL;
static void assert_is_object(cJSON *object_item)
{
TEST_ASSERT_NOT_NULL_MESSAGE(object_item, "Item is NULL.");
@@ -59,7 +57,7 @@ static void assert_not_object(const char *json)
parsebuffer.length = strlen(json) + sizeof("");
parsebuffer.offset = 0;
TEST_ASSERT_FALSE(parse_object(item, &parsebuffer, &error_pointer, &global_hooks));
TEST_ASSERT_FALSE(parse_object(item, &parsebuffer, &global_hooks));
assert_is_invalid(item);
reset(item);
}
@@ -71,7 +69,7 @@ static void assert_parse_object(const char *json)
parsebuffer.length = strlen(json) + sizeof("");
parsebuffer.offset = 0;
TEST_ASSERT_TRUE(parse_object(item, &parsebuffer, &error_pointer, &global_hooks));
TEST_ASSERT_TRUE(parse_object(item, &parsebuffer, &global_hooks));
assert_is_object(item);
}

View File

@@ -30,8 +30,6 @@
static cJSON item[1];
static const unsigned char *error_pointer = NULL;
static void assert_is_string(cJSON *string_item)
{
TEST_ASSERT_NOT_NULL_MESSAGE(string_item, "Item is NULL.");
@@ -52,7 +50,7 @@ static void assert_parse_string(const char *string, const char *expected)
buffer.length = strlen(string) + sizeof("");
buffer.offset = 0;
TEST_ASSERT_TRUE_MESSAGE(parse_string(item, &buffer, &error_pointer, &global_hooks), "Couldn't parse string.");
TEST_ASSERT_TRUE_MESSAGE(parse_string(item, &buffer, &global_hooks), "Couldn't parse string.");
assert_is_string(item);
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, item->valuestring, "The parsed result isn't as expected.");
global_hooks.deallocate(item->valuestring);
@@ -66,7 +64,7 @@ static void assert_not_parse_string(const char * const string)
buffer.length = strlen(string) + sizeof("");
buffer.offset = 0;
TEST_ASSERT_FALSE_MESSAGE(parse_string(item, &buffer, &error_pointer, &global_hooks), "Malformed string should not be accepted.");
TEST_ASSERT_FALSE_MESSAGE(parse_string(item, &buffer, &global_hooks), "Malformed string should not be accepted.");
assert_is_invalid(item);
}

View File

@@ -29,7 +29,6 @@
#include "common.h"
static cJSON item[1];
const unsigned char *error_pointer = NULL;
static void assert_is_value(cJSON *value_item, int type)
{
@@ -48,7 +47,7 @@ static void assert_parse_value(const char *string, int type)
buffer.content = (const unsigned char*) string;
buffer.length = strlen(string) + sizeof("");
buffer.offset = 0;
TEST_ASSERT_TRUE(parse_value(item, &buffer, &error_pointer, &global_hooks));
TEST_ASSERT_TRUE(parse_value(item, &buffer, &global_hooks));
assert_is_value(item, type);
}

View File

@@ -29,7 +29,6 @@ static void assert_print_array(const char * const expected, const char * const i
unsigned char printed_unformatted[1024];
unsigned char printed_formatted[1024];
const unsigned char *error_pointer;
cJSON item[1];
printbuffer formatted_buffer;
@@ -53,7 +52,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_TRUE_MESSAGE(parse_array(item, &parsebuffer, &error_pointer, &global_hooks), "Failed to parse array.");
TEST_ASSERT_TRUE_MESSAGE(parse_array(item, &parsebuffer, &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.");

View File

@@ -29,7 +29,6 @@ static void assert_print_object(const char * const expected, const char * const
unsigned char printed_unformatted[1024];
unsigned char printed_formatted[1024];
const unsigned char *error_pointer;
cJSON item[1];
printbuffer formatted_buffer;
@@ -54,7 +53,7 @@ static void assert_print_object(const char * const expected, const char * const
unformatted_buffer.noalloc = true;
memset(item, 0, sizeof(item));
TEST_ASSERT_TRUE_MESSAGE(parse_object(item, &parsebuffer, &error_pointer, &global_hooks), "Failed to parse object.");
TEST_ASSERT_TRUE_MESSAGE(parse_object(item, &parsebuffer, &global_hooks), "Failed to parse object.");
TEST_ASSERT_TRUE_MESSAGE(print_object(item, 0, false, &unformatted_buffer, &global_hooks), "Failed to print unformatted string.");
TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted object is not correct.");

View File

@@ -31,7 +31,6 @@
static void assert_print_value(const char *input)
{
unsigned char printed[1024];
const unsigned char *error_pointer = NULL;
cJSON item[1];
printbuffer buffer;
parse_buffer parsebuffer;
@@ -46,7 +45,7 @@ static void assert_print_value(const char *input)
memset(item, 0, sizeof(item));
TEST_ASSERT_TRUE_MESSAGE(parse_value(item, &parsebuffer, &error_pointer, &global_hooks), "Failed to parse value.");
TEST_ASSERT_TRUE_MESSAGE(parse_value(item, &parsebuffer, &global_hooks), "Failed to parse value.");
TEST_ASSERT_TRUE_MESSAGE(print_value(item, 0, false, &buffer, &global_hooks), "Failed to print value.");
TEST_ASSERT_EQUAL_STRING_MESSAGE(input, buffer.buffer, "Printed value is not as expected.");