16c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak/* 2d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * Licensed to the Apache Software Foundation (ASF) under one or more 3d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * contributor license agreements. See the NOTICE file distributed with 4d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * this work for additional information regarding copyright ownership. 5d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0 6d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * (the "License"); you may not use this file except in compliance with 7d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * the License. You may obtain a copy of the License at 86c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * 9d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 106c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * 11d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * Unless required by applicable law or agreed to in writing, software 12d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 13d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * See the License for the specific language governing permissions and 15d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * limitations under the License. 16d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 17d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamathpackage org.apache.harmony.tests.java.util.zip; 18d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 19e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamathimport java.io.File; 20e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamathimport java.io.FileOutputStream; 21d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamathimport java.io.IOException; 22d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamathimport java.io.InputStream; 236c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniakimport java.nio.file.attribute.FileTime; 24e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamathimport java.util.TimeZone; 25e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamathimport java.util.zip.ZipEntry; 26e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamathimport java.util.zip.ZipFile; 27e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamathimport libcore.io.Streams; 2827604018f783bf6354a13870b3e7785edca69b5fPaul Duffinimport libcore.junit.junit3.TestCaseWithRules; 2927604018f783bf6354a13870b3e7785edca69b5fPaul Duffinimport libcore.junit.util.ResourceLeakageDetector; 3027604018f783bf6354a13870b3e7785edca69b5fPaul Duffinimport org.junit.Rule; 3127604018f783bf6354a13870b3e7785edca69b5fPaul Duffinimport org.junit.rules.TestRule; 32d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamathimport tests.support.resource.Support_Resources; 33d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 3427604018f783bf6354a13870b3e7785edca69b5fPaul Duffinpublic class ZipEntryTest extends TestCaseWithRules { 3527604018f783bf6354a13870b3e7785edca69b5fPaul Duffin @Rule 3627604018f783bf6354a13870b3e7785edca69b5fPaul Duffin public TestRule guardRule = ResourceLeakageDetector.getRule(); 3727604018f783bf6354a13870b3e7785edca69b5fPaul Duffin 38d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // zip file hyts_ZipFile.zip must be included as a resource 39e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath private ZipEntry zentry; 40e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath private ZipFile zfile; 41d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 42e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath private long orgSize; 43e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath private long orgCompressedSize; 44e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath private long orgCrc; 45e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath private long orgTime; 46d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 47d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 48d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#ZipEntry(java.lang.String) 49d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 50d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_ConstructorLjava_lang_String() { 51d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method java.util.zip.ZipEntry(java.lang.String) 52d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = zfile.getEntry("File3.txt"); 53d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertNotNull("Failed to create ZipEntry", zentry); 54d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 55d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = zfile.getEntry(null); 56d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("NullPointerException not thrown"); 57d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (NullPointerException e) { 58d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 59d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath StringBuffer s = new StringBuffer(); 60d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath for (int i = 0; i < 65535; i++) { 61d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath s.append('a'); 62d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 63d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 64d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry(s.toString()); 65d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 66d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("Unexpected IllegalArgumentException During Test."); 67d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 68d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 69d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath s.append('a'); 70d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry(s.toString()); 71d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 72d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 73d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 74d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 75d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath String n = null; 76d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry(n); 77d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("NullPointerException not thrown"); 78d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (NullPointerException e) { 79d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 80d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 81d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 82d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 83d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getComment() 84d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 85d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getComment() { 86d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method java.lang.String java.util.zip.ZipEntry.getComment() 87d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry zipEntry = new ZipEntry("zippy.zip"); 88d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertNull("Incorrect Comment Returned.", zipEntry.getComment()); 89d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zipEntry.setComment("This Is A Comment"); 90d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Incorrect Comment Returned.", 91d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath "This Is A Comment", zipEntry.getComment()); 92d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 93d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 94d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 95d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getCompressedSize() 96d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 97d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getCompressedSize() { 98d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method long java.util.zip.ZipEntry.getCompressedSize() 99d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertTrue("Incorrect compressed size returned", zentry 100d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath .getCompressedSize() == orgCompressedSize); 101d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 102d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 103d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 104d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getCrc() 105d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 106d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getCrc() { 107d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method long java.util.zip.ZipEntry.getCrc() 108d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Failed to get Crc", orgCrc, zentry.getCrc()); 109d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 110d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 111d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 112d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getExtra() 113d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 114d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getExtra() { 115d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method byte [] java.util.zip.ZipEntry.getExtra() 116d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertNull("Incorrect extra information returned", 117d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.getExtra()); 118d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath byte[] ba = { 'T', 'E', 'S', 'T' }; 119d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry("test.tst"); 120d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setExtra(ba); 121d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Incorrect Extra Information Returned.", 122d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ba, zentry.getExtra()); 123d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 124d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 125d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 126d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getMethod() 127d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 128d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getMethod() { 129d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method int java.util.zip.ZipEntry.getMethod() 130d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = zfile.getEntry("File1.txt"); 131d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Incorrect compression method returned", 132d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath java.util.zip.ZipEntry.STORED, zentry.getMethod()); 133d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = zfile.getEntry("File3.txt"); 134d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Incorrect compression method returned", 135d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath java.util.zip.ZipEntry.DEFLATED, zentry.getMethod()); 136d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry("test.tst"); 137d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Incorrect Method Returned.", -1, zentry.getMethod()); 138d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 139d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 140d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 141d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getName() 142d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 143d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getName() { 144d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method java.lang.String java.util.zip.ZipEntry.getName() 145d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Incorrect name returned - Note return result somewhat ambiguous in spec", 146d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath "File1.txt", zentry.getName()); 147d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 148d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 149d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 150d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getSize() 151d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 152d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getSize() { 153d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method long java.util.zip.ZipEntry.getSize() 154d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Incorrect size returned", orgSize, zentry.getSize()); 155d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 156d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 157d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 158d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#getTime() 159d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 160d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_getTime() { 161d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method long java.util.zip.ZipEntry.getTime() 162d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Failed to get time", orgTime, zentry.getTime()); 163d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 164d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 165d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 1666c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * java.util.zip.ZipEntry#getCreationTime() 1676c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak */ 1686c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak public void test_getCreationTime() { 1696c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertNull(zentry.getCreationTime()); 1706c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak } 1716c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 1726c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak /** 1736c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * java.util.zip.ZipEntry#getLastAccessTime() 1746c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak */ 1756c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak public void test_getLastAccessTime() { 1766c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertNull(zentry.getLastAccessTime()); 1776c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak } 1786c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 1796c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak /** 1806c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * java.util.zip.ZipEntry#getLastModifiedTime() 1816c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak */ 1826c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak public void test_getLastModifiedTime() { 1836c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(orgTime, zentry.getLastModifiedTime().toMillis()); 1846c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak } 1856c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 1866c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak /** 187d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#isDirectory() 188d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 189d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_isDirectory() { 190d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method boolean java.util.zip.ZipEntry.isDirectory() 191d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertTrue("Entry should not answer true to isDirectory", !zentry 192d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath .isDirectory()); 193d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry("Directory/"); 194d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertTrue("Entry should answer true to isDirectory", zentry 195d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath .isDirectory()); 196d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 197d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 198d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 199d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#setComment(java.lang.String) 200d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 201d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_setCommentLjava_lang_String() { 202d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method void 203d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // java.util.zip.ZipEntry.setComment(java.lang.String) 204d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = zfile.getEntry("File1.txt"); 205d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setComment("Set comment using api"); 206d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Comment not correctly set", 207d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath "Set comment using api", zentry.getComment()); 208d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath String n = null; 209d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setComment(n); 210d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertNull("Comment not correctly set", zentry.getComment()); 211d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath StringBuffer s = new StringBuffer(); 212d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath for (int i = 0; i < 0xFFFF; i++) { 213d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath s.append('a'); 214d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 215d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 216d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setComment(s.toString()); 217d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 218d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("Unexpected IllegalArgumentException During Test."); 219d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 220d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 221d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath s.append('a'); 222d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setComment(s.toString()); 223d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 224d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 225d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 226d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 227d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 228d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 229d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#setCompressedSize(long) 230d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 231d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_setCompressedSizeJ() { 232d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method void java.util.zip.ZipEntry.setCompressedSize(long) 233d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCompressedSize(orgCompressedSize + 10); 234d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Set compressed size failed", 235d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath (orgCompressedSize + 10), zentry.getCompressedSize()); 236d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCompressedSize(0); 237d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Set compressed size failed", 238d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 0, zentry.getCompressedSize()); 239d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCompressedSize(-25); 240d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Set compressed size failed", 241d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath -25, zentry.getCompressedSize()); 242d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCompressedSize(4294967296l); 243d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Set compressed size failed", 244d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 4294967296l, zentry.getCompressedSize()); 245d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 246d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 247d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 248d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#setCrc(long) 249d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 250d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_setCrcJ() { 251d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method void java.util.zip.ZipEntry.setCrc(long) 252d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCrc(orgCrc + 100); 253d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Failed to set Crc", (orgCrc + 100), zentry.getCrc()); 254d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCrc(0); 255d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Failed to set Crc", 0, zentry.getCrc()); 256d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 257d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCrc(-25); 258d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 259d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 260d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 261d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 262d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCrc(4294967295l); 263d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 264d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("Unexpected IllegalArgumentException during test"); 265d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 266d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 267d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCrc(4294967296l); 268d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 269d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 270d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 271d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 272d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 273d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 274d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#setExtra(byte[]) 275d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 276d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_setExtra$B() { 277d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method void java.util.zip.ZipEntry.setExtra(byte []) 278d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = zfile.getEntry("File1.txt"); 279d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setExtra("Test setting extra information".getBytes()); 280d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Extra information not written properly", "Test setting extra information", new String(zentry 281d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath .getExtra(), 0, zentry.getExtra().length) 282d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ); 283d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry("test.tst"); 284d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath byte[] ba = new byte[0xFFFF]; 285d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 286d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setExtra(ba); 287d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 288d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("Unexpected IllegalArgumentException during test"); 289d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 290d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 291d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ba = new byte[0xFFFF + 1]; 292d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setExtra(ba); 293d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 294d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 295d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 296d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 297d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // One constructor 298d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry zeInput = new ZipEntry("InputZIP"); 299d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath byte[] extraB = { 'a', 'b', 'd', 'e' }; 300d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zeInput.setExtra(extraB); 301d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB, zeInput.getExtra()); 302d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB[3], zeInput.getExtra()[3]); 303d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB.length, zeInput.getExtra().length); 304d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 305d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // test another constructor 306d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry zeOutput = new ZipEntry(zeInput); 307d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]); 308d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length); 309d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB[3], zeOutput.getExtra()[3]); 310d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB.length, zeOutput.getExtra().length); 311d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 312d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 313d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 314d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#setMethod(int) 315d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 316d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_setMethodI() { 317d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method void java.util.zip.ZipEntry.setMethod(int) 318d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = zfile.getEntry("File3.txt"); 319d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setMethod(ZipEntry.STORED); 320d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Failed to set compression method", 321d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry.STORED, zentry.getMethod()); 322d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setMethod(ZipEntry.DEFLATED); 323d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Failed to set compression method", 324d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry.DEFLATED, zentry.getMethod()); 325d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 326d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath int error = 1; 327d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry = new ZipEntry("test.tst"); 328d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setMethod(error); 329d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 330d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 331d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 332d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 333d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 334d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 335d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#setSize(long) 336d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 337d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_setSizeJ() { 338d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method void java.util.zip.ZipEntry.setSize(long) 339d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setSize(orgSize + 10); 340d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Set size failed", (orgSize + 10), zentry.getSize()); 341d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setSize(0); 342d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Set size failed", 0, zentry.getSize()); 343d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 344d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setSize(-25); 345d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 346d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 347d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 348d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 349d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCrc(4294967295l); 350d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 351d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("Unexpected IllegalArgumentException during test"); 352d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 353d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 354d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCrc(4294967296l); 355d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath fail("IllegalArgumentException not thrown"); 356d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } catch (IllegalArgumentException e) { 357d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 358d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 359d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 360d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 361d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#setTime(long) 362d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 363d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_setTimeJ() { 364d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method void java.util.zip.ZipEntry.setTime(long) 365d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setTime(orgTime + 10000); 366d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Test 1: Failed to set time: " + zentry.getTime(), (orgTime + 10000), 367d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.getTime()); 368d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setTime(orgTime - 10000); 369d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Test 2: Failed to set time: " + zentry.getTime(), (orgTime - 10000), 370d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.getTime()); 371d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath TimeZone zone = TimeZone.getDefault(); 372d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 3736c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak // These cases are supported since Android O thanks to 3746c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak // Info-ZIP Extended Timestamp. Before Android O/openJdk8 3756c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak // these cases would behave differently. 376d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath TimeZone.setDefault(TimeZone.getTimeZone("EST")); 377d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setTime(0); 378d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Test 3: Failed to set time: " + zentry.getTime(), 3796c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 0L, zentry.getTime()); 380d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath TimeZone.setDefault(TimeZone.getTimeZone("GMT")); 381d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Test 3a: Failed to set time: " + zentry.getTime(), 3826c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 0L, zentry.getTime()); 383d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setTime(0); 384d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath TimeZone.setDefault(TimeZone.getTimeZone("EST")); 385d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Test 3b: Failed to set time: " + zentry.getTime(), 3866c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 0L, zentry.getTime()); 387d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 388d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setTime(-25); 389d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Test 4: Failed to set time: " + zentry.getTime(), 3906c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak -25L, zentry.getTime()); 391d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setTime(4354837200000L); 392d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("Test 5: Failed to set time: " + zentry.getTime(), 3936c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 4354837200000L, zentry.getTime()); 394d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } finally { 395d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath TimeZone.setDefault(zone); 396d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 397d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 398d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 399d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 4006c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * java.util.zip.ZipEntry#setLastModifiedTime(FileTime) 4016c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak */ 4026c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak public void test_setLastModifiedTime() { 4036c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak zentry.setLastModifiedTime(FileTime.fromMillis(0)); 4046c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(0, zentry.getLastModifiedTime().toMillis()); 4056c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(0, zentry.getTime()); 4066c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 4076c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak final long someTimestampValue = 1478624967000L; 4086c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak zentry.setLastModifiedTime(FileTime.fromMillis(someTimestampValue)); 4096c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(someTimestampValue, zentry.getLastModifiedTime().toMillis()); 4106c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(someTimestampValue, zentry.getTime()); 4116c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak } 4126c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 4136c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak /** 4146c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * java.util.zip.ZipEntry#setCreationTime(FileTime) 4156c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak */ 4166c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak public void test_setCreationTime() { 4176c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak zentry.setCreationTime(FileTime.fromMillis(0)); 4186c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(0, zentry.getCreationTime().toMillis()); 4196c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 4206c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak final long someTimestampValue = 1478624967000L; 4216c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak zentry.setCreationTime(FileTime.fromMillis(someTimestampValue)); 4226c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(someTimestampValue, zentry.getCreationTime().toMillis()); 4236c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak } 4246c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 4256c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak /** 4266c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak * java.util.zip.ZipEntry#setLastAccessTime(FileTime) 4276c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak */ 4286c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak public void test_setLastAccessTime() { 4296c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak zentry.setLastAccessTime(FileTime.fromMillis(0)); 4306c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(0, zentry.getLastAccessTime().toMillis()); 4316c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 4326c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak final long someTimestampValue = 1478624967000L; 4336c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak zentry.setLastAccessTime(FileTime.fromMillis(someTimestampValue)); 4346c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak assertEquals(someTimestampValue, zentry.getLastAccessTime().toMillis()); 4356c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak } 4366c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak 4376c970474e9416807cabde3620045906ad3903c6cPrzemyslaw Szczepaniak /** 438d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#toString() 439d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 440d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_toString() { 441d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method java.lang.String java.util.zip.ZipEntry.toString() 442d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertTrue("Returned incorrect entry name", zentry.toString().indexOf( 443d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath "File1.txt") >= 0); 444d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 445d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 446d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 447d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#ZipEntry(java.util.zip.ZipEntry) 448d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 449d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_ConstructorLjava_util_zip_ZipEntry() { 450d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method java.util.zip.ZipEntry(util.zip.ZipEntry) 451d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setSize(2); 452d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setCompressedSize(4); 453d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zentry.setComment("Testing"); 454d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry zentry2 = new ZipEntry(zentry); 455d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("ZipEntry Created With Incorrect Size.", 456d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 2, zentry2.getSize()); 457d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("ZipEntry Created With Incorrect Compressed Size.", 4, zentry2 458d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath .getCompressedSize()); 459d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("ZipEntry Created With Incorrect Comment.", "Testing", zentry2 460d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath .getComment()); 461d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("ZipEntry Created With Incorrect Crc.", 462d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath orgCrc, zentry2.getCrc()); 463d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("ZipEntry Created With Incorrect Time.", 464d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath orgTime, zentry2.getTime()); 465d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 466d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 467d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath /** 468d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath * java.util.zip.ZipEntry#clone() 469d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath */ 470d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath public void test_clone() { 471d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // Test for method java.util.zip.ZipEntry.clone() 472d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath Object obj = zentry.clone(); 473d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("toString()", zentry.toString(), obj.toString()); 474d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals("hashCode()", zentry.hashCode(), obj.hashCode()); 475d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 476d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // One constructor 477d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry zeInput = new ZipEntry("InputZIP"); 478d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath byte[] extraB = { 'a', 'b', 'd', 'e' }; 479d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zeInput.setExtra(extraB); 480d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB, zeInput.getExtra()); 481d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB[3], zeInput.getExtra()[3]); 482d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB.length, zeInput.getExtra().length); 483d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 484d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath // test Clone() 485d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath ZipEntry zeOutput = (ZipEntry) zeInput.clone(); 486d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]); 487d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length); 488d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB[3], zeOutput.getExtra()[3]); 489d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath assertEquals(extraB.length, zeOutput.getExtra().length); 490d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 491d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 492d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath @Override 493e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath protected void setUp() throws Exception { 494e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath // Create a local copy of the file since some tests want to alter 495e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath // information. 496e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath final File f = File.createTempFile("ZipEntryTest", ".zip"); 497e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath InputStream is = Support_Resources.getStream("hyts_ZipFile.zip"); 498e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath 499e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath FileOutputStream fos = new java.io.FileOutputStream(f); 500e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath Streams.copy(is, fos); 501e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath is.close(); 502e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath fos.close(); 503e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath 504e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath zfile = new ZipFile(f); 505e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath zentry = zfile.getEntry("File1.txt"); 506d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 507e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath orgSize = zentry.getSize(); 508e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath orgCompressedSize = zentry.getCompressedSize(); 509e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath orgCrc = zentry.getCrc(); 510e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath orgTime = zentry.getTime(); 511e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath } 512d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath 513d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath @Override 514d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath protected void tearDown() { 515d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath try { 516d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath if (zfile != null) { 517d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath zfile.close(); 518d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 519e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath } catch (IOException ignored) { 520d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 521d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath } 522d567f9025c4b94fc5e9b47f5702c1b48c2a45c96Narayan Kamath} 523