From d62c7dc45af3256c6cd70d12a11e91b5b872c7db Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 20 Feb 2021 19:18:28 -0500 Subject: 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. --- test/test_env.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'test/test_env.c') diff --git a/test/test_env.c b/test/test_env.c index 8dbc24a1..31446f69 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -4,7 +4,9 @@ #undef NDEBUG #include "serd/env.h" +#include "serd/event.h" #include "serd/node.h" +#include "serd/sink.h" #include "serd/status.h" #include "serd/string_view.h" @@ -12,12 +14,12 @@ #include static SerdStatus -count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri) +count_prefixes(void* handle, const SerdEvent* event) { - (void)name; - (void)uri; + if (event->type == SERD_PREFIX) { + ++*(int*)handle; + } - ++*(int*)handle; return SERD_SUCCESS; } @@ -73,10 +75,13 @@ test_env(void) assert(!serd_env_expand_node(env, blank)); serd_node_free(blank); - int n_prefixes = 0; + size_t n_prefixes = 0; + SerdSink* const count_prefixes_sink = + serd_sink_new(&n_prefixes, count_prefixes, NULL); + serd_env_set_prefix( env, serd_string("eg.2"), serd_string("http://example.org/")); - serd_env_foreach(env, count_prefixes, &n_prefixes); + serd_env_write_prefixes(env, count_prefixes_sink); assert(n_prefixes == 1); SerdNode* shorter_uri = serd_new_uri(serd_string("urn:foo")); @@ -93,6 +98,7 @@ test_env(void) assert(!serd_env_set_base_uri(env, serd_empty_string())); assert(!serd_env_base_uri(env)); + serd_sink_free(count_prefixes_sink); serd_node_free(shorter_uri); serd_node_free(badpre); serd_node_free(s); -- cgit v1.2.1