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.c75
1 files changed, 44 insertions, 31 deletions
diff --git a/test/test_writer.c b/test/test_writer.c
index e31119bf..df8ba520 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -27,12 +27,12 @@
static void
test_write_bad_event(void)
{
- SerdWorld* world = serd_world_new();
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
- SerdBuffer buffer = {NULL, 0};
- SerdWriter* writer =
- serd_writer_new(world, SERD_TURTLE, 0u, env, serd_buffer_sink, &buffer);
+ SerdWorld* world = serd_world_new();
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdBuffer buffer = {NULL, 0};
+ SerdByteSink* byte_sink = serd_byte_sink_new_buffer(&buffer);
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink);
assert(writer);
const SerdEvent event = {(SerdEventType)42};
@@ -45,6 +45,7 @@ test_write_bad_event(void)
serd_free(out);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
serd_world_free(world);
}
@@ -52,13 +53,13 @@ test_write_bad_event(void)
static void
test_write_bad_prefix(void)
{
- SerdWorld* world = serd_world_new();
- SerdNodes* nodes = serd_world_nodes(world);
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
- SerdBuffer buffer = {NULL, 0};
- SerdWriter* writer =
- serd_writer_new(world, SERD_TURTLE, 0u, env, serd_buffer_sink, &buffer);
+ SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdBuffer buffer = {NULL, 0};
+ SerdByteSink* byte_sink = serd_byte_sink_new_buffer(&buffer);
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink);
assert(writer);
const SerdNode* name = serd_nodes_string(nodes, SERD_STRING("eg"));
@@ -73,6 +74,7 @@ test_write_bad_prefix(void)
serd_free(out);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
serd_world_free(world);
}
@@ -80,13 +82,13 @@ test_write_bad_prefix(void)
static void
test_write_long_literal(void)
{
- SerdWorld* world = serd_world_new();
- SerdNodes* nodes = serd_world_nodes(world);
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
- SerdBuffer buffer = {NULL, 0};
- SerdWriter* writer =
- serd_writer_new(world, SERD_TURTLE, 0u, env, serd_buffer_sink, &buffer);
+ SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdBuffer buffer = {NULL, 0};
+ SerdByteSink* byte_sink = serd_byte_sink_new_buffer(&buffer);
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink);
assert(writer);
const SerdNode* s =
@@ -99,6 +101,7 @@ test_write_long_literal(void)
assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, o, NULL));
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
char* out = serd_buffer_sink_finish(&buffer);
@@ -128,12 +131,12 @@ null_sink(const void* const buf,
static void
test_writer_stack_overflow(void)
{
- SerdWorld* world = serd_world_new();
- SerdNodes* nodes = serd_world_nodes(world);
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdByteSink* byte_sink = serd_byte_sink_new_function(null_sink, NULL, 1u);
- SerdWriter* writer =
- serd_writer_new(world, SERD_TURTLE, 0u, env, null_sink, NULL);
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink);
const SerdSink* sink = serd_writer_sink(writer);
@@ -168,6 +171,7 @@ test_writer_stack_overflow(void)
assert(st == SERD_ERR_OVERFLOW);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
serd_world_free(world);
}
@@ -181,10 +185,12 @@ test_strict_write(void)
FILE* fd = fopen(path, "wb");
assert(fd);
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
- SerdWriter* writer =
- serd_writer_new(world, SERD_TURTLE, 0u, env, (SerdWriteFunc)fwrite, fd);
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+
+ SerdByteSink* byte_sink =
+ serd_byte_sink_new_function((SerdWriteFunc)fwrite, fd, 1);
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, byte_sink);
assert(writer);
const SerdSink* sink = serd_writer_sink(writer);
@@ -204,6 +210,7 @@ test_strict_write(void)
assert(serd_sink_write(sink, 0, s, p, bad_uri, 0) == SERD_ERR_BAD_TEXT);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
fclose(fd);
serd_world_free(world);
@@ -245,18 +252,20 @@ test_write_error(void)
// Test with setting errno
- SerdWriter* writer =
- serd_writer_new(world, SERD_TURTLE, 0u, env, faulty_sink, NULL);
+ SerdByteSink* byte_sink = serd_byte_sink_new_function(faulty_sink, NULL, 1);
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink);
assert(writer);
SerdStatus st = serd_sink_write(serd_writer_sink(writer), 0u, s, p, o, NULL);
assert(st == SERD_ERR_BAD_WRITE);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
// Test without setting errno
- writer = serd_writer_new(world, SERD_TURTLE, 0u, env, faulty_sink, world);
+ byte_sink = serd_byte_sink_new_function(faulty_sink, world, 1);
+ writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink);
assert(writer);
@@ -264,6 +273,7 @@ test_write_error(void)
SERD_ERR_BAD_WRITE);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
serd_world_free(world);
@@ -278,15 +288,17 @@ test_write_empty_syntax(void)
const SerdNode* s =
serd_nodes_uri(nodes, SERD_STRING("http://example.org/s"));
+
const SerdNode* p =
serd_nodes_uri(nodes, SERD_STRING("http://example.org/p"));
const SerdNode* o = serd_nodes_curie(nodes, SERD_STRING("eg:o"));
- SerdBuffer buffer = {NULL, 0};
+ SerdBuffer buffer = {NULL, 0};
+ SerdByteSink* byte_sink = serd_byte_sink_new_buffer(&buffer);
- SerdWriter* writer = serd_writer_new(
- world, SERD_SYNTAX_EMPTY, 0u, env, serd_buffer_sink, &buffer);
+ SerdWriter* writer =
+ serd_writer_new(world, SERD_SYNTAX_EMPTY, 0u, env, byte_sink);
assert(writer);
@@ -298,6 +310,7 @@ test_write_empty_syntax(void)
serd_free(out);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
serd_world_free(world);
}