aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_reader_writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-13 19:31:26 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit828c1018f38bab9a930cecce64646366d051d39b (patch)
tree38a60777520efb17017ed62fe3b299ba94aaccf2 /test/test_reader_writer.c
parenta083c64f506175029280ff76defa0ad7d7ae2ea0 (diff)
downloadserd-828c1018f38bab9a930cecce64646366d051d39b.tar.gz
serd-828c1018f38bab9a930cecce64646366d051d39b.tar.bz2
serd-828c1018f38bab9a930cecce64646366d051d39b.zip
Simplify output stream API
Diffstat (limited to 'test/test_reader_writer.c')
-rw-r--r--test/test_reader_writer.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index 1c4a415b..aa820fa6 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -9,10 +9,10 @@
#include "serd/input_stream.h"
#include "serd/memory.h"
#include "serd/node.h"
+#include "serd/output_stream.h"
#include "serd/reader.h"
#include "serd/sink.h"
#include "serd/status.h"
-#include "serd/stream.h"
#include "serd/string_view.h"
#include "serd/syntax.h"
#include "serd/world.h"
@@ -109,9 +109,12 @@ test_write_errors(void)
ctx.n_written = 0;
ctx.error_offset = o;
- SerdEnv* const env = serd_env_new(serd_empty_string());
+ SerdEnv* const env = serd_env_new(serd_empty_string());
+ SerdOutputStream out =
+ serd_open_output_stream(faulty_sink, NULL, NULL, &ctx);
+
SerdWriter* const writer =
- serd_writer_new(world, syntax, 0U, env, faulty_sink, &ctx);
+ serd_writer_new(world, syntax, 0U, env, &out, 1U);
const SerdSink* const sink = serd_writer_sink(writer);
SerdReader* const reader = serd_reader_new(world, SERD_TRIG, 0U, sink);
@@ -137,14 +140,14 @@ test_write_errors(void)
static void
test_writer(const char* const path)
{
- FILE* fd = fopen(path, "wb");
- SerdEnv* env = serd_env_new(serd_empty_string());
- assert(fd);
-
SerdWorld* world = serd_world_new();
+ SerdEnv* env = serd_env_new(serd_empty_string());
+
+ SerdOutputStream output = serd_open_output_file(path);
+
+ SerdWriter* writer =
+ serd_writer_new(world, SERD_TURTLE, SERD_WRITE_LAX, env, &output, 1U);
- SerdWriter* writer = serd_writer_new(
- world, SERD_TURTLE, SERD_WRITE_LAX, env, (SerdWriteFunc)fwrite, fd);
assert(writer);
serd_writer_chop_blank_prefix(writer, "tmp");
@@ -205,6 +208,7 @@ test_writer(const char* const path)
serd_node_free(hello);
serd_writer_free(writer);
+ serd_close_output(&output);
serd_node_free(lit);
serd_node_free(o);
@@ -212,19 +216,20 @@ test_writer(const char* const path)
serd_node_free(l);
// Test buffer sink
- SerdBuffer buffer = {NULL, 0};
- writer =
- serd_writer_new(world, SERD_TURTLE, 0, env, serd_buffer_write, &buffer);
+ SerdBuffer buffer = {NULL, 0};
+ SerdNode* const base = serd_new_uri(serd_string("http://example.org/base"));
- SerdNode* const base = serd_new_uri(serd_string("http://example.org/base"));
+ output = serd_open_output_buffer(&buffer);
+ writer = serd_writer_new(world, SERD_TURTLE, 0, env, &output, 1U);
serd_sink_write_base(serd_writer_sink(writer), base);
serd_node_free(base);
serd_writer_free(writer);
- serd_buffer_close(&buffer);
+ serd_close_output(&output);
char* const out = (char*)buffer.buf;
+ assert(out);
assert(!strcmp(out, "@base <http://example.org/base> .\n"));
serd_free(out);
@@ -233,7 +238,6 @@ test_writer(const char* const path)
serd_env_free(env);
serd_world_free(world);
- fclose(fd);
}
static void