From 98b2731a56d7044e9208fc08895373a8bbbfe8f9 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 26 Jan 2023 16:08:56 +0100 Subject: libio: add a test case for append_sparse fallback implementation Signed-off-by: David Oberhollenzer --- tests/libio/Makemodule.am | 7 +++-- tests/libio/sparse_fb.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 tests/libio/sparse_fb.c (limited to 'tests') diff --git a/tests/libio/Makemodule.am b/tests/libio/Makemodule.am index 3676d1a..2803b43 100644 --- a/tests/libio/Makemodule.am +++ b/tests/libio/Makemodule.am @@ -3,9 +3,12 @@ test_get_line_LDADD = libio.a libcompat.a test_get_line_CPPFLAGS = $(AM_CPPFLAGS) test_get_line_CPPFLAGS += -DTESTFILE=$(top_srcdir)/tests/libio/get_line.txt +test_sparse_fb_SOURCES = tests/libio/sparse_fb.c +test_sparse_fb_LDADD = libio.a libutil.a libcompat.a + if BUILD_TOOLS -check_PROGRAMS += test_get_line -TESTS += test_get_line +check_PROGRAMS += test_get_line test_sparse_fb +TESTS += test_get_line test_sparse_fb endif EXTRA_DIST += $(top_srcdir)/tests/libio/get_line.txt diff --git a/tests/libio/sparse_fb.c b/tests/libio/sparse_fb.c new file mode 100644 index 0000000..fa4b840 --- /dev/null +++ b/tests/libio/sparse_fb.c @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * get_line.c + * + * Copyright (C) 2019 David Oberhollenzer + */ +#include "config.h" + +#include "io/ostream.h" +#include "util/test.h" +#include "util/util.h" + +static ostream_t dummy; +static size_t total = 0; + +static int dummy_append(ostream_t *strm, const void *data, size_t size) +{ + bool bret; + + TEST_ASSERT(strm == &dummy); + TEST_NOT_NULL(data); + TEST_ASSERT(size > 0); + + bret = is_memory_zero(data, size); + TEST_ASSERT(bret); + + bret = SZ_ADD_OV(total, size, &total); + TEST_ASSERT(!bret); + return 0; +} + +static int dummy_flush(ostream_t *strm) +{ + TEST_ASSERT(strm == &dummy); + return 0; +} + +static ostream_t dummy = { + { + 1, + NULL, + NULL, + }, + dummy_append, + NULL, + dummy_flush, + NULL, +}; + +int main(int argc, char **argv) +{ + size_t ref; + int ret; + (void)argc; (void)argv; + + ref = 131072 + 1337; + + ret = ostream_append_sparse(&dummy, ref); + TEST_EQUAL_I(ret, 0); + + ret = ostream_flush(&dummy); + TEST_EQUAL_I(ret, 0); + + TEST_EQUAL_UI(ref, total); + return EXIT_SUCCESS; +} -- cgit v1.2.3