summaryrefslogtreecommitdiff
path: root/libarchive/test/test_open_filename.c
diff options
context:
space:
mode:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>2011-11-20 23:20:53 -0500
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>2011-11-20 23:20:53 -0500
commit87cc7b92eb771b1dafa8b070d16370ed85516136 (patch)
tree6bf70e1f58ea13c2aabc14f56cd6bcd37232837f /libarchive/test/test_open_filename.c
parentc451144c0a402671c91cf79b89dc0cf203dcda76 (diff)
downloadlibarchive-87cc7b92eb771b1dafa8b070d16370ed85516136.tar.gz
Add wchar_t filename support for archive_{read,write}_open_filename().
It would be useful for an internationalization programing on Windows. SVN-Revision: 3825
Diffstat (limited to 'libarchive/test/test_open_filename.c')
-rw-r--r--libarchive/test/test_open_filename.c93
1 files changed, 92 insertions, 1 deletions
diff --git a/libarchive/test/test_open_filename.c b/libarchive/test/test_open_filename.c
index ca3ac272..15646b86 100644
--- a/libarchive/test/test_open_filename.c
+++ b/libarchive/test/test_open_filename.c
@@ -25,7 +25,8 @@
#include "test.h"
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_open_filename.c 191183 2009-04-17 01:06:31Z kientzle $");
-DEFINE_TEST(test_open_filename)
+static void
+test_open_filename_mbs(void)
{
char buff[64];
struct archive_entry *ae;
@@ -107,3 +108,93 @@ DEFINE_TEST(test_open_filename)
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
+
+static void
+test_open_filename_wcs(void)
+{
+ char buff[64];
+ struct archive_entry *ae;
+ struct archive *a;
+
+ /* Write an archive through this FILE *. */
+ assert((a = archive_write_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a));
+ assertEqualIntA(a, ARCHIVE_OK,
+ archive_write_open_filename_w(a, L"test.tar"));
+
+ /*
+ * Write a file to it.
+ */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_set_mtime(ae, 1, 0);
+ archive_entry_copy_pathname_w(ae, L"file");
+ archive_entry_set_mode(ae, S_IFREG | 0755);
+ archive_entry_set_size(ae, 8);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
+ archive_entry_free(ae);
+ assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9));
+
+ /*
+ * Write a second file to it.
+ */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname_w(ae, L"file2");
+ archive_entry_set_mode(ae, S_IFREG | 0755);
+ archive_entry_set_size(ae, 819200);
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
+ archive_entry_free(ae);
+
+ /* Close out the archive. */
+ assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_write_free(a));
+
+ /*
+ * Now, read the data back.
+ */
+ 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,
+ archive_read_open_filename_w(a, L"test.tar", 512));
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualInt(1, archive_entry_mtime(ae));
+ assertEqualInt(0, archive_entry_mtime_nsec(ae));
+ assertEqualInt(0, archive_entry_atime(ae));
+ assertEqualInt(0, archive_entry_ctime(ae));
+ assertEqualWString(L"file", archive_entry_pathname_w(ae));
+ assert((S_IFREG | 0755) == archive_entry_mode(ae));
+ assertEqualInt(8, archive_entry_size(ae));
+ assertEqualIntA(a, 8, archive_read_data(a, buff, 10));
+ assertEqualMem(buff, "12345678", 8);
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualWString(L"file2", archive_entry_pathname_w(ae));
+ assert((S_IFREG | 0755) == archive_entry_mode(ae));
+ assertEqualInt(819200, archive_entry_size(ae));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a));
+
+ /* Verify the end of the archive. */
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+ /*
+ * Verify some of the error handling.
+ */
+ 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_FATAL,
+ archive_read_open_filename_w(a, L"nonexistent.tar", 512));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+
+}
+
+DEFINE_TEST(test_open_filename)
+{
+ test_open_filename_mbs();
+ test_open_filename_wcs();
+}