diff options
-rw-r--r-- | tests/serd_test.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c index 9277de88..675c22ca 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -60,20 +60,15 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri) return SERD_SUCCESS; } -typedef struct { - int n_statements; -} ReaderTest; - static SerdStatus -test_sink(void* handle, - SerdStatementFlags flags, - const SerdStatement* statement) +count_statements(void* handle, + SerdStatementFlags flags, + const SerdStatement* statement) { (void)flags; (void)statement; - ReaderTest* rt = (ReaderTest*)handle; - ++rt->n_statements; + ++*(size_t*)handle; return SERD_SUCCESS; } @@ -103,18 +98,19 @@ test_file_uri(const char* hostname, 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); - SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); + SerdWorld* world = serd_world_new(); + size_t n_statements = 0; + FILE* const f = tmpfile(); + static const char null = 0; + SerdSink* sink = serd_sink_new(&n_statements); + + assert(sink); + serd_sink_set_statement_func(sink, count_statements); + 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, @@ -134,37 +130,36 @@ test_read_chunks(void) // Read prefix st = serd_reader_read_chunk(reader); assert(st == SERD_SUCCESS); - assert(rt->n_statements == 0); + assert(n_statements == 0); // Read first statement st = serd_reader_read_chunk(reader); assert(st == SERD_SUCCESS); - assert(rt->n_statements == 1); + assert(n_statements == 1); // Read terminator st = serd_reader_read_chunk(reader); assert(st == SERD_FAILURE); - assert(rt->n_statements == 1); + assert(n_statements == 1); // Read second statement (after null terminator) st = serd_reader_read_chunk(reader); assert(st == SERD_SUCCESS); - assert(rt->n_statements == 2); + assert(n_statements == 2); // Read terminator st = serd_reader_read_chunk(reader); assert(st == SERD_FAILURE); - assert(rt->n_statements == 2); + assert(n_statements == 2); // EOF st = serd_reader_read_chunk(reader); assert(st == SERD_FAILURE); - assert(rt->n_statements == 2); + assert(n_statements == 2); serd_reader_free(reader); serd_sink_free(sink); fclose(f); - free(rt); serd_world_free(world); } @@ -758,9 +753,9 @@ test_reader(const char* path) { SerdWorld* world = serd_world_new(); - ReaderTest rt = { 0 }; - SerdSink* sink = serd_sink_new(&rt); - serd_sink_set_statement_func(sink, test_sink); + size_t n_statements = 0; + SerdSink* sink = serd_sink_new(&n_statements); + serd_sink_set_statement_func(sink, count_statements); SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096); assert(reader); @@ -774,7 +769,7 @@ test_reader(const char* path) assert(!serd_reader_start_file(reader, path, true)); assert(!serd_reader_read_document(reader)); - assert(rt.n_statements == 13); + assert(n_statements == 13); serd_reader_finish(reader); serd_reader_free(reader); |