diff options
Diffstat (limited to 'lib/io/test')
-rw-r--r-- | lib/io/test/istream_mem.c | 1 | ||||
-rw-r--r-- | lib/io/test/istream_read.c | 105 | ||||
-rw-r--r-- | lib/io/test/istream_skip.c | 94 | ||||
-rw-r--r-- | lib/io/test/stream_splice.c | 98 | ||||
-rw-r--r-- | lib/io/test/xfrm.c | 7 |
5 files changed, 5 insertions, 300 deletions
diff --git a/lib/io/test/istream_mem.c b/lib/io/test/istream_mem.c index f364fd3..d5e0c2c 100644 --- a/lib/io/test/istream_mem.c +++ b/lib/io/test/istream_mem.c @@ -8,6 +8,7 @@ #include "util/test.h" #include "io/mem.h" +#include "sqfs/io.h" static const size_t end0 = 449; /* region 1: filled with 'A' */ static const size_t end1 = 521; /* region 2: filled with 'B' */ diff --git a/lib/io/test/istream_read.c b/lib/io/test/istream_read.c deleted file mode 100644 index 66fec4b..0000000 --- a/lib/io/test/istream_read.c +++ /dev/null @@ -1,105 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * istream_read.c - * - * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "io/istream.h" -#include "util/test.h" -#include "io/mem.h" - -static const sqfs_u64 end0 = 449; /* region 1: filled with 'A' */ -static const sqfs_u64 end1 = 521; /* region 2: filled with 'B' */ -static const sqfs_u64 end2 = 941; /* region 3: filled with 'C' */ - -static sqfs_u8 rd_buffer[941]; - -static sqfs_u8 byte_at_offset(sqfs_u64 off) -{ - if (off < end0) - return 'A'; - if (off < end1) - return 'B'; - return 'C'; -} - -static void init_rd_buffer(void) -{ - for (size_t i = 0; i < end2; ++i) - rd_buffer[i] = byte_at_offset(i); -} - -int main(int argc, char **argv) -{ - sqfs_u8 read_buffer[61]; - sqfs_u64 read_off = 0; - sqfs_istream_t *dummy; - (void)argc; (void)argv; - - init_rd_buffer(); - dummy = istream_memory_create("dummy file", 103, - rd_buffer, sizeof(rd_buffer)); - TEST_NOT_NULL(dummy); - - /* region 1 */ - while (read_off < end0) { - size_t read_diff = end0 - read_off; - - if (read_diff > sizeof(read_buffer)) - read_diff = sizeof(read_buffer); - - int ret = istream_read(dummy, read_buffer, read_diff); - TEST_ASSERT(ret > 0); - TEST_ASSERT((size_t)ret <= read_diff); - - for (int i = 0; i < ret; ++i) { - TEST_EQUAL_UI(read_buffer[i], 'A'); - } - - read_off += ret; - } - - /* region 2 */ - while (read_off < end1) { - size_t read_diff = end1 - read_off; - - if (read_diff > sizeof(read_buffer)) - read_diff = sizeof(read_buffer); - - int ret = istream_read(dummy, read_buffer, read_diff); - TEST_ASSERT(ret > 0); - TEST_ASSERT((size_t)ret <= read_diff); - - for (int i = 0; i < ret; ++i) { - TEST_EQUAL_UI(read_buffer[i], 'B'); - } - - read_off += ret; - } - - /* region 3 */ - for (;;) { - size_t read_diff = sizeof(read_buffer); - - int ret = istream_read(dummy, read_buffer, read_diff); - TEST_ASSERT(ret >= 0); - TEST_ASSERT((size_t)ret <= read_diff); - - if (ret == 0) { - TEST_EQUAL_UI(read_off, end2); - break; - } - - for (int i = 0; i < ret; ++i) { - TEST_EQUAL_UI(read_buffer[i], 'C'); - } - - read_off += ret; - TEST_ASSERT(read_off <= end2); - } - - sqfs_drop(dummy); - return EXIT_SUCCESS; -} diff --git a/lib/io/test/istream_skip.c b/lib/io/test/istream_skip.c deleted file mode 100644 index 0fc3e11..0000000 --- a/lib/io/test/istream_skip.c +++ /dev/null @@ -1,94 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * istream_skip.c - * - * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "io/istream.h" -#include "util/test.h" -#include "io/mem.h" - -static const sqfs_u64 end0 = 449; /* region 1: filled with 'A' */ -static const sqfs_u64 end1 = 521; /* region 2: filled with 'B' */ -static const sqfs_u64 end2 = 941; /* region 3: filled with 'C' */ - -static sqfs_u8 rd_buffer[941]; - -static sqfs_u8 byte_at_offset(sqfs_u64 off) -{ - if (off < end0) - return 'A'; - if (off < end1) - return 'B'; - return 'C'; -} - -static void init_rd_buffer(void) -{ - for (size_t i = 0; i < end2; ++i) - rd_buffer[i] = byte_at_offset(i); -} - -int main(int argc, char **argv) -{ - sqfs_u8 read_buffer[61]; - sqfs_u64 read_off = 0; - sqfs_istream_t *dummy; - (void)argc; (void)argv; - - init_rd_buffer(); - dummy = istream_memory_create("dummy file", 103, - rd_buffer, sizeof(rd_buffer)); - TEST_NOT_NULL(dummy); - - /* region 1 */ - while (read_off < end0) { - size_t read_diff = end0 - read_off; - - if (read_diff > sizeof(read_buffer)) - read_diff = sizeof(read_buffer); - - int ret = istream_read(dummy, read_buffer, read_diff); - TEST_ASSERT(ret > 0); - TEST_ASSERT((size_t)ret <= read_diff); - - for (int i = 0; i < ret; ++i) { - TEST_EQUAL_UI(read_buffer[i], 'A'); - } - - read_off += ret; - } - - /* region 2 */ - { - int ret = istream_skip(dummy, end2 - end1); - TEST_EQUAL_I(ret, 0); - read_off += (end2 - end1); - } - - /* region 3 */ - for (;;) { - size_t read_diff = sizeof(read_buffer); - - int ret = istream_read(dummy, read_buffer, read_diff); - TEST_ASSERT(ret >= 0); - TEST_ASSERT((size_t)ret <= read_diff); - - if (ret == 0) { - TEST_EQUAL_UI(read_off, end2); - break; - } - - for (int i = 0; i < ret; ++i) { - TEST_EQUAL_UI(read_buffer[i], 'C'); - } - - read_off += ret; - TEST_ASSERT(read_off <= end2); - } - - sqfs_drop(dummy); - return EXIT_SUCCESS; -} diff --git a/lib/io/test/stream_splice.c b/lib/io/test/stream_splice.c deleted file mode 100644 index a9edd76..0000000 --- a/lib/io/test/stream_splice.c +++ /dev/null @@ -1,98 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * stream_splice.c - * - * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "io/istream.h" -#include "io/ostream.h" -#include "io/mem.h" -#include "util/test.h" - -static const sqfs_u64 end0 = 449; /* region 1: filled with 'A' */ -static const sqfs_u64 end1 = 521; /* region 2: filled with 'B' */ -static const sqfs_u64 end2 = 941; /* region 3: filled with 'C' */ - -static sqfs_u8 rd_buffer[941]; - -static sqfs_u8 byte_at_offset(sqfs_u64 off) -{ - if (off < end0) - return 'A'; - if (off < end1) - return 'B'; - return 'C'; -} - -static void init_rd_buffer(void) -{ - for (size_t i = 0; i < end2; ++i) - rd_buffer[i] = byte_at_offset(i); -} - -/*****************************************************************************/ - -static int out_append(sqfs_ostream_t *strm, const void *data, size_t size); - -static sqfs_u64 out_offset = 0; - -static sqfs_ostream_t out = { - { 1, NULL, NULL }, - out_append, - NULL, - NULL, - NULL, -}; - -static int out_append(sqfs_ostream_t *strm, const void *data, size_t size) -{ - const sqfs_u8 *ptr = data; - - TEST_ASSERT(strm == &out); - TEST_ASSERT(size > 0); - - while (size--) { - sqfs_u8 x = *(ptr++); - sqfs_u8 y = byte_at_offset(out_offset++); - - TEST_EQUAL_UI(x, y); - TEST_ASSERT(out_offset <= end2); - } - - return 0; -} - -/*****************************************************************************/ - -int main(int argc, char **argv) -{ - sqfs_u64 total = 0; - sqfs_istream_t *in; - sqfs_s32 ret; - (void)argc; (void)argv; - - init_rd_buffer(); - in = istream_memory_create("memory_in", 109, - rd_buffer, sizeof(rd_buffer)); - TEST_NOT_NULL(in); - - for (;;) { - ret = istream_splice(in, &out, 211); - TEST_ASSERT(ret >= 0); - - if (ret == 0) - break; - - total += ret; - TEST_ASSERT(total <= end2); - TEST_ASSERT(out_offset <= end2); - TEST_EQUAL_UI(total, out_offset); - } - - TEST_EQUAL_UI(total, end2); - TEST_EQUAL_UI(out_offset, end2); - sqfs_drop(in); - return EXIT_SUCCESS; -} diff --git a/lib/io/test/xfrm.c b/lib/io/test/xfrm.c index 1b48e6f..b871610 100644 --- a/lib/io/test/xfrm.c +++ b/lib/io/test/xfrm.c @@ -7,6 +7,7 @@ #include "xfrm/compress.h" #include "xfrm/stream.h" #include "util/test.h" +#include "sqfs/io.h" #include "io/xfrm.h" #include "io/mem.h" @@ -430,15 +431,15 @@ static void run_unpack_test(const void *blob, size_t size) TEST_EQUAL_UI(((sqfs_object_t *)mem_istream)->refcount, 2); for (i = 0; i < (sizeof(orig) - 1); ++i) { - ret = istream_read(istream, &c, 1); + ret = sqfs_istream_read(istream, &c, 1); TEST_EQUAL_I(ret, 1); TEST_EQUAL_I(c, orig[i]); } - ret = istream_read(istream, &c, 1); + ret = sqfs_istream_read(istream, &c, 1); TEST_EQUAL_I(ret, 0); - ret = istream_read(istream, &c, 1); + ret = sqfs_istream_read(istream, &c, 1); TEST_EQUAL_I(ret, 0); sqfs_drop(istream); |