aboutsummaryrefslogtreecommitdiff
path: root/lib/tar/test/tar_istream3.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-05-20 17:04:15 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-05-22 16:15:45 +0200
commit6351872732fce77186f401050eee92c7c3aa3461 (patch)
treec938233378d13dbc94e08f24e34bb84406b08d21 /lib/tar/test/tar_istream3.c
parent9a97a9a4fe224bcf53ad23af31bca67bbb71a824 (diff)
libtar: add a dir_iterator_t implementation for tar files
The existing istream_t wrapper is mered into this one as well, we can open the files via the iterators open_file_ro function. Unit tests and tar2sqfs are modified accordingly. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar/test/tar_istream3.c')
-rw-r--r--lib/tar/test/tar_istream3.c100
1 files changed, 0 insertions, 100 deletions
diff --git a/lib/tar/test/tar_istream3.c b/lib/tar/test/tar_istream3.c
deleted file mode 100644
index d287081..0000000
--- a/lib/tar/test/tar_istream3.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * tar_istream3.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-#include "io/file.h"
-#include "tar/tar.h"
-#include "util/test.h"
-
-static const struct {
- uint64_t offset;
- size_t size;
- int fill;
-} regions[] = {
- { 0, 4096, 'A' },
- { 262144, 4096, 'B' },
- { 524288, 4096, 'C' },
- { 786432, 4096, 'D' },
- { 1048576, 4096, 'E' },
- { 1310720, 4096, 'F' },
- { 1572864, 4096, 'G' },
- { 1835008, 4096, 'H' },
-};
-
-static int byte_from_offset(uint64_t offset)
-{
- sqfs_u64 diff;
- size_t i;
-
- for (i = 0; i < sizeof(regions) / sizeof(regions[0]); ++i) {
- if (offset >= regions[i].offset) {
- diff = (offset - regions[i].offset);
-
- if (diff < regions[i].size)
- return regions[i].fill;
- }
- }
-
- return '\0';
-}
-
-int main(int argc, char **argv)
-{
- unsigned char buffer[941];
- tar_header_decoded_t hdr;
- istream_t *fp, *ti;
- uint64_t offset;
- sqfs_s32 i, ret;
- (void)argc; (void)argv;
-
- fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE));
- TEST_NOT_NULL(fp);
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.uid, 01750);
- TEST_EQUAL_UI(hdr.gid, 01750);
- TEST_EQUAL_UI(hdr.actual_size, 2097152);
- TEST_EQUAL_UI(hdr.record_size, 32768);
- TEST_STR_EQUAL(hdr.name, "input.bin");
- TEST_ASSERT(!hdr.unknown_record);
-
- ti = tar_record_istream_create(fp, &hdr);
- TEST_EQUAL_UI(((sqfs_object_t *)fp)->refcount, 2);
- TEST_EQUAL_UI(((sqfs_object_t *)ti)->refcount, 1);
- clear_header(&hdr);
-
- offset = 0;
-
- for (;;) {
- ret = istream_read(ti, buffer, sizeof(buffer));
- TEST_ASSERT(ret >= 0);
-
- if (ret == 0)
- break;
-
- for (i = 0; i < ret; ++i) {
- int ref_byte = byte_from_offset(offset + i);
-
- if (buffer[i] != ref_byte) {
- fprintf(stderr, "Byte at offset %llu should "
- "be 0x%02X, but is 0x%02X\n",
- (unsigned long long)(offset + i),
- (unsigned int)ref_byte, buffer[i]);
- return EXIT_FAILURE;
- }
- }
-
- offset += ret;
- TEST_ASSERT(offset <= 2097152);
- }
-
- TEST_EQUAL_UI(offset, 2097152);
-
- sqfs_drop(ti);
- TEST_EQUAL_UI(((sqfs_object_t *)fp)->refcount, 1);
- sqfs_drop(fp);
- return EXIT_SUCCESS;
-}