aboutsummaryrefslogtreecommitdiff
path: root/libarchive/test/test_sparse_basic.c
diff options
context:
space:
mode:
Diffstat (limited to 'libarchive/test/test_sparse_basic.c')
-rw-r--r--libarchive/test/test_sparse_basic.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/libarchive/test/test_sparse_basic.c b/libarchive/test/test_sparse_basic.c
index 43e87df52451..133a85398547 100644
--- a/libarchive/test/test_sparse_basic.c
+++ b/libarchive/test/test_sparse_basic.c
@@ -364,9 +364,10 @@ verify_sparse_file(struct archive *a, const char *path,
#if DEBUG
fprintf(stderr, " overlapping hole expected_offset=%d, size=%d\n", (int)expected_offset, (int)sparse->size);
#endif
- /* Must be a hole, overlap must be filled with '\0' */
- if (assert(sparse->type == HOLE)) {
+ if (sparse->type == HOLE) {
assertMemoryFilledWith(start, end - start, '\0');
+ } else if (assert(sparse->type == DATA)) {
+ assertMemoryFilledWith(start, end - start, ' ');
}
start = end;
expected_offset += sparse->size;
@@ -410,9 +411,10 @@ verify_sparse_file(struct archive *a, const char *path,
#if DEBUG
fprintf(stderr, " trailing overlap expected_offset=%d, size=%d\n", (int)expected_offset, (int)sparse->size);
#endif
- /* Must be a hole, overlap must be filled with '\0' */
- if (assert(sparse->type == HOLE)) {
+ if (sparse->type == HOLE) {
assertMemoryFilledWith(start, end - start, '\0');
+ } else if (assert(sparse->type == DATA)) {
+ assertMemoryFilledWith(start, end - start, ' ');
}
}
last_offset = offset + bytes_read;
@@ -615,6 +617,33 @@ DEFINE_TEST(test_sparse_basic)
verify_sparse_file2(a, "file0", sparse_file0, 5, 1);
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ /*
+ * Test that setting ARCHIVE_READDISK_NO_SPARSE
+ * creates no sparse entries.
+ */
+ assert((a = archive_read_disk_new()) != NULL);
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_set_behavior(a,
+ ARCHIVE_READDISK_NO_SPARSE));
+
+ verify_sparse_file(a, "file0", sparse_file0, 0);
+ verify_sparse_file(a, "file1", sparse_file1, 0);
+ verify_sparse_file(a, "file2", sparse_file2, 0);
+ verify_sparse_file(a, "file3", sparse_file3, 0);
+ verify_sparse_file(a, "file4", sparse_file4, 0);
+
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ assert((a = archive_read_disk_new()) != NULL);
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_set_behavior(a,
+ ARCHIVE_READDISK_NO_SPARSE));
+
+ verify_sparse_file2(a, "file0", sparse_file0, 0, 0);
+ verify_sparse_file2(a, "file0", sparse_file0, 0, 1);
+
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
free(cwd);
}