test: update b_stream usage

This commit is contained in:
2025-10-24 12:51:54 +01:00
parent a956e21fc4
commit e499d8631f
12 changed files with 57 additions and 74 deletions

View File

@@ -1,18 +1,19 @@
#include <blue/core/stream.h>
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <stdio.h>
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);
b_stringstream *dest_stream = b_stringstream_create();
b_stream_buffer *buf = b_stream_buffer_create_dynamic(1024);
b_stream_read_all_bytes_s(b_stdin, dest_stream, buf, &nr_read);
printf("done. read %zu bytes total.\n", nr_read);
printf("%s\n", b_string_ptr(str));
printf("%s\n", b_stringstream_ptr(dest_stream));
b_stringstream_unref(dest_stream);
b_stream_buffer_unref(buf);
return 0;
}

View File

@@ -28,10 +28,13 @@ int main(void)
b_string_unref(str);
b_stringstream strv;
b_stringstream_begin_dynamic(&strv);
b_stringstream_add_many(&strv, "Hello", ", world", "!", NULL);
char *s = b_stringstream_end(&strv);
b_stringstream *strv = b_stringstream_create();
b_stream_write_string(strv, "Hello", NULL);
b_stream_write_string(strv, ", world", NULL);
b_stream_write_string(strv, "!", NULL);
char *s = b_stringstream_steal(strv);
b_stringstream_unref(strv);
printf("%s\n", s);
free(s);