diff options
-rw-r--r-- | unittests.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/unittests.c b/unittests.c index 95ce355..aea00e5 100644 --- a/unittests.c +++ b/unittests.c @@ -966,13 +966,15 @@ static int test_fwrite_writes_string(void) int fd; size_t num_bytes; Dynstr *dynstr; + Dynstr *dynstr2; + char buf[1024]; + int read_bytes; dynstr = new_from_cstring("life is too short for str* and mem* in apps"); fd = mkstemp(tempname); if (fd == -1) abort(); - close(fd); f = fopen(tempname, "w"); num_bytes = dynstr_fwrite(f, dynstr); @@ -981,6 +983,14 @@ static int test_fwrite_writes_string(void) FAIL_UNLESS_EQUAL(num_bytes, dynstr_len(dynstr)); /* FIXME: should compare contents of strings, too */ + read_bytes = read(fd, buf, sizeof(buf)); + if (read_bytes == -1) + abort(); + close(fd); + dynstr2 = dynstr_new_from_memory(buf, read_bytes); + FAIL_UNLESS_EQUAL(read_bytes, dynstr_len(dynstr)); + FAIL_UNLESS_EQUAL(dynstr_cmp(dynstr, dynstr2), 0); + dynstr_free(dynstr2); return true; } |