瀏覽代碼

Put format into internal_configuration

Max Bruckner 7 年之前
父節點
當前提交
479909d0a6
共有 13 個文件被更改,包括 51 次插入49 次删除
  1. 24 23
      cJSON.c
  2. 1 1
      cJSON.h
  3. 3 3
      tests/misc_tests.c
  4. 2 2
      tests/parse_array.c
  5. 1 1
      tests/parse_number.c
  6. 2 2
      tests/parse_object.c
  7. 2 2
      tests/parse_string.c
  8. 1 1
      tests/parse_value.c
  9. 5 5
      tests/print_array.c
  10. 1 1
      tests/print_number.c
  11. 5 5
      tests/print_object.c
  12. 1 1
      tests/print_string.c
  13. 3 2
      tests/print_value.c

+ 24 - 23
cJSON.c

@@ -120,6 +120,7 @@ static int case_insensitive_strcmp(const unsigned char *string1, const unsigned
 
 
 typedef struct internal_configuration
 typedef struct internal_configuration
 {
 {
+    cJSON_bool format;
     void *(*allocate)(size_t size);
     void *(*allocate)(size_t size);
     void (*deallocate)(void *pointer);
     void (*deallocate)(void *pointer);
     void *(*reallocate)(void *pointer, size_t size);
     void *(*reallocate)(void *pointer, size_t size);
@@ -145,7 +146,7 @@ static void *internal_realloc(void *pointer, size_t size)
 #define internal_realloc realloc
 #define internal_realloc realloc
 #endif
 #endif
 
 
-static internal_configuration global_configuration = { internal_malloc, internal_free, internal_realloc };
+static internal_configuration global_configuration = { true, internal_malloc, internal_free, internal_realloc };
 
 
 static unsigned char* custom_strdup(const unsigned char* string, const internal_configuration * const configuration)
 static unsigned char* custom_strdup(const unsigned char* string, const internal_configuration * const configuration)
 {
 {
@@ -355,7 +356,6 @@ typedef struct
     size_t offset;
     size_t offset;
     size_t depth; /* current nesting depth (for formatted printing) */
     size_t depth; /* current nesting depth (for formatted printing) */
     cJSON_bool noalloc;
     cJSON_bool noalloc;
-    cJSON_bool format; /* is this print a formatted print */
     internal_configuration configuration;
     internal_configuration configuration;
 } printbuffer;
 } printbuffer;
 
 
@@ -996,7 +996,7 @@ static parse_buffer *skip_utf8_bom(parse_buffer * const buffer)
 /* Parse an object - create a new root, and populate. */
 /* Parse an object - create a new root, and populate. */
 CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
 CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
 {
 {
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     cJSON *item = NULL;
     cJSON *item = NULL;
 
 
     /* reset error position */
     /* reset error position */
@@ -1081,7 +1081,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value)
 
 
 #define cjson_min(a, b) ((a < b) ? a : b)
 #define cjson_min(a, b) ((a < b) ? a : b)
 
 
-static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_configuration * const configuration)
+static unsigned char *print(const cJSON * const item, const internal_configuration * const configuration)
 {
 {
     static const size_t default_buffer_size = 256;
     static const size_t default_buffer_size = 256;
     printbuffer buffer[1];
     printbuffer buffer[1];
@@ -1092,7 +1092,6 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
     /* create buffer */
     /* create buffer */
     buffer->buffer = (unsigned char*) configuration->allocate(default_buffer_size);
     buffer->buffer = (unsigned char*) configuration->allocate(default_buffer_size);
     buffer->length = default_buffer_size;
     buffer->length = default_buffer_size;
-    buffer->format = format;
     buffer->configuration = *configuration;
     buffer->configuration = *configuration;
     if (buffer->buffer == NULL)
     if (buffer->buffer == NULL)
     {
     {
@@ -1150,17 +1149,19 @@ fail:
 /* Render a cJSON item/entity/structure to text. */
 /* Render a cJSON item/entity/structure to text. */
 CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item)
 CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item)
 {
 {
-    return (char*)print(item, true, &global_configuration);
+    return (char*)print(item, &global_configuration);
 }
 }
 
 
 CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item)
 CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item)
 {
 {
-    return (char*)print(item, false, &global_configuration);
+    internal_configuration configuration = global_configuration;
+    configuration.format = false;
+    return (char*)print(item, &configuration);
 }
 }
 
 
-CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt)
+CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool format)
 {
 {
-    printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
+    printbuffer p = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
 
 
     if (prebuffer < 0)
     if (prebuffer < 0)
     {
     {
@@ -1176,8 +1177,8 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON
     p.length = (size_t)prebuffer;
     p.length = (size_t)prebuffer;
     p.offset = 0;
     p.offset = 0;
     p.noalloc = false;
     p.noalloc = false;
-    p.format = fmt;
     p.configuration = global_configuration;
     p.configuration = global_configuration;
+    p.configuration.format = format;
 
 
     if (!print_value(item, &p))
     if (!print_value(item, &p))
     {
     {
@@ -1190,7 +1191,7 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON
 
 
 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format)
 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format)
 {
 {
-    printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
+    printbuffer p = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
 
 
     if ((length < 0) || (buffer == NULL))
     if ((length < 0) || (buffer == NULL))
     {
     {
@@ -1201,8 +1202,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, cons
     p.length = (size_t)length;
     p.length = (size_t)length;
     p.offset = 0;
     p.offset = 0;
     p.noalloc = true;
     p.noalloc = true;
-    p.format = format;
     p.configuration = global_configuration;
     p.configuration = global_configuration;
+    p.configuration.format = format;
 
 
     return print_value(item, &p);
     return print_value(item, &p);
 }
 }
@@ -1491,14 +1492,14 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp
         update_offset(output_buffer);
         update_offset(output_buffer);
         if (current_element->next)
         if (current_element->next)
         {
         {
-            length = (size_t) (output_buffer->format ? 2 : 1);
+            length = (size_t) (output_buffer->configuration.format ? 2 : 1);
             output_pointer = ensure(output_buffer, length + 1);
             output_pointer = ensure(output_buffer, length + 1);
             if (output_pointer == NULL)
             if (output_pointer == NULL)
             {
             {
                 return false;
                 return false;
             }
             }
             *output_pointer++ = ',';
             *output_pointer++ = ',';
-            if(output_buffer->format)
+            if(output_buffer->configuration.format)
             {
             {
                 *output_pointer++ = ' ';
                 *output_pointer++ = ' ';
             }
             }
@@ -1642,7 +1643,7 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
     }
     }
 
 
     /* Compose the output: */
     /* Compose the output: */
-    length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */
+    length = (size_t) (output_buffer->configuration.format ? 2 : 1); /* fmt: {\n */
     output_pointer = ensure(output_buffer, length + 1);
     output_pointer = ensure(output_buffer, length + 1);
     if (output_pointer == NULL)
     if (output_pointer == NULL)
     {
     {
@@ -1651,7 +1652,7 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
 
 
     *output_pointer++ = '{';
     *output_pointer++ = '{';
     output_buffer->depth++;
     output_buffer->depth++;
-    if (output_buffer->format)
+    if (output_buffer->configuration.format)
     {
     {
         *output_pointer++ = '\n';
         *output_pointer++ = '\n';
     }
     }
@@ -1659,7 +1660,7 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
 
 
     while (current_item)
     while (current_item)
     {
     {
-        if (output_buffer->format)
+        if (output_buffer->configuration.format)
         {
         {
             size_t i;
             size_t i;
             output_pointer = ensure(output_buffer, output_buffer->depth);
             output_pointer = ensure(output_buffer, output_buffer->depth);
@@ -1681,14 +1682,14 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
         }
         }
         update_offset(output_buffer);
         update_offset(output_buffer);
 
 
-        length = (size_t) (output_buffer->format ? 2 : 1);
+        length = (size_t) (output_buffer->configuration.format ? 2 : 1);
         output_pointer = ensure(output_buffer, length);
         output_pointer = ensure(output_buffer, length);
         if (output_pointer == NULL)
         if (output_pointer == NULL)
         {
         {
             return false;
             return false;
         }
         }
         *output_pointer++ = ':';
         *output_pointer++ = ':';
-        if (output_buffer->format)
+        if (output_buffer->configuration.format)
         {
         {
             *output_pointer++ = '\t';
             *output_pointer++ = '\t';
         }
         }
@@ -1702,7 +1703,7 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
         update_offset(output_buffer);
         update_offset(output_buffer);
 
 
         /* print comma if not last */
         /* print comma if not last */
-        length = (size_t) ((output_buffer->format ? 1 : 0) + (current_item->next ? 1 : 0));
+        length = (size_t) ((output_buffer->configuration.format ? 1 : 0) + (current_item->next ? 1 : 0));
         output_pointer = ensure(output_buffer, length + 1);
         output_pointer = ensure(output_buffer, length + 1);
         if (output_pointer == NULL)
         if (output_pointer == NULL)
         {
         {
@@ -1713,7 +1714,7 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
             *output_pointer++ = ',';
             *output_pointer++ = ',';
         }
         }
 
 
-        if (output_buffer->format)
+        if (output_buffer->configuration.format)
         {
         {
             *output_pointer++ = '\n';
             *output_pointer++ = '\n';
         }
         }
@@ -1723,12 +1724,12 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
         current_item = current_item->next;
         current_item = current_item->next;
     }
     }
 
 
-    output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2);
+    output_pointer = ensure(output_buffer, output_buffer->configuration.format ? (output_buffer->depth + 1) : 2);
     if (output_pointer == NULL)
     if (output_pointer == NULL)
     {
     {
         return false;
         return false;
     }
     }
-    if (output_buffer->format)
+    if (output_buffer->configuration.format)
     {
     {
         size_t i;
         size_t i;
         for (i = 0; i < (output_buffer->depth - 1); i++)
         for (i = 0; i < (output_buffer->depth - 1); i++)

+ 1 - 1
cJSON.h

@@ -147,7 +147,7 @@ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
 /* Render a cJSON entity to text for transfer/storage without any formatting. */
 /* Render a cJSON entity to text for transfer/storage without any formatting. */
 CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
 CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
 /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
 /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
-CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
+CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool format);
 /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
 /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
 /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
 /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
 CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);

+ 3 - 3
tests/misc_tests.c

@@ -419,7 +419,7 @@ static void *failing_realloc(void *pointer, size_t size)
 
 
 static void ensure_should_fail_on_failed_realloc(void)
 static void ensure_should_fail_on_failed_realloc(void)
 {
 {
-    printbuffer buffer = {NULL, 10, 0, 0, false, false, {&malloc, &free, &failing_realloc}};
+    printbuffer buffer = {NULL, 10, 0, 0, false, {false, &malloc, &free, &failing_realloc}};
     buffer.buffer = (unsigned char*)malloc(100);
     buffer.buffer = (unsigned char*)malloc(100);
     TEST_ASSERT_NOT_NULL(buffer.buffer);
     TEST_ASSERT_NOT_NULL(buffer.buffer);
 
 
@@ -429,7 +429,7 @@ static void ensure_should_fail_on_failed_realloc(void)
 static void skip_utf8_bom_should_skip_bom(void)
 static void skip_utf8_bom_should_skip_bom(void)
 {
 {
     const unsigned char string[] = "\xEF\xBB\xBF{}";
     const unsigned char string[] = "\xEF\xBB\xBF{}";
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = string;
     buffer.content = string;
     buffer.length = sizeof(string);
     buffer.length = sizeof(string);
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;
@@ -441,7 +441,7 @@ static void skip_utf8_bom_should_skip_bom(void)
 static void skip_utf8_bom_should_not_skip_bom_if_not_at_beginning(void)
 static void skip_utf8_bom_should_not_skip_bom_if_not_at_beginning(void)
 {
 {
     const unsigned char string[] = " \xEF\xBB\xBF{}";
     const unsigned char string[] = " \xEF\xBB\xBF{}";
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = string;
     buffer.content = string;
     buffer.length = sizeof(string);
     buffer.length = sizeof(string);
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;

+ 2 - 2
tests/parse_array.c

@@ -44,7 +44,7 @@ static void assert_is_array(cJSON *array_item)
 
 
 static void assert_not_array(const char *json)
 static void assert_not_array(const char *json)
 {
 {
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = (const unsigned char*)json;
     buffer.content = (const unsigned char*)json;
     buffer.length = strlen(json) + sizeof("");
     buffer.length = strlen(json) + sizeof("");
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;
@@ -55,7 +55,7 @@ static void assert_not_array(const char *json)
 
 
 static void assert_parse_array(const char *json)
 static void assert_parse_array(const char *json)
 {
 {
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = (const unsigned char*)json;
     buffer.content = (const unsigned char*)json;
     buffer.length = strlen(json) + sizeof("");
     buffer.length = strlen(json) + sizeof("");
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;

+ 1 - 1
tests/parse_number.c

@@ -45,7 +45,7 @@ static void assert_is_number(cJSON *number_item)
 
 
 static void assert_parse_number(const char *string, int integer, double real)
 static void assert_parse_number(const char *string, int integer, double real)
 {
 {
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = (const unsigned char*)string;
     buffer.content = (const unsigned char*)string;
     buffer.length = strlen(string) + sizeof("");
     buffer.length = strlen(string) + sizeof("");
 
 

+ 2 - 2
tests/parse_object.c

@@ -52,7 +52,7 @@ static void assert_is_child(cJSON *child_item, const char *name, int type)
 
 
 static void assert_not_object(const char *json)
 static void assert_not_object(const char *json)
 {
 {
-    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     parsebuffer.content = (const unsigned char*)json;
     parsebuffer.content = (const unsigned char*)json;
     parsebuffer.length = strlen(json) + sizeof("");
     parsebuffer.length = strlen(json) + sizeof("");
     parsebuffer.configuration = global_configuration;
     parsebuffer.configuration = global_configuration;
@@ -64,7 +64,7 @@ static void assert_not_object(const char *json)
 
 
 static void assert_parse_object(const char *json)
 static void assert_parse_object(const char *json)
 {
 {
-    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     parsebuffer.content = (const unsigned char*)json;
     parsebuffer.content = (const unsigned char*)json;
     parsebuffer.length = strlen(json) + sizeof("");
     parsebuffer.length = strlen(json) + sizeof("");
     parsebuffer.configuration = global_configuration;
     parsebuffer.configuration = global_configuration;

+ 2 - 2
tests/parse_string.c

@@ -45,7 +45,7 @@ static void assert_is_string(cJSON *string_item)
 
 
 static void assert_parse_string(const char *string, const char *expected)
 static void assert_parse_string(const char *string, const char *expected)
 {
 {
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = (const unsigned char*)string;
     buffer.content = (const unsigned char*)string;
     buffer.length = strlen(string) + sizeof("");
     buffer.length = strlen(string) + sizeof("");
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;
@@ -59,7 +59,7 @@ static void assert_parse_string(const char *string, const char *expected)
 
 
 static void assert_not_parse_string(const char * const string)
 static void assert_not_parse_string(const char * const string)
 {
 {
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = (const unsigned char*)string;
     buffer.content = (const unsigned char*)string;
     buffer.length = strlen(string) + sizeof("");
     buffer.length = strlen(string) + sizeof("");
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;

+ 1 - 1
tests/parse_value.c

@@ -43,7 +43,7 @@ static void assert_is_value(cJSON *value_item, int type)
 
 
 static void assert_parse_value(const char *string, int type)
 static void assert_parse_value(const char *string, int type)
 {
 {
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.content = (const unsigned char*) string;
     buffer.content = (const unsigned char*) string;
     buffer.length = strlen(string) + sizeof("");
     buffer.length = strlen(string) + sizeof("");
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;

+ 5 - 5
tests/print_array.c

@@ -31,10 +31,10 @@ static void assert_print_array(const char * const expected, const char * const i
 
 
     cJSON item[1];
     cJSON item[1];
 
 
-    printbuffer formatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
-    printbuffer unformatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
+    printbuffer formatted_buffer = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
+    printbuffer unformatted_buffer = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
 
 
-    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     parsebuffer.content = (const unsigned char*)input;
     parsebuffer.content = (const unsigned char*)input;
     parsebuffer.length = strlen(input) + sizeof("");
     parsebuffer.length = strlen(input) + sizeof("");
     parsebuffer.configuration = global_configuration;
     parsebuffer.configuration = global_configuration;
@@ -56,11 +56,11 @@ static void assert_print_array(const char * const expected, const char * const i
     memset(item, 0, sizeof(item));
     memset(item, 0, sizeof(item));
     TEST_ASSERT_TRUE_MESSAGE(parse_array(item, &parsebuffer), "Failed to parse array.");
     TEST_ASSERT_TRUE_MESSAGE(parse_array(item, &parsebuffer), "Failed to parse array.");
 
 
-    unformatted_buffer.format = false;
+    unformatted_buffer.configuration.format = false;
     TEST_ASSERT_TRUE_MESSAGE(print_array(item, &unformatted_buffer), "Failed to print unformatted string.");
     TEST_ASSERT_TRUE_MESSAGE(print_array(item, &unformatted_buffer), "Failed to print unformatted string.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted array is not correct.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted array is not correct.");
 
 
-    formatted_buffer.format = true;
+    formatted_buffer.configuration.format = true;
     TEST_ASSERT_TRUE_MESSAGE(print_array(item, &formatted_buffer), "Failed to print formatted string.");
     TEST_ASSERT_TRUE_MESSAGE(print_array(item, &formatted_buffer), "Failed to print formatted string.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed_formatted, "Formatted array is not correct.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed_formatted, "Formatted array is not correct.");
 
 

+ 1 - 1
tests/print_number.c

@@ -28,7 +28,7 @@ static void assert_print_number(const char *expected, double input)
 {
 {
     unsigned char printed[1024];
     unsigned char printed[1024];
     cJSON item[1];
     cJSON item[1];
-    printbuffer buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
+    printbuffer buffer = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.buffer = printed;
     buffer.buffer = printed;
     buffer.length = sizeof(printed);
     buffer.length = sizeof(printed);
     buffer.offset = 0;
     buffer.offset = 0;

+ 5 - 5
tests/print_object.c

@@ -31,9 +31,9 @@ static void assert_print_object(const char * const expected, const char * const
 
 
     cJSON item[1];
     cJSON item[1];
 
 
-    printbuffer formatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
-    printbuffer unformatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
-    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    printbuffer formatted_buffer = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
+    printbuffer unformatted_buffer = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
+    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
 
 
     /* buffer for parsing */
     /* buffer for parsing */
     parsebuffer.content = (const unsigned char*)input;
     parsebuffer.content = (const unsigned char*)input;
@@ -57,11 +57,11 @@ static void assert_print_object(const char * const expected, const char * const
     memset(item, 0, sizeof(item));
     memset(item, 0, sizeof(item));
     TEST_ASSERT_TRUE_MESSAGE(parse_object(item, &parsebuffer), "Failed to parse object.");
     TEST_ASSERT_TRUE_MESSAGE(parse_object(item, &parsebuffer), "Failed to parse object.");
 
 
-    unformatted_buffer.format = false;
+    unformatted_buffer.configuration.format = false;
     TEST_ASSERT_TRUE_MESSAGE(print_object(item, &unformatted_buffer), "Failed to print unformatted string.");
     TEST_ASSERT_TRUE_MESSAGE(print_object(item, &unformatted_buffer), "Failed to print unformatted string.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted object is not correct.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted object is not correct.");
 
 
-    formatted_buffer.format = true;
+    formatted_buffer.configuration.format = true;
     TEST_ASSERT_TRUE_MESSAGE(print_object(item, &formatted_buffer), "Failed to print formatted string.");
     TEST_ASSERT_TRUE_MESSAGE(print_object(item, &formatted_buffer), "Failed to print formatted string.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed_formatted, "Formatted ojbect is not correct.");
     TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed_formatted, "Formatted ojbect is not correct.");
 
 

+ 1 - 1
tests/print_string.c

@@ -27,7 +27,7 @@
 static void assert_print_string(const char *expected, const char *input)
 static void assert_print_string(const char *expected, const char *input)
 {
 {
     unsigned char printed[1024];
     unsigned char printed[1024];
-    printbuffer buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
+    printbuffer buffer = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.buffer = printed;
     buffer.buffer = printed;
     buffer.length = sizeof(printed);
     buffer.length = sizeof(printed);
     buffer.offset = 0;
     buffer.offset = 0;

+ 3 - 2
tests/print_value.c

@@ -32,13 +32,14 @@ static void assert_print_value(const char *input)
 {
 {
     unsigned char printed[1024];
     unsigned char printed[1024];
     cJSON item[1];
     cJSON item[1];
-    printbuffer buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
-    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } };
+    printbuffer buffer = { 0, 0, 0, 0, 0, { 0, 0, 0, 0 } };
+    parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0, 0 } };
     buffer.buffer = printed;
     buffer.buffer = printed;
     buffer.length = sizeof(printed);
     buffer.length = sizeof(printed);
     buffer.offset = 0;
     buffer.offset = 0;
     buffer.noalloc = true;
     buffer.noalloc = true;
     buffer.configuration = global_configuration;
     buffer.configuration = global_configuration;
+    buffer.configuration.format = false;
 
 
     parsebuffer.content = (const unsigned char*)input;
     parsebuffer.content = (const unsigned char*)input;
     parsebuffer.length = strlen(input) + sizeof("");
     parsebuffer.length = strlen(input) + sizeof("");