From a3b6babaf0186b34d801a75b62253573ef26a154 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 10 May 2018 20:59:45 +0200 Subject: Hide fopen wrapper and use reader interface consistently --- tests/serd_test.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'tests') 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"); -- cgit v1.2.1