diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-10-25 10:29:18 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-10-25 10:29:18 +0100 |
commit | 20da8374e9da7009da7fe7cfbf81387f6cc94dc6 (patch) | |
tree | 90d60ebe1e5c818edd3314a4979a4d78c163885a | |
parent | 14f4689353217eb64d95228143f0a9e37bc1c00f (diff) | |
download | dynstr-20da8374e9da7009da7fe7cfbf81387f6cc94dc6.tar.gz |
Modify test for dynstr_fwrite to check that it wrote correctly.
-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; } |