From 86d5b9d31d3d8215af24171ccd86c479c439d053 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 27 Jun 2025 21:54:10 +0100 Subject: [PATCH] test: add lots of stream tests --- core-test/streams.c | 10 ++++++++++ io-test/io-units.c | 4 ++-- io-test/streams.c | 27 +++++++++++++++++++++++++++ object-test/streams.c | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 core-test/streams.c create mode 100644 io-test/streams.c create mode 100644 object-test/streams.c diff --git a/core-test/streams.c b/core-test/streams.c new file mode 100644 index 0000000..3e236b5 --- /dev/null +++ b/core-test/streams.c @@ -0,0 +1,10 @@ +#include +#include + +int main(void) +{ + b_stream_read_line_s(b_stdin, b_stdout); + b_stream_write_char(b_stdout, '\n'); + + return 0; +} diff --git a/io-test/io-units.c b/io-test/io-units.c index 0d172e5..b264ab5 100644 --- a/io-test/io-units.c +++ b/io-test/io-units.c @@ -11,7 +11,7 @@ void test_path_1(CuTest *tc) b_stringstream str; b_stringstream_begin(&str, buf, sizeof buf); - b_to_string(B_OBJECT(path), &str); + b_to_string(B_OBJECT(path), (b_stream *)&str); printf("%s\n", buf); @@ -23,7 +23,7 @@ void test_path_1(CuTest *tc) b_path *path4 = b_path_join(paths, sizeof paths / sizeof paths[0]); b_stringstream_begin(&str, buf, sizeof buf); - b_to_string(B_OBJECT(path4), &str); + b_to_string(B_OBJECT(path4), (b_stream *)&str); printf("%s\n", buf); } diff --git a/io-test/streams.c b/io-test/streams.c new file mode 100644 index 0000000..ab904b5 --- /dev/null +++ b/io-test/streams.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +int main(int argc, const char **argv) +{ + b_file *dest; + b_path *path = b_path_create_from_cstr("data.txt"); + b_status status = b_file_open( + NULL, path, B_FILE_WRITE_ONLY | B_FILE_CREATE, &dest); + if (!B_OK(status)) { + fprintf(stderr, "cannot open file (%s)\n", + b_status_to_string(status)); + return -1; + } + + size_t nr_read = 0; + b_stream *dest_stream; + b_stream_pipeline *pipeline; + status = b_file_open_stream(dest, &dest_stream); + b_stream_pipeline_create(1024, &pipeline); + b_stream_read_all_bytes_s(b_stdin, dest_stream, pipeline, &nr_read); + + printf("done. read %zu bytes total.\n", nr_read); + return 0; +} diff --git a/object-test/streams.c b/object-test/streams.c new file mode 100644 index 0000000..7d6b54a --- /dev/null +++ b/object-test/streams.c @@ -0,0 +1,18 @@ +#include +#include +#include + +int main(int argc, const char **argv) +{ + size_t nr_read = 0; + b_string *str = b_string_create(); + b_stream *dest_stream; + b_stream_pipeline *pipeline; + b_status status = b_string_open_stream(str, &dest_stream); + b_stream_pipeline_create(1024, &pipeline); + b_stream_read_all_bytes_s(b_stdin, dest_stream, pipeline, &nr_read); + + printf("done. read %zu bytes total.\n", nr_read); + printf("%s\n", b_string_ptr(str)); + return 0; +}