aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--test/test_reader_writer.c45
-rw-r--r--test/test_writer.c55
2 files changed, 58 insertions, 42 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index 7302fa39..61874bc7 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -1,4 +1,4 @@
-// Copyright 2011-2024 David Robillard <d@drobilla.net>
+// Copyright 2011-2025 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#undef NDEBUG
@@ -172,7 +172,7 @@ test_writer(const char* const path)
SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/pred"));
SerdNode o = serd_node_from_string(SERD_LITERAL, buf);
- // Write 3 invalid statements (should write nothing)
+ // Attempt to write invalid statements (should write nothing)
const SerdNode* junk[][5] = {{&s, &p, &SERD_NODE_NULL, NULL, NULL},
{&s, &SERD_NODE_NULL, &o, NULL, NULL},
{&SERD_NODE_NULL, &p, &o, NULL, NULL},
@@ -190,9 +190,11 @@ test_writer(const char* const path)
junk[i][4]));
}
+ // Write some valid statements
const SerdNode t = serd_node_from_string(SERD_URI, USTR("urn:Type"));
const SerdNode l = serd_node_from_string(SERD_LITERAL, USTR("en"));
const SerdNode* good[][5] = {{&s, &p, &o, NULL, NULL},
+ {&s, &p, &lit, NULL, NULL},
{&s, &p, &o, &SERD_NODE_NULL, &SERD_NODE_NULL},
{&s, &p, &o, &t, NULL},
{&s, &p, &o, NULL, &l},
@@ -222,46 +224,7 @@ test_writer(const char* const path)
assert(!serd_writer_write_statement(
writer, 0, NULL, &s, &p, &bad_uri, NULL, NULL));
- // Write 1 valid statement
- o = serd_node_from_string(SERD_LITERAL, USTR("hello"));
- assert(!serd_writer_write_statement(writer, 0, NULL, &s, &p, &o, NULL, NULL));
-
- serd_writer_free(writer);
-
- // Test chunk sink
- SerdChunk chunk = {NULL, 0};
- writer = serd_writer_new(
- SERD_TURTLE, (SerdStyle)0, env, NULL, serd_chunk_sink, &chunk);
-
- o = serd_node_from_string(SERD_URI, USTR("http://example.org/base"));
- assert(!serd_writer_set_base_uri(writer, &o));
-
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);
-
- // Test writing empty node
- SerdNode nothing = serd_node_from_string(SERD_NOTHING, USTR(""));
-
- chunk.buf = NULL;
- chunk.len = 0;
- writer = serd_writer_new(
- SERD_TURTLE, (SerdStyle)0, env, NULL, serd_chunk_sink, &chunk);
-
- assert(!serd_writer_write_statement(
- writer, 0, NULL, &s, &p, &nothing, NULL, NULL));
-
- assert(
- !strncmp((const char*)chunk.buf, "<>\n\t<http://example.org/pred> ", 30));
-
- serd_writer_free(writer);
- 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);
assert(!fclose(fd));
}
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;
}