aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-10 20:59:45 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 18:23:15 +0200
commita3b6babaf0186b34d801a75b62253573ef26a154 (patch)
tree22d0d45a45827da2025073660a38c0a39f5fbba3 /tests
parent8d1dcc05f7072651c0056221d00d8f1bf3fb80a1 (diff)
downloadserd-a3b6babaf0186b34d801a75b62253573ef26a154.tar.gz
serd-a3b6babaf0186b34d801a75b62253573ef26a154.tar.bz2
serd-a3b6babaf0186b34d801a75b62253573ef26a154.zip
Hide fopen wrapper and use reader interface consistently
Diffstat (limited to 'tests')
-rw-r--r--tests/serd_test.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 5b60a03c..f5761fe7 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -632,8 +632,8 @@ main(void)
// Rewind and test reader
fseek(fd, 0, SEEK_SET);
- ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
- SerdSinkInterface sink = { rt, NULL, NULL, test_sink, NULL };
+ ReaderTest rt = { 0, NULL };
+ SerdSinkInterface sink = { &rt, NULL, NULL, test_sink, NULL };
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, &sink);
if (!reader) {
FAIL("Failed to create reader\n");
@@ -645,23 +645,25 @@ main(void)
serd_reader_add_blank_prefix(reader, NULL);
serd_node_free(g);
- if (!serd_reader_read_file(reader, "http://notafile")) {
- FAIL("Apparently read an http URI\n");
- } else if (!serd_reader_read_file(reader, "file:///better/not/exist")) {
- FAIL("Apparently read a non-existent file\n");
- } else if (!serd_reader_read_file(reader, "file://")) {
- FAIL("Apparently read a file with no path\n");
- }
-
- const SerdStatus st = serd_reader_read_file(reader, path);
- if (st) {
- FAILF("Error reading file (%s)\n", serd_strerror(st));
- } else if (rt->n_statements != 13) {
- FAILF("Bad statement count %d\n", rt->n_statements);
- } else if (!rt->graph || !serd_node_get_string(rt->graph) ||
- strcmp(serd_node_get_string(rt->graph), "http://example.org/")) {
- FAILF("Bad graph %p\n", rt->graph);
- }
+ if (!serd_reader_start_file(reader, "http://notafile", false)) {
+ FAIL("Apparently can read an http URI\n");
+ } else if (!serd_reader_start_file(reader, "file://invalid", false)) {
+ FAIL("Apparently can read an invalid file URI\n");
+ } else if (!serd_reader_start_file(reader, "file:///nonexistant", false)) {
+ FAIL("Apparently can read a non-existent file\n");
+ }
+
+ if (serd_reader_start_file(reader, path, true)) {
+ FAIL("Failed to open test file\n");
+ } else if (serd_reader_read_document(reader)) {
+ FAIL("Failed reading test document\n");
+ } else if (rt.n_statements != 13) {
+ FAILF("Bad statement count %d\n", rt.n_statements);
+ } else if (!rt.graph || !serd_node_get_string(rt.graph) ||
+ strcmp(serd_node_get_string(rt.graph), "http://example.org/")) {
+ FAILF("Bad graph %p\n", rt.graph);
+ }
+ serd_reader_end_stream(reader);
if (!serd_reader_read_string(reader, "This isn't Turtle at all.")) {
FAIL("Parsed invalid string successfully.\n");