summaryrefslogtreecommitdiffstats
path: root/test/test_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_state.c')
-rw-r--r--test/test_state.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/test/test_state.c b/test/test_state.c
index 533c3a9..e12bfdc 100644
--- a/test/test_state.c
+++ b/test/test_state.c
@@ -246,10 +246,12 @@ static const LilvPlugin*
load_test_plugin(const TestContext* const ctx)
{
LilvWorld* world = ctx->env->world;
- uint8_t* abs_bundle = (uint8_t*)lilv_path_absolute(LILV_TEST_BUNDLE);
- SerdNode bundle = serd_node_new_file_uri(abs_bundle, 0, 0, true);
- LilvNode* bundle_uri = lilv_new_uri(world, (const char*)bundle.buf);
- LilvNode* plugin_uri = lilv_new_uri(world, TEST_PLUGIN_URI);
+ char* abs_bundle = lilv_path_absolute(LILV_TEST_BUNDLE);
+ SerdNode* bundle =
+ serd_new_file_uri(SERD_MEASURE_STRING(abs_bundle), SERD_EMPTY_STRING());
+
+ LilvNode* bundle_uri = lilv_new_uri(world, serd_node_string(bundle));
+ LilvNode* plugin_uri = lilv_new_uri(world, TEST_PLUGIN_URI);
lilv_world_load_bundle(world, bundle_uri);
@@ -258,7 +260,7 @@ load_test_plugin(const TestContext* const ctx)
lilv_node_free(plugin_uri);
lilv_node_free(bundle_uri);
- serd_node_free(&bundle);
+ serd_node_free(bundle);
free(abs_bundle);
assert(plugin);
@@ -531,26 +533,13 @@ test_string_round_trip(void)
}
static SerdStatus
-count_sink(void* const handle,
- const SerdStatementFlags flags,
- const SerdNode* const graph,
- const SerdNode* const subject,
- const SerdNode* const predicate,
- const SerdNode* const object,
- const SerdNode* const object_datatype,
- const SerdNode* const object_lang)
+count_func(void* const handle, const SerdEvent* const event)
{
- (void)flags;
- (void)graph;
- (void)subject;
- (void)predicate;
- (void)object;
- (void)object_datatype;
- (void)object_lang;
-
size_t* const n_statements = (size_t*)handle;
- ++(*n_statements);
+ if (event->type == SERD_STATEMENT) {
+ ++(*n_statements);
+ }
return SERD_SUCCESS;
}
@@ -560,15 +549,27 @@ count_statements(const char* path)
{
size_t n_statements = 0;
- SerdReader* reader = serd_reader_new(
- SERD_TURTLE, &n_statements, NULL, NULL, NULL, count_sink, NULL);
+ SerdWorld* const world = serd_world_new();
+ const SerdStringView path_view = SERD_MEASURE_STRING(path);
+ SerdNode* const base = serd_new_file_uri(path_view, SERD_EMPTY_STRING());
+
+ SerdEnv* const env = serd_env_new(serd_node_string_view(base));
+ SerdSink* const sink = serd_sink_new(&n_statements, count_func, NULL);
+ SerdReader* const reader =
+ serd_reader_new(world, SERD_TURTLE, 0, env, sink, 4096);
- SerdNode uri = serd_node_new_file_uri((const uint8_t*)path, NULL, NULL, true);
+ SerdByteSource* const source = serd_byte_source_new_filename(path, 4096);
- assert(!serd_reader_read_file(reader, uri.buf));
+ SerdStatus st = SERD_SUCCESS;
+ assert(!(st = serd_reader_start(reader, source)));
+ assert(!(st = serd_reader_read_document(reader)));
- serd_node_free(&uri);
+ serd_byte_source_free(source);
serd_reader_free(reader);
+ serd_sink_free(sink);
+ serd_env_free(env);
+ serd_node_free(base);
+ serd_world_free(world);
return n_statements;
}
@@ -917,10 +918,10 @@ test_world_round_trip(void)
"state.ttl"));
// Load state bundle into world
- SerdNode bundle_uri =
- serd_node_new_file_uri((const uint8_t*)bundle_path, 0, 0, true);
+ SerdNode* bundle_uri =
+ serd_new_file_uri(SERD_MEASURE_STRING(bundle_path), SERD_EMPTY_STRING());
LilvNode* const bundle_node =
- lilv_new_uri(world, (const char*)bundle_uri.buf);
+ lilv_new_uri(world, serd_node_string(bundle_uri));
LilvNode* const state_node = lilv_new_uri(world, state_uri);
lilv_world_load_bundle(world, bundle_node);
lilv_world_load_resource(world, state_node);
@@ -944,7 +945,7 @@ test_world_round_trip(void)
lilv_state_free(restored);
lilv_node_free(state_node);
lilv_node_free(bundle_node);
- serd_node_free(&bundle_uri);
+ serd_node_free(bundle_uri);
lilv_state_free(start_state);
free(bundle_path);
test_context_free(ctx);