]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add test archiving the file whose name has unusable
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 27 Feb 2009 05:15:39 +0000 (00:15 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 27 Feb 2009 05:15:39 +0000 (00:15 -0500)
characters in Windows.

SVN-Revision: 718

libarchive/test/test_write_disk.c

index f26bbae9e7f170299902f49a3ad8bed3cc8c03f1..b3c53be288c32104fa10f57ea6fb362111bbb84b 100644 (file)
@@ -218,6 +218,46 @@ static void create_reg_file4(struct archive_entry *ae, const char *msg)
        failure(msg);
        assertEqualInt(st.st_size, sizeof(data));
 }
+
+#ifdef _WIN32
+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));
+}
+#endif /* _WIN32 */
 #endif
 
 DEFINE_TEST(test_write_disk)
@@ -285,5 +325,23 @@ DEFINE_TEST(test_write_disk)
        archive_entry_set_mode(ae, S_IFREG | 0744);
        create(ae, "Test creating a file over an existing dir.");
        archive_entry_free(ae);
+
+#ifdef _WIN32
+       /* A file with unusable characters in its file name. */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_copy_pathname(ae, "f:i*l?e\"f<i>l|e");
+       archive_entry_set_mode(ae, S_IFREG | 0755);
+       create_reg_file_win(ae, "Test creating a regular file"
+           " with unusable characters in its file name");
+       archive_entry_free(ae);
+
+       /* A file with unusable characters in its directory name. */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_copy_pathname(ae, "d:i*r?e\"c<t>o|ry/file1");
+       archive_entry_set_mode(ae, S_IFREG | 0755);
+       create_reg_file_win(ae, "Test creating a regular file"
+           " with unusable characters in its file name");
+       archive_entry_free(ae);
+#endif /* _WIN32 */
 #endif
 }