#include "test.h"
__FBSDID("$FreeBSD");
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define close _close
+#define open _open
+#endif
+
/*
* Extract a non-encoded file.
* The header of the 7z archive files is not encoded.
*/
static void
-test_copy()
+test_copy(int use_open_fd)
{
const char *refname = "test_read_format_7zip_copy.7z";
struct archive_entry *ae;
struct archive *a;
char buff[128];
+ int fd = -1;
extract_reference_file(refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
- assertEqualIntA(a, ARCHIVE_OK,
- archive_read_open_filename(a, refname, 10240));
+ if (use_open_fd) {
+ fd = open(refname, O_RDONLY | O_BINARY);
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_fd(a, fd, 10240));
+ } else {
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_read_open_filename(a, refname, 10240));
+ }
/* Verify regular file1. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("file1", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(60, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assert(archive_read_has_encrypted_entries(a) > ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED);
assertEqualInt(60, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, " ", 4);
/* Close the archive. */
assertEqualInt(ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ if (fd != -1)
+ close(fd);
}
/*
assertEqualString("empty", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(0, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(1, archive_file_count(a));
assertEqualString("file1", archive_entry_pathname(ae));
assertEqualInt(1322058763, archive_entry_mtime(ae));
assertEqualInt(2844, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(sizeof(buff), archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "The libarchive distribution ", 28);
assertEqualString("dir1/file1", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(13, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(13, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\n", 13);
assertEqualString("file2", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(26, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(26, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\nbbbbbbbbbbbb\n", 26);
assertEqualString("file3", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(39, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(39, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccc\n", 39);
assertEqualString("file4", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(52, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(52, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff,
"aaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccc\ndddddddddddd\n", 52);
assertEqualInt((AE_IFDIR | 0755), archive_entry_mode(ae));
assertEqualString("dir1/", archive_entry_pathname(ae));
assertEqualInt(2764801, archive_entry_mtime(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(5, archive_file_count(a));
assertEqualString("dir1/file1", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(13, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
/* Verify regular file2. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("file2", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(26, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
/* Verify regular file3. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("file3", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(39, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
/* Verify regular file4. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("file4", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(52, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(52, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff,
"aaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccc\ndddddddddddd\n", 52);
assertEqualInt((AE_IFDIR | 0755), archive_entry_mode(ae));
assertEqualString("dir1/", archive_entry_pathname(ae));
assertEqualInt(2764801, archive_entry_mtime(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(5, archive_file_count(a));
assertEqualString("dir1/file1", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(13, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(13, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\n", 13);
assertEqualString("file2", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(26, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(26, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\nbbbbbbbbbbbb\n", 26);
assertEqualString("file3", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(39, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(39, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccc\n", 39);
assertEqualString("file4", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(52, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(52, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff,
"aaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccc\ndddddddddddd\n", 52);
assertEqualString("dir1/zfile1", archive_entry_pathname(ae));
assertEqualInt(5184001, archive_entry_mtime(ae));
assertEqualInt(13, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(13, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\n", 13);
assertEqualString("zfile2", archive_entry_pathname(ae));
assertEqualInt(5184001, archive_entry_mtime(ae));
assertEqualInt(26, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(26, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\nbbbbbbbbbbbb\n", 26);
assertEqualString("zfile3", archive_entry_pathname(ae));
assertEqualInt(5184001, archive_entry_mtime(ae));
assertEqualInt(39, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(39, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "aaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccc\n", 39);
assertEqualString("zfile4", archive_entry_pathname(ae));
assertEqualInt(5184001, archive_entry_mtime(ae));
assertEqualInt(52, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(52, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff,
"aaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccc\ndddddddddddd\n", 52);
assertEqualInt((AE_IFDIR | 0755), archive_entry_mode(ae));
assertEqualString("dir1/", archive_entry_pathname(ae));
assertEqualInt(2764801, archive_entry_mtime(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(9, archive_file_count(a));
assertEqualString("file1", archive_entry_pathname(ae));
assertEqualInt(172802, archive_entry_mtime(ae));
assertEqualInt(27627, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
remaining = (size_t)archive_entry_size(ae);
while (remaining) {
if (remaining < sizeof(buff))
assertEqualString("x86exe", archive_entry_pathname(ae));
assertEqualInt(172802, archive_entry_mtime(ae));
assertEqualInt(27328, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
remaining = (size_t)archive_entry_size(ae);
while (remaining) {
if (remaining < sizeof(buff))
assertEqualString("ppmd_test.txt", archive_entry_pathname(ae));
assertEqualInt(1322464589, archive_entry_mtime(ae));
assertEqualInt(102400, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
remaining = (size_t)archive_entry_size(ae);
while (remaining) {
if (remaining < sizeof(buff))
assertEqualString("file1", archive_entry_pathname(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
assertEqualInt(32, archive_entry_size(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(32, archive_read_data(a, buff, sizeof(buff)));
assertEqualMem(buff, "hellohellohello\nhellohellohello\n", 32);
- /* Verify symbolic-linke symlinkfile. */
+ /* Verify symbolic-link symlinkfile. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt((AE_IFLNK | 0755), archive_entry_mode(ae));
assertEqualString("symlinkfile", archive_entry_pathname(ae));
assertEqualString("file1", archive_entry_symlink(ae));
assertEqualInt(86401, archive_entry_mtime(ae));
+ assertEqualInt(archive_entry_is_encrypted(ae), 0);
+ assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
assertEqualInt(2, archive_file_count(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
+DEFINE_TEST(test_read_format_7zip_from_fd)
+{
+ test_copy(1);/* read a 7zip file from a file descriptor. */
+}
+
DEFINE_TEST(test_read_format_7zip_copy)
{
- test_copy();
+ test_copy(0);
test_bcj("test_read_format_7zip_bcj_copy.7z");
test_bcj("test_read_format_7zip_bcj2_copy_1.7z");
test_bcj("test_read_format_7zip_bcj2_copy_2.7z");