aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-03-18 15:41:58 +0000
committerDavid Robillard <d@drobilla.net>2012-03-18 15:41:58 +0000
commit91ae836711ba3df5f44407dadcadb0bd9ac53621 (patch)
treef01047babb9d09230aa8a774e20bbe7cff505c3e /tests
parent90830a30aa7e16b4ebb3a249f1456da174b1eca3 (diff)
downloadserd-91ae836711ba3df5f44407dadcadb0bd9ac53621.tar.gz
serd-91ae836711ba3df5f44407dadcadb0bd9ac53621.tar.bz2
serd-91ae836711ba3df5f44407dadcadb0bd9ac53621.zip
Add serd_reader_set_default_graph() for reading a file as a named graph.
git-svn-id: http://svn.drobilla.net/serd/trunk@338 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'tests')
-rw-r--r--tests/serd_test.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 3a4584ed..73276204 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -59,17 +59,24 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri)
return SERD_SUCCESS;
}
+typedef struct {
+ int n_statements;
+ const SerdNode* graph;
+} ReaderTest;
+
static SerdStatus
-count_statements(void* handle,
- SerdStatementFlags flags,
- const SerdNode* graph,
- const SerdNode* subject,
- const SerdNode* predicate,
- const SerdNode* object,
- const SerdNode* object_datatype,
- const SerdNode* object_lang)
+test_sink(void* handle,
+ SerdStatementFlags flags,
+ const SerdNode* graph,
+ const SerdNode* subject,
+ const SerdNode* predicate,
+ const SerdNode* object,
+ const SerdNode* object_datatype,
+ const SerdNode* object_lang)
{
- ++*(int*)handle;
+ ReaderTest* rt = (ReaderTest*)handle;
+ ++rt->n_statements;
+ rt->graph = graph;
return SERD_SUCCESS;
}
@@ -459,9 +466,6 @@ main()
return failure("Failed to open file %s\n", path);
}
- int* n_statements = (int*)malloc(sizeof(int));
- *n_statements = 0;
-
SerdWriter* writer = serd_writer_new(
SERD_TURTLE, (SerdStyle)0, env, NULL, serd_file_sink, fd);
if (!writer) {
@@ -567,16 +571,22 @@ main()
// Rewind and test reader
fseek(fd, 0, SEEK_SET);
+ ReaderTest* rt = (ReaderTest*)malloc(sizeof(ReaderTest));
+ rt->n_statements = 0;
+ rt->graph = NULL;
+
SerdReader* reader = serd_reader_new(
- SERD_TURTLE, n_statements, free,
- NULL, NULL, count_statements, NULL);
+ SERD_TURTLE, rt, free,
+ NULL, NULL, test_sink, NULL);
if (!reader) {
return failure("Failed to create reader\n");
}
- if (serd_reader_get_handle(reader) != n_statements) {
+ if (serd_reader_get_handle(reader) != rt) {
return failure("Corrupt reader handle\n");
}
+ SerdNode g = serd_node_from_string(SERD_URI, USTR("http://example.org/"));
+ serd_reader_set_default_graph(reader, &g);
serd_reader_add_blank_prefix(reader, USTR("tmp"));
serd_reader_add_blank_prefix(reader, NULL);
@@ -591,8 +601,11 @@ main()
return failure("Error reading file (%s)\n", serd_strerror(st));
}
- if (*n_statements != 12) {
- return failure("Bad statement count %d\n", *n_statements);
+ if (rt->n_statements != 12) {
+ return failure("Bad statement count %d\n", rt->n_statements);
+ } else if (!rt->graph || !rt->graph->buf ||
+ strcmp((const char*)rt->graph->buf, "http://example.org/")) {
+ return failure("Bad graph %p\n", rt->graph);
}
if (!serd_reader_read_string(reader, USTR("This isn't Turtle at all."))) {