| 25 | #include "common.h" |
| 26 | |
| 27 | static void assert_print_object(const char * const expected, const char * const input) |
| 28 | { |
| 29 | unsigned char printed_unformatted[1024]; |
| 30 | unsigned char printed_formatted[1024]; |
| 31 | |
| 32 | cJSON item[1]; |
| 33 | |
| 34 | printbuffer formatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; |
| 35 | printbuffer unformatted_buffer = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; |
| 36 | parse_buffer parsebuffer = { 0, 0, 0, 0, { 0, 0, 0 } }; |
| 37 | |
| 38 | /* buffer for parsing */ |
| 39 | parsebuffer.content = (const unsigned char*)input; |
| 40 | parsebuffer.length = strlen(input) + sizeof(""); |
| 41 | parsebuffer.hooks = global_hooks; |
| 42 | |
| 43 | /* buffer for formatted printing */ |
| 44 | formatted_buffer.buffer = printed_formatted; |
| 45 | formatted_buffer.length = sizeof(printed_formatted); |
| 46 | formatted_buffer.offset = 0; |
| 47 | formatted_buffer.noalloc = true; |
| 48 | formatted_buffer.hooks = global_hooks; |
| 49 | |
| 50 | /* buffer for unformatted printing */ |
| 51 | unformatted_buffer.buffer = printed_unformatted; |
| 52 | unformatted_buffer.length = sizeof(printed_unformatted); |
| 53 | unformatted_buffer.offset = 0; |
| 54 | unformatted_buffer.noalloc = true; |
| 55 | unformatted_buffer.hooks = global_hooks; |
| 56 | |
| 57 | memset(item, 0, sizeof(item)); |
| 58 | TEST_ASSERT_TRUE_MESSAGE(parse_object(item, &parsebuffer), "Failed to parse object."); |
| 59 | |
| 60 | unformatted_buffer.format = false; |
| 61 | TEST_ASSERT_TRUE_MESSAGE(print_object(item, &unformatted_buffer), "Failed to print unformatted string."); |
| 62 | TEST_ASSERT_EQUAL_STRING_MESSAGE(input, printed_unformatted, "Unformatted object is not correct."); |
| 63 | |
| 64 | formatted_buffer.format = true; |
| 65 | TEST_ASSERT_TRUE_MESSAGE(print_object(item, &formatted_buffer), "Failed to print formatted string."); |
| 66 | TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, printed_formatted, "Formatted object is not correct."); |
| 67 | |
| 68 | reset(item); |
| 69 | } |
| 70 | |
| 71 | static void print_object_should_print_empty_objects(void) |
| 72 | { |
no test coverage detected
searching dependent graphs…