aboutsummaryrefslogtreecommitdiffstats
path: root/tests/serd_test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-06-28 23:26:48 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:59 +0100
commita3dda1c84a9a258721e26ef57ac32d548a24c148 (patch)
tree911ee23fdc27a198e0428892d4e1ee844d10caeb /tests/serd_test.c
parentba2dc6b53c8dd840651fc9e2c10790989b9cee9f (diff)
downloadserd-a3dda1c84a9a258721e26ef57ac32d548a24c148.tar.gz
serd-a3dda1c84a9a258721e26ef57ac32d548a24c148.tar.bz2
serd-a3dda1c84a9a258721e26ef57ac32d548a24c148.zip
WIP: Make Reader always read from a ByteSource
Diffstat (limited to 'tests/serd_test.c')
-rw-r--r--tests/serd_test.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index a0fbb234..9f85136e 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -103,12 +103,10 @@ test_read_chunks(void)
assert(reader);
assert(f);
- 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
@@ -150,6 +148,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);
@@ -220,18 +219,19 @@ test_read_string(void)
serd_sink_set_event_func(sink, count_statements);
- // Test reading a string that ends exactly at the end of input (no newline)
- assert(!serd_reader_start_string(
- reader,
+ SerdByteSource* byte_source = serd_byte_source_new_string(
"<http://example.org/s> <http://example.org/p> "
- "<http://example.org/o> .",
- NULL));
+ "<http://example.org/o> .", NULL);
+
+ // Test reading a string that ends exactly at the end of input (no newline)
+ 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);
}
@@ -675,20 +675,23 @@ 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");
serd_reader_add_blank_prefix(reader, NULL);
- 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));
+ // FIXME
+ /* 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 == 13);
serd_reader_finish(reader);
+ serd_byte_source_free(byte_source);
// A read of a big page hits EOF then fails to read chunks immediately
{
@@ -698,31 +701,31 @@ 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);