summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makemodule.am14
-rw-r--r--tests/tar_gnu.c143
-rw-r--r--tests/tar_pax.c125
-rw-r--r--tests/tar_sparse_gnu.c73
-rw-r--r--tests/tar_sparse_gnu1.c77
-rw-r--r--tests/tar_sparse_gnu2.c140
-rw-r--r--tests/tar_target_filled.c10
-rw-r--r--tests/tar_ustar.c143
-rw-r--r--tests/tar_xattr_bsd.c37
-rw-r--r--tests/tar_xattr_schily.c37
-rw-r--r--tests/tar_xattr_schily_bin.c10
-rw-r--r--tests/test_tar.h170
12 files changed, 235 insertions, 744 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 2aea363..2bca679 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -61,47 +61,53 @@ test_filename_sane_w32_SOURCES = tests/filename_sane.c
test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c
test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1
-test_tar_gnu_SOURCES = tests/tar_gnu.c tests/test.h
+test_tar_gnu_SOURCES = tests/tar_gnu.c tests/test.h tests/test_tar.h
test_tar_gnu_LDADD = libtar.a libcompat.a
test_tar_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
-test_tar_pax_SOURCES = tests/tar_pax.c tests/test.h
+test_tar_pax_SOURCES = tests/tar_pax.c tests/test.h tests/test_tar.h
test_tar_pax_LDADD = libtar.a libcompat.a
test_tar_pax_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
-test_tar_ustar_SOURCES = tests/tar_ustar.c tests/test.h
+test_tar_ustar_SOURCES = tests/tar_ustar.c tests/test.h tests/test_tar.h
test_tar_ustar_LDADD = libtar.a libcompat.a
test_tar_ustar_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_target_filled_SOURCES = tests/tar_target_filled.c tests/test.h
+test_tar_target_filled_SOURCES += tests/test_tar.h
test_tar_target_filled_LDADD = libtar.a libcompat.a
test_tar_target_filled_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_target_filled_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu_SOURCES = tests/tar_sparse_gnu.c tests/test.h
+test_tar_sparse_gnu_SOURCES += tests/test_tar.h
test_tar_sparse_gnu_LDADD = libtar.a libcompat.a
test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu1_SOURCES = tests/tar_sparse_gnu1.c tests/test.h
+test_tar_sparse_gnu1_SOURCES += tests/test_tar.h
test_tar_sparse_gnu1_LDADD = libtar.a libcompat.a
test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_sparse_gnu1_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_sparse_gnu2_SOURCES = tests/tar_sparse_gnu2.c tests/test.h
+test_tar_sparse_gnu2_SOURCES += tests/test_tar.h
test_tar_sparse_gnu2_LDADD = libtar.a libcompat.a
test_tar_sparse_gnu2_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_sparse_gnu2_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
-test_tar_xattr_bsd_SOURCES = tests/tar_xattr_bsd.c tests/test.h
+test_tar_xattr_bsd_SOURCES = tests/tar_xattr_bsd.c tests/test.h tests/test_tar.h
test_tar_xattr_bsd_LDADD = libtar.a libcompat.a
test_tar_xattr_bsd_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_xattr_schily_SOURCES = tests/tar_xattr_schily.c tests/test.h
+test_tar_xattr_schily_SOURCES += tests/test_tar.h
test_tar_xattr_schily_LDADD = libtar.a libcompat.a
test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_xattr_schily_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_xattr_schily_bin_SOURCES = tests/tar_xattr_schily_bin.c tests/test.h
+test_tar_xattr_schily_bin_SOURCES += tests/test_tar.h
test_tar_xattr_schily_bin_LDADD = libtar.a libcompat.a
test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_xattr_schily_bin_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
diff --git a/tests/tar_gnu.c b/tests/tar_gnu.c
index 9746cb0..b21c283 100644
--- a/tests/tar_gnu.c
+++ b/tests/tar_gnu.c
@@ -4,16 +4,7 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
static const char *filename =
"012345678901234567890123456789/012345678901234567890123456789/"
@@ -22,126 +13,20 @@ static const char *filename =
int main(void)
{
- tar_header_decoded_t hdr;
- char buffer[6];
- FILE *fp;
-
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("format-acceptance/gnu.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892);
- TEST_EQUAL_UI(hdr.mtime, 1542905892);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("format-acceptance/gnu-g.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 013375560044);
- TEST_EQUAL_UI(hdr.mtime, 013375560044);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("file-size/gnu.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 8589934592);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 013375730126);
- TEST_EQUAL_UI(hdr.mtime, 013375730126);
- TEST_STR_EQUAL(hdr.name, "big-file.bin");
- TEST_ASSERT(!hdr.unknown_record);
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("user-group-largenum/gnu.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 0x80000000);
- TEST_EQUAL_UI(hdr.sb.st_gid, 0x80000000);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 013376036700);
- TEST_EQUAL_UI(hdr.mtime, 013376036700);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data2", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("large-mtime/gnu.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
-
- if (sizeof(time_t) * CHAR_BIT < 64) {
- TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
- } else {
- TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
- }
-
- TEST_EQUAL_UI(hdr.mtime, 8589934592L);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data3", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("negative-mtime/gnu.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_I(hdr.sb.st_mtime, -315622800);
- TEST_EQUAL_I(hdr.mtime, -315622800);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data4", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("long-paths/gnu.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542909670);
- TEST_EQUAL_UI(hdr.mtime, 1542909670);
- TEST_STR_EQUAL(hdr.name, filename);
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data5", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
+ testcase_simple("format-acceptance/gnu.tar", 1542905892,
+ 1000, 1000, "input.txt");
+ testcase_simple("format-acceptance/gnu-g.tar", 013375560044,
+ 1000, 1000, "input.txt");
+ testcase_simple("user-group-largenum/gnu.tar", 013376036700,
+ 0x80000000, 0x80000000, "input.txt");
+ testcase_simple("negative-mtime/gnu.tar", -315622800,
+ 1000, 1000, "input.txt");
+ testcase_simple("long-paths/gnu.tar", 1542909670,
+ 1000, 1000, filename);
+ testcase_simple("large-mtime/gnu.tar", 8589934592L,
+ 1000, 1000, "input.txt");
+ test_case_file_size("file-size/gnu.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_pax.c b/tests/tar_pax.c
index 86dc186..52b3481 100644
--- a/tests/tar_pax.c
+++ b/tests/tar_pax.c
@@ -4,15 +4,7 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
static const char *filename =
"012345678901234567890123456789/012345678901234567890123456789/"
@@ -21,110 +13,19 @@ static const char *filename =
int main(void)
{
- tar_header_decoded_t hdr;
- char buffer[6];
- FILE *fp;
-
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("format-acceptance/pax.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892);
- TEST_EQUAL_UI(hdr.mtime, 1542905892);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("file-size/pax.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 8589934592);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542959190);
- TEST_EQUAL_UI(hdr.mtime, 1542959190);
- TEST_STR_EQUAL(hdr.name, "big-file.bin");
- TEST_ASSERT(!hdr.unknown_record);
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("user-group-largenum/pax.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 2147483648);
- TEST_EQUAL_UI(hdr.sb.st_gid, 2147483648);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 013376036700);
- TEST_EQUAL_UI(hdr.mtime, 013376036700);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("large-mtime/pax.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
-
- if (sizeof(time_t) * CHAR_BIT < 64) {
- TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
- } else {
- TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
- }
-
- TEST_EQUAL_UI(hdr.mtime, 8589934592L);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data2", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("negative-mtime/pax.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_I(hdr.sb.st_mtime, -315622800);
- TEST_EQUAL_UI(hdr.mtime, -315622800);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data3", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("long-paths/pax.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542909670);
- TEST_EQUAL_UI(hdr.mtime, 1542909670);
- TEST_STR_EQUAL(hdr.name, filename);
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data4", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
+ testcase_simple("format-acceptance/pax.tar", 1542905892,
+ 1000, 1000, "input.txt");
+ testcase_simple("user-group-largenum/pax.tar", 013376036700,
+ 2147483648UL, 2147483648UL, "input.txt");
+ testcase_simple("large-mtime/pax.tar", 8589934592L,
+ 1000, 1000, "input.txt");
+ testcase_simple("negative-mtime/pax.tar", -315622800,
+ 1000, 1000, "input.txt");
+ testcase_simple("long-paths/pax.tar", 1542909670,
+ 1000, 1000, filename);
+
+ test_case_file_size("file-size/pax.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_sparse_gnu.c b/tests/tar_sparse_gnu.c
index efbd8b8..fdeb53e 100644
--- a/tests/tar_sparse_gnu.c
+++ b/tests/tar_sparse_gnu.c
@@ -4,15 +4,7 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
int main(void)
{
@@ -53,67 +45,6 @@ int main(void)
clear_header(&hdr);
fclose(fp);
- fp = test_open_read("sparse-files/gnu.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 2097152);
- 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);
-
- sparse = hdr.sparse;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 0);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 262144);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 524288);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 786432);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1048576);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1310720);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1572864);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1835008);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 2097152);
- TEST_EQUAL_UI(sparse->count, 0);
-
- sparse = sparse->next;
- TEST_NULL(sparse);
-
- clear_header(&hdr);
- fclose(fp);
-
+ test_case_sparse("sparse-files/gnu.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_sparse_gnu1.c b/tests/tar_sparse_gnu1.c
index 9bfd5b5..1e74969 100644
--- a/tests/tar_sparse_gnu1.c
+++ b/tests/tar_sparse_gnu1.c
@@ -4,85 +4,12 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
int main(void)
{
- tar_header_decoded_t hdr;
- sparse_map_t *sparse;
- FILE *fp;
-
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("sparse-files/pax-gnu0-0.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 2097152);
- 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);
-
- sparse = hdr.sparse;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 0);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 262144);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 524288);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 786432);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1048576);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1310720);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1572864);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1835008);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 2097152);
- TEST_EQUAL_UI(sparse->count, 0);
-
- sparse = sparse->next;
- TEST_NULL(sparse);
-
- clear_header(&hdr);
- fclose(fp);
-
+ test_case_sparse("sparse-files/pax-gnu0-0.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_sparse_gnu2.c b/tests/tar_sparse_gnu2.c
index 2a54640..f08f286 100644
--- a/tests/tar_sparse_gnu2.c
+++ b/tests/tar_sparse_gnu2.c
@@ -4,147 +4,13 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
int main(void)
{
- tar_header_decoded_t hdr;
- sparse_map_t *sparse;
- FILE *fp;
-
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("sparse-files/pax-gnu0-1.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 2097152);
- 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);
-
- sparse = hdr.sparse;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 0);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 262144);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 524288);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 786432);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1048576);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1310720);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1572864);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1835008);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 2097152);
- TEST_EQUAL_UI(sparse->count, 0);
-
- sparse = sparse->next;
- TEST_NULL(sparse);
-
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("sparse-files/pax-gnu1-0.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 2097152);
- 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);
-
- sparse = hdr.sparse;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 0);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 262144);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 524288);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 786432);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1048576);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1310720);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1572864);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 1835008);
- TEST_EQUAL_UI(sparse->count, 4096);
-
- sparse = sparse->next;
- TEST_NOT_NULL(sparse);
- TEST_EQUAL_UI(sparse->offset, 2097152);
- TEST_EQUAL_UI(sparse->count, 0);
-
- sparse = sparse->next;
- TEST_NULL(sparse);
-
- clear_header(&hdr);
- fclose(fp);
-
+ test_case_sparse("sparse-files/pax-gnu0-1.tar");
+ test_case_sparse("sparse-files/pax-gnu1-0.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_target_filled.c b/tests/tar_target_filled.c
index 6e8d923..4098b39 100644
--- a/tests/tar_target_filled.c
+++ b/tests/tar_target_filled.c
@@ -4,15 +4,7 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
int main(void)
{
diff --git a/tests/tar_ustar.c b/tests/tar_ustar.c
index b794e30..8ca1b36 100644
--- a/tests/tar_ustar.c
+++ b/tests/tar_ustar.c
@@ -4,15 +4,7 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
static const char *filename =
"012345678901234567890123456789/012345678901234567890123456789/"
@@ -21,126 +13,21 @@ static const char *filename =
int main(void)
{
- tar_header_decoded_t hdr;
- char buffer[6];
- FILE *fp;
-
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("format-acceptance/ustar.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892);
- TEST_EQUAL_UI(hdr.mtime, 1542905892);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("format-acceptance/ustar-pre-posix.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892);
- TEST_EQUAL_UI(hdr.mtime, 1542905892);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("format-acceptance/v7.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892);
- TEST_EQUAL_UI(hdr.mtime, 1542905892);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data2", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("file-size/12-digit.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 8589934592);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 013375730126);
- TEST_EQUAL_UI(hdr.mtime, 013375730126);
- TEST_STR_EQUAL(hdr.name, "big-file.bin");
- TEST_ASSERT(!hdr.unknown_record);
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("user-group-largenum/8-digit.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 8388608);
- TEST_EQUAL_UI(hdr.sb.st_gid, 8388608);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 013376036700);
- TEST_EQUAL_UI(hdr.mtime, 013376036700);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data3", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("large-mtime/12-digit.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
-
- if (sizeof(time_t) * CHAR_BIT < 64) {
- TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
- } else {
- TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L);
- }
-
- TEST_EQUAL_UI(hdr.mtime, 8589934592L);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data4", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
- fp = test_open_read("long-paths/ustar.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1542909670);
- TEST_EQUAL_UI(hdr.mtime, 1542909670);
- TEST_STR_EQUAL(hdr.name, filename);
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data5", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
- clear_header(&hdr);
- fclose(fp);
-
+ testcase_simple("format-acceptance/ustar.tar", 1542905892,
+ 1000, 1000, "input.txt");
+ testcase_simple("format-acceptance/ustar-pre-posix.tar", 1542905892,
+ 1000, 1000, "input.txt");
+ testcase_simple("format-acceptance/v7.tar", 1542905892,
+ 1000, 1000, "input.txt");
+ testcase_simple("user-group-largenum/8-digit.tar", 1542995392,
+ 8388608, 8388608, "input.txt");
+ testcase_simple("large-mtime/12-digit.tar", 8589934592L,
+ 1000, 1000, "input.txt");
+ testcase_simple("long-paths/ustar.tar", 1542909670,
+ 1000, 1000, filename);
+
+ test_case_file_size("file-size/12-digit.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_xattr_bsd.c b/tests/tar_xattr_bsd.c
index 8b5f1b0..4918afe 100644
--- a/tests/tar_xattr_bsd.c
+++ b/tests/tar_xattr_bsd.c
@@ -4,45 +4,12 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
int main(void)
{
- tar_header_decoded_t hdr;
- char buffer[6];
- FILE *fp;
-
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("xattr/xattr-libarchive.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477);
- TEST_EQUAL_UI(hdr.mtime, 1543094477);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
-
- TEST_NOT_NULL(hdr.xattr);
- TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type");
- TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain");
- TEST_EQUAL_UI(hdr.xattr->value_len, 10);
- TEST_NULL(hdr.xattr->next);
-
- clear_header(&hdr);
- fclose(fp);
+ test_case_xattr_simple("xattr/xattr-libarchive.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_xattr_schily.c b/tests/tar_xattr_schily.c
index e1bf3f3..1ca735b 100644
--- a/tests/tar_xattr_schily.c
+++ b/tests/tar_xattr_schily.c
@@ -4,45 +4,12 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
int main(void)
{
- tar_header_decoded_t hdr;
- char buffer[6];
- FILE *fp;
-
TEST_ASSERT(chdir(TEST_PATH) == 0);
- fp = test_open_read("xattr/xattr-schily.tar");
- TEST_ASSERT(read_header(fp, &hdr) == 0);
- TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
- TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
- TEST_EQUAL_UI(hdr.sb.st_size, 5);
- TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477);
- TEST_EQUAL_UI(hdr.mtime, 1543094477);
- TEST_STR_EQUAL(hdr.name, "input.txt");
- TEST_ASSERT(!hdr.unknown_record);
- TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0);
- buffer[5] = '\0';
- TEST_STR_EQUAL(buffer, "test\n");
-
- TEST_NOT_NULL(hdr.xattr);
- TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type");
- TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain");
- TEST_EQUAL_UI(hdr.xattr->value_len, 10);
- TEST_NULL(hdr.xattr->next);
-
- clear_header(&hdr);
- fclose(fp);
+ test_case_xattr_simple("xattr/xattr-schily.tar");
return EXIT_SUCCESS;
}
diff --git a/tests/tar_xattr_schily_bin.c b/tests/tar_xattr_schily_bin.c
index 29587f6..0fe2004 100644
--- a/tests/tar_xattr_schily_bin.c
+++ b/tests/tar_xattr_schily_bin.c
@@ -4,15 +4,7 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#include "config.h"
-
-#include "tar.h"
-#include "test.h"
-
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
+#include "test_tar.h"
static const uint8_t value[] = {
0x00, 0x00, 0x00, 0x02,
diff --git a/tests/test_tar.h b/tests/test_tar.h
new file mode 100644
index 0000000..3bbf328
--- /dev/null
+++ b/tests/test_tar.h
@@ -0,0 +1,170 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * test_tar.h
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#ifndef TEST_TAR_H
+#define TEST_TAR_H
+
+#include "config.h"
+#include "tar.h"
+#include "test.h"
+
+#define STR(x) #x
+#define STRVALUE(x) STR(x)
+
+#define TEST_PATH STRVALUE(TESTPATH)
+
+static ATTRIB_UNUSED void testcase_simple(const char *path, sqfs_s64 ts,
+ sqfs_u32 uid, sqfs_u32 gid,
+ const char *fname)
+{
+ tar_header_decoded_t hdr;
+ char buffer[6];
+ FILE *fp;
+
+ fp = test_open_read(path);
+ TEST_ASSERT(read_header(fp, &hdr) == 0);
+ TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.sb.st_uid, uid);
+ TEST_EQUAL_UI(hdr.sb.st_gid, gid);
+ TEST_EQUAL_UI(hdr.sb.st_size, 5);
+
+ if (sizeof(time_t) < sizeof(ts) && ts > INT32_MAX) {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX);
+ } else {
+ TEST_EQUAL_UI(hdr.sb.st_mtime, ts);
+ }
+
+ TEST_EQUAL_UI(hdr.mtime, ts);
+ TEST_STR_EQUAL(hdr.name, fname);
+ TEST_ASSERT(!hdr.unknown_record);
+
+ TEST_ASSERT(read_retry("tar data", fp, buffer, 5) == 0);
+ buffer[5] = '\0';
+ TEST_STR_EQUAL(buffer, "test\n");
+ clear_header(&hdr);
+ fclose(fp);
+
+}
+
+static ATTRIB_UNUSED void test_case_file_size(const char *path)
+{
+ tar_header_decoded_t hdr;
+ FILE *fp;
+
+ fp = test_open_read(path);
+ TEST_ASSERT(read_header(fp, &hdr) == 0);
+ TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
+ TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
+ TEST_EQUAL_UI(hdr.sb.st_size, 8589934592);
+ TEST_EQUAL_UI(hdr.sb.st_mtime, 1542959190);
+ TEST_EQUAL_UI(hdr.mtime, 1542959190);
+ TEST_STR_EQUAL(hdr.name, "big-file.bin");
+ TEST_ASSERT(!hdr.unknown_record);
+ clear_header(&hdr);
+ fclose(fp);
+}
+
+static ATTRIB_UNUSED void test_case_sparse(const char *path)
+{
+ tar_header_decoded_t hdr;
+ sparse_map_t *sparse;
+ FILE *fp;
+
+ fp = test_open_read(path);
+ TEST_ASSERT(read_header(fp, &hdr) == 0);
+ TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
+ TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
+ TEST_EQUAL_UI(hdr.sb.st_size, 2097152);
+ 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);
+
+ sparse = hdr.sparse;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 0);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 262144);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 524288);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 786432);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 1048576);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 1310720);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 1572864);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 1835008);
+ TEST_EQUAL_UI(sparse->count, 4096);
+
+ sparse = sparse->next;
+ TEST_NOT_NULL(sparse);
+ TEST_EQUAL_UI(sparse->offset, 2097152);
+ TEST_EQUAL_UI(sparse->count, 0);
+
+ sparse = sparse->next;
+ TEST_NULL(sparse);
+
+ clear_header(&hdr);
+ fclose(fp);
+}
+
+static ATTRIB_UNUSED void test_case_xattr_simple(const char *path)
+{
+ tar_header_decoded_t hdr;
+ char buffer[6];
+ FILE *fp;
+
+ fp = test_open_read(path);
+ TEST_ASSERT(read_header(fp, &hdr) == 0);
+ TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(hdr.sb.st_uid, 01750);
+ TEST_EQUAL_UI(hdr.sb.st_gid, 01750);
+ TEST_EQUAL_UI(hdr.sb.st_size, 5);
+ TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477);
+ TEST_EQUAL_UI(hdr.mtime, 1543094477);
+ TEST_STR_EQUAL(hdr.name, "input.txt");
+ TEST_ASSERT(!hdr.unknown_record);
+ TEST_ASSERT(read_retry("reading tar data", fp, buffer, 5) == 0);
+ buffer[5] = '\0';
+ TEST_STR_EQUAL(buffer, "test\n");
+
+ TEST_NOT_NULL(hdr.xattr);
+ TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type");
+ TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain");
+ TEST_EQUAL_UI(hdr.xattr->value_len, 10);
+ TEST_NULL(hdr.xattr->next);
+
+ clear_header(&hdr);
+ fclose(fp);
+}
+
+#endif /* TEST_TAR_H */