Mercurial > libbuf
view test/test-putc.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-putc.c -- test buf_putc * * 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(putc, empty) { struct buf b = {0}; /* This will allocate one byte and then increase by power of two. */ RX_INT_REQUIRE_EQUAL(buf_putc(&b, 'a'), 0); RX_STR_REQUIRE_EQUAL(b.data, "a"); RX_UINT_REQUIRE_EQUAL(b.length, 1U); RX_UINT_REQUIRE_EQUAL(b.capacity, 1U); RX_INT_REQUIRE_EQUAL(buf_putc(&b, 'b'), 0); RX_STR_REQUIRE_EQUAL(b.data, "ab"); RX_UINT_REQUIRE_EQUAL(b.length, 2U); RX_UINT_REQUIRE_EQUAL(b.capacity, 2U); RX_INT_REQUIRE_EQUAL(buf_putc(&b, 'c'), 0); RX_STR_REQUIRE_EQUAL(b.data, "abc"); RX_UINT_REQUIRE_EQUAL(b.length, 3U); RX_UINT_REQUIRE_EQUAL(b.capacity, 4U); /* No reallocation since there is still one byte left. */ RX_INT_REQUIRE_EQUAL(buf_putc(&b, 'd'), 0); RX_STR_REQUIRE_EQUAL(b.data, "abcd"); RX_UINT_REQUIRE_EQUAL(b.length, 4U); RX_UINT_REQUIRE_EQUAL(b.capacity, 4U); /* New reallocation here. */ RX_INT_REQUIRE_EQUAL(buf_putc(&b, 'e'), 0); RX_STR_REQUIRE_EQUAL(b.data, "abcde"); RX_UINT_REQUIRE_EQUAL(b.length, 5U); RX_UINT_REQUIRE_EQUAL(b.capacity, 8U); buf_finish(&b); } int main(int argc, char **argv) { return rx_main(0, NULL, argc, (const char **)argv) == RX_SUCCESS ? 0 : 1; }