aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_writer.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_writer.c')
-rw-r--r--test/test_writer.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/test_writer.c b/test/test_writer.c
index 356dbfcb..d236d7e6 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -84,16 +84,82 @@ test_writer_cleanup(void)
// Finish writing without terminating nodes
assert(!(st = serd_writer_finish(writer)));
+ // Set the base to an empty URI
+ assert(!(st = serd_writer_set_base_uri(writer, NULL)));
+
// Free (which could leak if the writer doesn't clean up the stack properly)
serd_writer_free(writer);
serd_env_free(env);
}
+static void
+test_strict_write(void)
+{
+ const char* const path = "serd_strict_write_test.ttl";
+ FILE* const fd = fopen(path, "wb");
+ assert(fd);
+
+ SerdEnv* const env = serd_env_new(NULL);
+ SerdWriter* const writer = serd_writer_new(
+ SERD_TURTLE, (SerdStyle)SERD_STYLE_STRICT, env, NULL, null_sink, fd);
+
+ assert(writer);
+
+ const uint8_t bad_str[] = {0xFF, 0x90, 'h', 'i', 0};
+
+ SerdNode s = serd_node_from_string(SERD_URI, USTR("http://example.org/s"));
+ SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/p"));
+
+ SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, bad_str);
+ SerdNode bad_uri = serd_node_from_string(SERD_URI, bad_str);
+
+ assert(serd_writer_write_statement(
+ writer, 0, NULL, &s, &p, &bad_lit, NULL, NULL) == SERD_ERR_BAD_TEXT);
+
+ assert(serd_writer_write_statement(
+ writer, 0, NULL, &s, &p, &bad_uri, NULL, NULL) == SERD_ERR_BAD_TEXT);
+
+ serd_writer_free(writer);
+ serd_env_free(env);
+ fclose(fd);
+}
+
+// Produce a write error without setting errno
+static size_t
+error_sink(const void* const buf, const size_t len, void* const stream)
+{
+ (void)buf;
+ (void)len;
+ (void)stream;
+ return 0U;
+}
+
+static void
+test_write_error(void)
+{
+ SerdEnv* const env = serd_env_new(NULL);
+ SerdWriter* writer = NULL;
+ SerdStatus st = SERD_SUCCESS;
+
+ SerdNode u = serd_node_from_string(SERD_URI, USTR("http://example.com/u"));
+
+ writer =
+ serd_writer_new(SERD_TURTLE, (SerdStyle)0, env, NULL, error_sink, NULL);
+ assert(writer);
+ st = serd_writer_write_statement(writer, 0U, NULL, &u, &u, &u, NULL, NULL);
+ assert(st == SERD_ERR_BAD_WRITE);
+ serd_writer_free(writer);
+
+ serd_env_free(env);
+}
+
int
main(void)
{
test_write_long_literal();
test_writer_cleanup();
+ test_strict_write();
+ test_write_error();
return 0;
}