1
0
mirror of https://github.com/falk-werner/webfuse synced 2025-06-13 12:54:15 +00:00

added test of json writer

This commit is contained in:
Falk Werner 2020-07-16 17:08:44 +02:00
parent fa5f272e53
commit b0bc23410f
2 changed files with 8 additions and 7 deletions

View File

@ -263,12 +263,12 @@ wf_impl_json_write_bytes(
size_t length) size_t length)
{ {
size_t encoded_length = wf_impl_base64_encoded_size(length); size_t encoded_length = wf_impl_base64_encoded_size(length);
wf_impl_json_reserve(writer, length + WF_JSON_WRITER_ADDITIONAL_STRING_SIZE); wf_impl_json_reserve(writer, encoded_length + WF_JSON_WRITER_ADDITIONAL_STRING_SIZE);
wf_impl_json_begin_value(writer); wf_impl_json_begin_value(writer);
wf_impl_json_write_raw_char(writer, '\"'); wf_impl_json_write_raw_char(writer, '\"');
wf_impl_base64_encode((uint8_t const *) data, length, &(writer->data[writer->offset]), encoded_length); wf_impl_base64_encode((uint8_t const *) data, length, &(writer->data[writer->offset]), encoded_length);
writer->offset = encoded_length; writer->offset += encoded_length;
wf_impl_json_write_raw_char(writer, '\"'); wf_impl_json_write_raw_char(writer, '\"');
wf_impl_json_end_value(writer); wf_impl_json_end_value(writer);

View File

@ -200,7 +200,7 @@ TEST(json_writer, write_bytes)
writer writer; writer writer;
wf_impl_json_write_bytes(writer, "\0\0", 2); wf_impl_json_write_bytes(writer, "\0\0", 2);
ASSERT_EQ("\"AAA\"", writer.take()); ASSERT_EQ("\"AAA=\"", writer.take());
} }
TEST(json_writer, reset) TEST(json_writer, reset)
@ -238,10 +238,10 @@ TEST(json_writer, write_object_string_nocheck)
{ {
writer writer; writer writer;
wf_impl_json_write_object_begin(writer); wf_impl_json_write_object_begin(writer);
wf_impl_json_write_object_string(writer, "result", "Hello,\tWorld!"); wf_impl_json_write_object_string_nocheck(writer, "result", "Hello,\tWorld!");
wf_impl_json_write_object_end(writer); wf_impl_json_write_object_end(writer);
ASSERT_EQ("{\"result\": \"Hello,\tWorld!\"}", writer.take()); ASSERT_EQ("{\"result\":\"Hello,\tWorld!\"}", writer.take());
} }
TEST(json_writer, write_object_bytes) TEST(json_writer, write_object_bytes)
@ -251,7 +251,8 @@ TEST(json_writer, write_object_bytes)
wf_impl_json_write_object_bytes(writer, "result", "\0\0", 2); wf_impl_json_write_object_bytes(writer, "result", "\0\0", 2);
wf_impl_json_write_object_end(writer); wf_impl_json_write_object_end(writer);
ASSERT_EQ("{\"result\": \"AAA\"}", writer.take());
ASSERT_EQ("{\"result\":\"AAA=\"}", writer.take());
} }
TEST(json_writer, realloc_buffer) TEST(json_writer, realloc_buffer)
@ -259,7 +260,7 @@ TEST(json_writer, realloc_buffer)
writer writer(1); writer writer(1);
wf_impl_json_write_string(writer, "very large contents"); wf_impl_json_write_string(writer, "very large contents");
ASSERT_EQ("very large contents", writer.take()); ASSERT_EQ("\"very large contents\"", writer.take());
} }
TEST(json_writer, unexpected_end) TEST(json_writer, unexpected_end)