test_read_format_cab_filename.c revision 302001
1160814Ssimon/*- 2160814Ssimon * Copyright (c) 2011 Michihiro NAKAJIMA 3238405Sjkim * All rights reserved. 4160814Ssimon * 5160814Ssimon * Redistribution and use in source and binary forms, with or without 6160814Ssimon * modification, are permitted provided that the following conditions 7160814Ssimon * are met: 8160814Ssimon * 1. Redistributions of source code must retain the above copyright 9160814Ssimon * notice, this list of conditions and the following disclaimer. 10160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 11160814Ssimon * notice, this list of conditions and the following disclaimer in the 12160814Ssimon * documentation and/or other materials provided with the distribution. 13160814Ssimon * 14160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15160814Ssimon * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16160814Ssimon * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17160814Ssimon * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18160814Ssimon * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20160814Ssimon * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21160814Ssimon * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22160814Ssimon * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23160814Ssimon * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24160814Ssimon */ 25160814Ssimon#include "test.h" 26238405Sjkim__FBSDID("$FreeBSD"); 27238405Sjkim 28160814Ssimon#include <locale.h> 29160814Ssimon 30160814Ssimonstatic void 31160814Ssimontest_read_format_cab_filename_CP932_eucJP(const char *refname) 32160814Ssimon{ 33160814Ssimon struct archive *a; 34160814Ssimon struct archive_entry *ae; 35160814Ssimon 36160814Ssimon /* 37160814Ssimon * Read CAB filename in ja_JP.eucJP with "hdrcharset=CP932" option. 38160814Ssimon */ 39160814Ssimon if (NULL == setlocale(LC_ALL, "ja_JP.eucJP")) { 40160814Ssimon skipping("ja_JP.eucJP locale not available on this system."); 41160814Ssimon return; 42160814Ssimon } 43160814Ssimon 44238405Sjkim assert((a = archive_read_new()) != NULL); 45238405Sjkim assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 46238405Sjkim assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 47238405Sjkim if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP932")) { 48238405Sjkim skipping("This system cannot convert character-set" 49238405Sjkim " from CP932 to eucJP."); 50160814Ssimon goto cleanup; 51160814Ssimon } 52160814Ssimon assertEqualIntA(a, ARCHIVE_OK, 53238405Sjkim archive_read_open_filename(a, refname, 10240)); 54238405Sjkim 55238405Sjkim /* Verify regular file. */ 56238405Sjkim assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 57238405Sjkim assertEqualString( 58238405Sjkim "\xc9\xbd\xa4\xc0\xa4\xe8\x2f\xb4\xc1\xbb\xfa\x2e\x74\x78\x74", 59238405Sjkim archive_entry_pathname(ae)); 60238405Sjkim assertEqualInt(5, archive_entry_size(ae)); 61238405Sjkim assertEqualInt(archive_entry_is_encrypted(ae), 0); 62238405Sjkim assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 63238405Sjkim 64160814Ssimon /* Verify regular file. */ 65238405Sjkim assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 66238405Sjkim assertEqualString( 67160814Ssimon "\xc9\xbd\xa4\xc0\xa4\xe8\x2f\xb0\xec\xcd\xf7\xc9\xbd\x2e\x74\x78\x74", 68238405Sjkim archive_entry_pathname(ae)); 69238405Sjkim assertEqualInt(5, archive_entry_size(ae)); 70238405Sjkim assertEqualInt(archive_entry_is_encrypted(ae), 0); 71238405Sjkim assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 72238405Sjkim 73160814Ssimon 74238405Sjkim /* End of archive. */ 75238405Sjkim assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 76238405Sjkim 77238405Sjkim /* Verify archive format. */ 78238405Sjkim assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); 79238405Sjkim assertEqualIntA(a, ARCHIVE_FORMAT_CAB, archive_format(a)); 80238405Sjkim 81238405Sjkim /* Close the archive. */ 82238405Sjkimcleanup: 83238405Sjkim assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 84238405Sjkim assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 85238405Sjkim} 86238405Sjkim 87238405Sjkimstatic void 88238405Sjkimtest_read_format_cab_filename_CP932_UTF8(const char *refname) 89238405Sjkim{ 90238405Sjkim struct archive *a; 91238405Sjkim struct archive_entry *ae; 92238405Sjkim 93238405Sjkim /* 94238405Sjkim * Read CAB filename in en_US.UTF-8 with "hdrcharset=CP932" option. 95238405Sjkim */ 96238405Sjkim if (NULL == setlocale(LC_ALL, "en_US.UTF-8")) { 97194206Ssimon skipping("en_US.UTF-8 locale not available on this system."); 98194206Ssimon return; 99160814Ssimon } 100160814Ssimon 101238405Sjkim assert((a = archive_read_new()) != NULL); 102160814Ssimon assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 103160814Ssimon assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 104160814Ssimon if (ARCHIVE_OK != archive_read_set_options(a, "hdrcharset=CP932")) { 105160814Ssimon skipping("This system cannot convert character-set" 106160814Ssimon " from CP932 to UTF-8."); 107160814Ssimon goto cleanup; 108160814Ssimon } 109194206Ssimon assertEqualIntA(a, ARCHIVE_OK, 110160814Ssimon archive_read_open_filename(a, refname, 10240)); 111160814Ssimon 112160814Ssimon /* Verify regular file. */ 113160814Ssimon assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 114160814Ssimon#if defined(__APPLE__) 115238405Sjkim /* Compare NFD string. */ 116160814Ssimon assertEqualUTF8String( 117238405Sjkim "\xe8\xa1\xa8\xe3\x81\x9f\xe3\x82\x99\xe3\x82\x88\x2f" 118238405Sjkim "\xe6\xbc\xa2\xe5\xad\x97\x2e\x74\x78\x74", 119238405Sjkim archive_entry_pathname(ae)); 120238405Sjkim assertEqualInt(5, archive_entry_size(ae)); 121238405Sjkim#else 122238405Sjkim /* Compare NFC string. */ 123238405Sjkim assertEqualUTF8String( 124296317Sdelphij "\xe8\xa1\xa8\xe3\x81\xa0\xe3\x82\x88\x2f" 125238405Sjkim "\xe6\xbc\xa2\xe5\xad\x97\x2e\x74\x78\x74", 126194206Ssimon archive_entry_pathname(ae)); 127160814Ssimon assertEqualInt(5, archive_entry_size(ae)); 128160814Ssimon#endif 129160814Ssimon assertEqualInt(archive_entry_is_encrypted(ae), 0); 130160814Ssimon assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 131160814Ssimon 132160814Ssimon /* Verify regular file. */ 133160814Ssimon assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 134160814Ssimon#if defined(__APPLE__) 135160814Ssimon /* Compare NFD string. */ 136160814Ssimon assertEqualUTF8String( 137160814Ssimon "\xe8\xa1\xa8\xe3\x81\x9f\xe3\x82\x99\xe3\x82\x88\x2f" 138160814Ssimon "\xe4\xb8\x80\xe8\xa6\xa7\xe8\xa1\xa8\x2e\x74\x78\x74", 139160814Ssimon archive_entry_pathname(ae)); 140160814Ssimon#else 141238405Sjkim /* Compare NFC string. */ 142194206Ssimon assertEqualUTF8String( 143160814Ssimon "\xe8\xa1\xa8\xe3\x81\xa0\xe3\x82\x88\x2f" 144194206Ssimon "\xe4\xb8\x80\xe8\xa6\xa7\xe8\xa1\xa8\x2e\x74\x78\x74", 145194206Ssimon archive_entry_pathname(ae)); 146160814Ssimon#endif 147238405Sjkim assertEqualInt(5, archive_entry_size(ae)); 148238405Sjkim assertEqualInt(archive_entry_is_encrypted(ae), 0); 149238405Sjkim assertEqualIntA(a, archive_read_has_encrypted_entries(a), ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED); 150238405Sjkim 151238405Sjkim 152238405Sjkim /* End of archive. */ 153238405Sjkim assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 154238405Sjkim 155160814Ssimon /* Verify archive format. */ 156160814Ssimon assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0)); 157160814Ssimon assertEqualIntA(a, ARCHIVE_FORMAT_CAB, archive_format(a)); 158160814Ssimon 159194206Ssimon /* Close the archive. */ 160160814Ssimoncleanup: 161160814Ssimon assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 162238405Sjkim assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 163238405Sjkim} 164238405Sjkim 165160814SsimonDEFINE_TEST(test_read_format_cab_filename) 166160814Ssimon{ 167238405Sjkim const char *refname = "test_read_format_cab_filename_cp932.cab"; 168238405Sjkim 169238405Sjkim extract_reference_file(refname); 170238405Sjkim test_read_format_cab_filename_CP932_eucJP(refname); 171238405Sjkim test_read_format_cab_filename_CP932_UTF8(refname); 172160814Ssimon} 173160814Ssimon