]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
sparse: Add archive_entry_sparse_reset test 3020/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 28 Apr 2026 16:29:06 +0000 (18:29 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 10 May 2026 12:41:41 +0000 (14:41 +0200)
Check that archive_entry_sparse_reset resets all internal variables.

Test case created and issue reported by Linke Li.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/test/test_sparse_basic.c

index 93710cb64033cd475f7f7ebaf6954cb61181390a..d4405ddae48e7930f56ac8cced163b0feb033b42 100644 (file)
@@ -695,3 +695,29 @@ DEFINE_TEST(test_fully_sparse_files)
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
        free(cwd);
 }
+
+DEFINE_TEST(test_sparse_iterator)
+{
+       struct archive_entry *entry;
+       int64_t offset, length;
+       int count;
+
+       entry = archive_entry_new();
+       archive_entry_set_pathname(entry, "testfile");
+       archive_entry_set_mode(entry, 0100644);
+       archive_entry_set_size(entry, 1024);
+
+       /* Add one sparse block covering the entire file */
+       archive_entry_sparse_add_entry(entry, 0, 1024);
+
+       /* Should remove the only block covering the entire file */
+       archive_entry_sparse_reset(entry);
+
+       count = 0;
+       while (archive_entry_sparse_next(entry, &offset, &length) == ARCHIVE_OK)
+               count++;
+       assertEqualInt(0, count);
+       assertEqualInt(0, archive_entry_sparse_count(entry));
+
+       archive_entry_free(entry);
+}