aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_reader_writer.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_reader_writer.c')
-rw-r--r--test/test_reader_writer.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index c1472e0a..c634bc79 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -5,7 +5,6 @@
#include "serd/buffer.h"
#include "serd/env.h"
-#include "serd/error.h"
#include "serd/memory.h"
#include "serd/node.h"
#include "serd/reader.h"
@@ -15,6 +14,7 @@
#include "serd/stream.h"
#include "serd/string_view.h"
#include "serd/syntax.h"
+#include "serd/world.h"
#include "serd/writer.h"
#ifdef _WIN32
@@ -184,9 +184,10 @@ test_read_nquads_chunks(const char* const path)
fseek(f, 0, SEEK_SET);
+ SerdWorld* const world = serd_world_new();
ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
SerdSink* const sink = serd_sink_new(rt, NULL);
- SerdReader* const reader = serd_reader_new(SERD_NQUADS, sink, 4096);
+ SerdReader* const reader = serd_reader_new(world, SERD_NQUADS, sink, 4096);
assert(reader);
assert(sink);
@@ -245,6 +246,7 @@ test_read_nquads_chunks(const char* const path)
serd_reader_free(reader);
serd_sink_free(sink);
free(rt);
+ serd_world_free(world);
fclose(f);
remove(path);
}
@@ -266,9 +268,10 @@ test_read_turtle_chunks(const char* const path)
fwrite(&null, sizeof(null), 1, f);
fseek(f, 0, SEEK_SET);
- ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
- SerdSink* const sink = serd_sink_new(rt, NULL);
- SerdReader* const reader = serd_reader_new(SERD_TURTLE, sink, 4096);
+ SerdWorld* world = serd_world_new();
+ ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
+ SerdSink* sink = serd_sink_new(rt, NULL);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
assert(sink);
@@ -343,6 +346,7 @@ test_read_turtle_chunks(const char* const path)
serd_reader_free(reader);
serd_sink_free(sink);
free(rt);
+ serd_world_free(world);
fclose(f);
remove(path);
}
@@ -350,9 +354,10 @@ test_read_turtle_chunks(const char* const path)
static void
test_read_string(void)
{
+ SerdWorld* world = serd_world_new();
ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
SerdSink* sink = serd_sink_new(rt, NULL);
- SerdReader* reader = serd_reader_new(SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
assert(sink);
@@ -378,6 +383,7 @@ test_read_string(void)
serd_reader_free(reader);
serd_sink_free(sink);
free(rt);
+ serd_world_free(world);
}
static size_t
@@ -404,18 +410,11 @@ faulty_sink(const void* const buf,
return nmemb;
}
-static SerdStatus
-quiet_error_sink(void* const handle, const SerdError* const e)
-{
- (void)handle;
- (void)e;
- return SERD_SUCCESS;
-}
-
static void
test_write_errors(void)
{
- ErrorContext ctx = {0U, 0U};
+ SerdWorld* const world = serd_world_new();
+ ErrorContext ctx = {0U, 0U};
const SerdWriterFlags style =
(SerdWriterFlags)(SERD_WRITE_STRICT | SERD_WRITE_CURIED);
@@ -430,13 +429,10 @@ test_write_errors(void)
SerdEnv* const env = serd_env_new(serd_empty_string());
SerdWriter* const writer =
- serd_writer_new(syntax, style, env, faulty_sink, &ctx);
+ serd_writer_new(world, syntax, style, env, faulty_sink, &ctx);
- const SerdSink* const sink = serd_writer_sink(writer);
- SerdReader* const reader = serd_reader_new(SERD_TRIG, sink, 4096U);
-
- serd_reader_set_error_sink(reader, quiet_error_sink, NULL);
- serd_writer_set_error_sink(writer, quiet_error_sink, NULL);
+ const SerdSink* const sink = serd_writer_sink(writer);
+ SerdReader* const reader = serd_reader_new(world, SERD_TRIG, sink, 4096U);
SerdStatus st = serd_reader_start_string(reader, doc_string);
assert(!st);
@@ -448,6 +444,8 @@ test_write_errors(void)
serd_env_free(env);
}
}
+
+ serd_world_free(world);
}
static void
@@ -457,8 +455,10 @@ test_writer(const char* const path)
SerdEnv* env = serd_env_new(serd_empty_string());
assert(fd);
+ SerdWorld* world = serd_world_new();
+
SerdWriter* writer =
- serd_writer_new(SERD_TURTLE, 0, env, (SerdWriteFunc)fwrite, fd);
+ serd_writer_new(world, SERD_TURTLE, 0, env, (SerdWriteFunc)fwrite, fd);
assert(writer);
serd_writer_chop_blank_prefix(writer, "tmp");
@@ -527,7 +527,8 @@ test_writer(const char* const path)
// Test buffer sink
SerdBuffer buffer = {NULL, 0};
- writer = serd_writer_new(SERD_TURTLE, 0, env, serd_buffer_sink, &buffer);
+ writer =
+ serd_writer_new(world, SERD_TURTLE, 0, env, serd_buffer_sink, &buffer);
SerdNode* const base = serd_new_uri(serd_string("http://example.org/base"));
@@ -544,14 +545,16 @@ test_writer(const char* const path)
serd_node_free(s);
serd_env_free(env);
+ serd_world_free(world);
fclose(fd);
}
static void
test_reader(const char* path)
{
- ReaderTest rt = {0, 0, 0, 0, NULL};
- SerdSink* const sink = serd_sink_new(&rt, NULL);
+ SerdWorld* world = serd_world_new();
+ ReaderTest rt = {0, 0, 0, 0, NULL};
+ SerdSink* const sink = serd_sink_new(&rt, NULL);
assert(sink);
serd_sink_set_base_func(sink, test_base_sink);
@@ -560,9 +563,9 @@ test_reader(const char* path)
serd_sink_set_end_func(sink, test_end_sink);
// Test that too little stack space fails gracefully
- assert(!serd_reader_new(SERD_TURTLE, sink, 32));
+ assert(!serd_reader_new(world, SERD_TURTLE, sink, 32));
- SerdReader* reader = serd_reader_new(SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
@@ -630,6 +633,7 @@ test_reader(const char* path)
serd_reader_free(reader);
serd_sink_free(sink);
+ serd_world_free(world);
}
int