aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_free_null.c1
-rw-r--r--test/test_overflow.c5
-rw-r--r--test/test_read_chunk.c25
-rw-r--r--test/test_reader_writer.c58
4 files changed, 50 insertions, 39 deletions
diff --git a/test/test_free_null.c b/test/test_free_null.c
index 62615a02..a101379a 100644
--- a/test/test_free_null.c
+++ b/test/test_free_null.c
@@ -24,6 +24,7 @@ int
main(void)
{
serd_free(NULL);
+ serd_byte_source_free(NULL);
serd_byte_sink_free(NULL);
serd_node_free(NULL);
serd_world_free(NULL);
diff --git a/test/test_overflow.c b/test/test_overflow.c
index 8d451f2a..5a65d887 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -24,11 +24,14 @@
static SerdStatus
test(SerdWorld* world, SerdSink* sink, const char* str, size_t stack_size)
{
+ SerdByteSource* byte_source = serd_byte_source_new_string(str, NULL);
+
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0, sink, stack_size);
- serd_reader_start_string(reader, str, NULL);
+ serd_reader_start(reader, byte_source);
const SerdStatus st = serd_reader_read_document(reader);
serd_reader_free(reader);
+ serd_byte_source_free(byte_source);
return st;
}
diff --git a/test/test_read_chunk.c b/test/test_read_chunk.c
index 1bbe2709..1cb19aaf 100644
--- a/test/test_read_chunk.c
+++ b/test/test_read_chunk.c
@@ -94,20 +94,22 @@ main(void)
SerdWorld* world = serd_world_new();
SerdSink* sink = serd_sink_new(NULL, on_event, NULL);
+ SerdByteSource* byte_source =
+ serd_byte_source_new_string("@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",
+ NULL);
+
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0, sink, 4096);
assert(reader);
- 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",
- NULL));
+ assert(!serd_reader_start(reader, byte_source));
assert(!serd_reader_read_chunk(reader) && n_prefix == 1);
assert(!serd_reader_read_chunk(reader) && n_base == 1);
@@ -121,6 +123,7 @@ main(void)
assert(!serd_reader_finish(reader));
serd_reader_free(reader);
+ serd_byte_source_free(byte_source);
serd_sink_free(sink);
serd_world_free(world);
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index a4f57a0f..86c6b442 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -19,7 +19,6 @@
#include "serd/serd.h"
#include <assert.h>
-#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -80,8 +79,10 @@ test_read_chunks(void)
SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0, sink, 4096);
assert(reader);
- SerdStatus st = serd_reader_start_stream(
- reader, (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, f, NULL, 1);
+ SerdByteSource* byte_source = serd_byte_source_new_function(
+ (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, f, NULL, 1);
+
+ SerdStatus st = serd_reader_start(reader, byte_source);
assert(st == SERD_SUCCESS);
// Write two statement separated by null characters
@@ -123,6 +124,7 @@ test_read_chunks(void)
assert(n_statements == 2);
serd_reader_free(reader);
+ serd_byte_source_free(byte_source);
serd_sink_free(sink);
fclose(f);
serd_world_free(world);
@@ -197,18 +199,20 @@ test_read_string(void)
SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0, sink, 4096);
assert(reader);
+ SerdByteSource* byte_source =
+ serd_byte_source_new_string("<http://example.org/s> <http://example.org/p> "
+ "<http://example.org/o> .",
+ NULL);
+
// Test reading a string that ends exactly at the end of input (no newline)
- assert(
- !serd_reader_start_string(reader,
- "<http://example.org/s> <http://example.org/p> "
- "<http://example.org/o> .",
- NULL));
+ assert(!serd_reader_start(reader, byte_source));
assert(!serd_reader_read_document(reader));
assert(n_statements == 1);
assert(!serd_reader_finish(reader));
serd_reader_free(reader);
+ serd_byte_source_free(byte_source);
serd_sink_free(sink);
serd_world_free(world);
}
@@ -334,8 +338,8 @@ test_reader(const char* path)
SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0, sink, 4096);
assert(reader);
- assert(serd_reader_read_document(reader) == SERD_FAILURE);
- assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
+ assert(serd_reader_read_document(reader) == SERD_ERR_BAD_CALL);
+ assert(serd_reader_read_chunk(reader) == SERD_ERR_BAD_CALL);
serd_reader_add_blank_prefix(reader, "tmp");
@@ -348,14 +352,12 @@ test_reader(const char* path)
# pragma GCC diagnostic pop
#endif
- 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));
-
- assert(!serd_reader_start_file(reader, path, true));
+ SerdByteSource* byte_source = serd_byte_source_new_filename(path, 4096);
+ assert(!serd_reader_start(reader, byte_source));
assert(!serd_reader_read_document(reader));
assert(n_statements == 6);
serd_reader_finish(reader);
+ serd_byte_source_free(byte_source);
// A read of a big page hits EOF then fails to read chunks immediately
{
@@ -365,35 +367,37 @@ test_reader(const char* path)
fflush(temp);
fseek(temp, 0L, SEEK_SET);
- serd_reader_start_stream(reader,
- (SerdReadFunc)fread,
- (SerdStreamErrorFunc)ferror,
- temp,
- NULL,
- 4096);
+ byte_source = serd_byte_source_new_function(
+ (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, temp, NULL, 4096);
+ assert(serd_reader_start(reader, byte_source) == SERD_SUCCESS);
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_finish(reader);
+ serd_byte_source_free(byte_source);
fclose(temp);
}
// A byte-wise reader that hits EOF once then continues (like a socket)
{
size_t n_reads = 0;
- serd_reader_start_stream(reader,
- (SerdReadFunc)eof_test_read,
- (SerdStreamErrorFunc)eof_test_error,
- &n_reads,
- NULL,
- 1);
+ byte_source =
+ serd_byte_source_new_function((SerdReadFunc)eof_test_read,
+ (SerdStreamErrorFunc)eof_test_error,
+ &n_reads,
+ NULL,
+ 1);
+
+ assert(serd_reader_start(reader, byte_source) == SERD_SUCCESS);
assert(serd_reader_read_chunk(reader) == SERD_SUCCESS);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
assert(serd_reader_read_chunk(reader) == SERD_SUCCESS);
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
+ assert(!serd_reader_finish(reader));
+ serd_byte_source_free(byte_source);
}
serd_reader_free(reader);