From 9a8e06aa5bdc62ed589bd8ed5789bd059cec0700 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 16 Aug 2020 12:42:58 +0200 Subject: Simplify reader interface --- test/test_read_chunk.c | 38 +++++++++++++++----------------------- test/test_reader_writer.c | 19 ++++++++++--------- 2 files changed, 25 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/test_read_chunk.c b/test/test_read_chunk.c index dd2961ac..76e9b642 100644 --- a/test/test_read_chunk.c +++ b/test/test_read_chunk.c @@ -19,8 +19,7 @@ #include "serd/serd.h" #include -#include -#include +#include static size_t n_base = 0; static size_t n_prefix = 0; @@ -80,39 +79,32 @@ on_end(void* handle, const SerdNode* node) int main(void) { - FILE* file = tmpfile(); - - fprintf(file, - "@prefix eg: .\n" - "@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); - SerdReader* reader = serd_reader_new( SERD_TURTLE, NULL, NULL, on_base, on_prefix, on_statement, on_end); - assert(reader); - assert(!serd_reader_start_stream(reader, file, NULL, true)); + + assert(!serd_reader_start_string(reader, + "@prefix eg: .\n" + "@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_end_stream(reader)); - serd_reader_free(reader); - fclose(file); + serd_reader_free(reader); return 0; } diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 5431462a..48bb508e 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -19,7 +19,6 @@ #include "serd/serd.h" #include -#include #include #include #include @@ -89,7 +88,8 @@ test_read_chunks(void) assert(serd_reader_handle(reader) == rt); assert(f); - SerdStatus st = serd_reader_start_stream(reader, f, NULL, false); + SerdStatus st = serd_reader_start_stream( + reader, (SerdSource)fread, (SerdStreamErrorFunc)ferror, f, NULL, 1); assert(st == SERD_SUCCESS); // Write two statement separated by null characters @@ -292,7 +292,8 @@ 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, (SerdSource)fread, (SerdStreamErrorFunc)ferror, temp, NULL, 4096); assert(serd_reader_read_chunk(reader) == SERD_SUCCESS); assert(serd_reader_read_chunk(reader) == SERD_FAILURE); @@ -305,12 +306,12 @@ test_reader(const char* path) // A byte-wise reader that hits EOF once then continues (like a socket) { size_t n_reads = 0; - serd_reader_start_source_stream(reader, - (SerdSource)eof_test_read, - (SerdStreamErrorFunc)eof_test_error, - &n_reads, - NULL, - 1); + serd_reader_start_stream(reader, + (SerdSource)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); -- cgit v1.2.1