diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-10-22 21:19:56 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-10-22 21:19:56 +0100 |
commit | 7902dbd60f7469896e7315ba3ef354212a2e7f40 (patch) | |
tree | ace3f171f39717474ebd0ba27a2c84d27a368714 | |
parent | 0e8324567b8f9cf7263619857c3c392d004c9fec (diff) | |
download | dynstr-7902dbd60f7469896e7315ba3ef354212a2e7f40.tar.gz |
Free up some more strings used by unit tests.
-rw-r--r-- | unittests.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/unittests.c b/unittests.c index 4fc121d..81753c9 100644 --- a/unittests.c +++ b/unittests.c @@ -205,6 +205,8 @@ static int test_creates_from_cstring(void) size = dynstr_memcpy(newbytes, dynstr, 0, strlen(bytes)); FAIL_UNLESS_EQUAL(size, strlen(bytes)); FAIL_UNLESS_EQUAL(memcmp(bytes, newbytes, sizeof(bytes)), 0); + + dynstr_free(dynstr); return true; } @@ -222,6 +224,8 @@ static int test_creates_from_memory(void) size = dynstr_memcpy(newbytes, dynstr, 0, sizeof(bytes)); FAIL_UNLESS_EQUAL(size, sizeof(bytes)); FAIL_UNLESS_EQUAL(memcmp(bytes, newbytes, sizeof(bytes)), 0); + + dynstr_free(dynstr); return true; } @@ -244,6 +248,7 @@ static int test_creates_from_constant_cstring(void) dynstr_memcpy(newbytes, dynstr, 0, strlen(bytes)); FAIL_UNLESS_EQUAL(memcmp(bytes, newbytes, sizeof(bytes)), 0); + dynstr_free(dynstr); return true; } @@ -266,6 +271,7 @@ static int test_creates_from_constant_memory(void) dynstr_memcpy(newbytes, dynstr, 0, sizeof(bytes)); FAIL_UNLESS_EQUAL(memcmp(bytes, newbytes, sizeof(bytes)), 0); + dynstr_free(dynstr); return true; } @@ -278,6 +284,7 @@ static int test_memcpy_returns_zero_if_offset_is_too_large(void) dynstr = dynstr_new_from_cstring("hello"); FAIL_UNLESS_EQUAL(dynstr_memcpy(mem, dynstr, dynstr_len(dynstr), 1), 0); FAIL_UNLESS_EQUAL(dynstr_memcpy(mem, dynstr, dynstr_len(dynstr) + 1, 1), 0); + dynstr_free(dynstr); return true; } @@ -292,6 +299,7 @@ static int test_memcpy_truncates_if_copying_too_much(void) len = dynstr_len(dynstr); FAIL_UNLESS_EQUAL(dynstr_memcpy(mem, dynstr, 0, len), len); FAIL_UNLESS_EQUAL(dynstr_memcpy(mem, dynstr, 0, len + 1), len); + dynstr_free(dynstr); return true; } @@ -307,6 +315,7 @@ static int test_memcpy_copies_whole_string_ok(void) len = dynstr_len(dynstr); dynstr_memcpy(mem, dynstr, 0, len); FAIL_UNLESS_EQUAL(memcmp(data, mem, len), 0); + dynstr_free(dynstr); return true; } @@ -322,6 +331,7 @@ static int test_memcpy_copies_substring_ok(void) len = dynstr_len(dynstr); dynstr_memcpy(mem, dynstr, 1, len-2); FAIL_UNLESS_EQUAL(memcmp(data + 1, mem, len-2), 0); + dynstr_free(dynstr); return true; } @@ -337,6 +347,8 @@ static int test_copies_empty_substring_ok(void) sub = dynstr_substr(dynstr, 1, 0); size = dynstr_memcpy(buf, sub, 0, dynstr_len(sub)); FAIL_UNLESS_EQUAL(size, 0); + dynstr_free(dynstr); + dynstr_free(sub); return true; } @@ -353,6 +365,8 @@ static int test_copies_single_byte_substring_ok(void) size = dynstr_memcpy(buf, sub, 0, dynstr_len(sub)); FAIL_UNLESS_EQUAL(size, 1); FAIL_UNLESS_EQUAL(memcmp(buf, "b", 1), 0); + dynstr_free(dynstr); + dynstr_free(sub); return true; } @@ -369,6 +383,8 @@ static int test_copies_middle_substring_ok(void) size = dynstr_memcpy(buf, sub, 0, dynstr_len(sub)); FAIL_UNLESS_EQUAL(size, 4); FAIL_UNLESS_EQUAL(memcmp(buf, "bcde", 4), 0); + dynstr_free(dynstr); + dynstr_free(sub); return true; } @@ -385,6 +401,8 @@ static int test_copies_initial_substring_ok(void) size = dynstr_memcpy(buf, sub, 0, dynstr_len(sub)); FAIL_UNLESS_EQUAL(size, 5); FAIL_UNLESS_EQUAL(memcmp(buf, "abcde", 5), 0); + dynstr_free(dynstr); + dynstr_free(sub); return true; } @@ -401,6 +419,8 @@ static int test_copies_final_substring_ok(void) size = dynstr_memcpy(buf, sub, 0, dynstr_len(sub)); FAIL_UNLESS_EQUAL(size, 5); FAIL_UNLESS_EQUAL(memcmp(buf, "bcdef", 5), 0); + dynstr_free(dynstr); + dynstr_free(sub); return true; } @@ -416,6 +436,8 @@ static int test_copies_empty_substring_when_offset_too_big(void) sub = dynstr_substr(dynstr, 100, 1); size = dynstr_memcpy(buf, sub, 0, dynstr_len(sub)); FAIL_UNLESS_EQUAL(size, 0); + dynstr_free(dynstr); + dynstr_free(sub); return true; } @@ -432,6 +454,8 @@ static int test_copies_partial_substring_when_length_too_big(void) size = dynstr_memcpy(buf, sub, 0, dynstr_len(sub)); FAIL_UNLESS_EQUAL(size, 5); FAIL_UNLESS_EQUAL(memcmp(buf, "bcdef", 5), 0); + dynstr_free(dynstr); + dynstr_free(sub); return true; } @@ -450,6 +474,9 @@ static int test_cats_ok(void) size = dynstr_memcpy(buf, c, 0, dynstr_len(c)); FAIL_UNLESS_EQUAL(size, 6); FAIL_UNLESS_EQUAL(memcmp(buf, "abcdef", 6), 0); + dynstr_free(a); + dynstr_free(b); + dynstr_free(c); return true; } @@ -465,6 +492,8 @@ static int test_cat_returns_NULL_for_first_malloc_failure(void) dynstr_set_malloc(fail_malloc); c = dynstr_cat(a, b, NULL); FAIL_UNLESS_EQUAL(c, NULL); + dynstr_free(a); + dynstr_free(b); return true; } @@ -481,6 +510,8 @@ static int test_cat_returns_NULL_for_second_malloc_failure(void) fail_malloc_after = 1; c = dynstr_cat(a, b, NULL); FAIL_UNLESS_EQUAL(c, NULL); + dynstr_free(a); + dynstr_free(b); return true; } |