static void verifyEmpty(void) { struct archive_entry *ae; struct archive *a; assert((a = archive_read_new()) != NULL); assertA(0 == archive_read_support_compression_all(a)); assertA(0 == archive_read_support_format_all(a)); assertA(0 == archive_read_open_memory(a, archiveEmpty, 512)); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); failure("512 zero bytes should be recognized as a tar archive."); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); assert(0 == archive_read_close(a)); #if ARCHIVE_API_VERSION > 1 assert(0 == archive_read_finish(a)); #else archive_read_finish(a); #endif }
static void unpack_test(const char *from, const char *options, const char *se) { int r; /* Create a work dir named after the file we're unpacking. */ assertMakeDir(from, 0775); assertChdir(from); /* * Use cpio to unpack the sample archive */ extract_reference_file(from); r = systemf("%s -i %s < %s >unpack.out 2>unpack.err", testprog, options, from); failure("Error invoking %s -i %s < %s", testprog, options, from); assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ if (canSymlink()) { failure("Error invoking %s -i %s < %s", testprog, options, from); assertTextFileContents(se, "unpack.err"); } /* * Verify unpacked files. */ /* Regular file with 2 links. */ assertIsReg("file", 0644); failure("%s", from); assertFileSize("file", 10); assertFileSize("linkfile", 10); failure("%s", from); assertFileNLinks("file", 2); /* Another name for the same file. */ failure("%s", from); assertIsHardlink("linkfile", "file"); assertFileSize("file", 10); assertFileSize("linkfile", 10); /* Symlink */ if (canSymlink()) assertIsSymlink("symlink", "file"); /* dir */ assertIsDir("dir", 0775); assertChdir(".."); }
/* * Unpack the archive in a new dir. */ static void unpack(const char *dirname, const char *option) { int r; assertMakeDir(dirname, 0755); assertChdir(dirname); extract_reference_file("test_option_f.cpio"); r = systemf("%s -i %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option); assertEqualInt(0, r); assertChdir(".."); }
/* * Issue 225: Errors extracting MSDOS Zip archives with directories. */ static void compat_zip_6_verify(struct archive *a) { struct archive_entry *ae; assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("New Folder/New Folder/", archive_entry_pathname(ae)); assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); /* Zip timestamps are local time, so vary by time zone. */ /* TODO: A more complex assert would work here; we could verify that it's within +/- 24 hours of a particular value. */ /* assertEqualInt(1327314468, archive_entry_mtime(ae)); */ assertEqualInt(0, archive_entry_size(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("New Folder/New Folder/New Text Document.txt", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); /* Zip timestamps are local time, so vary by time zone. */ /* assertEqualInt(1327314476, archive_entry_mtime(ae)); */ assertEqualInt(11, archive_entry_size(ae)); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); }
static void verifyxL(struct archive_entry *ae) { assert(S_ISLNK(archive_entry_mode(ae))); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); assertEqualString(archive_entry_uname(ae), "tim"); assertEqualString(archive_entry_gname(ae), "tim"); assertEqualString(archive_entry_pathname(ae), "symlink"); assertEqualString(archive_entry_symlink(ae), "this_is_a_very_long_symlink_body_abcdefghijklmnopqrstuvwxyz_" "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz"); assert(archive_entry_hardlink(ae) == NULL); assertEqualInt(archive_entry_mtime(ae), 1184390648); }
static void copy_basic(void) { int r; /* NOTE: for proper operation on cygwin-1.5 and windows, the * length of the name of the directory below, "plain", must be * less than or equal to the lengthe of the name of the original * directory, "original" This restriction derives from the * extremely limited pathname lengths on those platforms. */ assertMakeDir("plain", 0775); assertEqualInt(0, chdir("plain")); /* * Use the tar program to create an archive. */ r = systemf("%s cf archive -C ../original f d l m s >pack.out 2>pack.err", testprog); failure("Error invoking \"%s cf\"", testprog); assertEqualInt(r, 0); /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("pack.err"); assertEmptyFile("pack.out"); /* * Use tar to unpack the archive into another directory. */ r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog); failure("Error invoking %s xf archive", testprog); assertEqualInt(r, 0); /* Verify that nothing went to stdout or stderr. */ assertEmptyFile("unpack.err"); assertEmptyFile("unpack.out"); verify_tree(LIMIT_NONE); assertEqualInt(0, chdir("..")); }
/* * All of the sample files have the same contents; they're just * compressed in different ways. */ static void compat_bzip2(const char *name) { const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; struct archive_entry *ae; struct archive *a; int i; assert((a = archive_read_new()) != NULL); if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) { skipping("Unsupported bzip2"); return; } assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); extract_reference_file(name); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { failure("Could not read file %d (%s) from %s", i, n[i], name); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(n[i], archive_entry_pathname(ae)); } /* Verify the end-of-archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify that the format detection worked. */ assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); assertEqualString(archive_compression_name(a), "bzip2"); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); assertEqualString(archive_compression_name(a), "bzip2"); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
/* * An archive file has one empty file. It means there is no content * in the archive file except for a header. */ static void test_empty_file() { const char *refname = "test_read_format_7zip_empty_file.7z"; struct archive_entry *ae; struct archive *a; 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)); /* Verify regular empty. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae)); assertEqualString("empty", archive_entry_pathname(ae)); assertEqualInt(86401, archive_entry_mtime(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualInt(1, archive_file_count(a)); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test_symname() { const char *refname = "test_read_format_7zip_symbolic_name.7z"; struct archive_entry *ae; struct archive *a; char buff[128]; 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)); /* Verify regular file1. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae)); assertEqualString("file1", archive_entry_pathname(ae)); assertEqualInt(86401, archive_entry_mtime(ae)); assertEqualInt(32, archive_entry_size(ae)); assertEqualInt(32, archive_read_data(a, buff, sizeof(buff))); assertEqualMem(buff, "hellohellohello\nhellohellohello\n", 32); /* Verify symbolic-linke 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(2, archive_file_count(a)); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
/* * Sparse test with directory traversals. */ static void verify_sparse_file(struct archive *a, const char *path, const struct sparse *sparse, int blocks, int expected_data_blocks) { struct archive_entry *ae; const void *buff; size_t bytes_read; int64_t offset; int64_t total; int data_blocks, hole; create_sparse_file(path, sparse); assert((ae = archive_entry_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_open(a, path)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header2(a, ae)); /* Verify the number of holes only, not its offset nor its * length because those alignments are deeply dependence on * its filesystem. */ assertEqualInt(blocks, archive_entry_sparse_count(ae)); total = 0; data_blocks = 0; hole = 0; while (ARCHIVE_OK == archive_read_data_block(a, &buff, &bytes_read, &offset)) { if (offset > total || offset == 0) { if (offset > total) hole = 1; data_blocks++; } total = offset + bytes_read; } assertEqualInt(expected_data_blocks, data_blocks); if (blocks > 1) assert(hole); /* There must be a hole if > 1 blocks were encoded */ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); archive_entry_free(ae); }
/* * All of the sample files have the same contents; they're just * compressed in different ways. */ static void compat_lzma(const char *name) { const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; struct archive_entry *ae; struct archive *a; int i, r; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); r = archive_read_support_filter_lzma(a); if (r == ARCHIVE_WARN) { skipping("lzma reading not fully supported on this platform"); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); return; } assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); extract_reference_file(name); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); /* Read entries, match up names with list above. */ for (i = 0; i < 6; ++i) { failure("Could not read file %d (%s) from %s", i, n[i], name); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(n[i], archive_entry_pathname(ae)); } /* Verify the end-of-archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify that the format detection worked. */ assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_LZMA); assertEqualString(archive_filter_name(a, 0), "lzma"); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void test2(void) { struct archive_entry *ae; struct archive *a; const char *name = "test_read_format_iso_2.iso.Z"; extract_reference_file(name); assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 512)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(".", archive_entry_pathname(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("A", archive_entry_pathname(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("A/B", archive_entry_pathname(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("C", archive_entry_pathname(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("C/D", archive_entry_pathname(ae)); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); }
/* This is a test for RAR files compressed using a technique where compression * switches back and forth to and from ppmd and lzss decoding. */ static void test_ppmd_lzss_conversion(void) { const char reffile[] = "test_read_format_rar_ppmd_lzss_conversion.rar"; const char test_txt[] = "gin-bottom: 0in\"><BR>\n</P>\n</BODY>\n</HTML>"; int size = 241647978, offset = 0; char buff[64]; struct archive_entry *ae; struct archive *a; extract_reference_file(reffile); assert((a = archive_read_new()) != NULL); assertA(0 == archive_read_support_filter_all(a)); assertA(0 == archive_read_support_format_all(a)); assertA(0 == archive_read_open_file(a, reffile, 10240)); /* First header. */ assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("ppmd_lzss_conversion_test.txt", archive_entry_pathname(ae)); assertA((int)archive_entry_mtime(ae)); assertA((int)archive_entry_ctime(ae)); assertA((int)archive_entry_atime(ae)); assertEqualInt(size, archive_entry_size(ae)); assertEqualInt(33188, archive_entry_mode(ae)); while (offset + (int)sizeof(buff) < size) { assertA(sizeof(buff) == archive_read_data(a, buff, sizeof(buff))); offset += sizeof(buff); } assertA(size - offset == archive_read_data(a, buff, size - offset)); assertEqualMem(buff, test_txt, size - offset); /* Test EOF */ assertA(1 == archive_read_next_header(a, &ae)); assertEqualInt(1, archive_file_count(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static bool test_iset(TTestContext* ctx) { TInst inst; TVM* vm = ((TTestMVM*)ctx)->fVM; inst.uNull.fOp = op_iset; inst.uIH.fIdx = reg_r0; inst.uIH.fValue = 0x0001; vm->fRegister[reg_r0] = 0; TVM_Exec(vm, inst); if (!assertEqualInt(1, vm->fRegister[reg_r0], ctx, "")) return false; return true; };
/* * Read a manually-created archive that has filenames that are * stored in binary instead of UTF-8 and verify that we get * the right filename returned and that we get a warning only * if the header isn't marked as binary. */ static void test_pax_filename_encoding_1(void) { static const char testname[] = "test_pax_filename_encoding.tar"; /* * \314\214 is a valid 2-byte UTF-8 sequence. * \374 is invalid in UTF-8. */ char filename[] = "abc\314\214mno\374xyz"; struct archive *a; struct archive_entry *entry; /* * Read an archive that has non-UTF8 pax filenames in it. */ extract_reference_file(testname); a = archive_read_new(); assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a)); assertEqualInt(ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualInt(ARCHIVE_OK, archive_read_open_filename(a, testname, 10240)); /* * First entry in this test archive has an invalid UTF-8 sequence * in it, but the header is not marked as hdrcharset=BINARY, so that * requires a warning. */ failure("Invalid UTF8 in a pax archive pathname should cause a warning"); assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); assertEqualString(filename, archive_entry_pathname(entry)); /* * Second entry is identical except that it does have * hdrcharset=BINARY, so no warning should be generated. */ failure("A pathname with hdrcharset=BINARY can have invalid UTF8\n" " characters in it without generating a warning"); assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &entry)); assertEqualString(filename, archive_entry_pathname(entry)); archive_read_free(a); }
static bool test_next4(TTestContext* ctx) { TInst inst; TVM* vm = ((TTestMVM*)ctx)->fVM; inst.uNull.fOp = op_next; vm->fRegister[reg_current_player_idx] = 3; vm->fRegister[reg_active_mask] = 2+4+8; TVM_Exec(vm, inst); if (!assertEqualInt(1, vm->fRegister[reg_current_player_idx], ctx, "")) return false; return true; }
static void basic_cpio(const char *target, const char *pack_options, const char *unpack_options, const char *se, const char *se2) { int r; if (!assertMakeDir(target, 0775)) return; /* Use the cpio program to create an archive. */ r = systemf("%s -o %s < filelist >%s/archive 2>%s/pack.err", testprog, pack_options, target, target); failure("Error invoking %s -o %s", testprog, pack_options); assertEqualInt(r, 0); assertChdir(target); /* Verify stderr. */ failure("Expected: %s, options=%s", se, pack_options); assertTextFileContents(se, "pack.err"); /* * Use cpio to unpack the archive into another directory. */ r = systemf("%s -i %s< archive >unpack.out 2>unpack.err", testprog, unpack_options); failure("Error invoking %s -i %s", testprog, unpack_options); assertEqualInt(r, 0); /* Verify stderr. */ failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target); assertTextFileContents(se2, "unpack.err"); verify_files(pack_options); assertChdir(".."); }
/* * Do not translate CP1251 into CP866 if non Windows platform. */ static void test_zip_filename_encoding_ru_RU_CP1251(void) { struct archive *a; struct archive_entry *entry; char buff[4096]; size_t used; if (NULL == setlocale(LC_ALL, "ru_RU.CP1251")) { skipping("Russian_Russia locale not available on this system."); return; } /* * Verify that CP1251 filenames are not translated into any * other character-set, in particular, CP866. */ a = archive_write_new(); assertEqualInt(ARCHIVE_OK, archive_write_set_format_zip(a)); assertEqualInt(ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used)); entry = archive_entry_new2(a); /* Set a CP1251 filename. */ archive_entry_set_pathname(entry, "\xEF\xF0\xE8"); archive_entry_set_filetype(entry, AE_IFREG); archive_entry_set_size(entry, 0); assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); archive_entry_free(entry); assertEqualInt(ARCHIVE_OK, archive_write_free(a)); /* A bit 11 of general purpose flag should be 0, * which indicates the filename charset is unknown. */ assertEqualInt(0, buff[7]); /* Above three characters in CP1251 should not translate into * any other character-set. */ assertEqualMem(buff + 30, "\xEF\xF0\xE8", 3); }
/* * Extract a non-encoded file. * The header of the 7z archive files is not encoded. */ static void 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)); 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)); assertEqualInt((AE_IFREG | 0666), archive_entry_mode(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); assertEqualInt(1, archive_file_count(a)); /* End of archive. */ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify archive format. */ assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_7ZIP, archive_format(a)); /* Close the archive. */ assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); if (fd != -1) close(fd); }
/* * Read Info-ZIP New Unix Extra Field 0x7875 "ux". * Currently stores Unix UID/GID up to 32 bits. */ static void verify_info_zip_ux(struct archive *a, int seek_checks) { struct archive_entry *ae; char *buff[128]; assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("file1", archive_entry_pathname(ae)); assertEqualInt(1300668680, archive_entry_mtime(ae)); assertEqualInt(18, archive_entry_size(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); if (seek_checks) assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae)); failure("zip reader should read Info-ZIP New Unix Extra Field"); assertEqualInt(1001, archive_entry_uid(ae)); assertEqualInt(1001, archive_entry_gid(ae)); if (archive_zlib_version() != NULL) { failure("archive_read_data() returns number of bytes read"); assertEqualInt(18, archive_read_data(a, buff, 19)); assertEqualMem(buff, "hello\nhello\nhello\n", 18); } else { assertEqualInt(ARCHIVE_FAILED, archive_read_data(a, buff, 19)); assertEqualString(archive_error_string(a), "Unsupported ZIP compression method (deflation)"); assert(archive_errno(a) != 0); } assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); /* Verify the number of files read. */ failure("the archive file has just one file"); assertEqualInt(1, archive_file_count(a)); assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); assertEqualIntA(a, ARCHIVE_FORMAT_ZIP, archive_format(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static bool test_jump_on_double_1(TTestContext* ctx) { TInst inst; TVM* vm = ((TTestMVM*)ctx)->fVM; inst.uNull.fOp = op_jump_on_doubles; inst.uIH.fValue = 300; vm->fRegister[reg_pc] = 0; vm->fRegister[reg_dieA] = 1; vm->fRegister[reg_dieB] = 2; TVM_Exec(vm, inst); if (!assertEqualInt(0, vm->fRegister[reg_pc], ctx, "")) return false; return true; }
static bool test_jump_on_3rd_2(TTestContext* ctx) { TInst inst; TVM* vm = ((TTestMVM*)ctx)->fVM; inst.uNull.fOp = op_jump_on_3rd; inst.uIH.fValue = 300; vm->fRegister[reg_pc] = 0; vm->fRegister[reg_current_player_idx] = 0; vm->fRegister[reg_player0_state] = 3; TVM_Exec(vm, inst); if (!assertEqualInt(300, vm->fRegister[reg_pc], ctx, "")) return false; return true; }
static void test_symlink(void) { const char *refname = "test_read_format_zip_symlink.zip"; char *p; size_t s; struct archive *a; struct archive_entry *ae; extract_reference_file(refname); p = slurpfile(&s, refname); /* Symlinks can only be extracted with the seeking reader. */ assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("file", archive_entry_pathname(ae)); assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("symlink", archive_entry_pathname(ae)); assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualString("file", archive_entry_symlink(ae)); assertEqualInt(archive_entry_is_encrypted(ae), 0); assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a)); free(p); }
static void test_binary(void) { const char reffile[] = "test_read_format_rar_binary_data.rar"; char file1_buff[1048576]; int file1_size = sizeof(file1_buff); const char file1_test_txt[] = "\x37\xef\xb2\xbe\x33\xf6\xcc\xcb\xee\x2a\x10" "\x9d\x2e\x01\xe9\xf6\xf9\xe5\xe6\x67\x0c\x2b" "\xd8\x6b\xa0\x26\x9a\xf7\x93\x87\x42\xf1\x08" "\x42\xdc\x9b\x76\x91\x20\xa4\x01\xbe\x67\xbd" "\x08\x74\xde\xec"; char file2_buff[32618]; int file2_size = sizeof(file2_buff); const char file2_test_txt[] = "\x00\xee\x78\x00\x00\x4d\x45\x54\x41\x2d\x49" "\x4e\x46\x2f\x6d\x61\x6e\x69\x66\x65\x73\x74" "\x2e\x78\x6d\x6c\x50\x4b\x05\x06\x00\x00\x00" "\x00\x12\x00\x12\x00\xaa\x04\x00\x00\xaa\x7a" "\x00\x00\x00\x00"; struct archive_entry *ae; struct archive *a; extract_reference_file(reffile); assert((a = archive_read_new()) != NULL); assertA(0 == archive_read_support_filter_all(a)); assertA(0 == archive_read_support_format_all(a)); assertA(0 == archive_read_open_file(a, reffile, 10240)); /* First header. */ assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("random_data.bin", archive_entry_pathname(ae)); assertA((int)archive_entry_mtime(ae)); assertA((int)archive_entry_ctime(ae)); assertA((int)archive_entry_atime(ae)); assertEqualInt(file1_size, archive_entry_size(ae)); assertEqualInt(33188, archive_entry_mode(ae)); assertA(file1_size == archive_read_data(a, file1_buff, file1_size)); assertEqualMem(&file1_buff[file1_size - sizeof(file1_test_txt) + 1], file1_test_txt, sizeof(file1_test_txt) - 1); /* Second header. */ assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("LibarchiveAddingTest.odt", archive_entry_pathname(ae)); assertA((int)archive_entry_mtime(ae)); assertA((int)archive_entry_ctime(ae)); assertA((int)archive_entry_atime(ae)); assertEqualInt(file2_size, archive_entry_size(ae)); assertEqualInt(33188, archive_entry_mode(ae)); assertA(file2_size == archive_read_data(a, file2_buff, file2_size)); assertEqualMem(&file2_buff[file2_size + 1 - sizeof(file2_test_txt)], file2_test_txt, sizeof(file2_test_txt) - 1); /* Test EOF */ assertA(1 == archive_read_next_header(a, &ae)); assertEqualInt(2, archive_file_count(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static void create_reg_file_win(struct archive_entry *ae, const char *msg) { static const char data[]="abcdefghijklmnopqrstuvwxyz"; struct archive *ad; struct stat st; char *p, *fname; size_t l; /* Write the entry to disk. */ assert((ad = archive_write_disk_new()) != NULL); archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); failure("%s", msg); archive_entry_set_size(ae, sizeof(data)); archive_entry_set_mtime(ae, 123456789, 0); assertEqualIntA(ad, 0, archive_write_header(ad, ae)); assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); #if ARCHIVE_VERSION_NUMBER < 2000000 archive_write_finish(ad); #else assertEqualInt(0, archive_write_finish(ad)); #endif /* Test the entries on disk. */ l = strlen(archive_entry_pathname(ae)); fname = malloc(l + 1); assert(NULL != fname); strcpy(fname, archive_entry_pathname(ae)); /* Replace unusable characters in Windows to '_' */ for (p = fname; *p != '\0'; p++) if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || *p == '<' || *p == '>' || *p == '|') *p = '_'; assert(0 == stat(fname, &st)); failure("st.st_mode=%o archive_entry_mode(ae)=%o", st.st_mode, archive_entry_mode(ae)); assertEqualInt(st.st_size, sizeof(data)); }
/* Copy this function for each test file and adjust it accordingly. */ static void test_compat_zip_1(void) { char name[] = "test_compat_zip_1.zip"; struct archive_entry *ae; struct archive *a; int r; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a)); extract_reference_file(name); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); /* Read first entry. */ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString("META-INF/MANIFEST.MF", archive_entry_pathname(ae)); /* Read second entry. */ r = archive_read_next_header(a, &ae); if (r == ARCHIVE_FATAL && !libz_enabled) { skipping("Skipping ZIP compression check: %s", archive_error_string(a)); goto finish; } assertEqualIntA(a, ARCHIVE_OK, r); assertEqualString("tmp.class", archive_entry_pathname(ae)); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ZIP); finish: assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); }
static bool test_move_n_1(TTestContext* ctx) { TInst inst; TVM* vm = ((TTestMVM*)ctx)->fVM; inst.uNull.fOp = op_move_n; vm->fRegister[reg_current_player_idx] = 0; vm->fRegister[reg_player0_pos] = 0; vm->fRegister[reg_dieA] = 1; vm->fRegister[reg_dieB] = 2; TVM_Exec(vm, inst); if (!assertEqualInt(3, vm->fRegister[reg_player0_pos], ctx, "")) return false; return true; }
static void test_read_format_mtree2(void) { static char archive[] = "#mtree\n" "d type=dir content=.\n"; struct archive_entry *ae; struct archive *a; assert((a = archive_read_new()) != NULL); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, archive, sizeof(archive))); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); assertEqualString(archive_entry_pathname(ae), "d"); assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); }
static bool test_cmp_gt(TTestContext* ctx) { TInst inst; TVM* vm = ((TTestMVM*)ctx)->fVM; inst.uNull.fOp = op_cmp; inst.uIII.fFirst = reg_r0; inst.uIII.fSecond = reg_r1; inst.uIII.fThird = reg_r2; vm->fRegister[reg_r0] = 0; vm->fRegister[reg_r1] = -2; TVM_Exec(vm, inst); if (!assertEqualInt(1, vm->fRegister[reg_r2], ctx, "")) return false; return true; }
static void create_reg_file(struct archive_entry *ae, const char *msg) { static const char data[]="abcdefghijklmnopqrstuvwxyz"; struct archive *ad; struct stat st; /* Write the entry to disk. */ assert((ad = archive_write_disk_new()) != NULL); failure("%s", msg); assertEqualIntA(ad, 0, archive_write_header(ad, ae)); assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); #if ARCHIVE_API_VERSION > 1 assertEqualInt(0, archive_write_finish(ad)); #else archive_write_finish(ad); #endif /* Test the entries on disk. */ assert(0 == stat(archive_entry_pathname(ae), &st)); failure("st.st_mode=%o archive_entry_mode(ae)=%o", st.st_mode, archive_entry_mode(ae)); assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); assertEqualInt(st.st_size, sizeof(data)); }