|
| 1 | +package net.sf.sevenzipjbinding.junit.encoding; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertNotEquals; |
| 5 | + |
| 6 | +import java.io.RandomAccessFile; |
| 7 | +import java.io.UnsupportedEncodingException; |
| 8 | +import java.nio.charset.StandardCharsets; |
| 9 | +import java.util.Arrays; |
| 10 | +import java.util.Collection; |
| 11 | + |
| 12 | +import org.junit.Test; |
| 13 | +import org.junit.runners.Parameterized.Parameters; |
| 14 | + |
| 15 | +import net.sf.sevenzipjbinding.ArchiveFormat; |
| 16 | +import net.sf.sevenzipjbinding.IInArchive; |
| 17 | +import net.sf.sevenzipjbinding.ISequentialOutStream; |
| 18 | +import net.sf.sevenzipjbinding.PropID; |
| 19 | +import net.sf.sevenzipjbinding.SevenZip; |
| 20 | +import net.sf.sevenzipjbinding.SevenZipException; |
| 21 | +import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream; |
| 22 | +import net.sf.sevenzipjbinding.junit.JUnitNativeTestBase; |
| 23 | +import net.sf.sevenzipjbinding.junit.VoidContext; |
| 24 | +import net.sf.sevenzipjbinding.simple.ISimpleInArchive; |
| 25 | +import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem; |
| 26 | + |
| 27 | +public class JapaneseFilenamesInArchive extends JUnitNativeTestBase<VoidContext> { |
| 28 | + |
| 29 | + private final ArchiveFormat archiveFormat; |
| 30 | + |
| 31 | + public JapaneseFilenamesInArchive(ArchiveFormat archiveFormat) { |
| 32 | + this.archiveFormat = archiveFormat; |
| 33 | + } |
| 34 | + |
| 35 | + @Parameters |
| 36 | + public static Collection<Object> data() { |
| 37 | + return Arrays.asList(new Object[] { ArchiveFormat.ZIP }); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testUpperLowerCaseUnicode() throws Throwable { |
| 42 | + RandomAccessFile randomAccessFile = null; |
| 43 | + IInArchive inArchive = null; |
| 44 | + Throwable throwable = null; |
| 45 | + |
| 46 | + log("Testing for " + archiveFormat); |
| 47 | + try { |
| 48 | + randomAccessFile = new RandomAccessFile("testdata/encoding/jpn_file_names." |
| 49 | + + archiveFormat.getMethodName().toLowerCase(), "r"); |
| 50 | + inArchive = SevenZip.openInArchive(archiveFormat, new RandomAccessFileInStream(randomAccessFile)); |
| 51 | + ISimpleInArchive simpleInterface = inArchive.getSimpleInterface(); |
| 52 | + |
| 53 | + int numItems = simpleInterface.getNumberOfItems(); |
| 54 | + assertEquals(2, numItems); |
| 55 | + |
| 56 | + ISimpleInArchiveItem[] archiveItems = simpleInterface.getArchiveItems(); |
| 57 | + |
| 58 | + String[] truth = {"123アアパート.txt", "テスト日本語.txt"}; |
| 59 | + |
| 60 | + |
| 61 | + for (int i = 0; i < numItems; i++) { |
| 62 | + String t = truth[i]; |
| 63 | + String path = archiveItems[i].getPath(); |
| 64 | + assertNotEquals(t, path); |
| 65 | + |
| 66 | + byte[] pathBytes = (byte[])inArchive.getProperty(i, PropID.PATH_BYTES); |
| 67 | + String encodedPath = new String(pathBytes, StandardCharsets.UTF_8); |
| 68 | + |
| 69 | + assertEquals(t, encodedPath); |
| 70 | + } |
| 71 | + } catch (Throwable e) { |
| 72 | + throwable = e; |
| 73 | + } finally { |
| 74 | + try { |
| 75 | + if (inArchive != null) { |
| 76 | + inArchive.close(); |
| 77 | + } |
| 78 | + } catch (Throwable e) { |
| 79 | + if (throwable == null) { |
| 80 | + throwable = e; |
| 81 | + } |
| 82 | + } |
| 83 | + if (randomAccessFile != null) { |
| 84 | + try { |
| 85 | + randomAccessFile.close(); |
| 86 | + } catch (Throwable e) { |
| 87 | + if (throwable == null) { |
| 88 | + throwable = e; |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + if (throwable != null) { |
| 95 | + throw throwable; |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments