aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_read_chunk.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-02-20 19:18:28 -0500
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:05 -0500
commitb983d2a94b0f84b4c06889be77fbdacc502f2d7b (patch)
tree8fa3a46d95fc6b08aa323797436aa5582522b1cd /test/test_read_chunk.c
parent846553f8894264d64cdd1dfb08df56fe08189dac (diff)
downloadserd-b983d2a94b0f84b4c06889be77fbdacc502f2d7b.tar.gz
serd-b983d2a94b0f84b4c06889be77fbdacc502f2d7b.tar.bz2
serd-b983d2a94b0f84b4c06889be77fbdacc502f2d7b.zip
Replace multiple stream callbacks with SerdEvent
This makes plumbing easier since everything goes through the same "stream" and only one callback is required to handling everything. It's also more easily extensible in case more event types need to be added in the future.
Diffstat (limited to 'test/test_read_chunk.c')
-rw-r--r--test/test_read_chunk.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/test/test_read_chunk.c b/test/test_read_chunk.c
index d77c3398..0f24089d 100644
--- a/test/test_read_chunk.c
+++ b/test/test_read_chunk.c
@@ -70,15 +70,29 @@ on_end(void* handle, const SerdNode* node)
return SERD_SUCCESS;
}
+static SerdStatus
+on_event(void* handle, const SerdEvent* event)
+{
+ switch (event->type) {
+ case SERD_BASE:
+ return on_base(handle, event->base.uri);
+ case SERD_PREFIX:
+ return on_prefix(handle, event->prefix.name, event->prefix.uri);
+ case SERD_STATEMENT:
+ return on_statement(
+ handle, event->statement.flags, event->statement.statement);
+ case SERD_END:
+ return on_end(handle, event->end.node);
+ }
+
+ return SERD_SUCCESS;
+}
+
int
main(void)
{
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);
+ SerdSink* sink = serd_sink_new(NULL, on_event, NULL);
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
@@ -109,5 +123,6 @@ main(void)
serd_reader_free(reader);
serd_sink_free(sink);
serd_world_free(world);
+
return 0;
}