]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Minor corrections to symlink tests.
authorTim Kientzle <kientzle@gmail.com>
Thu, 24 Sep 2009 15:13:01 +0000 (11:13 -0400)
committerTim Kientzle <kientzle@gmail.com>
Thu, 24 Sep 2009 15:13:01 +0000 (11:13 -0400)
SVN-Revision: 1466

libarchive/test/test_read_extract.c
libarchive/test/test_write_disk_symlink.c

index eb416b01ef61786e029c4f467f8659ebfc0222ac..7aad65057b0d1cb7e18b875760668a531da4684b 100644 (file)
@@ -33,7 +33,7 @@ DEFINE_TEST(test_read_extract)
        struct archive_entry *ae;
        struct archive *a;
        size_t used;
-       int i;
+       int i, numEntries = 0;
        char *buff, *file_buff;
 
        buff = malloc(BUFF_SIZE);
@@ -48,12 +48,14 @@ DEFINE_TEST(test_read_extract)
        assertA(0 == archive_write_set_compression_none(a));
        assertA(0 == archive_write_open_memory(a, buff, BUFF_SIZE, &used));
        /* A directory to be restored with EXTRACT_PERM. */
+       ++numEntries;
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "dir_0775");
        archive_entry_set_mode(ae, S_IFDIR | 0775);
        assertA(0 == archive_write_header(a, ae));
        archive_entry_free(ae);
        /* A regular file. */
+       ++numEntries;
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "file");
        archive_entry_set_mode(ae, S_IFREG | 0755);
@@ -64,49 +66,53 @@ DEFINE_TEST(test_read_extract)
        assertA(FILE_BUFF_SIZE == archive_write_data(a, file_buff, FILE_BUFF_SIZE));
        archive_entry_free(ae);
        /* A directory that should obey umask when restored. */
+       ++numEntries;
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "dir");
        archive_entry_set_mode(ae, S_IFDIR | 0777);
        assertA(0 == archive_write_header(a, ae));
        archive_entry_free(ae);
        /* A file in the directory. */
+       ++numEntries;
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "dir/file");
        archive_entry_set_mode(ae, S_IFREG | 0700);
        assertA(0 == archive_write_header(a, ae));
        archive_entry_free(ae);
        /* A file in a dir that is not already in the archive. */
+       ++numEntries;
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "dir2/file");
        archive_entry_set_mode(ae, S_IFREG | 0000);
        assertA(0 == archive_write_header(a, ae));
        archive_entry_free(ae);
        /* A dir with a trailing /. */
+       ++numEntries;
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "dir3/.");
        archive_entry_set_mode(ae, S_IFDIR | 0710);
        assertA(0 == archive_write_header(a, ae));
        archive_entry_free(ae);
        /* Multiple dirs with a single entry. */
+       ++numEntries;
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "dir4/a/../b/../c/");
        archive_entry_set_mode(ae, S_IFDIR | 0711);
        assertA(0 == archive_write_header(a, ae));
        archive_entry_free(ae);
        /* A symlink. */
-       assert((ae = archive_entry_new()) != NULL);
-       archive_entry_copy_pathname(ae, "symlink");
-       archive_entry_set_mode(ae, AE_IFLNK | 0755);
-       archive_entry_set_symlink(ae, "file");
-       assertA(0 == archive_write_header(a, ae));
-       archive_entry_free(ae);
+       if (canSymlink()) {
+               ++numEntries;
+               assert((ae = archive_entry_new()) != NULL);
+               archive_entry_copy_pathname(ae, "symlink");
+               archive_entry_set_mode(ae, AE_IFLNK | 0755);
+               archive_entry_set_symlink(ae, "file");
+               assertA(0 == archive_write_header(a, ae));
+               archive_entry_free(ae);
+       }
        /* Close out the archive. */
        assertA(0 == archive_write_close(a));
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_write_finish(a);
-#else
        assertA(0 == archive_write_finish(a));
-#endif
 
        /* Extract the entries to disk. */
        assert((a = archive_read_new()) != NULL);
@@ -118,7 +124,7 @@ DEFINE_TEST(test_read_extract)
        assertA(0 == archive_read_next_header(a, &ae));
        assertA(0 == archive_read_extract(a, ae, ARCHIVE_EXTRACT_PERM));
        /* Rest of entries get restored with no flags. */
-       for (i = 0; i < 7; i++) {
+       for (i = 1; i < numEntries; i++) {
                failure("Error reading entry %d", i);
                assertA(0 == archive_read_next_header(a, &ae));
                failure("Failed to extract entry %d: %s", i,
@@ -127,13 +133,8 @@ DEFINE_TEST(test_read_extract)
        }
        assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
        assert(0 == archive_read_close(a));
-#if ARCHIVE_VERSION_NUMBER < 2000000
-       archive_read_finish(a);
-#else
        assert(0 == archive_read_finish(a));
-#endif
 
-#if !defined(_WIN32) || defined(__CYGWIN__)
        /* Test the entries on disk. */
        /* This first entry was extracted with ARCHIVE_EXTRACT_PERM,
         * so the permissions should have been restored exactly,
@@ -159,8 +160,8 @@ DEFINE_TEST(test_read_extract)
        assertIsDir("dir4/a", 0755);
        assertIsDir("dir4/b", 0755);
        assertIsDir("dir4/c", 0711);
-       assertIsSymlink("symlink", NULL); /* TODO: Assert value of symlink */
-#endif
+       if (canSymlink())
+               assertIsSymlink("symlink", "file");
 
        free(buff);
        free(file_buff);
index e8da067ddefaf6d157c346ca1ab55839f5e5cfbe..861f3bf6704e5c165565f2628722709adcd3daea 100644 (file)
@@ -35,6 +35,11 @@ DEFINE_TEST(test_write_disk_symlink)
        struct archive_entry *ae;
        int r;
 
+       if (!canSymlink()) {
+               skipping("Symlinks not supported");
+               return;
+       }
+
        /* Write entries to disk. */
        assert((ad = archive_write_disk_new()) != NULL);
 
@@ -45,7 +50,7 @@ DEFINE_TEST(test_write_disk_symlink)
        /* Regular file: link1a */
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "link1a");
-       archive_entry_set_mode(ae, S_IFREG | 0755);
+       archive_entry_set_mode(ae, AE_IFREG | 0755);
        archive_entry_set_size(ae, sizeof(data));
        assertEqualIntA(ad, 0, archive_write_header(ad, ae));
        assertEqualInt(sizeof(data),
@@ -56,15 +61,12 @@ DEFINE_TEST(test_write_disk_symlink)
        /* Symbolic Link: link1b -> link1a */
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "link1b");
-       archive_entry_set_mode(ae, S_IFREG | 0642);
+       archive_entry_set_mode(ae, AE_IFLNK | 0642);
        archive_entry_set_size(ae, 0);
        archive_entry_copy_symlink(ae, "link1a");
        assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
-       if (r >= ARCHIVE_WARN) {
-               assertEqualInt(ARCHIVE_WARN,
-                   archive_write_data(ad, data, sizeof(data)));
+       if (r >= ARCHIVE_WARN)
                assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
-       }
        archive_entry_free(ae);
 
        /*
@@ -75,7 +77,7 @@ DEFINE_TEST(test_write_disk_symlink)
        /* Symbolic link: link2b -> link2a */
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "link2b");
-       archive_entry_set_mode(ae, S_IFLNK | 0642);
+       archive_entry_set_mode(ae, AE_IFLNK | 0642);
        archive_entry_unset_size(ae);
        archive_entry_copy_symlink(ae, "link2a");
        assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
@@ -89,7 +91,7 @@ DEFINE_TEST(test_write_disk_symlink)
        /* File: link2a */
        assert((ae = archive_entry_new()) != NULL);
        archive_entry_copy_pathname(ae, "link2a");
-       archive_entry_set_mode(ae, S_IFREG | 0755);
+       archive_entry_set_mode(ae, AE_IFREG | 0755);
        archive_entry_set_size(ae, sizeof(data));
        assertEqualIntA(ad, 0, archive_write_header(ad, ae));
        assertEqualInt(sizeof(data),