Skip to content

Commit

Permalink
Update test_entry.c
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-- committed Nov 27, 2023
1 parent 4b9c8fc commit 4e91b8d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/test_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down

0 comments on commit 4e91b8d

Please sign in to comment.