aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-11 20:47:51 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commit6eb1fa15a06ab7de08e33add1540a45b83c5f0d8 (patch)
tree86d3cfedbf2ff76878eba6d14dc7fc259d1cbf46 /test
parentd1ba721d37af61f2b529faaa16bd20ba1e161b06 (diff)
downloadserd-6eb1fa15a06ab7de08e33add1540a45b83c5f0d8.tar.gz
serd-6eb1fa15a06ab7de08e33add1540a45b83c5f0d8.tar.bz2
serd-6eb1fa15a06ab7de08e33add1540a45b83c5f0d8.zip
Add SerdWorld for shared library state
Diffstat (limited to 'test')
-rw-r--r--test/test_free_null.c2
-rw-r--r--test/test_overflow.c25
-rw-r--r--test/test_reader_writer.c58
-rw-r--r--test/test_writer.c35
4 files changed, 75 insertions, 45 deletions
diff --git a/test/test_free_null.c b/test/test_free_null.c
index d3248cb5..72783328 100644
--- a/test/test_free_null.c
+++ b/test/test_free_null.c
@@ -8,6 +8,7 @@
#include "serd/node.h"
#include "serd/reader.h"
#include "serd/sink.h"
+#include "serd/world.h"
#include "serd/writer.h"
#include <stddef.h>
@@ -17,6 +18,7 @@ main(void)
{
serd_free(NULL);
serd_node_free(NULL);
+ serd_world_free(NULL);
serd_env_free(NULL);
serd_sink_free(NULL);
serd_reader_free(NULL);
diff --git a/test/test_overflow.c b/test/test_overflow.c
index ac4a490b..a304ae1c 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -12,12 +12,13 @@ static const size_t min_stack_size = 4U * sizeof(size_t) + 240U;
static const size_t max_stack_size = 1024U;
static SerdStatus
-test_size(const char* const str,
+test_size(SerdWorld* const world,
+ const char* const str,
const SerdSyntax syntax,
const size_t stack_size)
{
SerdSink* sink = serd_sink_new(NULL, NULL);
- SerdReader* const reader = serd_reader_new(syntax, sink, stack_size);
+ SerdReader* const reader = serd_reader_new(world, syntax, sink, stack_size);
if (!reader) {
return SERD_BAD_STACK;
}
@@ -31,15 +32,17 @@ test_size(const char* const str,
}
static void
-test_all_sizes(const char* const str, const SerdSyntax syntax)
+test_all_sizes(SerdWorld* const world,
+ const char* const str,
+ const SerdSyntax syntax)
{
// Ensure reading with the maximum stack size succeeds
- SerdStatus st = test_size(str, syntax, max_stack_size);
+ SerdStatus st = test_size(world, str, syntax, max_stack_size);
assert(!st);
// Test with an increasingly smaller stack
for (size_t size = max_stack_size; size > min_stack_size; --size) {
- if ((st = test_size(str, syntax, size))) {
+ if ((st = test_size(world, str, syntax, size))) {
assert(st == SERD_BAD_STACK);
}
}
@@ -55,9 +58,13 @@ test_ntriples_overflow(void)
NULL,
};
+ SerdWorld* const world = serd_world_new();
+
for (const char* const* t = test_strings; *t; ++t) {
- test_all_sizes(*t, SERD_NTRIPLES);
+ test_all_sizes(world, *t, SERD_NTRIPLES);
}
+
+ serd_world_free(world);
}
static void
@@ -138,9 +145,13 @@ test_turtle_overflow(void)
NULL,
};
+ SerdWorld* const world = serd_world_new();
+
for (const char* const* t = test_strings; *t; ++t) {
- test_all_sizes(*t, SERD_TURTLE);
+ test_all_sizes(world, *t, SERD_TURTLE);
}
+
+ serd_world_free(world);
}
int
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
diff --git a/test/test_writer.c b/test/test_writer.c
index 5a4e5ab0..db68454f 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -12,6 +12,7 @@
#include "serd/status.h"
#include "serd/string_view.h"
#include "serd/syntax.h"
+#include "serd/world.h"
#include "serd/writer.h"
#include <assert.h>
@@ -22,10 +23,11 @@
static void
test_write_bad_prefix(void)
{
+ SerdWorld* world = serd_world_new();
SerdEnv* env = serd_env_new(serd_empty_string());
SerdBuffer buffer = {NULL, 0};
SerdWriter* writer =
- serd_writer_new(SERD_TURTLE, 0U, env, serd_buffer_sink, &buffer);
+ serd_writer_new(world, SERD_TURTLE, 0U, env, serd_buffer_sink, &buffer);
assert(writer);
@@ -44,15 +46,17 @@ test_write_bad_prefix(void)
serd_node_free(name);
serd_writer_free(writer);
serd_env_free(env);
+ serd_world_free(world);
}
static void
test_write_long_literal(void)
{
+ SerdWorld* world = serd_world_new();
SerdEnv* env = serd_env_new(serd_empty_string());
SerdBuffer buffer = {NULL, 0};
SerdWriter* writer =
- serd_writer_new(SERD_TURTLE, 0U, env, serd_buffer_sink, &buffer);
+ serd_writer_new(world, SERD_TURTLE, 0U, env, serd_buffer_sink, &buffer);
assert(writer);
@@ -76,6 +80,8 @@ test_write_long_literal(void)
assert(!strcmp((char*)out, expected));
serd_free(out);
+
+ serd_world_free(world);
}
static size_t
@@ -93,9 +99,11 @@ null_sink(const void* const buf,
static void
test_writer_cleanup(void)
{
- SerdStatus st = SERD_SUCCESS;
- SerdEnv* env = serd_env_new(serd_empty_string());
- SerdWriter* writer = serd_writer_new(SERD_TURTLE, 0U, env, null_sink, NULL);
+ SerdStatus st = SERD_SUCCESS;
+ SerdWorld* world = serd_world_new();
+ SerdEnv* env = serd_env_new(serd_empty_string());
+ SerdWriter* writer =
+ serd_writer_new(world, SERD_TURTLE, 0U, env, null_sink, NULL);
const SerdSink* sink = serd_writer_sink(writer);
@@ -134,6 +142,7 @@ test_writer_cleanup(void)
serd_node_free(s);
serd_writer_free(writer);
serd_env_free(env);
+ serd_world_free(world);
}
static void
@@ -143,9 +152,10 @@ test_strict_write(void)
FILE* const fd = fopen(path, "wb");
assert(fd);
+ SerdWorld* world = serd_world_new();
SerdEnv* const env = serd_env_new(serd_empty_string());
SerdWriter* const writer = serd_writer_new(
- SERD_TURTLE, (SerdWriterFlags)SERD_WRITE_STRICT, env, null_sink, fd);
+ world, SERD_TURTLE, (SerdWriterFlags)SERD_WRITE_STRICT, env, null_sink, fd);
assert(writer);
@@ -168,6 +178,7 @@ test_strict_write(void)
serd_node_free(s);
serd_writer_free(writer);
serd_env_free(env);
+ serd_world_free(world);
fclose(fd);
remove(path);
}
@@ -189,14 +200,15 @@ error_sink(const void* const buf,
static void
test_write_error(void)
{
- SerdEnv* const env = serd_env_new(serd_empty_string());
- SerdWriter* writer = NULL;
- SerdStatus st = SERD_SUCCESS;
+ SerdWorld* const world = serd_world_new();
+ SerdEnv* const env = serd_env_new(serd_empty_string());
+ SerdWriter* writer = NULL;
+ SerdStatus st = SERD_SUCCESS;
SerdNode* u = serd_new_uri(serd_string("http://example.com/u"));
- writer =
- serd_writer_new(SERD_TURTLE, (SerdWriterFlags)0, env, error_sink, NULL);
+ writer = serd_writer_new(
+ world, SERD_TURTLE, (SerdWriterFlags)0, env, error_sink, NULL);
assert(writer);
const SerdSink* const sink = serd_writer_sink(writer);
@@ -207,6 +219,7 @@ test_write_error(void)
serd_node_free(u);
serd_env_free(env);
+ serd_world_free(world);
}
int