view test/test-reserve.c @ 28:dbdc17e11648

misc: update copyright years
author David Demelier <markand@malikania.fr>
date Sun, 02 Jan 2022 10:15:18 +0100
parents 0cc98943f6e2
children 5493466d6e56
line wrap: on
line source

/*
 * test-reserve.c -- test buf_reserve
 *
 * Copyright (c) 2019-2022 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(reserve, simple)
{
	struct buf b = {0};

	/* Reserve allocates but does not change length. */
	RX_INT_REQUIRE_EQUAL(buf_reserve(&b, 100U), 0);
	RX_REQUIRE(b.data);
	RX_UINT_REQUIRE_EQUAL(b.length, 0U);
	RX_UINT_REQUIRE_EQUAL(b.capacity, 100U);

	/*
	 * Now we have a capacity of 100, if I request 100 again it should not
	 * change capacity.
	 */
	RX_INT_REQUIRE_EQUAL(buf_reserve(&b, 100U), 0);
	RX_REQUIRE(b.data);
	RX_UINT_REQUIRE_EQUAL(b.length, 0U);
	RX_UINT_REQUIRE_EQUAL(b.capacity, 100U);

	/* But if I reserve more, it should. */
	RX_INT_REQUIRE_EQUAL(buf_reserve(&b, 200U), 0);
	RX_REQUIRE(b.data);
	RX_UINT_REQUIRE_EQUAL(b.length, 0U);
	RX_UINT_REQUIRE_EQUAL(b.capacity, 200U);

	buf_finish(&b);
}

int
main(int argc, char **argv)
{
	return rx_main(0, NULL, argc, (const char **)argv) == RX_SUCCESS ? 0 : 1;
}