Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java (working copy) @@ -239,6 +239,9 @@ a2.putValue("One", "1"); a2.putValue("TWO", "2"); assertEquals(a1, a2); + assertEquals(a1, a1); + a2=null; + assertFalse(a1.equals(a2)); } /** Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java (working copy) @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.jar.JarException; import java.util.jar.Manifest; import junit.framework.TestCase; @@ -35,4 +36,18 @@ // correct } } + + /** + * @tests java.util.jar.JarException#JarException(java.lang.String) + */ + public void test_ConstructorLjava_lang_String1() throws Exception { + assertEquals("Jar Exception", new JarException("Jar Exception").getMessage()); + } + + /** + * @tests java.util.jar.JarException#JarException() + */ + public void test_Constructor_void() throws Exception { + new JarException(); + } } Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java (working copy) @@ -287,6 +287,8 @@ // java.util.jar.JarFile.getManifest() Support_Resources.copyFile(resources, null, JAR1); JarFile jarFile = new JarFile(new File(resources, JAR1)); + InputStream is = jarFile.getInputStream(jarFile.getEntry(JAR1_ENTRY1)); + assertTrue(is.available() > 0); assertNotNull("Error--Manifest not returned", jarFile.getManifest()); jarFile.close(); Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarOutputStreamTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarOutputStreamTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarOutputStreamTest.java (working copy) @@ -120,6 +120,13 @@ } catch (IOException ee) { // expected } + + try { + new JarOutputStream(fos, null); + fail("NullPointerException expected"); + } catch (NullPointerException ee) { + // expected + } } public void test_JarOutputStreamLjava_io_OutputStream() throws IOException { Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java (working copy) @@ -44,6 +44,8 @@ private final String MANIFEST_NAME = "manifest/hyts_MANIFEST.MF"; private static final String MANIFEST_CONTENTS = "Manifest-Version: 1.0\nBundle-Name: ClientSupport\nBundle-Description: Provides SessionService, AuthenticationService. Extends RegistryService.\nBundle-Activator: com.ibm.ive.eccomm.client.support.ClientSupportActivator\nImport-Package: com.ibm.ive.eccomm.client.services.log,\n com.ibm.ive.eccomm.client.services.registry,\n com.ibm.ive.eccomm.service.registry; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.session; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.framework; specification-version=1.2.0,\n org.osgi.framework; specification-version=1.0.0,\n org.osgi.service.log; specification-version=1.0.0,\n com.ibm.ive.eccomm.flash; specification-version=1.2.0,\n com.ibm.ive.eccomm.client.xml,\n com.ibm.ive.eccomm.client.http.common,\n com.ibm.ive.eccomm.client.http.client\nImport-Service: org.osgi.service.log.LogReaderService\n org.osgi.service.log.LogService,\n com.ibm.ive.eccomm.service.registry.RegistryService\nExport-Package: com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.common; specification-version=1.0.0,\n com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0\nExport-Service: com.ibm.ive.eccomm.service.authentication.AuthenticationService,\n com.ibm.ive.eccomm.service.session.SessionService\nBundle-Vendor: IBM\nBundle-Version: 1.2.0\n"; + + private static final String MANIFEST_CONTENTS_1 = "Manifest-Version: 2.0\nBundle-Name: ClientSupport\nBundle-Description: Provides SessionService, AuthenticationService. Extends RegistryService.\nBundle-Activator: com.ibm.ive.eccomm.client.support.ClientSupportActivator\nImport-Package: com.ibm.ive.eccomm.client.services.log,\n com.ibm.ive.eccomm.client.services.registry,\n com.ibm.ive.eccomm.service.registry; specification-version=2.0.0,\n com.ibm.ive.eccomm.service.session; specification-version=2.0.0,\n com.ibm.ive.eccomm.service.framework; specification-version=2.1.0,\n org.osgi.framework; specification-version=2.0.0,\n org.osgi.service.log; specification-version=2.0.0,\n com.ibm.ive.eccomm.flash; specification-version=2.2.0,\n com.ibm.ive.eccomm.client.xml,\n com.ibm.ive.eccomm.client.http.common,\n com.ibm.ive.eccomm.client.http.client\nImport-Service: org.osgi.service.log.LogReaderService\n org.osgi.service.log.LogService,\n com.ibm.ive.eccomm.service.registry.RegistryService\nExport-Package: com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,\n com.ibm.ive.eccomm.common; specification-version=1.0.0,\n com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0\nExport-Service: com.ibm.ive.eccomm.service.authentication.AuthenticationService,\n com.ibm.ive.eccomm.service.session.SessionService\nBundle-Vendor: IBM\nBundle-Version: 1.2.0\n"; private File resources; @@ -182,6 +184,14 @@ MANIFEST_CONTENTS.getBytes("ISO-8859-1"))); assertEquals(firstManifest, secondManifest); + + Manifest thirdManifest = new Manifest(new ByteArrayInputStream( + MANIFEST_CONTENTS_1.getBytes("ISO-8859-1"))); + assertNotSame(firstManifest, thirdManifest); + + firstManifest=null; + assertFalse(secondManifest.equals(firstManifest)); + assertFalse(secondManifest.equals(new String("abc"))); //non Manifest Object } /** Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java (working copy) @@ -104,6 +104,7 @@ // System.out.print(checkIn.getChecksum().getValue()); assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum() .getValue()); + assertEquals(0, checkIn.skip(0)); checkInput.close(); } Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterInputStreamTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterInputStreamTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterInputStreamTest.java (working copy) @@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.DeflaterInputStream; @@ -305,6 +306,13 @@ } /** + * @tests DataFormatException#DataFormatException() + */ + public void testDataFormatException() { + new DataFormatException(); + } + + /** * @tests DeflaterInputStream#DeflaterInputStream(InputStream,Deflater) */ public void testDeflaterInputStreamInputStreamDeflater() { Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java (working copy) @@ -676,6 +676,17 @@ defl.end(); } + Deflater defl = new Deflater(); + defl.setLevel(2); + outPutBuf = new byte[500]; + defl.setInput(byteArray); + try{ + defl.setLevel(3); + fail("IllegalStateException expected"); + }catch(IllegalStateException ise){ + //expected + } + // testing boundaries try { Deflater boundDefl = new Deflater(); @@ -745,6 +756,16 @@ mdefl.end(); } + byte outPutBuf[] = new byte[500]; + MyDeflater mdefl = new MyDeflater(); + mdefl.setStrategy(mdefl.getDefStrategy()); + mdefl.setInput(byteArray); + try{ + mdefl.setStrategy(mdefl.getHuffman()); + fail("IllegalStateException expected"); + }catch(IllegalStateException ise){ + //expected + } // Attempting to setStrategy to an invalid value try { Deflater defl = new Deflater(); @@ -886,6 +907,18 @@ fail("IllegalArgumentException not thrown when setting level to a number > 9."); } catch (IllegalArgumentException e) { } + + try { + Deflater boundDefl = new Deflater(-2, true); + fail("IllegalArgumentException not thrown when passing level to a number < 0."); + } catch (IllegalArgumentException e) { + } + + try { + Deflater boundDefl = new Deflater(10, true); + fail("IllegalArgumentException not thrown when passing level to a number > 9."); + } catch (IllegalArgumentException e) { + } } /** @@ -1007,6 +1040,22 @@ } catch (NullPointerException e) { } + // Methods where we expect NullPointerException to be thrown + try { + defl.getBytesRead(); + fail("defl.reset() can still be used after " + desc + + " is called in test_" + desc); + } catch (NullPointerException e) { + } + + // Methods where we expect NullPointerException to be thrown + try { + defl.getBytesWritten(); + fail("defl.getBytesWritten() can still be used after " + desc + + " is called in test_" + desc); + } catch (NullPointerException e) { + } + // Methods that should be allowed to be called after end() is called defl.needsInput(); defl.setStrategy(1); Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java (working copy) @@ -92,6 +92,25 @@ assertEquals("the CRC value of the inputStream is not zero", 0, inGZIP .getChecksum().getValue()); inGZIP.close(); + + try{ + TestGZIPInputStream inGZIP1 = new TestGZIPInputStream(gInput + .openConnection().getInputStream(), 0); + fail("IllegalArgumentException expected"); + }catch(IllegalArgumentException ioe){ + //expected + } + + Support_Resources.copyFile(resources, null, "hyts_checkInput.txt"); + final URL jarInput = new File(resources.toString()+ "/hyts_checkInput.txt").toURL(); + try{ + TestGZIPInputStream inGZIP1 = new TestGZIPInputStream(jarInput + .openConnection().getInputStream(), 200); + fail("IOException expected"); + }catch(IOException ex){ + //expected + } + } catch (IOException e) { fail( "an IO error occured while trying to open the input file"); Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java (working copy) @@ -112,6 +112,36 @@ } /** + * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream, + * java.util.zip.Inflater, int) + */ + public void test_ConstructorLjava_io_InputStreamLjava_util_zip_InflaterI_1() throws IOException { + InputStream infile = Support_Resources.getStream("hyts_constru(ODI).bin"); + Inflater inflate = new Inflater(); + InflaterInputStream inflatIP = null; + try{ + inflatIP = new InflaterInputStream(infile, null, 1); + fail("NullPointerException expected"); + }catch(NullPointerException NPE){ + //expected + } + + try{ + inflatIP = new InflaterInputStream(null, inflate, 1); + fail("NullPointerException expected"); + }catch(NullPointerException NPE){ + //expected + } + + try{ + inflatIP = new InflaterInputStream(infile, inflate, -1); + fail("IllegalArgumentException expected"); + }catch(IllegalArgumentException iae){ + //expected + } + } + + /** * @tests java.util.zip.InflaterInputStream#mark(int) */ public void test_markI() { @@ -160,6 +190,41 @@ } } + /** + * @tests java.util.zip.InflaterInputStream#read(byte [], int, int) + */ + public void test_read_LBII() throws IOException { + int result = 0; + InputStream infile = Support_Resources.getStream("hyts_constru(OD).bin"); + Inflater inflate = new Inflater(); + InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate); + + byte[] b = new byte[3]; + try{ + result = inflatIP.read(null, 0, 1); + fail("NullPointerException expected"); + }catch(NullPointerException npe){ + //expected + } + + assertEquals(0, inflatIP.read(b, 0, 0)); + + try{ + result = inflatIP.read(b, 5, 2); //offset higher + fail("IndexOutOfBoundsException expected"); + }catch(IndexOutOfBoundsException iobe){ + //expected + } + + inflatIP.close(); + try { + inflatIP.read(b, 0, 1); //read after close + fail("IOException expected"); + }catch(IOException ioe){ + //expected + } + } + public void testAvailableNonEmptySource() throws Exception { // this byte[] is a deflation of these bytes: { 1, 3, 4, 6 } byte[] deflated = { 72, -119, 99, 100, 102, 97, 3, 0, 0, 31, 0, 15, 0 }; Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java (working copy) @@ -363,6 +363,7 @@ try { while (!(inflate.finished())) { if (inflate.needsInput()) { + assertEquals(0, inflate.inflate(outPutInf, 0, 1)); inflate.setInput(outPutBuff1); } y += inflate.inflate(outPutInf, y, outPutInf.length - y); @@ -395,6 +396,21 @@ r = 1; } assertEquals("out of bounds error did not get caught", 1, r); + + try { + assertEquals(0, inflate.inflate(outPutInf, offSet, 0)); + } catch (DataFormatException e) { + fail("Invalid input to be decompressed"); + } + inflate.end(); + try { + inflate.inflate(outPutInf, offSet, 1); + fail("IllegalStateException expected"); + } catch (DataFormatException e) { + fail("Invalid input to be decompressed"); + } catch (IllegalStateException e) { + //expected + } } public void test_inflate$BII1() { @@ -517,6 +533,7 @@ assertEquals(0,inf.getTotalOut()); assertEquals(0,inf.getBytesRead()); assertEquals(0,inf.getBytesWritten()); + assertEquals(1, inf.getAdler()); } /** @@ -924,6 +941,12 @@ // expected. } infl1.end(); + try{ + infl1.setDictionary(dictionary2.getBytes()); + fail("IllegalStateException expected"); + }catch(IllegalStateException ise){ + //expected + } } public void testSetDictionary$BII() throws Exception { @@ -992,6 +1015,7 @@ Inflater infl1 = new Inflater(); Inflater infl2 = new Inflater(); Inflater infl3 = new Inflater(); + Inflater infl4 = new Inflater(); byte[] result = new byte[100]; int decLen; @@ -1026,6 +1050,62 @@ infl3.end(); assertEquals(inputString, new String(result, 0, decLen)); + //exception test + infl4.setInput(output3, 0, dataLen3); + decLen = infl4.inflate(result); + assertTrue(infl4.needsDictionary()); + + try{ + infl4.setDictionary(dictionary1.getBytes(), 4, 4); + fail("ArrayIndexOutOfBoundsException expected"); + }catch(ArrayIndexOutOfBoundsException aiob){ + //expected + } } + public void testExceptions() throws Exception { + byte byteArray[] = { 5, 2, 3, 7, 8 }; + + int r = 0; + Inflater inflate = new Inflater(); + inflate.setInput(byteArray); + inflate.end(); + + try{ + inflate.getAdler(); + fail("IllegalStateException expected"); + }catch(IllegalStateException ise){ + //expected + } + + try{ + inflate.getBytesRead(); + fail("NullPointerException expected"); + }catch(NullPointerException ise){ + //expected + } + + try{ + inflate.getBytesWritten(); + fail("NullPointerException expected"); + }catch(NullPointerException ise){ + //expected + } + + + try{ + inflate.getTotalIn(); + fail("IllegalStateException expected"); + }catch(IllegalStateException ise){ + //expected + } + + try{ + inflate.getTotalOut(); + fail("IllegalStateException expected"); + }catch(IllegalStateException ise){ + //expected + } + + } } Index: classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java =================================================================== --- classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java (revision 984148) +++ classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java (working copy) @@ -49,11 +49,16 @@ private ZipFile zfile; /** + * @throws IOException * @tests java.util.zip.ZipFile#ZipFile(java.io.File) */ - public void test_ConstructorLjava_io_File() { + public void test_ConstructorLjava_io_File() throws IOException { // Test for method java.util.zip.ZipFile(java.io.File) - assertTrue("Used to test", true); + zfile.close(); // about to reopen the same temp file + File file = new File(tempFileName); + ZipFile zip = new ZipFile(file); + assertTrue("Zip should exist", file.exists()); + zip.close(); } /** @@ -66,6 +71,14 @@ | ZipFile.OPEN_READ); zip.close(); assertTrue("Zip should not exist", !file.exists()); + + file = new File(tempFileName); + try{ + zip = new ZipFile(file, 3); //passing unkown argument + fail("Should throw IllegalArgumentException"); + }catch(IllegalArgumentException iae ){ + //expected + } } /**