aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-26 16:08:56 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-26 16:08:56 +0100
commit98b2731a56d7044e9208fc08895373a8bbbfe8f9 (patch)
tree17bc6854126a8c0f0e7dcc667fb389c2b481fc82
parentccb43b0f6d3c1577ffb32053d8436aee69e0aea9 (diff)
libio: add a test case for append_sparse fallback implementation
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--tests/libio/Makemodule.am7
-rw-r--r--tests/libio/sparse_fb.c66
2 files changed, 71 insertions, 2 deletions
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 <goliath@infraroot.at>
+ */
+#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;
+}