aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2025-02-25 08:07:23 -0500
committerDavid Robillard <d@drobilla.net>2025-02-25 18:18:28 -0500
commiteb7e973b25a8e5556b2f1175d8375e5e513ba664 (patch)
tree470978187f0639be20037b5a728c199675a15b0b /test/test_writer.c
parent9766872b2ef28126a46f14f4c3d1070bc3116368 (diff)
downloadserd-eb7e973b25a8e5556b2f1175d8375e5e513ba664.tar.gz
serd-eb7e973b25a8e5556b2f1175d8375e5e513ba664.tar.bz2
serd-eb7e973b25a8e5556b2f1175d8375e5e513ba664.zip
Isolate standalone writer tests
Move these to test_writer so that test_reader_writer is focused on the file-based case where the writer output is later read.
Diffstat (limited to 'test/test_writer.c')
-rw-r--r--test/test_writer.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/test/test_writer.c b/test/test_writer.c
index 28c8e117..27ce6138 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -1,4 +1,4 @@
-// Copyright 2011-2023 David Robillard <d@drobilla.net>
+// Copyright 2011-2025 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#undef NDEBUG
@@ -272,6 +272,57 @@ test_write_error(void)
serd_env_free(env);
}
+static void
+test_chunk_sink(void)
+{
+ SerdEnv* const env = serd_env_new(NULL);
+ assert(env);
+
+ SerdChunk chunk = {NULL, 0};
+ SerdWriter* const writer = serd_writer_new(
+ SERD_TURTLE, (SerdStyle)0, env, NULL, serd_chunk_sink, &chunk);
+ assert(writer);
+
+ const SerdNode base =
+ serd_node_from_string(SERD_URI, USTR("http://example.org/base"));
+ assert(!serd_writer_set_base_uri(writer, &base));
+
+ serd_writer_free(writer);
+ uint8_t* out = serd_chunk_sink_finish(&chunk);
+
+ assert(!strcmp((const char*)out, "@base <http://example.org/base> .\n"));
+ serd_free(out);
+ serd_env_free(env);
+}
+
+static void
+test_write_nothing_node(void)
+{
+ SerdEnv* const env = serd_env_new(NULL);
+ assert(env);
+
+ SerdChunk chunk = {NULL, 0};
+ SerdWriter* const writer = serd_writer_new(
+ SERD_TURTLE, (SerdStyle)0, env, NULL, serd_chunk_sink, &chunk);
+ assert(writer);
+
+ SerdNode s = serd_node_from_string(SERD_URI, USTR(""));
+ SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/pred"));
+ SerdNode o = serd_node_from_string(SERD_NOTHING, USTR(""));
+ assert(!serd_writer_write_statement(writer, 0, NULL, &s, &p, &o, NULL, NULL));
+
+ assert(
+ !strncmp((const char*)chunk.buf, "<>\n\t<http://example.org/pred> ", 30));
+
+ serd_writer_free(writer);
+
+ uint8_t* const out = serd_chunk_sink_finish(&chunk);
+ assert(!strcmp((const char*)out, "<>\n\t<http://example.org/pred> .\n"));
+ serd_free(out);
+
+ serd_env_free(env);
+}
+
int
main(void)
{
@@ -281,6 +332,8 @@ main(void)
test_write_bad_anon_stack();
test_strict_write();
test_write_error();
+ test_chunk_sink();
+ test_write_nothing_node();
return 0;
}