aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-12-30 12:34:24 -0500
committerDavid Robillard <d@drobilla.net>2019-12-19 20:57:48 -0500
commit918599ec2ddfc6d6b3afd6a13f46a7e5da0bd652 (patch)
tree8cc642b1b0a806797ec4201f64ef76c29d3bfbc6
parentde5806d34301c0c1d9e61b3916e1bc8c106ad022 (diff)
downloadserd-918599ec2ddfc6d6b3afd6a13f46a7e5da0bd652.tar.gz
serd-918599ec2ddfc6d6b3afd6a13f46a7e5da0bd652.tar.bz2
serd-918599ec2ddfc6d6b3afd6a13f46a7e5da0bd652.zip
Simplify reader test sink
-rw-r--r--tests/serd_test.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index d6411e4e..bda58668 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);