test: add lots of stream tests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
27
io-test/streams.c
Normal file
27
io-test/streams.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <blue/core/stream.h>
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user