]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Separate test_write_format_7zip.c into three files.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 2 Dec 2012 22:34:06 +0000 (07:34 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 2 Dec 2012 22:34:06 +0000 (07:34 +0900)
Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_write_format_7zip.c
libarchive/test/test_write_format_7zip_empty.c [new file with mode: 0644]
libarchive/test/test_write_format_7zip_large.c [new file with mode: 0644]

index 2a6fe8a3beb5dc40282fcecaa35caeb0504639de..1c7c8cbef687544f0c05fbefdaec5bff9faa79e3 100644 (file)
@@ -441,6 +441,8 @@ libarchive_test_SOURCES=                                    \
        libarchive/test/test_write_filter_uuencode.c            \
        libarchive/test/test_write_filter_xz.c                  \
        libarchive/test/test_write_format_7zip.c                \
+       libarchive/test/test_write_format_7zip_empty.c          \
+       libarchive/test/test_write_format_7zip_large.c          \
        libarchive/test/test_write_format_ar.c                  \
        libarchive/test/test_write_format_cpio.c                \
        libarchive/test/test_write_format_cpio_empty.c          \
index 4a28322455e6960816b4ac2b3dee160546191383..7239bb16085e7afe6b50ba517e0f79adf87a0002 100644 (file)
@@ -176,6 +176,8 @@ IF(ENABLE_TEST)
     test_write_filter_uuencode.c
     test_write_filter_xz.c
     test_write_format_7zip.c
+    test_write_format_7zip_empty.c
+    test_write_format_7zip_large.c
     test_write_format_ar.c
     test_write_format_cpio.c
     test_write_format_cpio_empty.c
index 7c2702fad5e5e18eaf94160710fa6d03cb90eac9..c8fdcd02cc84a11e99468735cb209784293f7d2d 100644 (file)
@@ -524,371 +524,6 @@ test_basic2(const char *compression_type)
        free(buff);
 }
 
-/*
- * Test writing an empty archive.
- */
-static void
-test_empty_archive(void)
-{
-       struct archive *a;
-       size_t buffsize = 1000;
-       char *buff;
-       size_t used;
-
-       buff = malloc(buffsize);
-
-       /* Create a new archive in memory. */
-       assert((a = archive_write_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
-       assertEqualIntA(a, ARCHIVE_OK,
-           archive_write_open_memory(a, buff, buffsize, &used));
-
-       /* Close out the archive. */
-       assertEqualInt(ARCHIVE_OK, archive_write_close(a));
-       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
-       /* Verify the archive file size. */
-       assertEqualInt(32, used);
-
-       /* Verify the initial header. */
-       assertEqualMem(buff,
-               "\x37\x7a\xbc\xaf\x27\x1c\x00\x03"
-               "\x8d\x9b\xd5\x0f\x00\x00\x00\x00"
-               "\x00\x00\x00\x00\x00\x00\x00\x00"
-               "\x00\x00\x00\x00\x00\x00\x00\x00", 32);
-
-       free(buff);
-}
-
-/*
- * Test writing an empty file.
- */
-static void
-test_only_empty_file(void)
-{
-       struct archive *a;
-       struct archive_entry *ae;
-       size_t buffsize = 1000;
-       char *buff;
-       size_t used;
-
-       buff = malloc(buffsize);
-
-       /* Create a new archive in memory. */
-       assert((a = archive_write_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
-       assertEqualIntA(a, ARCHIVE_OK,
-           archive_write_open_memory(a, buff, buffsize, &used));
-
-       /*
-        * Write an empty file to it.
-        */
-       assert((ae = archive_entry_new()) != NULL);
-       archive_entry_set_mtime(ae, 1, 10);
-       assertEqualInt(1, archive_entry_mtime(ae));
-       assertEqualInt(10, archive_entry_mtime_nsec(ae));
-       archive_entry_set_atime(ae, 2, 20);
-       assertEqualInt(2, archive_entry_atime(ae));
-       assertEqualInt(20, archive_entry_atime_nsec(ae));
-       archive_entry_set_ctime(ae, 0, 100);
-       assertEqualInt(0, archive_entry_ctime(ae));
-       assertEqualInt(100, archive_entry_ctime_nsec(ae));
-       archive_entry_copy_pathname(ae, "empty");
-       assertEqualString("empty", archive_entry_pathname(ae));
-       archive_entry_set_mode(ae, AE_IFREG | 0755);
-       assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae));
-
-       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
-       archive_entry_free(ae);
-
-       /* Close out the archive. */
-       assertEqualInt(ARCHIVE_OK, archive_write_close(a));
-       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
-       /* Verify the archive file size. */
-       assertEqualInt(102, used);
-
-       /* Verify the initial header. */
-       assertEqualMem(buff,
-               "\x37\x7a\xbc\xaf\x27\x1c\x00\x03"
-               "\x00\x5b\x58\x25\x00\x00\x00\x00"
-               "\x00\x00\x00\x00\x46\x00\x00\x00"
-               "\x00\x00\x00\x00\x8f\xce\x1d\xf3", 32);
-
-       /*
-        * Now, read the data back.
-        */
-       /* With the test memory reader -- seeking mode. */
-       assert((a = archive_read_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
-       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
-
-       /*
-        * Read and verify an empty file.
-        */
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
-       assertEqualInt(1, archive_entry_mtime(ae));
-       assertEqualInt(0, archive_entry_mtime_nsec(ae));
-       assertEqualInt(2, archive_entry_atime(ae));
-       assertEqualInt(0, archive_entry_atime_nsec(ae));
-       assertEqualInt(0, archive_entry_ctime(ae));
-       assertEqualInt(100, archive_entry_ctime_nsec(ae));
-       assertEqualString("empty", archive_entry_pathname(ae));
-       assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
-       assertEqualInt(0, archive_entry_size(ae));
-
-       /* Verify the end of the 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));
-
-       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
-       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
-       free(buff);
-}
-
-static void
-test_only_empty_files(void)
-{
-       struct archive *a;
-       struct archive_entry *ae;
-       size_t buffsize = 1000;
-       char *buff;
-       size_t used;
-
-       buff = malloc(buffsize);
-
-       /* Create a new archive in memory. */
-       assert((a = archive_write_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
-       assertEqualIntA(a, ARCHIVE_OK,
-           archive_write_open_memory(a, buff, buffsize, &used));
-
-       /*
-        * Write an empty file to it.
-        */
-       assert((ae = archive_entry_new()) != NULL);
-       archive_entry_set_mtime(ae, 1, 10);
-       assertEqualInt(1, archive_entry_mtime(ae));
-       assertEqualInt(10, archive_entry_mtime_nsec(ae));
-       archive_entry_set_atime(ae, 2, 20);
-       assertEqualInt(2, archive_entry_atime(ae));
-       assertEqualInt(20, archive_entry_atime_nsec(ae));
-       archive_entry_copy_pathname(ae, "empty");
-       assertEqualString("empty", archive_entry_pathname(ae));
-       archive_entry_set_mode(ae, AE_IFREG | 0755);
-       assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
-
-       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
-       archive_entry_free(ae);
-
-       /*
-        * Write second empty file to it.
-        */
-       assert((ae = archive_entry_new()) != NULL);
-       archive_entry_set_mtime(ae, 2, 10);
-       assertEqualInt(2, archive_entry_mtime(ae));
-       assertEqualInt(10, archive_entry_mtime_nsec(ae));
-       archive_entry_set_ctime(ae, 2, 10);
-       assertEqualInt(2, archive_entry_ctime(ae));
-       assertEqualInt(10, archive_entry_ctime_nsec(ae));
-       archive_entry_copy_pathname(ae, "empty2");
-       assertEqualString("empty2", archive_entry_pathname(ae));
-       archive_entry_set_mode(ae, AE_IFREG | 0644);
-       assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae));
-
-       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
-       archive_entry_free(ae);
-
-       /*
-        * Write third empty file to it.
-        */
-       assert((ae = archive_entry_new()) != NULL);
-       archive_entry_set_mtime(ae, 3, 10);
-       assertEqualInt(3, archive_entry_mtime(ae));
-       assertEqualInt(10, archive_entry_mtime_nsec(ae));
-       archive_entry_copy_pathname(ae, "empty3");
-       assertEqualString("empty3", archive_entry_pathname(ae));
-       archive_entry_set_mode(ae, AE_IFREG | 0644);
-       assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae));
-
-       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
-       archive_entry_free(ae);
-
-       /* Close out the archive. */
-       assertEqualInt(ARCHIVE_OK, archive_write_close(a));
-       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
-       /* Verify the initial header. */
-       assertEqualMem(buff, "\x37\x7a\xbc\xaf\x27\x1c\x00\x03", 8);
-
-       /*
-        * Now, read the data back.
-        */
-       /* With the test memory reader -- seeking mode. */
-       assert((a = archive_read_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
-       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
-
-       /*
-        * Read and verify an empty file.
-        */
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
-       assertEqualInt(1, archive_entry_mtime(ae));
-       assertEqualInt(0, archive_entry_mtime_nsec(ae));
-       assertEqualInt(2, archive_entry_atime(ae));
-       assertEqualInt(0, archive_entry_atime_nsec(ae));
-       assertEqualInt(0, archive_entry_ctime(ae));
-       assertEqualString("empty", archive_entry_pathname(ae));
-       assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
-       assertEqualInt(0, archive_entry_size(ae));
-
-       /*
-        * Read and verify second empty file.
-        */
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
-       assertEqualInt(2, archive_entry_mtime(ae));
-       assertEqualInt(0, archive_entry_mtime_nsec(ae));
-       assertEqualInt(0, archive_entry_atime(ae));
-       assertEqualInt(2, archive_entry_ctime(ae));
-       assertEqualInt(0, archive_entry_ctime_nsec(ae));
-       assertEqualString("empty2", archive_entry_pathname(ae));
-       assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
-       assertEqualInt(0, archive_entry_size(ae));
-
-       /*
-        * Read and verify third empty file.
-        */
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
-       assertEqualInt(3, archive_entry_mtime(ae));
-       assertEqualInt(0, archive_entry_mtime_nsec(ae));
-       assertEqualInt(0, archive_entry_atime(ae));
-       assertEqualInt(0, archive_entry_ctime(ae));
-       assertEqualString("empty3", archive_entry_pathname(ae));
-       assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
-       assertEqualInt(0, archive_entry_size(ae));
-
-       /* Verify the end of the 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));
-
-       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
-       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
-       free(buff);
-}
-
-#define LARGE_SIZE     (16*1024*1024)
-static void
-test_large(const char *compression_type)
-{
-       static char filedata[LARGE_SIZE];
-       static char filedata2[LARGE_SIZE];
-       struct archive_entry *ae;
-       struct archive *a;
-       size_t used;
-       size_t buffsize = LARGE_SIZE + 1024 * 256;
-       char *buff;
-       unsigned i;
-
-       buff = malloc(buffsize);
-
-       /* Create a new archive in memory. */
-       assert((a = archive_write_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
-       if (compression_type != NULL &&
-           ARCHIVE_OK != archive_write_set_format_option(a, "7zip",
-           "compression", compression_type)) {
-               skipping("%s writing not fully supported on this platform",
-                  compression_type);
-               assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-               free(buff);
-               return;
-       }
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
-       assertEqualIntA(a, ARCHIVE_OK,
-           archive_write_open_memory(a, buff, buffsize, &used));
-
-       /*
-        * Write a large file to it.
-        */
-       assert((ae = archive_entry_new()) != NULL);
-       archive_entry_set_mtime(ae, 1, 100);
-       assertEqualInt(1, archive_entry_mtime(ae));
-       assertEqualInt(100, archive_entry_mtime_nsec(ae));
-       archive_entry_copy_pathname(ae, "file");
-       assertEqualString("file", archive_entry_pathname(ae));
-       archive_entry_set_mode(ae, AE_IFREG | 0755);
-       assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
-       archive_entry_set_size(ae, sizeof(filedata));
-
-       assertEqualInt(0, archive_write_header(a, ae));
-       archive_entry_free(ae);
-       if (strcmp(compression_type, "ppmd") == 0) {
-               /* NOTE: PPMd cannot handle random data correctly.*/
-               memset(filedata, 'a', sizeof(filedata));
-       } else {
-               for (i = 0; i < sizeof(filedata); i++)
-                       filedata[i] = (char)rand();
-       }
-       assertEqualInt(sizeof(filedata),
-           archive_write_data(a, filedata, sizeof(filedata)));
-
-       /* Close out the archive. */
-       assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
-       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
-
-       /* Verify the initial header. */
-       assertEqualMem(buff, "\x37\x7a\xbc\xaf\x27\x1c\x00\x03", 8);
-
-       /*
-        * Now, read the data back.
-        */
-       /* With the test memory reader -- seeking mode. */
-       assert((a = archive_read_new()) != NULL);
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
-       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
-
-       /*
-        * Read and verify a large file.
-        */
-       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
-       assertEqualInt(1, archive_entry_mtime(ae));
-       assertEqualInt(100, archive_entry_mtime_nsec(ae));
-       assertEqualInt(0, archive_entry_atime(ae));
-       assertEqualInt(0, archive_entry_ctime(ae));
-       assertEqualString("file", archive_entry_pathname(ae));
-       assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
-       assertEqualInt(sizeof(filedata), archive_entry_size(ae));
-       assertEqualIntA(a, sizeof(filedata2),
-           archive_read_data(a, filedata2, sizeof(filedata2)));
-       assertEqualMem(filedata, filedata2, sizeof(filedata));
-
-       /* Verify the end of the 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));
-
-       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
-       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-
-       free(buff);
-}
-
 DEFINE_TEST(test_write_format_7zip)
 {
        /* Test that making a 7-Zip archive file by default compression
@@ -933,48 +568,3 @@ DEFINE_TEST(test_write_format_7zip_basic_ppmd)
        /* Test that making a 7-Zip archive file with PPMd compression. */
        test_basic("ppmd");
 }
-
-DEFINE_TEST(test_write_format_7zip_empty)
-{
-       /* Test that making an empty 7-Zip archive file. */
-       test_empty_archive();
-       /* Test that write an empty file. */
-       test_only_empty_file();
-       test_only_empty_files();
-}
-
-DEFINE_TEST(test_write_format_7zip_large_bzip2)
-{
-       /* Test that making a 7-Zip archive file with bzip2 compression. */
-       test_large("bzip2");
-}
-
-DEFINE_TEST(test_write_format_7zip_large_copy)
-{
-       /* Test that making a 7-Zip archive file without compression. */
-       test_large("copy");
-}
-
-DEFINE_TEST(test_write_format_7zip_large_deflate)
-{
-       /* Test that making a 7-Zip archive file with deflate compression. */
-       test_large("deflate");
-}
-
-DEFINE_TEST(test_write_format_7zip_large_lzma1)
-{
-       /* Test that making a 7-Zip archive file with lzma1 compression. */
-       test_large("lzma1");
-}
-
-DEFINE_TEST(test_write_format_7zip_large_lzma2)
-{
-       /* Test that making a 7-Zip archive file with lzma2 compression. */
-       test_large("lzma2");
-}
-
-DEFINE_TEST(test_write_format_7zip_large_ppmd)
-{
-       /* Test that making a 7-Zip archive file with PPMd compression. */
-       test_large("ppmd");
-}
diff --git a/libarchive/test/test_write_format_7zip_empty.c b/libarchive/test/test_write_format_7zip_empty.c
new file mode 100644 (file)
index 0000000..9a503e9
--- /dev/null
@@ -0,0 +1,299 @@
+/*-
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+/*
+ * Test writing an empty archive.
+ */
+DEFINE_TEST(test_write_format_7zip_empty_archive)
+{
+       struct archive *a;
+       size_t buffsize = 1000;
+       char *buff;
+       size_t used;
+
+       buff = malloc(buffsize);
+
+       /* Create a new archive in memory. */
+       assert((a = archive_write_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_write_open_memory(a, buff, buffsize, &used));
+
+       /* Close out the archive. */
+       assertEqualInt(ARCHIVE_OK, archive_write_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+       /* Verify the archive file size. */
+       assertEqualInt(32, used);
+
+       /* Verify the initial header. */
+       assertEqualMem(buff,
+               "\x37\x7a\xbc\xaf\x27\x1c\x00\x03"
+               "\x8d\x9b\xd5\x0f\x00\x00\x00\x00"
+               "\x00\x00\x00\x00\x00\x00\x00\x00"
+               "\x00\x00\x00\x00\x00\x00\x00\x00", 32);
+
+       free(buff);
+}
+
+/*
+ * Test writing an empty file.
+ */
+static void
+test_only_empty_file(void)
+{
+       struct archive *a;
+       struct archive_entry *ae;
+       size_t buffsize = 1000;
+       char *buff;
+       size_t used;
+
+       buff = malloc(buffsize);
+
+       /* Create a new archive in memory. */
+       assert((a = archive_write_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_write_open_memory(a, buff, buffsize, &used));
+
+       /*
+        * Write an empty file to it.
+        */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_set_mtime(ae, 1, 10);
+       assertEqualInt(1, archive_entry_mtime(ae));
+       assertEqualInt(10, archive_entry_mtime_nsec(ae));
+       archive_entry_set_atime(ae, 2, 20);
+       assertEqualInt(2, archive_entry_atime(ae));
+       assertEqualInt(20, archive_entry_atime_nsec(ae));
+       archive_entry_set_ctime(ae, 0, 100);
+       assertEqualInt(0, archive_entry_ctime(ae));
+       assertEqualInt(100, archive_entry_ctime_nsec(ae));
+       archive_entry_copy_pathname(ae, "empty");
+       assertEqualString("empty", archive_entry_pathname(ae));
+       archive_entry_set_mode(ae, AE_IFREG | 0755);
+       assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae));
+
+       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
+       archive_entry_free(ae);
+
+       /* Close out the archive. */
+       assertEqualInt(ARCHIVE_OK, archive_write_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+       /* Verify the archive file size. */
+       assertEqualInt(102, used);
+
+       /* Verify the initial header. */
+       assertEqualMem(buff,
+               "\x37\x7a\xbc\xaf\x27\x1c\x00\x03"
+               "\x00\x5b\x58\x25\x00\x00\x00\x00"
+               "\x00\x00\x00\x00\x46\x00\x00\x00"
+               "\x00\x00\x00\x00\x8f\xce\x1d\xf3", 32);
+
+       /*
+        * Now, read the data back.
+        */
+       /* With the test memory reader -- seeking mode. */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
+
+       /*
+        * Read and verify an empty file.
+        */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualInt(1, archive_entry_mtime(ae));
+       assertEqualInt(0, archive_entry_mtime_nsec(ae));
+       assertEqualInt(2, archive_entry_atime(ae));
+       assertEqualInt(0, archive_entry_atime_nsec(ae));
+       assertEqualInt(0, archive_entry_ctime(ae));
+       assertEqualInt(100, archive_entry_ctime_nsec(ae));
+       assertEqualString("empty", archive_entry_pathname(ae));
+       assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
+       assertEqualInt(0, archive_entry_size(ae));
+
+       /* Verify the end of the 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));
+
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+       free(buff);
+}
+
+static void
+test_only_empty_files(void)
+{
+       struct archive *a;
+       struct archive_entry *ae;
+       size_t buffsize = 1000;
+       char *buff;
+       size_t used;
+
+       buff = malloc(buffsize);
+
+       /* Create a new archive in memory. */
+       assert((a = archive_write_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_write_open_memory(a, buff, buffsize, &used));
+
+       /*
+        * Write an empty file to it.
+        */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_set_mtime(ae, 1, 10);
+       assertEqualInt(1, archive_entry_mtime(ae));
+       assertEqualInt(10, archive_entry_mtime_nsec(ae));
+       archive_entry_set_atime(ae, 2, 20);
+       assertEqualInt(2, archive_entry_atime(ae));
+       assertEqualInt(20, archive_entry_atime_nsec(ae));
+       archive_entry_copy_pathname(ae, "empty");
+       assertEqualString("empty", archive_entry_pathname(ae));
+       archive_entry_set_mode(ae, AE_IFREG | 0755);
+       assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
+
+       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
+       archive_entry_free(ae);
+
+       /*
+        * Write second empty file to it.
+        */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_set_mtime(ae, 2, 10);
+       assertEqualInt(2, archive_entry_mtime(ae));
+       assertEqualInt(10, archive_entry_mtime_nsec(ae));
+       archive_entry_set_ctime(ae, 2, 10);
+       assertEqualInt(2, archive_entry_ctime(ae));
+       assertEqualInt(10, archive_entry_ctime_nsec(ae));
+       archive_entry_copy_pathname(ae, "empty2");
+       assertEqualString("empty2", archive_entry_pathname(ae));
+       archive_entry_set_mode(ae, AE_IFREG | 0644);
+       assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae));
+
+       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
+       archive_entry_free(ae);
+
+       /*
+        * Write third empty file to it.
+        */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_set_mtime(ae, 3, 10);
+       assertEqualInt(3, archive_entry_mtime(ae));
+       assertEqualInt(10, archive_entry_mtime_nsec(ae));
+       archive_entry_copy_pathname(ae, "empty3");
+       assertEqualString("empty3", archive_entry_pathname(ae));
+       archive_entry_set_mode(ae, AE_IFREG | 0644);
+       assertEqualInt((AE_IFREG | 0644), archive_entry_mode(ae));
+
+       assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae));
+       archive_entry_free(ae);
+
+       /* Close out the archive. */
+       assertEqualInt(ARCHIVE_OK, archive_write_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+       /* Verify the initial header. */
+       assertEqualMem(buff, "\x37\x7a\xbc\xaf\x27\x1c\x00\x03", 8);
+
+       /*
+        * Now, read the data back.
+        */
+       /* With the test memory reader -- seeking mode. */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
+
+       /*
+        * Read and verify an empty file.
+        */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualInt(1, archive_entry_mtime(ae));
+       assertEqualInt(0, archive_entry_mtime_nsec(ae));
+       assertEqualInt(2, archive_entry_atime(ae));
+       assertEqualInt(0, archive_entry_atime_nsec(ae));
+       assertEqualInt(0, archive_entry_ctime(ae));
+       assertEqualString("empty", archive_entry_pathname(ae));
+       assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
+       assertEqualInt(0, archive_entry_size(ae));
+
+       /*
+        * Read and verify second empty file.
+        */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualInt(2, archive_entry_mtime(ae));
+       assertEqualInt(0, archive_entry_mtime_nsec(ae));
+       assertEqualInt(0, archive_entry_atime(ae));
+       assertEqualInt(2, archive_entry_ctime(ae));
+       assertEqualInt(0, archive_entry_ctime_nsec(ae));
+       assertEqualString("empty2", archive_entry_pathname(ae));
+       assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
+       assertEqualInt(0, archive_entry_size(ae));
+
+       /*
+        * Read and verify third empty file.
+        */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualInt(3, archive_entry_mtime(ae));
+       assertEqualInt(0, archive_entry_mtime_nsec(ae));
+       assertEqualInt(0, archive_entry_atime(ae));
+       assertEqualInt(0, archive_entry_ctime(ae));
+       assertEqualString("empty3", archive_entry_pathname(ae));
+       assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
+       assertEqualInt(0, archive_entry_size(ae));
+
+       /* Verify the end of the 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));
+
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+       free(buff);
+}
+
+DEFINE_TEST(test_write_format_7zip_empty_files)
+{
+       /* Test that write an empty file. */
+       test_only_empty_file();
+       test_only_empty_files();
+}
diff --git a/libarchive/test/test_write_format_7zip_large.c b/libarchive/test/test_write_format_7zip_large.c
new file mode 100644 (file)
index 0000000..5c49f59
--- /dev/null
@@ -0,0 +1,174 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+#define LARGE_SIZE     (16*1024*1024)
+static void
+test_large(const char *compression_type)
+{
+       struct archive_entry *ae;
+       struct archive *a;
+       size_t used;
+       size_t buffsize = LARGE_SIZE + 1024 * 256;
+       size_t datasize = LARGE_SIZE;
+       char *buff, *filedata, *filedata2;
+       unsigned i;
+
+       assert((buff = malloc(buffsize)) != NULL);
+       assert((filedata = malloc(datasize)) != NULL);
+       assert((filedata2 = malloc(datasize)) != NULL);
+
+       /* Create a new archive in memory. */
+       assert((a = archive_write_new()) != NULL);
+       if (a == NULL || buff == NULL || filedata == NULL || filedata2 == NULL) {
+               archive_write_free(a);
+               free(buff);
+               free(filedata);
+               free(filedata2);
+               return;
+       }
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_7zip(a));
+       if (compression_type != NULL &&
+           ARCHIVE_OK != archive_write_set_format_option(a, "7zip",
+           "compression", compression_type)) {
+               skipping("%s writing not fully supported on this platform",
+                  compression_type);
+               assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+               free(buff);
+               free(filedata);
+               free(filedata2);
+               return;
+       }
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_add_filter_none(a));
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_write_open_memory(a, buff, buffsize, &used));
+
+       /*
+        * Write a large file to it.
+        */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_set_mtime(ae, 1, 100);
+       assertEqualInt(1, archive_entry_mtime(ae));
+       assertEqualInt(100, archive_entry_mtime_nsec(ae));
+       archive_entry_copy_pathname(ae, "file");
+       assertEqualString("file", archive_entry_pathname(ae));
+       archive_entry_set_mode(ae, AE_IFREG | 0755);
+       assertEqualInt((AE_IFREG | 0755), archive_entry_mode(ae));
+       archive_entry_set_size(ae, datasize);
+
+       assertEqualInt(0, archive_write_header(a, ae));
+       archive_entry_free(ae);
+       if (strcmp(compression_type, "ppmd") == 0) {
+               /* NOTE: PPMd cannot handle random data correctly.*/
+               memset(filedata, 'a', datasize);
+       } else {
+               for (i = 0; i < datasize; i++)
+                       filedata[i] = (char)rand();
+       }
+       assertEqualInt(datasize, archive_write_data(a, filedata, datasize));
+
+       /* Close out the archive. */
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+       /* Verify the initial header. */
+       assertEqualMem(buff, "\x37\x7a\xbc\xaf\x27\x1c\x00\x03", 8);
+
+       /*
+        * Now, read the data back.
+        */
+       /* With the test memory reader -- seeking mode. */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, buff, used, 7));
+
+       /*
+        * Read and verify a large file.
+        */
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualInt(1, archive_entry_mtime(ae));
+       assertEqualInt(100, archive_entry_mtime_nsec(ae));
+       assertEqualInt(0, archive_entry_atime(ae));
+       assertEqualInt(0, archive_entry_ctime(ae));
+       assertEqualString("file", archive_entry_pathname(ae));
+       assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
+       assertEqualInt(datasize, archive_entry_size(ae));
+       assertEqualIntA(a, datasize, archive_read_data(a, filedata2, datasize));
+       assertEqualMem(filedata, filedata2, datasize);
+
+       /* Verify the end of the 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));
+
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+       free(buff);
+       free(filedata);
+       free(filedata2);
+}
+
+DEFINE_TEST(test_write_format_7zip_large_bzip2)
+{
+       /* Test that making a 7-Zip archive file with bzip2 compression. */
+       test_large("bzip2");
+}
+
+DEFINE_TEST(test_write_format_7zip_large_copy)
+{
+       /* Test that making a 7-Zip archive file without compression. */
+       test_large("copy");
+}
+
+DEFINE_TEST(test_write_format_7zip_large_deflate)
+{
+       /* Test that making a 7-Zip archive file with deflate compression. */
+       test_large("deflate");
+}
+
+DEFINE_TEST(test_write_format_7zip_large_lzma1)
+{
+       /* Test that making a 7-Zip archive file with lzma1 compression. */
+       test_large("lzma1");
+}
+
+DEFINE_TEST(test_write_format_7zip_large_lzma2)
+{
+       /* Test that making a 7-Zip archive file with lzma2 compression. */
+       test_large("lzma2");
+}
+
+DEFINE_TEST(test_write_format_7zip_large_ppmd)
+{
+       /* Test that making a 7-Zip archive file with PPMd compression. */
+       test_large("ppmd");
+}