aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-10 19:29:22 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 18:21:57 +0200
commit9bc71471086b9f5d5789d76fb28a45c47a058cf8 (patch)
tree23e3a630acc35797d3dcf4a9f1acabae35b18756 /tests
parentfe86b69752e84f25ca211e97122601ae66e3b044 (diff)
downloadserd-9bc71471086b9f5d5789d76fb28a45c47a058cf8.tar.gz
serd-9bc71471086b9f5d5789d76fb28a45c47a058cf8.tar.bz2
serd-9bc71471086b9f5d5789d76fb28a45c47a058cf8.zip
Add SerdSinkInterface and hide implementations
Diffstat (limited to 'tests')
-rw-r--r--tests/read_chunk_test.c9
-rw-r--r--tests/serd_test.c34
2 files changed, 16 insertions, 27 deletions
diff --git a/tests/read_chunk_test.c b/tests/read_chunk_test.c
index aadbe2c8..ed648e5f 100644
--- a/tests/read_chunk_test.c
+++ b/tests/read_chunk_test.c
@@ -59,13 +59,8 @@ on_end(void* handle, const SerdNode* node)
int
main(int argc, char** argv)
{
- SerdReader* reader = serd_reader_new(SERD_TURTLE,
- NULL,
- NULL,
- on_base,
- on_prefix,
- on_statement,
- on_end);
+ SerdSinkInterface sink = { 0, on_base, on_prefix, on_statement, on_end };
+ SerdReader* reader = serd_reader_new(SERD_TURTLE, &sink);
if (!reader) {
FAIL("Failed to create reader\n");
}
diff --git a/tests/serd_test.c b/tests/serd_test.c
index b96de49f..9fd52852 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -504,12 +504,13 @@ main(void)
serd_writer_chop_blank_prefix(writer, "tmp");
serd_writer_chop_blank_prefix(writer, NULL);
- if (!serd_writer_set_base_uri(writer, lit)) {
+ const SerdSinkInterface* iface = serd_writer_get_sink_interface(writer);
+ if (!iface->base(iface->handle, lit)) {
FAILF("Set base URI to %s\n", serd_node_get_string(lit));
- } else if (!serd_writer_set_prefix(writer, lit, lit)) {
+ } else if (!iface->prefix(iface->handle, lit, lit)) {
FAILF("Set prefix %s to %s\n",
serd_node_get_string(lit), serd_node_get_string(lit));
- } else if (!serd_writer_end_anon(writer, NULL)) {
+ } else if (!iface->end(iface->handle, NULL)) {
FAIL("Ended non-existent anonymous node\n");
} else if (serd_writer_get_env(writer) != env) {
FAIL("Writer has incorrect env\n");
@@ -532,8 +533,8 @@ main(void)
{ s, p, NULL },
{ NULL, NULL, NULL } };
for (unsigned i = 0; i < sizeof(junk) / (sizeof(SerdNode*) * 5); ++i) {
- if (!serd_writer_write_statement(
- writer, 0, NULL,
+ if (!iface->statement(
+ iface->handle, 0, NULL,
junk[i][0], junk[i][1], junk[i][2])) {
FAILF("Successfully wrote junk statement %d\n", i);
}
@@ -552,8 +553,8 @@ main(void)
{ s, p, o },
{ s, p, o } };
for (unsigned i = 0; i < sizeof(good) / (sizeof(SerdNode*) * 5); ++i) {
- if (serd_writer_write_statement(
- writer, 0, NULL, good[i][0], good[i][1], good[i][2])) {
+ if (iface->statement(
+ iface->handle, 0, NULL, good[i][0], good[i][1], good[i][2])) {
FAILF("Failed to write good statement %d\n", i);
}
}
@@ -562,11 +563,9 @@ main(void)
const char bad_str[] = { (char)0xFF, (char)0x90, 'h', 'i', 0 };
SerdNode* bad_lit = serd_node_new_string(SERD_LITERAL, bad_str);
SerdNode* bad_uri = serd_node_new_string(SERD_URI, bad_str);
- if (serd_writer_write_statement(writer, 0, NULL,
- s, p, bad_lit)) {
+ if (iface->statement(iface->handle, 0, NULL, s, p, bad_lit)) {
FAIL("Failed to write junk UTF-8 literal\n");
- } else if (serd_writer_write_statement(writer, 0, NULL,
- s, p, bad_uri)) {
+ } else if (iface->statement(iface->handle, 0, NULL, s, p, bad_uri)) {
FAIL("Failed to write junk UTF-8 URI\n");
}
serd_node_free(bad_uri);
@@ -575,8 +574,7 @@ main(void)
// Write 1 valid statement
serd_node_free(o);
o = serd_node_new_string(SERD_LITERAL, "hello");
- if (serd_writer_write_statement(writer, 0, NULL,
- s, p, o)) {
+ if (iface->statement(iface->handle, 0, NULL, s, p, o)) {
FAIL("Failed to write valid statement\n");
}
@@ -611,16 +609,12 @@ main(void)
// Rewind and test reader
fseek(fd, 0, SEEK_SET);
- ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
- SerdReader* reader = serd_reader_new(
- SERD_TURTLE, rt, free,
- NULL, NULL, test_sink, NULL);
+ ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
+ SerdSinkInterface sink = { rt, NULL, NULL, test_sink, NULL };
+ SerdReader* reader = serd_reader_new(SERD_TURTLE, &sink);
if (!reader) {
FAIL("Failed to create reader\n");
}
- if (serd_reader_get_handle(reader) != rt) {
- FAIL("Corrupt reader handle\n");
- }
SerdNode* g = serd_node_new_string(SERD_URI, "http://example.org/");
serd_reader_set_default_graph(reader, g);