summaryrefslogtreecommitdiff
path: root/test/tokeniser.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/tokeniser.c')
-rw-r--r--test/tokeniser.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/test/tokeniser.c b/test/tokeniser.c
index 0614e78..29a2a7e 100644
--- a/test/tokeniser.c
+++ b/test/tokeniser.c
@@ -59,31 +59,22 @@ int main(int argc, char **argv)
origlen = len = ftell(fp);
fseek(fp, 0, SEEK_SET);
- while (len >= CHUNK_SIZE) {
- fread(buf, 1, CHUNK_SIZE, fp);
-
- assert(parserutils_inputstream_append(stream,
- buf, CHUNK_SIZE) == HUBBUB_OK);
-
- len -= CHUNK_SIZE;
-
- assert(hubbub_tokeniser_run(tok) == HUBBUB_OK);
- }
-
- if (len > 0) {
- fread(buf, 1, len, fp);
-
+ while (len > 0) {
+ ssize_t bytes_read = fread(buf, 1, CHUNK_SIZE, fp);
+
+ if (bytes_read < 1)
+ break;
+
assert(parserutils_inputstream_append(stream,
- buf, len) == HUBBUB_OK);
+ buf, bytes_read) == HUBBUB_OK);
- len = 0;
-
- assert(parserutils_inputstream_append(stream, NULL, 0) ==
- HUBBUB_OK);
+ len -= bytes_read;
assert(hubbub_tokeniser_run(tok) == HUBBUB_OK);
}
-
+
+ assert(len == 0);
+
fclose(fp);
hubbub_tokeniser_destroy(tok);