diff options
author | kientzle <kientzle@FreeBSD.org> | 2009-03-07 07:23:04 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2009-03-07 07:23:04 +0000 |
commit | 75dde6e038bfb963bde327a29d4eb13ee9f8f294 (patch) | |
tree | 5fa236b46e4aecd1290b64bd99a45e5bcf0c7304 | |
parent | 028251f74affd6aa68aed90a5301003e2ee5f153 (diff) | |
download | FreeBSD-src-75dde6e038bfb963bde327a29d4eb13ee9f8f294.zip FreeBSD-src-75dde6e038bfb963bde327a29d4eb13ee9f8f294.tar.gz |
Merge r718 from libarchive.googlecode.com: Some additional
tests of restoring files to disk with unusual characters, specifically
to exercise Windows issues.
-rw-r--r-- | lib/libarchive/test/test_write_disk.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/libarchive/test/test_write_disk.c b/lib/libarchive/test/test_write_disk.c index 789f571..72c9444 100644 --- a/lib/libarchive/test/test_write_disk.c +++ b/lib/libarchive/test/test_write_disk.c @@ -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 } |