Mercurial > libbuf
view test/test-shrink.c @ 26:0cc98943f6e2
tests: switch to rexo
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 12 Oct 2021 09:24:18 +0200 |
parents | d87e84936795 |
children | dbdc17e11648 |
line wrap: on
line source
/* * test-shrink.c -- test buf_shrink * * Copyright (c) 2019-2021 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <rexo.h> #include "buf.h" RX_TEST_CASE(shrink, set) { struct buf b = {0}; /* Reserve 10 but write 5 character, shrink should set a capacity of 5. */ RX_INT_REQUIRE_EQUAL(buf_reserve(&b, 10U), 0); RX_INT_REQUIRE_EQUAL(buf_puts(&b, "abcde"), 0); RX_INT_REQUIRE_EQUAL(buf_shrink(&b), 0); RX_STR_REQUIRE_EQUAL(b.data, "abcde"); RX_UINT_REQUIRE_EQUAL(b.length, 5U); RX_UINT_REQUIRE_EQUAL(b.capacity, 5U); buf_finish(&b); } RX_TEST_CASE(shrink, empty) { struct buf b = {0}; /* * Reserve 10, the data should be allocated but since we have a null * length it should be completely free'd. */ RX_INT_REQUIRE_EQUAL(buf_reserve(&b, 10U), 0); RX_INT_REQUIRE_EQUAL(buf_shrink(&b), 0); RX_REQUIRE(!b.data); RX_UINT_REQUIRE_EQUAL(b.length, 0U); RX_UINT_REQUIRE_EQUAL(b.capacity, 0U); buf_finish(&b); } RX_TEST_CASE(shrink, null) { struct buf b = {0}; RX_INT_REQUIRE_EQUAL(buf_shrink(&b), 0); RX_REQUIRE(!b.data); RX_UINT_REQUIRE_EQUAL(b.length, 0U); RX_UINT_REQUIRE_EQUAL(b.capacity, 0U); buf_finish(&b); } int main(int argc, char **argv) { return rx_main(0, NULL, argc, (const char **)argv) == RX_SUCCESS ? 0 : 1; }