aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_read_chunk.c36
-rw-r--r--test/test_reader_writer.c61
2 files changed, 47 insertions, 50 deletions
diff --git a/test/test_read_chunk.c b/test/test_read_chunk.c
index 8dd176e7..ce529b67 100644
--- a/test/test_read_chunk.c
+++ b/test/test_read_chunk.c
@@ -19,8 +19,7 @@
#include "serd/serd.h"
#include <assert.h>
-#include <stdbool.h>
-#include <stdio.h>
+#include <stddef.h>
static size_t n_base = 0;
static size_t n_prefix = 0;
@@ -80,21 +79,6 @@ on_end(void* handle, const SerdNode* node)
int
main(void)
{
- FILE* file = tmpfile();
-
- fprintf(file,
- "@prefix eg: <http://example.org/> .\n"
- "@base <http://example.org/base> .\n"
- "eg:s1 eg:p1 eg:o1 ;\n"
- " eg:p2 eg:o2 ,\n"
- " eg:o3 .\n"
- "eg:s2 eg:p1 eg:o1 ;\n"
- " eg:p2 eg:o2 .\n"
- "eg:s3 eg:p1 eg:o1 .\n"
- "eg:s4 eg:p1 [ eg:p3 eg:o1 ] .\n");
-
- fseek(file, 0, SEEK_SET);
-
SerdSink* sink = serd_sink_new(NULL, NULL);
serd_sink_set_base_func(sink, on_base);
serd_sink_set_prefix_func(sink, on_prefix);
@@ -104,22 +88,30 @@ main(void)
SerdReader* reader = serd_reader_new(SERD_TURTLE, sink);
assert(reader);
- assert(reader);
- assert(!serd_reader_start_stream(reader, file, NULL, true));
+ assert(!serd_reader_start_string(reader,
+ "@prefix eg: <http://example.org/> .\n"
+ "@base <http://example.org/base> .\n"
+ "eg:s1 eg:p1 eg:o1 ;\n"
+ " eg:p2 eg:o2 ,\n"
+ " eg:o3 .\n"
+ "eg:s2 eg:p1 eg:o1 ;\n"
+ " eg:p2 eg:o2 .\n"
+ "eg:s3 eg:p1 eg:o1 .\n"
+ "eg:s4 eg:p1 [ eg:p3 eg:o1 ] .\n"));
assert(!serd_reader_read_chunk(reader) && n_prefix == 1);
assert(!serd_reader_read_chunk(reader) && n_base == 1);
assert(!serd_reader_read_chunk(reader) && n_statement == 3);
assert(!serd_reader_read_chunk(reader) && n_statement == 5);
assert(!serd_reader_read_chunk(reader) && n_statement == 6);
- assert(!serd_reader_read_chunk(reader) && n_statement == 8 && n_end == 1);
+ assert(!serd_reader_read_chunk(reader) && n_statement == 8);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
+ assert(n_end == 1);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
+ assert(!serd_reader_finish(reader));
- assert(!serd_reader_end_stream(reader));
serd_reader_free(reader);
serd_sink_free(sink);
- fclose(file);
return 0;
}
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index ed1c87cb..d5669db0 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -107,7 +107,8 @@ test_read_chunks(void)
assert(f);
serd_sink_set_statement_func(sink, test_sink);
- SerdStatus st = serd_reader_start_stream(reader, f, NULL, false);
+ SerdStatus st = serd_reader_start_stream(
+ reader, (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, f, NULL, 1);
assert(st == SERD_SUCCESS);
// Write two statement separated by null characters
@@ -167,13 +168,14 @@ test_read_string(void)
serd_sink_set_statement_func(sink, test_sink);
// Test reading a string that ends exactly at the end of input (no newline)
- const SerdStatus st =
- serd_reader_read_string(reader,
- "<http://example.org/s> <http://example.org/p> "
- "<http://example.org/o> .");
+ assert(
+ !serd_reader_start_string(reader,
+ "<http://example.org/s> <http://example.org/p> "
+ "<http://example.org/o> ."));
- assert(!st);
+ assert(!serd_reader_read_document(reader));
assert(rt->n_statements == 1);
+ assert(!serd_reader_finish(reader));
serd_reader_free(reader);
serd_sink_free(sink);
@@ -273,12 +275,12 @@ test_writer(const char* const path)
static void
test_reader(const char* path)
{
- ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest));
- SerdSink* const sink = serd_sink_new(rt, NULL);
+ ReaderTest rt = {0, NULL};
+ SerdSink* const sink = serd_sink_new(&rt, NULL);
SerdReader* reader = serd_reader_new(SERD_TURTLE, sink);
- assert(sink);
assert(reader);
+ assert(sink);
serd_sink_set_statement_func(sink, test_sink);
SerdNode* g = serd_new_uri(SERD_STRING("http://example.org/"));
@@ -296,17 +298,16 @@ test_reader(const char* path)
serd_node_free(g);
- assert(serd_reader_read_file(reader, "http://notafile"));
- assert(serd_reader_read_file(reader, "file:///better/not/exist"));
- assert(serd_reader_read_file(reader, "file://"));
+ 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));
- const SerdStatus st = serd_reader_read_file(reader, path);
- assert(!st);
- assert(rt->n_statements == 6);
- assert(rt->graph && serd_node_string(rt->graph) &&
- !strcmp(serd_node_string(rt->graph), "http://example.org/"));
-
- assert(serd_reader_read_string(reader, "This isn't Turtle at all."));
+ 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/"));
+ serd_reader_finish(reader);
// A read of a big page hits EOF then fails to read chunks immediately
{
@@ -316,25 +317,30 @@ test_reader(const char* path)
fflush(temp);
fseek(temp, 0L, SEEK_SET);
- serd_reader_start_stream(reader, temp, NULL, true);
+ serd_reader_start_stream(reader,
+ (SerdReadFunc)fread,
+ (SerdStreamErrorFunc)ferror,
+ temp,
+ NULL,
+ 4096);
assert(serd_reader_read_chunk(reader) == SERD_SUCCESS);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
- serd_reader_end_stream(reader);
+ serd_reader_finish(reader);
fclose(temp);
}
// A byte-wise reader that hits EOF once then continues (like a socket)
{
size_t n_reads = 0;
- serd_reader_start_source_stream(reader,
- (SerdReadFunc)eof_test_read,
- (SerdStreamErrorFunc)eof_test_error,
- &n_reads,
- NULL,
- 1);
+ serd_reader_start_stream(reader,
+ (SerdReadFunc)eof_test_read,
+ (SerdStreamErrorFunc)eof_test_error,
+ &n_reads,
+ NULL,
+ 1);
assert(serd_reader_read_chunk(reader) == SERD_SUCCESS);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
@@ -344,7 +350,6 @@ test_reader(const char* path)
serd_reader_free(reader);
serd_sink_free(sink);
- free(rt);
}
int