diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_byte_sink.c | 2 | ||||
-rw-r--r-- | test/test_model.c | 35 | ||||
-rw-r--r-- | test/test_reader_writer.c | 5 | ||||
-rw-r--r-- | test/test_writer.c | 29 |
4 files changed, 41 insertions, 30 deletions
diff --git a/test/test_byte_sink.c b/test/test_byte_sink.c index 1982a436..71f1e62d 100644 --- a/test/test_byte_sink.c +++ b/test/test_byte_sink.c @@ -26,7 +26,7 @@ main(void) { assert(!serd_byte_sink_new_filename("file.ttl", 0)); assert(!serd_byte_sink_new_filename("/does/not/exist.ttl", 1)); - assert(!serd_byte_sink_new_function((SerdWriteFunc)fwrite, NULL, 0)); + assert(!serd_byte_sink_new_function((SerdWriteFunc)fwrite, NULL, NULL, 0)); return 0; } diff --git a/test/test_model.c b/test/test_model.c index 4cedfb2b..d5b5eb8c 100644 --- a/test/test_model.c +++ b/test/test_model.c @@ -1062,16 +1062,18 @@ test_write_flat_range(SerdWorld* world, const unsigned n_quads) serd_cursor_free(all); serd_writer_finish(writer); - const char* str = serd_buffer_sink_finish(&buffer); - const char* expected = "<urn:s>\n" - " <urn:p> _:b1 ,\n" - " _:b2 .\n" - "\n" - "_:b1\n" - " <urn:p> <urn:o> .\n" - "\n" - "_:b2\n" - " <urn:p> <urn:o> .\n"; + serd_byte_sink_close(out); + + const char* const str = (const char*)buffer.buf; + static const char* const expected = "<urn:s>\n" + "\t<urn:p> _:b1 ,\n" + "\t\t_:b2 .\n" + "\n" + "_:b1\n" + "\t<urn:p> <urn:o> .\n" + "\n" + "_:b2\n" + "\t<urn:p> <urn:o> .\n"; assert(!strcmp(str, expected)); @@ -1126,7 +1128,9 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads) serd_cursor_free(all); serd_writer_finish(writer); - const char* str = serd_buffer_sink_finish(&buffer); + serd_byte_sink_close(out); + + const char* str = (const char*)buffer.buf; const char* expected = "<urn:s>\n" " <urn:p> (\n" " \"a\"\n" @@ -1188,7 +1192,8 @@ test_write_infinite_list(SerdWorld* world, const unsigned n_quads) serd_cursor_free(all); serd_writer_finish(writer); - const char* str = serd_buffer_sink_finish(&buffer); + serd_byte_sink_close(out); + const char* str = (const char*)buffer.buf; const char* expected = "<urn:s>\n" " <urn:p> _:l1 .\n" "\n" @@ -1265,7 +1270,8 @@ test_write_error_in_list_subject(SerdWorld* world, const unsigned n_quads) for (size_t max_successes = 0; max_successes < 18; ++max_successes) { FailingWriteFuncState state = {0, max_successes}; SerdByteSink* out = - serd_byte_sink_new_function(failing_write_func, &state, 1); + serd_byte_sink_new_function(failing_write_func, NULL, &state, 1); + SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, out); const SerdSink* const sink = serd_writer_sink(writer); @@ -1320,7 +1326,8 @@ test_write_error_in_list_object(SerdWorld* world, const unsigned n_quads) for (size_t max_successes = 0; max_successes < 21; ++max_successes) { FailingWriteFuncState state = {0, max_successes}; SerdByteSink* out = - serd_byte_sink_new_function(failing_write_func, &state, 1); + serd_byte_sink_new_function(failing_write_func, NULL, &state, 1); + SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, out); const SerdSink* const sink = serd_writer_sink(writer); diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index cab33ff5..c0af313a 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -43,8 +43,8 @@ test_writer(const char* const path) SerdWorld* world = serd_world_new(); SerdNodes* nodes = serd_world_nodes(world); - SerdByteSink* byte_sink = - serd_byte_sink_new_function((SerdWriteFunc)fwrite, fd, 1); + SerdByteSink* byte_sink = serd_byte_sink_new_function( + (SerdWriteFunc)fwrite, (SerdStreamCloseFunc)fclose, fd, 1); SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, SERD_WRITE_LAX, env, byte_sink); @@ -131,7 +131,6 @@ test_writer(const char* const path) serd_env_free(env); serd_world_free(world); - fclose(fd); } static void diff --git a/test/test_writer.c b/test/test_writer.c index 9a59d92f..89531eee 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -40,7 +40,9 @@ test_write_bad_event(void) assert(serd_sink_write_event(serd_writer_sink(writer), &event) == SERD_ERR_BAD_ARG); - char* const out = serd_buffer_sink_finish(&buffer); + assert(!serd_byte_sink_close(byte_sink)); + + char* const out = (char*)buffer.buf; assert(!strcmp(out, "")); serd_free(out); @@ -109,10 +111,11 @@ 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()); - SerdByteSink* byte_sink = serd_byte_sink_new_function(null_sink, NULL, 1u); + 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, NULL, 1u); SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink); @@ -165,8 +168,8 @@ test_strict_write(void) SerdEnv* env = serd_env_new(SERD_EMPTY_STRING()); - SerdByteSink* byte_sink = - serd_byte_sink_new_function((SerdWriteFunc)fwrite, fd, 1); + SerdByteSink* byte_sink = serd_byte_sink_new_function( + (SerdWriteFunc)fwrite, (SerdStreamCloseFunc)fclose, fd, 1); SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, byte_sink); assert(writer); @@ -190,7 +193,6 @@ test_strict_write(void) serd_writer_free(writer); serd_byte_sink_free(byte_sink); serd_env_free(env); - fclose(fd); serd_world_free(world); } @@ -230,7 +232,8 @@ test_write_error(void) // Test with setting errno - SerdByteSink* byte_sink = serd_byte_sink_new_function(faulty_sink, NULL, 1); + SerdByteSink* byte_sink = + serd_byte_sink_new_function(faulty_sink, NULL, NULL, 1); SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink); assert(writer); @@ -242,7 +245,7 @@ test_write_error(void) serd_byte_sink_free(byte_sink); // Test without setting errno - byte_sink = serd_byte_sink_new_function(faulty_sink, world, 1); + byte_sink = serd_byte_sink_new_function(faulty_sink, NULL, world, 1); writer = serd_writer_new(world, SERD_TURTLE, 0u, env, byte_sink); assert(writer); @@ -282,8 +285,9 @@ test_write_empty_syntax(void) assert(writer); assert(!serd_sink_write(serd_writer_sink(writer), 0u, s, p, o, NULL)); + assert(!serd_byte_sink_close(byte_sink)); - char* out = serd_buffer_sink_finish(&buffer); + char* const out = (char*)buffer.buf; assert(strlen(out) == 0); serd_free(out); @@ -323,7 +327,8 @@ test_write_bad_uri(void) assert(st); assert(st == SERD_ERR_BAD_ARG); - serd_free(serd_buffer_sink_finish(&buffer)); + serd_byte_sink_close(byte_sink); + serd_free(buffer.buf); serd_writer_free(writer); serd_byte_sink_free(byte_sink); serd_env_free(env); |