aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/model_test.c21
-rw-r--r--tests/serd_test.c48
-rw-r--r--tests/terse_write_test.c10
3 files changed, 39 insertions, 40 deletions
diff --git a/tests/model_test.c b/tests/model_test.c
index 694fc119..bf717df0 100644
--- a/tests/model_test.c
+++ b/tests/model_test.c
@@ -723,10 +723,11 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads)
serd_model_add(model, list2, prest, norest, NULL);
serd_model_add(model, norest, pfirst, val2, NULL);
- SerdBuffer buffer = {NULL, 0};
- SerdEnv* env = serd_env_new(NULL);
- SerdWriter* writer = serd_writer_new(
- world, SERD_TURTLE, 0, env, serd_buffer_sink, &buffer);
+ SerdBuffer buffer = {NULL, 0};
+ SerdEnv* env = serd_env_new(NULL);
+ SerdByteSink* byte_sink = serd_byte_sink_new_buffer(&buffer);
+
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, byte_sink);
SerdRange* all = serd_model_all(model);
serd_range_serialise(all, serd_writer_get_sink(writer), 0);
@@ -746,6 +747,7 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads)
free(buffer.buf);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_model_free(model);
serd_env_free(env);
serd_nodes_free(nodes);
@@ -798,9 +800,13 @@ test_write_error_in_list(SerdWorld* world, const unsigned n_quads)
SerdEnv* env = serd_env_new(NULL);
for (size_t max_successes = 0; max_successes < 21; ++max_successes) {
- FailingWriteFuncState state = {0, max_successes};
- SerdWriter* writer = serd_writer_new(
- world, SERD_TURTLE, 0, env, failing_write_func, &state);
+ FailingWriteFuncState state = {0, max_successes};
+
+ SerdByteSink* byte_sink =
+ serd_byte_sink_new_function(failing_write_func, &state, 1);
+
+ SerdWriter* writer =
+ serd_writer_new(world, SERD_TURTLE, 0, env, byte_sink);
const SerdSink* const sink = serd_writer_get_sink(writer);
SerdRange* const all = serd_model_all(model);
@@ -810,6 +816,7 @@ test_write_error_in_list(SerdWorld* world, const unsigned n_quads)
assert(st == SERD_ERR_BAD_WRITE);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
}
serd_env_free(env);
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 82126c0c..a0fbb234 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -175,16 +175,16 @@ test_get_blank(void)
static int
test_strict_write(void)
{
- SerdWorld* world = serd_world_new();
- const char* path = "serd_strict_write_test.ttl";
- FILE* fd = fopen(path, "wb");
- SerdEnv* env = serd_env_new(NULL);
- SerdWriter* writer = serd_writer_new(world,
- SERD_TURTLE,
- 0,
- env,
- (SerdWriteFunc)fwrite,
- fd);
+ SerdWorld* world = serd_world_new();
+ const char* path = "serd_strict_write_test.ttl";
+ FILE* fd = fopen(path, "wb");
+ SerdEnv* env = serd_env_new(NULL);
+
+ 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(fd);
assert(writer);
@@ -202,6 +202,7 @@ test_strict_write(void)
serd_node_free(p);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_env_free(env);
fclose(fd);
serd_world_free(world);
@@ -559,12 +560,12 @@ test_writer(const char* const path)
SerdWorld* world = serd_world_new();
- SerdWriter* writer = serd_writer_new(world,
- SERD_TURTLE,
- SERD_WRITE_LAX,
- env,
- (SerdWriteFunc)fwrite,
- fd);
+ SerdByteSink* byte_sink =
+ serd_byte_sink_new_function((SerdWriteFunc)fwrite, fd, 1);
+
+ SerdWriter* writer =
+ serd_writer_new(world, SERD_TURTLE, SERD_WRITE_LAX, env, byte_sink);
+
assert(writer);
serd_writer_chop_blank_prefix(writer, "tmp");
@@ -633,6 +634,7 @@ test_writer(const char* const path)
assert(!serd_sink_write(iface, 0, s, p, o, 0));
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_node_free(lit);
serd_node_free(o);
serd_node_free(t);
@@ -640,16 +642,10 @@ test_writer(const char* const path)
serd_node_free(urn_Type);
// Test buffer sink
- SerdBuffer buffer = { NULL, 0 };
- SerdByteSink* byte_sink =
- serd_byte_sink_new((SerdWriteFunc)serd_buffer_sink, &buffer, 1);
-
- writer = serd_writer_new(world,
- SERD_TURTLE,
- 0,
- env,
- (SerdWriteFunc)serd_byte_sink_write,
- byte_sink);
+ SerdBuffer buffer = {NULL, 0};
+
+ byte_sink = serd_byte_sink_new_buffer(&buffer);
+ writer = serd_writer_new(world, SERD_TURTLE, 0, env, byte_sink);
o = serd_new_uri("http://example.org/base");
assert(!serd_writer_set_base_uri(writer, o));
diff --git a/tests/terse_write_test.c b/tests/terse_write_test.c
index 4b6a80c4..924dfbc9 100644
--- a/tests/terse_write_test.c
+++ b/tests/terse_write_test.c
@@ -67,13 +67,8 @@ test(void)
serd_env_set_prefix_from_strings(env, "rdf", NS_RDF);
- SerdWriter* writer = serd_writer_new(world,
- SERD_TURTLE,
- 0,
- env,
- (SerdWriteFunc)serd_buffer_sink,
- &buffer);
-
+ SerdByteSink* byte_sink = serd_byte_sink_new_buffer(&buffer);
+ SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, byte_sink);
const SerdSink* sink = serd_writer_get_sink(writer);
// Simple lone list
@@ -102,6 +97,7 @@ test(void)
serd_buffer_sink_finish(&buffer);
serd_writer_free(writer);
+ serd_byte_sink_free(byte_sink);
serd_nodes_free(nodes);
serd_env_free(env);
serd_world_free(world);