diff options
author | David Robillard <d@drobilla.net> | 2021-07-10 15:05:14 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-07-10 15:05:14 -0400 |
commit | acfb9ce1762d5136f846cdfb1356c0126d05f332 (patch) | |
tree | ccbc609a274e8b15d55e5107271c9d2f1d688596 /test | |
parent | a59968ee39851932ec6471e9293e70cfad4ad1df (diff) | |
download | serd-acfb9ce1762d5136f846cdfb1356c0126d05f332.tar.gz serd-acfb9ce1762d5136f846cdfb1356c0126d05f332.tar.bz2 serd-acfb9ce1762d5136f846cdfb1356c0126d05f332.zip |
Clean up socket-like stream reading test
Diffstat (limited to 'test')
-rw-r--r-- | test/test_reader_writer.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 134c7a8e..233a3871 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -55,24 +55,36 @@ test_sink(void* handle, return SERD_SUCCESS; } -/// Returns EOF after a statement, then succeeds again (like a socket) +/// Reads a null byte 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(size == 1); assert(nmemb == 1); + (void)size; 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)) { + size_t* const count = (size_t*)stream; + + // Normal reading for the first statement + if (*count < 35) { + *(char*)buf = string[*count]; + ++*count; + return nmemb; + } + + // EOF for the first read at the start of the second statement + if (*count == 35) { + assert(string[*count] == '_'); ++*count; return 0; } - memcpy((char*)buf, string + *count, size * nmemb); - *count += nmemb; + // Normal reading after the EOF, adjusting for the skipped index 35 + *(char*)buf = string[*count - 1]; + ++*count; return nmemb; } |