diff options
author | David Robillard <d@drobilla.net> | 2018-06-15 15:15:55 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | 0aff74b23f4d85d7f157f25d399c14b6a78e998b (patch) | |
tree | 917ef773266f5b9417a1c394f2f8451ae774a49c /tests | |
parent | 9baa0127ea016c3ee409a64563b960cff135bbdb (diff) | |
download | serd-0aff74b23f4d85d7f157f25d399c14b6a78e998b.tar.gz serd-0aff74b23f4d85d7f157f25d399c14b6a78e998b.tar.bz2 serd-0aff74b23f4d85d7f157f25d399c14b6a78e998b.zip |
Make SerdSink opaque
Diffstat (limited to 'tests')
-rw-r--r-- | tests/free_null_test.c | 1 | ||||
-rw-r--r-- | tests/read_chunk_test.c | 13 | ||||
-rw-r--r-- | tests/serd_test.c | 35 |
3 files changed, 33 insertions, 16 deletions
diff --git a/tests/free_null_test.c b/tests/free_null_test.c index 40f72ba7..1068ca01 100644 --- a/tests/free_null_test.c +++ b/tests/free_null_test.c @@ -27,6 +27,7 @@ main(void) serd_node_free(NULL); serd_world_free(NULL); serd_env_free(NULL); + serd_sink_free(NULL); serd_reader_free(NULL); serd_writer_free(NULL); serd_cursor_free(NULL); diff --git a/tests/read_chunk_test.c b/tests/read_chunk_test.c index 6efdc37f..8ff3e03e 100644 --- a/tests/read_chunk_test.c +++ b/tests/read_chunk_test.c @@ -73,10 +73,14 @@ on_end(void* handle, const SerdNode* node) int main(void) { - SerdWorld* world = serd_world_new(); - const SerdSink sink = {NULL, on_base, on_prefix, on_statement, on_end}; - - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, &sink, 4096); + SerdWorld* world = serd_world_new(); + SerdSink* sink = serd_sink_new(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(world, SERD_TURTLE, sink, 4096); assert(reader); assert(!serd_reader_start_string(reader, @@ -102,6 +106,7 @@ main(void) assert(serd_reader_read_chunk(reader) == SERD_FAILURE); serd_reader_free(reader); + serd_sink_free(sink); serd_world_free(world); return 0; } diff --git a/tests/serd_test.c b/tests/serd_test.c index 786c92f3..515b0579 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -126,12 +126,14 @@ test_read_chunks(void) ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); FILE* const f = tmpfile(); static const char null = 0; - SerdSink sink = {rt, NULL, NULL, test_sink, NULL}; - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, &sink, 4096); + SerdSink* sink = serd_sink_new(rt); + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); assert(reader); assert(f); + serd_sink_set_statement_func(sink, test_sink); + SerdStatus st = serd_reader_start_stream(reader, (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, @@ -179,6 +181,7 @@ test_read_chunks(void) assert(rt->n_statements == 2); serd_reader_free(reader); + serd_sink_free(sink); fclose(f); free(rt); serd_world_free(world); @@ -204,12 +207,14 @@ test_get_blank(void) static void test_read_string(void) { - SerdWorld* world = serd_world_new(); - ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); - SerdSink sink = {rt, NULL, NULL, test_sink, NULL}; - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, &sink, 4096); + SerdWorld* world = serd_world_new(); + ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); + SerdSink* sink = serd_sink_new(rt); + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); assert(reader); + serd_sink_set_statement_func(sink, test_sink); + // Test reading a string that ends exactly at the end of input (no newline) assert(!serd_reader_start_string( reader, @@ -222,6 +227,7 @@ test_read_string(void) assert(!serd_reader_finish(reader)); serd_reader_free(reader); + serd_sink_free(sink); serd_world_free(world); } @@ -602,9 +608,9 @@ test_writer(const char* const path) SerdNode* lit = serd_new_string("hello"); const SerdSink* iface = serd_writer_get_sink(writer); - assert(iface->base(iface->handle, lit)); - assert(iface->prefix(iface->handle, lit, lit)); - assert(iface->end(iface->handle, NULL)); + assert(serd_sink_write_base(iface, lit)); + assert(serd_sink_write_prefix(iface, lit, lit)); + assert(serd_sink_write_end(iface, NULL)); assert(serd_writer_env(writer) == env); uint8_t buf[] = { 0xEF, 0xBF, 0xBD, 0 }; @@ -692,9 +698,12 @@ static void test_reader(const char* path) { SerdWorld* world = serd_world_new(); - ReaderTest rt = { 0, NULL }; - SerdSink sink = { &rt, NULL, NULL, test_sink, NULL }; - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, &sink, 4096); + + ReaderTest rt = { 0, NULL }; + SerdSink* sink = serd_sink_new(&rt); + serd_sink_set_statement_func(sink, test_sink); + + SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); assert(reader); SerdNode* g = serd_new_uri("http://example.org/"); @@ -754,6 +763,8 @@ test_reader(const char* path) } serd_reader_free(reader); + serd_sink_free(sink); + serd_world_free(world); } |