From 20da8374e9da7009da7fe7cfbf81387f6cc94dc6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 25 Oct 2010 10:29:18 +0100 Subject: Modify test for dynstr_fwrite to check that it wrote correctly. --- unittests.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.1