rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 9c5aa667b93e1cf5d378c1abdf673eeaeb600469
parent 962db29c4f3781e546a0c2f6b60670ba7ba36333
Author: vaplv <vaplv@free.fr>
Date:   Fri, 26 May 2017 14:23:14 +0200

Add and test the big_buffer clear function

Diffstat:
Msrc/big_buffer.h | 6++++++
Msrc/test_big_buffer.c | 42++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/src/big_buffer.h b/src/big_buffer.h @@ -378,6 +378,12 @@ error: goto exit; } +static FINLINE res_T +BIGBUF_FUNC__(clear)(struct BIGBUF__* bigbuf) +{ + return BIGBUF_FUNC__(resize)(bigbuf, 0); +} + static INLINE res_T BIGBUF_FUNC__(set) (struct BIGBUF__* bigbuf, const size_t at, const BIGBUF_DATA* data) diff --git a/src/test_big_buffer.c b/src/test_big_buffer.c @@ -134,6 +134,20 @@ test_byte(struct mem_allocator* allocator) CHECK((size_t)byte, i); } + CHECK(bigbuf_byte_clear(&bytes), RES_OK); + CHECK(bigbuf_byte_size_get(&bytes), 0); + CHECK(bigbuf_byte_at(&bytes, 0, &byte), RES_BAD_ARG); + CHECK(bigbuf_byte_set(&bytes, 0, &byte), RES_BAD_ARG); + FOR_EACH(i, 0, 16) { + byte = (char)i; + CHECK(bigbuf_byte_push_back(&bytes, &byte), RES_OK); + } + CHECK(bigbuf_byte_size_get(&bytes), 16); + FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { + CHECK(bigbuf_byte_at(&bytes, i, &byte), RES_OK); + CHECK((size_t)byte, i); + } + bigbuf_byte_release(&bytes); } @@ -218,6 +232,20 @@ test_integer(struct mem_allocator* allocator) CHECK(integer, -(int)i); } + CHECK(bigbuf_integer_clear(&ints2), RES_OK); + CHECK(bigbuf_integer_size_get(&ints2), 0); + CHECK(bigbuf_integer_at(&ints2, 0, &integer), RES_BAD_ARG); + CHECK(bigbuf_integer_set(&ints2, 0, &integer), RES_BAD_ARG); + FOR_EACH(i, 0, 64) { + integer = (int)i; + CHECK(bigbuf_integer_push_back(&ints2, &integer), RES_OK); + } + CHECK(bigbuf_integer_size_get(&ints2), 64); + FOR_EACH(i, 0, bigbuf_integer_size_get(&ints2)) { + CHECK(bigbuf_integer_at(&ints2, i, &integer), RES_OK); + CHECK(integer, (int)i); + } + bigbuf_integer_release(&ints2); fclose(stream); } @@ -311,6 +339,20 @@ test_real(struct mem_allocator* allocator) } } + CHECK(bigbuf_real_clear(&reals2), RES_OK); + CHECK(bigbuf_real_size_get(&reals2), 0); + CHECK(bigbuf_real_at(&reals2, 0, &real), RES_BAD_ARG); + CHECK(bigbuf_real_set(&reals2, 0, &real), RES_BAD_ARG); + FOR_EACH(i, 0, 64) { + real = (double)i; + CHECK(bigbuf_real_push_back(&reals2, &real), RES_OK); + } + CHECK(bigbuf_real_size_get(&reals2), 64); + FOR_EACH(i, 0, bigbuf_real_size_get(&reals2)) { + CHECK(bigbuf_real_at(&reals2, i, &real), RES_OK); + CHECK(real, (double)i); + } + bigbuf_real_release(&reals); bigbuf_real_release(&reals2); fclose(stream);