nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 0609d1b3eb8381cf3144f362c3e7bad668d5511c
parent edb4c964489bdf862bf0db918ebe264bf12bb3e3
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Fri,  8 May 2020 21:16:50 +0200

tests: check stralloc allocation size behavior

Diffstat:
Mtests/unittest_stralloc.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)

diff --git a/tests/unittest_stralloc.c b/tests/unittest_stralloc.c @@ -17,12 +17,66 @@ START_TEST(test_stralloc_thingy) } END_TEST +START_TEST(test_stralloc_sizes) +{ + stralloc thingy = {0}; + const char *input = "thingy"; + unsigned int olen; + + // make room for exactly 42 bytes + int r = stralloc_ready(&thingy, 42); + ck_assert_int_eq(r, 1); + ck_assert_uint_eq(thingy.len, 0); + ck_assert_uint_eq(thingy.a, 42); + // make sure that there is room for 42 more bytes + // given that there are 42 bytes in it and nothing is used this does nothing + r = stralloc_readyplus(&thingy, 42); + ck_assert_int_eq(r, 1); + ck_assert_uint_eq(thingy.len, 0); + ck_assert_uint_eq(thingy.a, 42); + // make sure there is room for 16 more bytes + // there is already more room available, so this does nothing + r = stralloc_readyplus(&thingy, 16); + ck_assert_int_eq(r, 1); + ck_assert_uint_eq(thingy.len, 0); + ck_assert_uint_eq(thingy.a, 42); + + r = stralloc_copys(&thingy,input); + ck_assert_int_eq(r, 1); + ck_assert_uint_eq(thingy.len, strlen(input)); + ck_assert_uint_eq(thingy.a, 42); + + r = stralloc_0(&thingy); + ck_assert_int_eq(r, 1); + ck_assert_uint_eq(thingy.len, strlen(input) + 1); + ck_assert_uint_eq(thingy.a, 42); + + // make sure that there is room for 42 more bytes + r = stralloc_readyplus(&thingy, 42); + ck_assert_int_eq(r, 1); + ck_assert_uint_eq(thingy.len, strlen(input) + 1); + ck_assert_uint_ge(thingy.a, thingy.len + 42); + olen = thingy.a; + + // another stralloc_ready should not touch anything + r = stralloc_ready(&thingy, 42); + ck_assert_int_eq(r, 1); + ck_assert_uint_eq(thingy.len, strlen(input) + 1); + ck_assert_uint_ge(thingy.a, olen); + + ck_assert_str_eq(input, thingy.s); + + alloc_free(thingy.s); +} +END_TEST + TCase *stralloc_something(void) { TCase *tc = tcase_create("basic operations"); tcase_add_test(tc, test_stralloc_thingy); + tcase_add_test(tc, test_stralloc_sizes); return tc; }