diff options
Diffstat (limited to 'framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip')
8 files changed, 0 insertions, 1272 deletions
diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java deleted file mode 100644 index 873b3f50..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.zip; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * JUnit testcases for org.apache.tools.zip.AsiExtraField. - * - */ -public class AsiExtraFieldTest implements UnixStat { - - /** - * Test file mode magic. - */ - @Test - public void testModes() { - AsiExtraField a = new AsiExtraField(); - a.setMode(0123); - assertEquals("plain file", 0100123, a.getMode()); - a.setDirectory(true); - assertEquals("directory", 040123, a.getMode()); - a.setLinkedFile("test"); - assertEquals("symbolic link", 0120123, a.getMode()); - } - - /** - * Test content. - */ - @Test - public void testContent() { - AsiExtraField a = new AsiExtraField(); - a.setMode(0123); - a.setUserId(5); - a.setGroupId(6); - byte[] b = a.getLocalFileDataData(); - - // CRC manually calculated, sorry - byte[] expect = {(byte)0xC6, 0x02, 0x78, (byte)0xB6, // CRC - 0123, (byte)0x80, // mode - 0, 0, 0, 0, // link length - 5, 0, 6, 0}; // uid, gid - assertEquals("no link", expect.length, b.length); - for (int i=0; i<expect.length; i++) { - assertEquals("no link, byte "+i, expect[i], b[i]); - } - - a.setLinkedFile("test"); - expect = new byte[] {0x75, (byte)0x8E, 0x41, (byte)0xFD, // CRC - 0123, (byte)0xA0, // mode - 4, 0, 0, 0, // link length - 5, 0, 6, 0, // uid, gid - (byte)'t', (byte)'e', (byte)'s', (byte)'t'}; - b = a.getLocalFileDataData(); - assertEquals("no link", expect.length, b.length); - for (int i=0; i<expect.length; i++) { - assertEquals("no link, byte "+i, expect[i], b[i]); - } - - } - - /** - * Test reparse - */ - @Test - public void testReparse() throws Exception { - // CRC manually calculated, sorry - byte[] data = {(byte)0xC6, 0x02, 0x78, (byte)0xB6, // CRC - 0123, (byte)0x80, // mode - 0, 0, 0, 0, // link length - 5, 0, 6, 0}; // uid, gid - AsiExtraField a = new AsiExtraField(); - a.parseFromLocalFileData(data, 0, data.length); - assertEquals("length plain file", data.length, - a.getLocalFileDataLength().getValue()); - assertTrue("plain file, no link", !a.isLink()); - assertTrue("plain file, no dir", !a.isDirectory()); - assertEquals("mode plain file", FILE_FLAG | 0123, a.getMode()); - assertEquals("uid plain file", 5, a.getUserId()); - assertEquals("gid plain file", 6, a.getGroupId()); - - data = new byte[] {0x75, (byte)0x8E, 0x41, (byte)0xFD, // CRC - 0123, (byte)0xA0, // mode - 4, 0, 0, 0, // link length - 5, 0, 6, 0, // uid, gid - (byte)'t', (byte)'e', (byte)'s', (byte)'t'}; - a = new AsiExtraField(); - a.parseFromLocalFileData(data, 0, data.length); - assertEquals("length link", data.length, - a.getLocalFileDataLength().getValue()); - assertTrue("link, is link", a.isLink()); - assertTrue("link, no dir", !a.isDirectory()); - assertEquals("mode link", LINK_FLAG | 0123, a.getMode()); - assertEquals("uid link", 5, a.getUserId()); - assertEquals("gid link", 6, a.getGroupId()); - assertEquals("test", a.getLinkedFile()); - - data = new byte[] {(byte)0x8E, 0x01, (byte)0xBF, (byte)0x0E, // CRC - 0123, (byte)0x40, // mode - 0, 0, 0, 0, // link - 5, 0, 6, 0}; // uid, gid - a = new AsiExtraField(); - a.parseFromLocalFileData(data, 0, data.length); - assertEquals("length dir", data.length, - a.getLocalFileDataLength().getValue()); - assertTrue("dir, no link", !a.isLink()); - assertTrue("dir, is dir", a.isDirectory()); - assertEquals("mode dir", DIR_FLAG | 0123, a.getMode()); - assertEquals("uid dir", 5, a.getUserId()); - assertEquals("gid dir", 6, a.getGroupId()); - - data = new byte[] {0, 0, 0, 0, // bad CRC - 0123, (byte)0x40, // mode - 0, 0, 0, 0, // link - 5, 0, 6, 0}; // uid, gid - a = new AsiExtraField(); - try { - a.parseFromLocalFileData(data, 0, data.length); - fail("should raise bad CRC exception"); - } catch (Exception e) { - assertEquals("bad CRC checksum 0 instead of ebf018e", - e.getMessage()); - } - } - - @Test - public void testClone() { - AsiExtraField s1 = new AsiExtraField(); - s1.setUserId(42); - s1.setGroupId(12); - s1.setLinkedFile("foo"); - s1.setMode(0644); - s1.setDirectory(true); - AsiExtraField s2 = (AsiExtraField) s1.clone(); - assertNotSame(s1, s2); - assertEquals(s1.getUserId(), s2.getUserId()); - assertEquals(s1.getGroupId(), s2.getGroupId()); - assertEquals(s1.getLinkedFile(), s2.getLinkedFile()); - assertEquals(s1.getMode(), s2.getMode()); - assertEquals(s1.isDirectory(), s2.isDirectory()); - } -} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java deleted file mode 100644 index 95a6779e..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.zip; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * JUnit 3 testcases for org.apache.tools.zip.ExtraFieldUtils. - * - */ -public class ExtraFieldUtilsTest implements UnixStat { - - /** - * Header-ID of a ZipExtraField not supported by Ant. - * - * <p>Used to be ZipShort(1) but this is the ID of the Zip64 extra - * field.</p> - */ - static final ZipShort UNRECOGNIZED_HEADER = new ZipShort(0x5555); - - private AsiExtraField a; - private UnrecognizedExtraField dummy; - private byte[] data; - private byte[] aLocal; - - @Before - public void setUp() { - a = new AsiExtraField(); - a.setMode(0755); - a.setDirectory(true); - dummy = new UnrecognizedExtraField(); - dummy.setHeaderId(UNRECOGNIZED_HEADER); - dummy.setLocalFileDataData(new byte[] {0}); - dummy.setCentralDirectoryData(new byte[] {0}); - - aLocal = a.getLocalFileDataData(); - byte[] dummyLocal = dummy.getLocalFileDataData(); - data = new byte[4 + aLocal.length + 4 + dummyLocal.length]; - System.arraycopy(a.getHeaderId().getBytes(), 0, data, 0, 2); - System.arraycopy(a.getLocalFileDataLength().getBytes(), 0, data, 2, 2); - System.arraycopy(aLocal, 0, data, 4, aLocal.length); - System.arraycopy(dummy.getHeaderId().getBytes(), 0, data, - 4+aLocal.length, 2); - System.arraycopy(dummy.getLocalFileDataLength().getBytes(), 0, data, - 4+aLocal.length+2, 2); - System.arraycopy(dummyLocal, 0, data, - 4+aLocal.length+4, dummyLocal.length); - - } - - /** - * test parser. - */ - @Test - public void testParse() throws Exception { - ZipExtraField[] ze = ExtraFieldUtils.parse(data); - assertEquals("number of fields", 2, ze.length); - assertTrue("type field 1", ze[0] instanceof AsiExtraField); - assertEquals("mode field 1", 040755, - ((AsiExtraField) ze[0]).getMode()); - assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); - assertEquals("data length field 2", 1, - ze[1].getLocalFileDataLength().getValue()); - - byte[] data2 = new byte[data.length-1]; - System.arraycopy(data, 0, data2, 0, data2.length); - try { - ExtraFieldUtils.parse(data2); - fail("data should be invalid"); - } catch (Exception e) { - assertEquals("message", - "bad extra field starting at "+(4 + aLocal.length) - + ". Block length of 1 bytes exceeds remaining data of 0 bytes.", - e.getMessage()); - } - } - - @Test - public void testParseWithRead() throws Exception { - ZipExtraField[] ze = - ExtraFieldUtils.parse(data, true, - ExtraFieldUtils.UnparseableExtraField.READ); - assertEquals("number of fields", 2, ze.length); - assertTrue("type field 1", ze[0] instanceof AsiExtraField); - assertEquals("mode field 1", 040755, - ((AsiExtraField) ze[0]).getMode()); - assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); - assertEquals("data length field 2", 1, - ze[1].getLocalFileDataLength().getValue()); - - byte[] data2 = new byte[data.length-1]; - System.arraycopy(data, 0, data2, 0, data2.length); - ze = ExtraFieldUtils.parse(data2, true, - ExtraFieldUtils.UnparseableExtraField.READ); - assertEquals("number of fields", 2, ze.length); - assertTrue("type field 1", ze[0] instanceof AsiExtraField); - assertEquals("mode field 1", 040755, - ((AsiExtraField) ze[0]).getMode()); - assertTrue("type field 2", ze[1] instanceof UnparseableExtraFieldData); - assertEquals("data length field 2", 4, - ze[1].getLocalFileDataLength().getValue()); - for (int i = 0; i < 4; i++) { - assertEquals("byte number " + i, - data2[data.length - 5 + i], - ze[1].getLocalFileDataData()[i]); - } - } - - @Test - public void testParseWithSkip() throws Exception { - ZipExtraField[] ze = - ExtraFieldUtils.parse(data, true, - ExtraFieldUtils.UnparseableExtraField.SKIP); - assertEquals("number of fields", 2, ze.length); - assertTrue("type field 1", ze[0] instanceof AsiExtraField); - assertEquals("mode field 1", 040755, - ((AsiExtraField) ze[0]).getMode()); - assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); - assertEquals("data length field 2", 1, - ze[1].getLocalFileDataLength().getValue()); - - byte[] data2 = new byte[data.length-1]; - System.arraycopy(data, 0, data2, 0, data2.length); - ze = ExtraFieldUtils.parse(data2, true, - ExtraFieldUtils.UnparseableExtraField.SKIP); - assertEquals("number of fields", 1, ze.length); - assertTrue("type field 1", ze[0] instanceof AsiExtraField); - assertEquals("mode field 1", 040755, - ((AsiExtraField) ze[0]).getMode()); - } - - /** - * Test merge methods - */ - @Test - public void testMerge() { - byte[] local = - ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, dummy}); - assertEquals("local length", data.length, local.length); - for (int i=0; i<local.length; i++) { - assertEquals("local byte "+i, data[i], local[i]); - } - - byte[] dummyCentral = dummy.getCentralDirectoryData(); - byte[] data2 = new byte[4 + aLocal.length + 4 + dummyCentral.length]; - System.arraycopy(data, 0, data2, 0, 4 + aLocal.length + 2); - System.arraycopy(dummy.getCentralDirectoryLength().getBytes(), 0, - data2, 4+aLocal.length+2, 2); - System.arraycopy(dummyCentral, 0, data2, - 4+aLocal.length+4, dummyCentral.length); - - - byte[] central = - ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] {a, dummy}); - assertEquals("central length", data2.length, central.length); - for (int i=0; i<central.length; i++) { - assertEquals("central byte "+i, data2[i], central[i]); - } - - } - - @Test - public void testMergeWithUnparseableData() throws Exception { - ZipExtraField d = new UnparseableExtraFieldData(); - byte[] b = UNRECOGNIZED_HEADER.getBytes(); - d.parseFromLocalFileData(new byte[] {b[0], b[1], 1, 0}, 0, 4); - byte[] local = - ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, d}); - assertEquals("local length", data.length - 1, local.length); - for (int i = 0; i < local.length; i++) { - assertEquals("local byte " + i, data[i], local[i]); - } - - byte[] dCentral = d.getCentralDirectoryData(); - byte[] data2 = new byte[4 + aLocal.length + dCentral.length]; - System.arraycopy(data, 0, data2, 0, 4 + aLocal.length + 2); - System.arraycopy(dCentral, 0, data2, - 4 + aLocal.length, dCentral.length); - - - byte[] central = - ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] {a, d}); - assertEquals("central length", data2.length, central.length); - for (int i = 0; i < central.length; i++) { - assertEquals("central byte " + i, data2[i], central[i]); - } - - } -} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java deleted file mode 100644 index 38b2df58..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.zip; - -import java.io.File; -import java.io.InputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Enumeration; -import java.util.zip.CRC32; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class UTF8ZipFilesTest { - - private static final String UTF_8 = "utf-8"; - private static final String CP437 = "cp437"; - private static final String US_ASCII = "US-ASCII"; - private static final String ASCII_TXT = "ascii.txt"; - private static final String EURO_FOR_DOLLAR_TXT = "\u20AC_for_Dollar.txt"; - private static final String OIL_BARREL_TXT = "\u00D6lf\u00E4sser.txt"; - - @Test - public void testUtf8FileRoundtripExplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(UTF_8, true, true); - } - - @Test - public void testUtf8FileRoundtripNoEFSExplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(UTF_8, false, true); - } - - @Test - public void testCP437FileRoundtripExplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(CP437, false, true); - } - - @Test - public void testASCIIFileRoundtripExplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(US_ASCII, false, true); - } - - @Test - public void testUtf8FileRoundtripImplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(UTF_8, true, false); - } - - @Test - public void testUtf8FileRoundtripNoEFSImplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(UTF_8, false, false); - } - - @Test - public void testCP437FileRoundtripImplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(CP437, false, false); - } - - @Test - public void testASCIIFileRoundtripImplicitUnicodeExtra() - throws IOException { - testFileRoundtrip(US_ASCII, false, false); - } - - @Test - public void testZipFileReadsUnicodeFields() throws IOException { - File file = File.createTempFile("unicode-test", ".zip"); - ZipFile zf = null; - try { - createTestFile(file, US_ASCII, false, true); - zf = new ZipFile(file, US_ASCII, true); - assertCanRead(zf, ASCII_TXT); - assertCanRead(zf, EURO_FOR_DOLLAR_TXT); - assertCanRead(zf, OIL_BARREL_TXT); - } finally { - ZipFile.closeQuietly(zf); - if (file.exists()) { - file.delete(); - } - } - } - - private static void testFileRoundtrip(String encoding, boolean withEFS, - boolean withExplicitUnicodeExtra) - throws IOException { - - File file = File.createTempFile(encoding + "-test", ".zip"); - try { - createTestFile(file, encoding, withEFS, withExplicitUnicodeExtra); - testFile(file, encoding); - } finally { - if (file.exists()) { - file.delete(); - } - } - } - - private static void createTestFile(File file, String encoding, - boolean withEFS, - boolean withExplicitUnicodeExtra) - throws IOException { - - ZipEncoding zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); - - ZipOutputStream zos = null; - try { - zos = new ZipOutputStream(file); - zos.setEncoding(encoding); - zos.setUseLanguageEncodingFlag(withEFS); - zos.setCreateUnicodeExtraFields(withExplicitUnicodeExtra ? - ZipOutputStream - .UnicodeExtraFieldPolicy.NEVER - : ZipOutputStream - .UnicodeExtraFieldPolicy.ALWAYS); - - ZipEntry ze = new ZipEntry(OIL_BARREL_TXT); - if (withExplicitUnicodeExtra - && !zipEncoding.canEncode(ze.getName())) { - - ByteBuffer en = zipEncoding.encode(ze.getName()); - - ze.addExtraField(new UnicodePathExtraField(ze.getName(), - en.array(), - en.arrayOffset(), - en.limit())); - } - - zos.putNextEntry(ze); - zos.write("Hello, world!".getBytes("US-ASCII")); - zos.closeEntry(); - - ze = new ZipEntry(EURO_FOR_DOLLAR_TXT); - if (withExplicitUnicodeExtra - && !zipEncoding.canEncode(ze.getName())) { - - ByteBuffer en = zipEncoding.encode(ze.getName()); - - ze.addExtraField(new UnicodePathExtraField(ze.getName(), - en.array(), - en.arrayOffset(), - en.limit())); - } - - zos.putNextEntry(ze); - zos.write("Give me your money!".getBytes("US-ASCII")); - zos.closeEntry(); - - ze = new ZipEntry(ASCII_TXT); - - if (withExplicitUnicodeExtra - && !zipEncoding.canEncode(ze.getName())) { - - ByteBuffer en = zipEncoding.encode(ze.getName()); - - ze.addExtraField(new UnicodePathExtraField(ze.getName(), - en.array(), - en.arrayOffset(), - en.limit())); - } - - zos.putNextEntry(ze); - zos.write("ascii".getBytes("US-ASCII")); - zos.closeEntry(); - } finally { - if (zos != null) { - try { - zos.close(); - } catch (IOException e) { /* swallow */ } - } - } - } - - private static void testFile(File file, String encoding) - throws IOException { - ZipFile zf = null; - try { - zf = new ZipFile(file, encoding, false); - - Enumeration e = zf.getEntries(); - while (e.hasMoreElements()) { - ZipEntry ze = (ZipEntry) e.nextElement(); - - if (ze.getName().endsWith("sser.txt")) { - assertUnicodeName(ze, OIL_BARREL_TXT, encoding); - - } else if (ze.getName().endsWith("_for_Dollar.txt")) { - assertUnicodeName(ze, EURO_FOR_DOLLAR_TXT, encoding); - } else if (!ze.getName().equals(ASCII_TXT)) { - throw new AssertionError("Urecognized ZIP entry with name [" - + ze.getName() + "] found."); - } - } - } finally { - ZipFile.closeQuietly(zf); - } - } - - private static UnicodePathExtraField findUniCodePath(ZipEntry ze) { - return (UnicodePathExtraField) - ze.getExtraField(UnicodePathExtraField.UPATH_ID); - } - - private static void assertUnicodeName(ZipEntry ze, - String expectedName, - String encoding) - throws IOException { - if (!expectedName.equals(ze.getName())) { - UnicodePathExtraField ucpf = findUniCodePath(ze); - assertNotNull(ucpf); - - ZipEncoding enc = ZipEncodingHelper.getZipEncoding(encoding); - ByteBuffer ne = enc.encode(ze.getName()); - - CRC32 crc = new CRC32(); - crc.update(ne.array(),ne.arrayOffset(),ne.limit()); - - assertEquals(crc.getValue(), ucpf.getNameCRC32()); - assertEquals(expectedName, new String(ucpf.getUnicodeName(), - UTF_8)); - } - } - - private static void assertCanRead(ZipFile zf, String fileName) throws IOException { - ZipEntry entry = zf.getEntry(fileName); - assertNotNull("Entry " + fileName + " doesn't exist", entry); - InputStream is = zf.getInputStream(entry); - assertNotNull("InputStream is null", is); - try { - is.read(); - } finally { - is.close(); - } - } - -} - diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java deleted file mode 100644 index 826e410a..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tools.zip; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Test zip encodings. - */ -public class ZipEncodingTest { - private static final String UNENC_STRING = "\u2016"; - - // stress test for internal grow method. - private static final String BAD_STRING = - "\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016"; - - private static final String BAD_STRING_ENC = - "%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016"; - - @Test - public void testSimpleCp437Encoding() throws IOException { - - doSimpleEncodingTest("Cp437", null); - } - - @Test - public void testSimpleCp850Encoding() throws IOException { - - doSimpleEncodingTest("Cp850", null); - } - - @Test - public void testNioCp1252Encoding() throws IOException { - // CP1252 has some undefined code points, these are - // the defined ones - // retrieved by - // awk '/^0x/ && NF>2 {print $1;}' CP1252.TXT - byte[] b = - new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - (byte) 0x80, (byte) 0x82, (byte) 0x83, (byte) 0x84, - (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, - (byte) 0x89, (byte) 0x8A, (byte) 0x8B, (byte) 0x8C, - (byte) 0x8E, (byte) 0x91, (byte) 0x92, (byte) 0x93, - (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97, - (byte) 0x98, (byte) 0x99, (byte) 0x9A, (byte) 0x9B, - (byte) 0x9C, (byte) 0x9E, (byte) 0x9F, (byte) 0xA0, - (byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4, - (byte) 0xA5, (byte) 0xA6, (byte) 0xA7, (byte) 0xA8, - (byte) 0xA9, (byte) 0xAA, (byte) 0xAB, (byte) 0xAC, - (byte) 0xAD, (byte) 0xAE, (byte) 0xAF, (byte) 0xB0, - (byte) 0xB1, (byte) 0xB2, (byte) 0xB3, (byte) 0xB4, - (byte) 0xB5, (byte) 0xB6, (byte) 0xB7, (byte) 0xB8, - (byte) 0xB9, (byte) 0xBA, (byte) 0xBB, (byte) 0xBC, - (byte) 0xBD, (byte) 0xBE, (byte) 0xBF, (byte) 0xC0, - (byte) 0xC1, (byte) 0xC2, (byte) 0xC3, (byte) 0xC4, - (byte) 0xC5, (byte) 0xC6, (byte) 0xC7, (byte) 0xC8, - (byte) 0xC9, (byte) 0xCA, (byte) 0xCB, (byte) 0xCC, - (byte) 0xCD, (byte) 0xCE, (byte) 0xCF, (byte) 0xD0, - (byte) 0xD1, (byte) 0xD2, (byte) 0xD3, (byte) 0xD4, - (byte) 0xD5, (byte) 0xD6, (byte) 0xD7, (byte) 0xD8, - (byte) 0xD9, (byte) 0xDA, (byte) 0xDB, (byte) 0xDC, - (byte) 0xDD, (byte) 0xDE, (byte) 0xDF, (byte) 0xE0, - (byte) 0xE1, (byte) 0xE2, (byte) 0xE3, (byte) 0xE4, - (byte) 0xE5, (byte) 0xE6, (byte) 0xE7, (byte) 0xE8, - (byte) 0xE9, (byte) 0xEA, (byte) 0xEB, (byte) 0xEC, - (byte) 0xED, (byte) 0xEE, (byte) 0xEF, (byte) 0xF0, - (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4, - (byte) 0xF5, (byte) 0xF6, (byte) 0xF7, (byte) 0xF8, - (byte) 0xF9, (byte) 0xFA, (byte) 0xFB, (byte) 0xFC, - (byte) 0xFD, (byte) 0xFE, (byte) 0xFF }; - - doSimpleEncodingTest("Cp1252",b); - } - - private static void assertByteEquals(byte[] expected, ByteBuffer actual) { - - assertEquals(expected.length, actual.limit()); - - for (int i = 0; i < expected.length; ++i) { - - byte a = actual.get(); - assertEquals(expected[i], a); - } - - } - - private void doSimpleEncodingTest(String name, byte[] testBytes) - throws IOException { - - ZipEncoding enc = ZipEncodingHelper.getZipEncoding(name); - - if (testBytes == null) { - - testBytes = new byte[256]; - for (int i = 0; i < 256; ++i) { - testBytes[i] = (byte) i; - } - } - - String decoded = enc.decode(testBytes); - - assertEquals(true, enc.canEncode(decoded)); - - ByteBuffer encoded = enc.encode(decoded); - - assertByteEquals(testBytes, encoded); - - assertEquals(false, enc.canEncode(UNENC_STRING)); - assertByteEquals("%U2016".getBytes("US-ASCII"), enc.encode(UNENC_STRING)); - assertEquals(false, enc.canEncode(BAD_STRING)); - assertByteEquals(BAD_STRING_ENC.getBytes("US-ASCII"), - enc.encode(BAD_STRING)); - } - -} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java deleted file mode 100644 index 3c21f6f3..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.zip; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; - -/** - * JUnit 3 testcases for org.apache.tools.zip.ZipEntry. - * - */ -public class ZipEntryTest { - - - /** - * test handling of extra fields - */ - @Test - public void testExtraFields() { - AsiExtraField a = new AsiExtraField(); - a.setDirectory(true); - a.setMode(0755); - UnrecognizedExtraField u = new UnrecognizedExtraField(); - u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); - u.setLocalFileDataData(new byte[0]); - - ZipEntry ze = new ZipEntry("test/"); - ze.setExtraFields(new ZipExtraField[] {a, u}); - byte[] data1 = ze.getExtra(); - ZipExtraField[] result = ze.getExtraFields(); - assertEquals("first pass", 2, result.length); - assertSame(a, result[0]); - assertSame(u, result[1]); - - UnrecognizedExtraField u2 = new UnrecognizedExtraField(); - u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); - u2.setLocalFileDataData(new byte[] {1}); - - ze.addExtraField(u2); - byte[] data2 = ze.getExtra(); - result = ze.getExtraFields(); - assertEquals("second pass", 2, result.length); - assertSame(a, result[0]); - assertSame(u2, result[1]); - assertEquals("length second pass", data1.length+1, data2.length); - - UnrecognizedExtraField u3 = new UnrecognizedExtraField(); - u3.setHeaderId(new ZipShort(2)); - u3.setLocalFileDataData(new byte[] {1}); - ze.addExtraField(u3); - result = ze.getExtraFields(); - assertEquals("third pass", 3, result.length); - - ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); - byte[] data3 = ze.getExtra(); - result = ze.getExtraFields(); - assertEquals("fourth pass", 2, result.length); - assertSame(a, result[0]); - assertSame(u3, result[1]); - assertEquals("length fourth pass", data2.length, data3.length); - - try { - ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); - fail("should be no such element"); - } catch (java.util.NoSuchElementException nse) { - //TODO assert exception values - } - } - - /** - * test handling of extra fields via central directory - */ - @Test - public void testExtraFieldMerging() { - AsiExtraField a = new AsiExtraField(); - a.setDirectory(true); - a.setMode(0755); - UnrecognizedExtraField u = new UnrecognizedExtraField(); - u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); - u.setLocalFileDataData(new byte[0]); - - ZipEntry ze = new ZipEntry("test/"); - ze.setExtraFields(new ZipExtraField[] {a, u}); - - // merge - // Header-ID 1 + length 1 + one byte of data - byte[] b = ExtraFieldUtilsTest.UNRECOGNIZED_HEADER.getBytes(); - ze.setCentralDirectoryExtra(new byte[] {b[0], b[1], 1, 0, 127}); - - ZipExtraField[] result = ze.getExtraFields(); - assertEquals("first pass", 2, result.length); - assertSame(a, result[0]); - assertEquals(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER, - result[1].getHeaderId()); - assertEquals(new ZipShort(0), result[1].getLocalFileDataLength()); - assertEquals(new ZipShort(1), result[1].getCentralDirectoryLength()); - - // add new - // Header-ID 2 + length 0 - ze.setCentralDirectoryExtra(new byte[] {2, 0, 0, 0}); - - result = ze.getExtraFields(); - assertEquals("second pass", 3, result.length); - - // merge - // Header-ID 2 + length 1 + one byte of data - ze.setExtra(new byte[] {2, 0, 1, 0, 127}); - - result = ze.getExtraFields(); - assertEquals("third pass", 3, result.length); - assertSame(a, result[0]); - assertEquals(new ZipShort(2), result[2].getHeaderId()); - assertEquals(new ZipShort(1), result[2].getLocalFileDataLength()); - assertEquals(new ZipShort(0), result[2].getCentralDirectoryLength()); - } - - /** - * test handling of extra fields - */ - @Test - public void testAddAsFirstExtraField() { - AsiExtraField a = new AsiExtraField(); - a.setDirectory(true); - a.setMode(0755); - UnrecognizedExtraField u = new UnrecognizedExtraField(); - u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); - u.setLocalFileDataData(new byte[0]); - - ZipEntry ze = new ZipEntry("test/"); - ze.setExtraFields(new ZipExtraField[] {a, u}); - byte[] data1 = ze.getExtra(); - - UnrecognizedExtraField u2 = new UnrecognizedExtraField(); - u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); - u2.setLocalFileDataData(new byte[] {1}); - - ze.addAsFirstExtraField(u2); - byte[] data2 = ze.getExtra(); - ZipExtraField[] result = ze.getExtraFields(); - assertEquals("second pass", 2, result.length); - assertSame(u2, result[0]); - assertSame(a, result[1]); - assertEquals("length second pass", data1.length + 1, data2.length); - - UnrecognizedExtraField u3 = new UnrecognizedExtraField(); - u3.setHeaderId(new ZipShort(2)); - u3.setLocalFileDataData(new byte[] {1}); - ze.addAsFirstExtraField(u3); - result = ze.getExtraFields(); - assertEquals("third pass", 3, result.length); - assertSame(u3, result[0]); - assertSame(u2, result[1]); - assertSame(a, result[2]); - } - - @Test - public void testUnixMode() { - ZipEntry ze = new ZipEntry("foo"); - assertEquals(0, ze.getPlatform()); - ze.setUnixMode(0755); - assertEquals(3, ze.getPlatform()); - assertEquals(0755, - (ze.getExternalAttributes() >> 16) & 0xFFFF); - assertEquals(0, ze.getExternalAttributes() & 0xFFFF); - - ze.setUnixMode(0444); - assertEquals(3, ze.getPlatform()); - assertEquals(0444, - (ze.getExternalAttributes() >> 16) & 0xFFFF); - assertEquals(1, ze.getExternalAttributes() & 0xFFFF); - - ze = new ZipEntry("foo/"); - assertEquals(0, ze.getPlatform()); - ze.setUnixMode(0777); - assertEquals(3, ze.getPlatform()); - assertEquals(0777, - (ze.getExternalAttributes() >> 16) & 0xFFFF); - assertEquals(0x10, ze.getExternalAttributes() & 0xFFFF); - - ze.setUnixMode(0577); - assertEquals(3, ze.getPlatform()); - assertEquals(0577, - (ze.getExternalAttributes() >> 16) & 0xFFFF); - assertEquals(0x11, ze.getExternalAttributes() & 0xFFFF); - } - - /** - * Test case for - * <a href="https://issues.apache.org/jira/browse/COMPRESS-94" - * >COMPRESS-94</a>. - */ - @Test - public void testNotEquals() { - ZipEntry entry1 = new ZipEntry("foo"); - ZipEntry entry2 = new ZipEntry("bar"); - assertFalse(entry1.equals(entry2)); - } - - @Test - public void testCopyConstructor() throws Exception { - ZipEntry archiveEntry = new ZipEntry("fred"); - archiveEntry.setUnixMode(0664); - archiveEntry.setMethod(ZipEntry.DEFLATED); - archiveEntry.getGeneralPurposeBit().useStrongEncryption(true); - ZipEntry copy = new ZipEntry(archiveEntry); - assertEquals(archiveEntry, copy); - } -} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipLongTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipLongTest.java deleted file mode 100644 index a7ece044..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipLongTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.zip; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; - -/** - * JUnit testcases for org.apache.tools.zip.ZipLong. - * - */ -public class ZipLongTest { - - /** - * Test conversion to bytes. - */ - @Test - public void testToBytes() { - ZipLong zl = new ZipLong(0x12345678); - byte[] result = zl.getBytes(); - assertEquals("length getBytes", 4, result.length); - assertEquals("first byte getBytes", 0x78, result[0]); - assertEquals("second byte getBytes", 0x56, result[1]); - assertEquals("third byte getBytes", 0x34, result[2]); - assertEquals("fourth byte getBytes", 0x12, result[3]); - } - - /** - * Test conversion from bytes. - */ - @Test - public void testFromBytes() { - byte[] val = new byte[] {0x78, 0x56, 0x34, 0x12}; - ZipLong zl = new ZipLong(val); - assertEquals("value from bytes", 0x12345678, zl.getValue()); - } - - /** - * Test the contract of the equals method. - */ - @Test - public void testEquals() { - ZipLong zl = new ZipLong(0x12345678); - ZipLong zl2 = new ZipLong(0x12345678); - ZipLong zl3 = new ZipLong(0x87654321); - - assertTrue("reflexive", zl.equals(zl)); - - assertTrue("works", zl.equals(zl2)); - assertTrue("works, part two", !zl.equals(zl3)); - - assertTrue("symmetric", zl2.equals(zl)); - - assertTrue("null handling", !zl.equals(null)); - assertTrue("non ZipLong handling", !zl.equals(new Integer(0x1234))); - } - - /** - * Test sign handling. - */ - @Test - public void testSign() { - ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF}); - assertEquals(0x00000000FFFFFFFFl, zl.getValue()); - } - - @Test - public void testClone() { - ZipLong s1 = new ZipLong(42); - ZipLong s2 = (ZipLong) s1.clone(); - assertNotSame(s1, s2); - assertEquals(s1, s2); - assertEquals(s1.getValue(), s2.getValue()); - } -} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java deleted file mode 100644 index a69db6c1..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.zip; - -import org.junit.Before; -import org.junit.Test; - -import java.util.Calendar; -import java.util.Date; - -import static org.junit.Assert.assertEquals; - -public class ZipOutputStreamTest { - - private Date time; - private ZipLong zl; - - @Before - public void setUp() throws Exception { - time = new Date(); - Calendar cal = Calendar.getInstance(); - cal.setTime(time); - int year = cal.get(Calendar.YEAR); - int month = cal.get(Calendar.MONTH) + 1; - long value = ((year - 1980) << 25) - | (month << 21) - | (cal.get(Calendar.DAY_OF_MONTH) << 16) - | (cal.get(Calendar.HOUR_OF_DAY) << 11) - | (cal.get(Calendar.MINUTE) << 5) - | (cal.get(Calendar.SECOND) >> 1); - - byte[] result = new byte[4]; - result[0] = (byte) ((value & 0xFF)); - result[1] = (byte) ((value & 0xFF00) >> 8); - result[2] = (byte) ((value & 0xFF0000) >> 16); - result[3] = (byte) ((value & 0xFF000000L) >> 24); - zl = new ZipLong(result); - } - - - @Test - public void testZipLong() throws Exception { - ZipLong test = ZipOutputStream.toDosTime(time); - assertEquals(test.getValue(), zl.getValue()); - } - - @Test - public void testAdjustToLong() { - assertEquals((long) Integer.MAX_VALUE, - ZipOutputStream.adjustToLong(Integer.MAX_VALUE)); - assertEquals(((long) Integer.MAX_VALUE) + 1, - ZipOutputStream.adjustToLong(Integer.MAX_VALUE + 1)); - assertEquals(2 * ((long) Integer.MAX_VALUE), - ZipOutputStream.adjustToLong(2 * Integer.MAX_VALUE)); - } - -} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipShortTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipShortTest.java deleted file mode 100644 index a6aa3e78..00000000 --- a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipShortTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.zip; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; - -/** - * JUnit 3 testcases for org.apache.tools.zip.ZipShort. - * - */ -public class ZipShortTest { - - /** - * Test conversion to bytes. - */ - @Test - public void testToBytes() { - ZipShort zs = new ZipShort(0x1234); - byte[] result = zs.getBytes(); - assertEquals("length getBytes", 2, result.length); - assertEquals("first byte getBytes", 0x34, result[0]); - assertEquals("second byte getBytes", 0x12, result[1]); - } - - /** - * Test conversion from bytes. - */ - @Test - public void testFromBytes() { - byte[] val = new byte[] {0x34, 0x12}; - ZipShort zs = new ZipShort(val); - assertEquals("value from bytes", 0x1234, zs.getValue()); - } - - /** - * Test the contract of the equals method. - */ - @Test - public void testEquals() { - ZipShort zs = new ZipShort(0x1234); - ZipShort zs2 = new ZipShort(0x1234); - ZipShort zs3 = new ZipShort(0x5678); - - assertTrue("reflexive", zs.equals(zs)); - - assertTrue("works", zs.equals(zs2)); - assertTrue("works, part two", !zs.equals(zs3)); - - assertTrue("symmetric", zs2.equals(zs)); - - assertTrue("null handling", !zs.equals(null)); - assertTrue("non ZipShort handling", !zs.equals(new Integer(0x1234))); - } - - /** - * Test sign handling. - */ - @Test - public void testSign() { - ZipShort zs = new ZipShort(new byte[] {(byte)0xFF, (byte)0xFF}); - assertEquals(0x0000FFFF, zs.getValue()); - } - - @Test - public void testClone() { - ZipShort s1 = new ZipShort(42); - ZipShort s2 = (ZipShort) s1.clone(); - assertNotSame(s1, s2); - assertEquals(s1, s2); - assertEquals(s1.getValue(), s2.getValue()); - } -} |