aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/serd_test.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 3d6b6ac9..8802dc72 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -87,6 +87,33 @@ test_sink(void* handle,
return SERD_SUCCESS;
}
+/// Returns EOF after a statement, then succeeds again (like a socket)
+static size_t
+eof_test_read(void* buf, size_t size, size_t nmemb, void* stream)
+{
+ assert(nmemb == 1);
+
+ static const char* const string = "_:s1 <http://example.org/p> _:o1 .\n"
+ "_:s2 <http://example.org/p> _:o2 .\n";
+
+ size_t* count = (size_t*)stream;
+ if (*count == 34 || *count == 35 || *count + nmemb >= strlen(string)) {
+ ++*count;
+ return 0;
+ }
+
+ memcpy((char*)buf, string + *count, size * nmemb);
+ *count += nmemb;
+ return nmemb;
+}
+
+static int
+eof_test_error(void* stream)
+{
+ (void)stream;
+ return 0;
+}
+
static void
test_file_uri(const char* hostname,
const char* path,
@@ -636,6 +663,40 @@ test_reader(const char* path)
assert(serd_reader_read_string(reader, USTR("This isn't Turtle at all.")));
+ // A read of a big page hits EOF then fails to read chunks immediately
+ {
+ FILE* temp = tmpfile();
+ assert(temp);
+ fprintf(temp, "_:s <http://example.org/p> _:o .\n");
+ fflush(temp);
+ fseek(temp, 0L, SEEK_SET);
+
+ serd_reader_start_stream(reader, temp, NULL, true);
+
+ 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);
+ 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,
+ (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);
+ assert(serd_reader_read_chunk(reader) == SERD_SUCCESS);
+ assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
+ }
+
serd_reader_free(reader);
}