diff --git a/test/test_entry.c b/test/test_entry.c index e86282b3..e3059cf6 100644 --- a/test/test_entry.c +++ b/test/test_entry.c @@ -272,6 +272,54 @@ MU_TEST(test_entries_deletebyindex) { zip_close(zip); } + +MU_TEST(test_entries_deleteinvalid) { + size_t entries[] = {111, 222, 333, 444}; + + struct zip_t *zip = zip_open(ZIPNAME, 0, 'd'); + mu_check(zip != NULL); + + mu_assert_int_eq(0, zip_entries_deletebyindex(zip, entries, 4)); + + zip_close(zip); + + zip = zip_open(ZIPNAME, 0, 'r'); + mu_check(zip != NULL); + + mu_assert_int_eq(0, zip_entry_open(zip, "delete.me")); + mu_assert_int_eq(0, zip_entry_close(zip)); + + mu_assert_int_eq(0, zip_entry_open(zip, "_")); + mu_assert_int_eq(0, zip_entry_close(zip)); + + mu_assert_int_eq(0, zip_entry_open(zip, "delete/file.1")); + mu_assert_int_eq(0, zip_entry_close(zip)); + + mu_assert_int_eq(0, zip_entry_open(zip, "deleteme/file.3")); + mu_assert_int_eq(0, zip_entry_close(zip)); + + mu_assert_int_eq(0, zip_entry_open(zip, "delete/file.2")); + mu_assert_int_eq(0, zip_entry_close(zip)); + + mu_assert_int_eq(total_entries, zip_entries_total(zip)); + + mu_assert_int_eq(0, zip_entry_open(zip, "delete/file.4")); + + size_t buftmp = 0; + char *buf = NULL; + ssize_t bufsize = zip_entry_read(zip, (void **)&buf, &buftmp); + + mu_assert_int_eq(bufsize, strlen(TESTDATA2)); + mu_assert_int_eq((size_t)bufsize, buftmp); + mu_assert_int_eq(0, strncmp(buf, TESTDATA2, bufsize)); + mu_assert_int_eq(0, zip_entry_close(zip)); + + free(buf); + buf = NULL; + + zip_close(zip); +} + MU_TEST(test_entries_delete) { char *entries[] = {"delete.me", "_", "delete/file.1", "deleteme/file.3", "delete/file.2"};