svn commit: r189487 - head/lib/libarchive/test
Tim Kientzle
kientzle at FreeBSD.org
Fri Mar 6 23:23:05 PST 2009
Author: kientzle
Date: Sat Mar 7 07:23:04 2009
New Revision: 189487
URL: http://svn.freebsd.org/changeset/base/189487
Log:
Merge r718 from libarchive.googlecode.com: Some additional
tests of restoring files to disk with unusual characters, specifically
to exercise Windows issues.
Modified:
head/lib/libarchive/test/test_write_disk.c
Modified: head/lib/libarchive/test/test_write_disk.c
==============================================================================
--- head/lib/libarchive/test/test_write_disk.c Sat Mar 7 07:19:25 2009 (r189486)
+++ head/lib/libarchive/test/test_write_disk.c Sat Mar 7 07:23:04 2009 (r189487)
@@ -218,6 +218,46 @@ static void create_reg_file4(struct arch
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
}
More information about the svn-src-head
mailing list