diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_free_null.c | 1 | ||||
-rw-r--r-- | test/test_overflow.c | 25 | ||||
-rw-r--r-- | test/test_read_chunk.c | 6 | ||||
-rw-r--r-- | test/test_reader_writer.c | 26 | ||||
-rw-r--r-- | test/test_writer.c | 17 |
5 files changed, 54 insertions, 21 deletions
diff --git a/test/test_free_null.c b/test/test_free_null.c index af1ae149..3977507c 100644 --- a/test/test_free_null.c +++ b/test/test_free_null.c @@ -25,6 +25,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 13516388..a1f32a42 100644 --- a/test/test_overflow.c +++ b/test/test_overflow.c @@ -25,12 +25,13 @@ static const size_t min_stack_size = 4 * sizeof(size_t) + 256u; 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); assert(reader); serd_reader_start_string(reader, str); @@ -42,15 +43,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_ERR_OVERFLOW); } } @@ -66,9 +69,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 @@ -149,9 +156,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_read_chunk.c b/test/test_read_chunk.c index 17421a52..602af540 100644 --- a/test/test_read_chunk.c +++ b/test/test_read_chunk.c @@ -79,13 +79,14 @@ on_end(void* handle, const SerdNode* node) int main(void) { - SerdSink* sink = serd_sink_new(NULL, NULL); + SerdWorld* world = serd_world_new(); + SerdSink* sink = serd_sink_new(NULL, NULL); serd_sink_set_base_func(sink, on_base); serd_sink_set_prefix_func(sink, on_prefix); serd_sink_set_statement_func(sink, on_statement); serd_sink_set_end_func(sink, on_end); - SerdReader* reader = serd_reader_new(SERD_TURTLE, sink, 4096); + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); assert(reader); assert(!serd_reader_start_string(reader, @@ -112,6 +113,7 @@ main(void) serd_reader_free(reader); serd_sink_free(sink); + serd_world_free(world); return 0; } diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 7a9cc390..c71c377a 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -96,11 +96,12 @@ eof_test_error(void* stream) static void test_read_chunks(void) { + SerdWorld* world = serd_world_new(); ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); FILE* const f = tmpfile(); static const char null = 0; 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); @@ -153,14 +154,16 @@ test_read_chunks(void) serd_sink_free(sink); fclose(f); free(rt); + serd_world_free(world); } 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); @@ -180,6 +183,7 @@ test_read_string(void) serd_reader_free(reader); serd_sink_free(sink); free(rt); + serd_world_free(world); } static void @@ -189,8 +193,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"); @@ -259,7 +265,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")); @@ -276,21 +283,23 @@ 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, NULL}; - SerdSink* const sink = serd_sink_new(&rt, NULL); + SerdWorld* world = serd_world_new(); + ReaderTest rt = {0, NULL}; + SerdSink* const sink = serd_sink_new(&rt, NULL); assert(sink); serd_sink_set_statement_func(sink, test_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); SerdNode* g = serd_new_uri(SERD_STRING("http://example.org/")); @@ -360,6 +369,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 be90b09e..e24a8218 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -25,10 +25,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); @@ -47,15 +48,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); @@ -79,6 +82,8 @@ test_write_long_literal(void) assert(!strcmp((char*)out, expected)); serd_free(out); + + serd_world_free(world); } static size_t @@ -96,8 +101,11 @@ null_sink(const void* const buf, static void test_writer_stack_overflow(void) { - SerdEnv* env = serd_env_new(SERD_EMPTY_STRING()); - SerdWriter* writer = serd_writer_new(SERD_TURTLE, 0u, env, null_sink, NULL); + 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); @@ -133,6 +141,7 @@ test_writer_stack_overflow(void) serd_node_free(s); serd_writer_free(writer); serd_env_free(env); + serd_world_free(world); } int |