aboutsummaryrefslogtreecommitdiff
path: root/lib/io/test/stream_splice.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/io/test/stream_splice.c')
-rw-r--r--lib/io/test/stream_splice.c56
1 files changed, 19 insertions, 37 deletions
diff --git a/lib/io/test/stream_splice.c b/lib/io/test/stream_splice.c
index c5ca38e..5379b39 100644
--- a/lib/io/test/stream_splice.c
+++ b/lib/io/test/stream_splice.c
@@ -8,12 +8,15 @@
#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)
@@ -23,6 +26,12 @@ static sqfs_u8 byte_at_offset(sqfs_u64 off)
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(ostream_t *strm, const void *data, size_t size);
@@ -57,47 +66,20 @@ static int out_append(ostream_t *strm, const void *data, size_t size)
/*****************************************************************************/
-static int in_precache(istream_t *strm);
-
-static sqfs_u8 in_buffer[109];
-static sqfs_u64 in_offset = 0;
-
-static istream_t in = {
- { 1, NULL, NULL },
- 0,
- 0,
- false,
- in_buffer,
- in_precache,
- NULL,
-};
-
-static int in_precache(istream_t *strm)
-{
- TEST_ASSERT(strm == &in);
-
- while (strm->buffer_used < sizeof(in_buffer)) {
- if (in_offset == end2) {
- strm->eof = true;
- break;
- }
-
- in_buffer[strm->buffer_used++] = byte_at_offset(in_offset++);
- }
-
- return 0;
-}
-
-/*****************************************************************************/
-
int main(int argc, char **argv)
{
sqfs_u64 total = 0;
+ 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 = ostream_append_from_istream(&out, &in, 211);
+ ret = ostream_append_from_istream(&out, in, 211);
TEST_ASSERT(ret >= 0);
if (ret == 0)
@@ -106,13 +88,13 @@ int main(int argc, char **argv)
total += ret;
TEST_ASSERT(total <= end2);
TEST_ASSERT(out_offset <= end2);
- TEST_ASSERT(in_offset <= end2);
- TEST_ASSERT(in_offset >= out_offset);
TEST_EQUAL_UI(total, out_offset);
}
+ TEST_ASSERT(in->eof);
+ TEST_ASSERT(in->buffer_offset >= in->buffer_used);
TEST_EQUAL_UI(total, end2);
TEST_EQUAL_UI(out_offset, end2);
- TEST_EQUAL_UI(in_offset, end2);
+ sqfs_drop(in);
return EXIT_SUCCESS;
}