aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-12-26 20:04:27 -0500
committerDavid Robillard <d@drobilla.net>2022-01-13 23:03:49 -0500
commit1752a00ebefb22564fb805d4c89deb39ec5e218b (patch)
treeb780261bd9983eadda743b8735c2ea489f6cdb05 /test
parentcc03e614b22b5695a1bbe0bedebd1bf0cf284bf7 (diff)
downloadserd-1752a00ebefb22564fb805d4c89deb39ec5e218b.tar.gz
serd-1752a00ebefb22564fb805d4c89deb39ec5e218b.tar.bz2
serd-1752a00ebefb22564fb805d4c89deb39ec5e218b.zip
Remove serd_reader_set_default_graph()
Diffstat (limited to 'test')
-rw-r--r--test/test_reader_writer.c60
1 files changed, 23 insertions, 37 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index c71c377a..b741c1ae 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -22,14 +22,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
-typedef struct {
- int n_statements;
- const SerdNode* graph;
-} ReaderTest;
-
static SerdStatus
test_sink(void* handle,
SerdStatementFlags flags,
@@ -42,10 +36,10 @@ test_sink(void* handle,
(void)subject;
(void)predicate;
(void)object;
+ (void)graph;
+
+ ++*(size_t*)handle;
- ReaderTest* rt = (ReaderTest*)handle;
- ++rt->n_statements;
- rt->graph = graph;
return SERD_SUCCESS;
}
@@ -96,11 +90,11 @@ eof_test_error(void* stream)
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, NULL);
+ 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, NULL);
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
@@ -123,47 +117,46 @@ 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);
}
static void
test_read_string(void)
{
- SerdWorld* world = serd_world_new();
- ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
- SerdSink* sink = serd_sink_new(rt, NULL);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdWorld* world = serd_world_new();
+ size_t n_statements = 0;
+ SerdSink* sink = serd_sink_new(&n_statements, NULL);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
assert(sink);
@@ -177,12 +170,11 @@ test_read_string(void)
"<http://example.org/o> ."));
assert(!serd_reader_read_document(reader));
- assert(rt->n_statements == 1);
+ assert(n_statements == 1);
assert(!serd_reader_finish(reader));
serd_reader_free(reader);
serd_sink_free(sink);
- free(rt);
serd_world_free(world);
}
@@ -290,9 +282,9 @@ test_writer(const char* const path)
static void
test_reader(const char* path)
{
- SerdWorld* world = serd_world_new();
- ReaderTest rt = {0, NULL};
- SerdSink* const sink = serd_sink_new(&rt, NULL);
+ SerdWorld* world = serd_world_new();
+ size_t n_statements = 0;
+ SerdSink* const sink = serd_sink_new(&n_statements, NULL);
assert(sink);
serd_sink_set_statement_func(sink, test_sink);
@@ -302,8 +294,6 @@ test_reader(const char* path)
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
assert(reader);
- SerdNode* g = serd_new_uri(SERD_STRING("http://example.org/"));
- serd_reader_set_default_graph(reader, g);
serd_reader_add_blank_prefix(reader, "tmp");
#if defined(__GNUC__)
@@ -315,17 +305,13 @@ test_reader(const char* path)
# pragma GCC diagnostic pop
#endif
- serd_node_free(g);
-
assert(serd_reader_start_file(reader, "http://notafile", false));
assert(serd_reader_start_file(reader, "file://invalid", false));
assert(serd_reader_start_file(reader, "file:///nonexistant", false));
assert(!serd_reader_start_file(reader, path, true));
assert(!serd_reader_read_document(reader));
- assert(rt.n_statements == 6);
- assert(rt.graph && serd_node_string(rt.graph) &&
- !strcmp(serd_node_string(rt.graph), "http://example.org/"));
+ assert(n_statements == 6);
serd_reader_finish(reader);
// A read of a big page hits EOF then fails to read chunks immediately