harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r397192 [2/3] - in /incubator/harmony/enhanced/classlib/trunk: modules/archive/src/test/java/org/apache/harmony/archive/ modules/archive/src/test/java/org/apache/harmony/archive/tests/ modules/archive/src/test/java/org/apache/harmony/archiv...
Date Wed, 26 Apr 2006 13:04:23 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java?rev=397192&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java Wed Apr 26 06:04:19 2006
@@ -0,0 +1,182 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.archive.tests.java.util.zip;
+
+import java.util.zip.CRC32;
+
+public class CRC32Test extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.zip.CRC32#CRC32()
+	 */
+	public void test_Constructor() {
+		// test methods of java.util.zip.CRC32()
+		CRC32 crc = new CRC32();
+		assertEquals("Constructor of CRC32 failed", 0, crc.getValue());
+	}
+
+	/**
+	 * @tests java.util.zip.CRC32#getValue()
+	 */
+	public void test_getValue() {
+		// test methods of java.util.zip.crc32.getValue()
+		CRC32 crc = new CRC32();
+		assertEquals("getValue() should return a zero as a result of constructing a CRC32 instance",
+				0, crc.getValue());
+
+		crc.reset();
+		crc.update(Integer.MAX_VALUE);
+		// System.out.print("value of crc " + crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 4278190080
+		assertEquals("update(max) failed to update the checksum to the correct value ",
+				4278190080L, crc.getValue());
+
+		crc.reset();
+		byte byteEmpty[] = new byte[10000];
+		crc.update(byteEmpty);
+		// System.out.print("value of crc"+crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 1295764014
+		assertEquals("update(byte[]) failed to update the checksum to the correct value ",
+				1295764014L, crc.getValue());
+
+		crc.reset();
+		crc.update(1);
+		// System.out.print("value of crc"+crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 2768625435
+		// assertEquals("update(int) failed to update the checksum to the correct
+		// value ",2768625435L, crc.getValue());
+		crc.reset();
+		assertEquals("reset failed to reset the checksum value to zero", 0, crc
+				.getValue());
+	}
+
+	/**
+	 * @tests java.util.zip.CRC32#reset()
+	 */
+	public void test_reset() {
+		// test methods of java.util.zip.crc32.reset()
+		CRC32 crc = new CRC32();
+		crc.update(1);
+		// System.out.print("value of crc"+crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 2768625435
+		assertEquals("update(int) failed to update the checksum to the correct value ",
+				2768625435L, crc.getValue());
+		crc.reset();
+		assertEquals("reset failed to reset the checksum value to zero", 0, crc
+				.getValue());
+
+	}
+
+	/**
+	 * @tests java.util.zip.CRC32#update(int)
+	 */
+	public void test_updateI() {
+		// test methods of java.util.zip.crc32.update(int)
+		CRC32 crc = new CRC32();
+		crc.update(1);
+		// System.out.print("value of crc"+crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 2768625435
+		assertEquals("update(1) failed to update the checksum to the correct value ",
+				2768625435L, crc.getValue());
+
+		crc.reset();
+		crc.update(Integer.MAX_VALUE);
+		// System.out.print("value of crc " + crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 4278190080
+		assertEquals("update(max) failed to update the checksum to the correct value ",
+				4278190080L, crc.getValue());
+
+		crc.reset();
+		crc.update(Integer.MIN_VALUE);
+		// System.out.print("value of crc " + crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 3523407757
+		assertEquals("update(min) failed to update the checksum to the correct value ",
+				3523407757L, crc.getValue());
+	}
+
+	/**
+	 * @tests java.util.zip.CRC32#update(byte[])
+	 */
+	public void test_update$B() {
+		// test methods of java.util.zip.crc32.update(byte[])
+		byte byteArray[] = { 1, 2 };
+		CRC32 crc = new CRC32();
+		crc.update(byteArray);
+		// System.out.print("value of crc"+crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 3066839698
+		assertEquals("update(byte[]) failed to update the checksum to the correct value ",
+				3066839698L, crc.getValue());
+
+		crc.reset();
+		byte byteEmpty[] = new byte[10000];
+		crc.update(byteEmpty);
+		// System.out.print("value of crc"+crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 1295764014
+		assertEquals("update(byte[]) failed to update the checksum to the correct value ",
+				1295764014L, crc.getValue());
+	}
+
+	/**
+	 * @tests java.util.zip.CRC32#update(byte[], int, int)
+	 */
+	public void test_update$BII() {
+		// test methods of java.util.zip.update(byte[],int,int)
+		byte[] byteArray = { 1, 2, 3 };
+		CRC32 crc = new CRC32();
+		int off = 2;// accessing the 2nd element of byteArray
+		int len = 1;
+		int lenError = 3;
+		int offError = 4;
+		crc.update(byteArray, off, len);
+		// System.out.print("value of crc"+crc.getValue());
+		// Ran JDK and discovered that the value of the CRC should be
+		// 1259060791
+		assertEquals("update(byte[],int,int) failed to update the checksum to the correct value ",
+				1259060791L, crc.getValue());
+		int r = 0;
+		try {
+			crc.update(byteArray, off, lenError);
+		} catch (ArrayIndexOutOfBoundsException e) {
+			r = 1;
+		}
+		assertEquals("update(byte[],int,int) failed b/c lenError>byte[].length-off",
+				1, r);
+
+		try {
+			crc.update(byteArray, offError, len);
+		} catch (ArrayIndexOutOfBoundsException e) {
+			r = 2;
+		}
+		assertEquals("update(byte[],int,int) failed b/c offError>byte[].length",
+				2, r);
+	}
+
+	protected void setUp() {
+
+	}
+
+	protected void tearDown() {
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java?rev=397192&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java Wed Apr 26 06:04:19 2006
@@ -0,0 +1,139 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.archive.tests.java.util.zip;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
+
+import tests.support.resource.Support_Resources;
+
+public class CheckedInputStreamTest extends junit.framework.TestCase {
+	InputStream checkInput;
+
+	/**
+	 * @tests java.util.zip.CheckedInputStream#CheckedInputStream(java.io.InputStream,
+	 *        java.util.zip.Checksum)
+	 */
+	public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum() {
+		// test method java.util.zip.checkedInputStream.constructor()
+		try {
+			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+			CheckedInputStream checkIn = new CheckedInputStream(checkInput,
+					new CRC32());
+			assertEquals("constructor of checkedInputStream has failed", 0, checkIn
+					.getChecksum().getValue());
+			checkInput.close();
+		} catch (FileNotFoundException e) {
+			fail("File for checkInputStream is not found");
+		} catch (IOException e) {
+			fail("error occured while trying to open input file");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.CheckedInputStream#getChecksum()
+	 */
+	public void test_getChecksum() {
+		// test method java.util.zip.checkInputStream.getChecksum()
+		byte outBuf[] = new byte[100];
+		try {
+			// testing getChecksum for an empty file
+			FileOutputStream outEmp = new FileOutputStream("empty.txt");
+			outEmp.close();
+			InputStream inEmp = new FileInputStream("empty.txt");
+			CheckedInputStream checkEmpty = new CheckedInputStream(inEmp,
+					new CRC32());
+			while (checkEmpty.read() >= 0) {
+			}
+			assertEquals("the checkSum value of an empty file is not zero",
+					0, checkEmpty.getChecksum().getValue());
+			inEmp.close();
+
+			// testing getChecksum for the file checkInput
+			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+			CheckedInputStream checkIn = new CheckedInputStream(checkInput,
+					new CRC32());
+			while (checkIn.read() >= 0) {
+			}
+			// ran JDK and found that the checkSum value of this is 2036203193
+			// System.out.print(" " + checkIn.getChecksum().getValue());
+			assertEquals("the checksum value is incorrect", 2036203193, checkIn.getChecksum()
+					.getValue());
+			checkInput.close();
+			// testing getChecksum for file checkInput
+			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+			CheckedInputStream checkIn2 = new CheckedInputStream(checkInput,
+					new CRC32());
+			checkIn2.read(outBuf, 0, 10);
+			// ran JDK and found that the checkSum value of this is 2235765342
+			// System.out.print(" " + checkIn2.getChecksum().getValue());
+			assertEquals("the checksum value is incorrect", 2235765342L, checkIn2
+					.getChecksum().getValue());
+			checkInput.close();
+		} catch (FileNotFoundException e) {
+			fail("File for checkInputStream is not found");
+		} catch (IOException e) {
+			fail("error occured while trying to open input file");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.CheckedInputStream#skip(long)
+	 */
+	public void test_skipJ() {
+		// test method java.util.zip.skip
+		try {
+			// testing that the return by skip is valid
+			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+			CheckedInputStream checkIn = new CheckedInputStream(checkInput,
+					new CRC32());
+			long skipValue = 5;
+			assertTrue(
+					"the value returned by skip(n) is not the same as its parameter",
+					checkIn.skip(skipValue) == skipValue);
+			checkIn.skip(skipValue);
+			// ran JDK and found the checkSum value is 2235765342
+			// System.out.print(checkIn.getChecksum().getValue());
+			assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
+					.getValue());
+			checkInput.close();
+		} catch (FileNotFoundException e) {
+			fail("File for checkInputStream is not found");
+		} catch (IOException e) {
+			fail("error occured while trying to open input file");
+		}
+	}
+
+	protected void setUp() {
+
+	}
+
+	protected void tearDown() {
+		try {
+			File deletedFile = new File("empty.txt");
+			deletedFile.delete();
+		} catch (SecurityException e) {
+			fail("Cannot delete file for security reasons");
+		}
+
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java?rev=397192&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java Wed Apr 26 06:04:19 2006
@@ -0,0 +1,147 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.archive.tests.java.util.zip;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.Adler32;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedOutputStream;
+
+public class CheckedOutputStreamTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.zip.CheckedOutputStream#CheckedOutputStream(java.io.OutputStream,
+	 *        java.util.zip.Checksum)
+	 */
+	public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Checksum() {
+		// test method java.util.zip.checkedOutputStream.constructor
+		try {
+			FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+			CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
+					new CRC32());
+			assertEquals("the checkSum value of the constructor is not 0", 0, chkOut
+					.getChecksum().getValue());
+			outFile.close();
+		} catch (IOException e) {
+			fail("Unable to find file");
+		} catch (SecurityException e) {
+			fail(
+					"file cannot be opend for writing due to security reasons");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.CheckedOutputStream#getChecksum()
+	 */
+	public void test_getChecksum() {
+		// test method java.util.zip.checkedOutputStream.getChecksum()
+		byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
+		try {
+			FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+			CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
+					new Adler32());
+			chkOut.write(byteArray[4]);
+			// ran JDK and found that checkSum value is 7536755
+			// System.out.print(chkOut.getChecksum().getValue());
+
+			assertEquals("the checkSum value for writeI is incorrect", 7536755, chkOut
+					.getChecksum().getValue());
+			chkOut.getChecksum().reset();
+			chkOut.write(byteArray, 5, 4);
+			// ran JDK and found that checkSum value is 51708133
+			// System.out.print(" " +chkOut.getChecksum().getValue());
+
+			assertEquals("the checkSum value for writeBII is incorrect ", 51708133, chkOut
+					.getChecksum().getValue());
+			outFile.close();
+		} catch (IOException e) {
+			fail("Unable to find file");
+		} catch (SecurityException e) {
+			fail(
+					"file cannot be opend for writing due to security reasons");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.CheckedOutputStream#write(int)
+	 */
+	public void test_writeI() {
+		// test method java.util.zip.checkedOutputStream.writeI()
+		byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
+		try {
+			FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+			CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
+					new CRC32());
+			for (int i = 0; i < byteArray.length; i++) {
+				chkOut.write(byteArray[i]);
+			}
+			assertTrue(
+					"the checkSum value is zero, no bytes are written to the output file",
+					chkOut.getChecksum().getValue() != 0);
+			outFile.close();
+		} catch (IOException e) {
+			fail("Unable to find file");
+		} catch (SecurityException e) {
+			fail("File cannot be opened for writing due to security reasons");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.CheckedOutputStream#write(byte[], int, int)
+	 */
+	public void test_write$BII() {
+		// test method java.util.zip.checkOutputStream.writeBII()
+		byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
+		try {
+			FileOutputStream outFile = new FileOutputStream("chkOut.txt");
+			CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
+					new CRC32());
+			chkOut.write(byteArray, 4, 5);
+			assertTrue(
+					"the checkSum value is zero, no bytes are written to the output file",
+					chkOut.getChecksum().getValue() != 0);
+			int r = 0;
+			try {
+				chkOut.write(byteArray, 4, 6);
+			} catch (IndexOutOfBoundsException e) {
+				r = 1;
+			}
+			assertEquals("boundary check is not performed", 1, r);
+			outFile.close();
+		} catch (IOException e) {
+			fail("Unable to find file");
+		} catch (SecurityException e) {
+			fail(
+					"file cannot be opend for writing due to security reasons");
+		} catch (IndexOutOfBoundsException e) {
+			fail("Index for write is out of bounds");
+		}
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+		try {
+			File deletedFile = new File("chkOut.txt");
+			deletedFile.delete();
+		} catch (SecurityException e) {
+			fail("Cannot delete file for security reasons");
+		}
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java?rev=397192&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java Wed Apr 26 06:04:19 2006
@@ -0,0 +1,455 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.archive.tests.java.util.zip;
+
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.Deflater;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.InflaterInputStream;
+
+public class DeflaterOutputStreamTest extends junit.framework.TestCase {
+	byte outPutBuf[] = new byte[500];
+
+	class MyDeflaterOutputStream extends java.util.zip.DeflaterOutputStream {
+		MyDeflaterOutputStream(OutputStream out) {
+			super(out);
+		}
+
+		MyDeflaterOutputStream(OutputStream out, Deflater defl) {
+			super(out, defl);
+		}
+
+		MyDeflaterOutputStream(OutputStream out, Deflater defl, int size) {
+			super(out, defl, size);
+		}
+
+		byte[] getProtectedBuf() {
+			return buf;
+		}
+
+		void myDeflate() throws IOException {
+			deflate();
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
+	 *        java.util.zip.Deflater)
+	 */
+	public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Deflater() {
+		// Test for method
+		// java.util.zip.deflaterOutputStream.DeflaterOutPutStream(OutputStream,Deflater)
+
+		try {
+			byte byteArray[] = { 1, 3, 4, 7, 8 };
+			File f1 = new File("hyts_Constru(OD).tst");
+			FileOutputStream fos = new FileOutputStream(f1);
+			Deflater defl = null;
+			MyDeflaterOutputStream dos;
+			// Test for a null Deflater.
+			try {
+				dos = new MyDeflaterOutputStream(fos, defl);
+				fail("NullPointerException Not Thrown");
+			} catch (NullPointerException e) {
+			}
+			defl = new Deflater();
+			dos = new MyDeflaterOutputStream(fos, defl);
+
+			// Test to see if DflaterOutputStream was created with the correct
+			// buffer.
+			assertEquals("Incorrect Buffer Size",
+					512, dos.getProtectedBuf().length);
+
+			dos.write(byteArray);
+			dos.close();
+			f1.delete();
+		} catch (SecurityException e) {
+			fail("SecurityException During Test");
+		} catch (IOException e) {
+			fail("IOException During Test");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream)
+	 */
+	public void test_ConstructorLjava_io_OutputStream() {
+		// Test for method
+		// java.util.zip.deflaterOutputStream.DeflaterOutPutStream(OutputStream)
+
+		try {
+			File f1 = new File("hyts_Constru(O).tst");
+			FileOutputStream fos = new FileOutputStream(f1);
+			MyDeflaterOutputStream dos = new MyDeflaterOutputStream(fos);
+
+			// Test to see if DflaterOutputStream was created with the correct
+			// buffer.
+			assertEquals("Incorrect Buffer Size",
+					512, dos.getProtectedBuf().length);
+
+			dos.write(outPutBuf);
+			dos.close();
+			f1.delete();
+		} catch (SecurityException e) {
+			fail("SecurityException During Test");
+		} catch (IOException e) {
+			fail("IOException During Test");
+		}
+
+	}
+
+	/**
+	 * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
+	 *        java.util.zip.Deflater, int)
+	 */
+	public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_DeflaterI() {
+		// Test for method
+		// java.util.zip.deflaterOutputStream.DeflaterOutPutStream(OutputStream,Deflater,int)
+
+		try {
+			int buf = 5;
+			int negBuf = -5;
+			int zeroBuf = 0;
+			byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
+			File f1 = new File("hyts_Constru(ODI).tst");
+			FileOutputStream fos = new FileOutputStream(f1);
+			Deflater defl = null;
+			MyDeflaterOutputStream dos;
+
+			// Test for a null Deflater.
+			try {
+				dos = new MyDeflaterOutputStream(fos, defl, buf);
+				fail("NullPointerException Not Thrown");
+			} catch (NullPointerException e) {
+			}
+			defl = new Deflater();
+
+			// Test for a negative buf.
+			try {
+				dos = new MyDeflaterOutputStream(fos, defl, negBuf);
+				fail("IllegalArgumentException Not Thrown");
+			} catch (IllegalArgumentException e) {
+			}
+
+			// Test for a zero buf.
+			try {
+				dos = new MyDeflaterOutputStream(fos, defl, zeroBuf);
+				fail("IllegalArgumentException Not Thrown");
+			} catch (IllegalArgumentException e) {
+			}
+
+			// Test to see if DflaterOutputStream was created with the correct
+			// buffer.
+			dos = new MyDeflaterOutputStream(fos, defl, buf);
+			assertEquals("Incorrect Buffer Size",
+					5, dos.getProtectedBuf().length);
+
+			dos.write(byteArray);
+			dos.close();
+			f1.delete();
+		} catch (SecurityException e) {
+			fail("SecurityException During Test");
+		} catch (IOException e) {
+			fail("IOException During Test");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.DeflaterOutputStream#close()
+	 */
+	public void test_close() {
+		// Test for method java.util.zip.DeflaterOutputStream.close()
+		try {
+			File f1 = new File("close.tst");
+			FileOutputStream fos = new FileOutputStream(f1);
+			DeflaterOutputStream dos = new DeflaterOutputStream(fos);
+			byte byteArray[] = { 1, 3, 4, 6 };
+			dos.write(byteArray);
+
+			FileInputStream fis = new FileInputStream(f1);
+			InflaterInputStream iis = new InflaterInputStream(fis);
+			try {
+				iis.read();
+				fail("EOFException Not Thrown");
+			} catch (EOFException e) {
+			}
+
+			dos.close();
+
+			// Test to see if the finish method wrote the bytes to the file.
+			assertEquals("Incorrect Byte Returned.", 1, iis.read());
+			assertEquals("Incorrect Byte Returned.", 3, iis.read());
+			assertEquals("Incorrect Byte Returned.", 4, iis.read());
+			assertEquals("Incorrect Byte Returned.", 6, iis.read());
+			assertEquals("Incorrect Byte Returned.", -1, iis.read());
+			assertEquals("Incorrect Byte Returned.", -1, iis.read());
+			iis.close();
+
+			// Not sure if this test will stay.
+			FileOutputStream fos2 = new FileOutputStream(f1);
+			DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
+			fos2.close();
+			try {
+				dos2.close();
+				fail("IOException not thrown");
+			} catch (IOException e) {
+			}
+
+			// Test to write to a closed DeflaterOutputStream
+			try {
+				dos.write(5);
+				fail(
+						"DeflaterOutputStream Able To Write After Being Closed.");
+			} catch (IOException e) {
+			}
+
+			// Test to write to a FileOutputStream that should have been closed
+			// by
+			// the DeflaterOutputStream.
+			try {
+				fos.write(("testing").getBytes());
+				fail(
+						"FileOutputStream Able To Write After Being Closed.");
+			} catch (IOException e) {
+			}
+
+			f1.delete();
+		} catch (SecurityException e) {
+			fail("Unexpected SecurityException during test");
+		} catch (IOException e) {
+			fail("Unexpected IOException during test");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.DeflaterOutputStream#finish()
+	 */
+	public void test_finish() {
+		// Test for method java.util.zip.DeflaterOutputStream.finish()
+
+		// Need test to see if method finish() actually finishes
+		// Only testing possible errors, not if it actually works
+
+		try {
+			File f1 = new File("finish.tst");
+			FileOutputStream fos1 = new FileOutputStream(f1);
+			DeflaterOutputStream dos = new DeflaterOutputStream(fos1);
+			byte byteArray[] = { 1, 3, 4, 6 };
+			dos.write(byteArray);
+			dos.finish();
+
+			// Test to see if the same FileOutputStream can be used with the
+			// DeflaterOutputStream after finish is called.
+			try {
+				dos.write(1);
+				fail("IOException not thrown");
+			} catch (IOException e) {
+			}
+
+			// Test for writing with a new FileOutputStream using the same
+			// DeflaterOutputStream.
+			FileOutputStream fos2 = new FileOutputStream(f1);
+			try {
+				dos = new DeflaterOutputStream(fos2);
+				dos.write(1);
+			} catch (IOException e) {
+				fail("Unexpected IOException");
+			}
+
+			// Test for writing to FileOutputStream fos1, which should be open.
+			try {
+				fos1.write(("testing").getBytes());
+			} catch (IOException e) {
+				fail(
+						"Unexpected IOException While Using The FileOutputStream 1.");
+			}
+
+			// Test for writing to FileOutputStream fos2, which should be open.
+			try {
+				fos2.write(("testing").getBytes());
+			} catch (IOException e) {
+				fail("Unexpected IOException while using the FileOutputStream 2");
+			}
+
+			// Not sure if this test will stay.
+			FileOutputStream fos3 = new FileOutputStream(f1);
+			DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
+			fos3.close();
+			try {
+				dos3.finish();
+				fail("IOException not thrown");
+			} catch (IOException e) {
+			}
+
+			// dos.close() won't close fos1 because it has been re-assigned to
+			// fos2
+			fos1.close();
+			dos.close();
+			f1.delete();
+		} catch (SecurityException e) {
+			fail("Unexpected SecurityException during test");
+		} catch (IOException e) {
+			fail("Unexpected IOException during test");
+		}
+
+	}
+
+	/**
+	 * @tests java.util.zip.DeflaterOutputStream#write(int)
+	 */
+	public void test_writeI() {
+		// Test for method java.util.zip.deflaterOutputStream.write(int)
+
+		try {
+			File f1 = new File("writeI1.tst");
+			FileOutputStream fos = new FileOutputStream(f1);
+			DeflaterOutputStream dos = new DeflaterOutputStream(fos);
+			for (int i = 0; i < 3; i++)
+				dos.write(i);
+			dos.close();
+			FileInputStream fis = new FileInputStream(f1);
+			InflaterInputStream iis = new InflaterInputStream(fis);
+			for (int i = 0; i < 3; i++)
+				assertTrue("Incorrect Byte Returned.", iis.read() == i);
+			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+			iis.close();
+
+			// Not sure if this test is that important.
+			// Checks to see if you can write using the DeflaterOutputStream
+			// after
+			// the FileOutputStream has been closed.
+			FileOutputStream fos2 = new FileOutputStream(f1);
+			DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
+			fos2.close();
+			try {
+				dos2.write(2);
+				fail("IOException not thrown");
+			} catch (IOException e) {
+			}
+
+			f1.delete();
+		} catch (SecurityException e) {
+			fail("Unexpected SecurityException during test");
+		} catch (IOException e) {
+			fail("Unexpected IOException during test.");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.DeflaterOutputStream#write(byte[], int, int)
+	 */
+	public void test_write$BII() {
+		// Test method
+		// java.util.zip.deflaterOutputStream.write(byteArrat,int,int)
+		try {
+			byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
+
+			// Test to see if the correct bytes are saved.
+			File f1 = new File("writeBII.tst");
+			FileOutputStream fos1 = new FileOutputStream(f1);
+			DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1);
+			dos1.write(byteArray, 2, 3);
+			dos1.close();
+			FileInputStream fis = new FileInputStream(f1);
+			InflaterInputStream iis = new InflaterInputStream(fis);
+			assertEquals("Incorrect Byte Returned.", 4, iis.read());
+			assertEquals("Incorrect Byte Returned.", 7, iis.read());
+			assertEquals("Incorrect Byte Returned.", 8, iis.read());
+			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+			iis.close();
+			f1.delete();
+
+			// Test for trying to write more bytes than available from the array
+			File f2 = new File("writeBII2.tst");
+			FileOutputStream fos2 = new FileOutputStream(f2);
+			DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
+			try {
+				dos2.write(byteArray, 2, 10);
+				fail("IndexOutOfBoundsException not thrown");
+			} catch (IndexOutOfBoundsException e) {
+			}
+
+			// Test for trying to write a negative number of bytes.
+			try {
+				dos2.write(byteArray, 2, Integer.MIN_VALUE);
+				fail("IndexOutOfBoundsException not thrown");
+			} catch (IndexOutOfBoundsException e) {
+			}
+
+			// Test for trying to start writing from a byte < 0 from the array.
+			try {
+				dos2.write(byteArray, Integer.MIN_VALUE, 2);
+				fail("IndexOutOfBoundsException not thrown");
+			} catch (IndexOutOfBoundsException e) {
+			}
+
+			// Test for trying to start writing from a byte > than the array
+			// size.
+			try {
+				dos2.write(byteArray, 10, 2);
+				fail("IndexOutOfBoundsException not thrown");
+			} catch (IndexOutOfBoundsException e) {
+			}
+			dos2.close();
+
+			// Not sure if this test is that important.
+			// Checks to see if you can write using the DeflaterOutputStream
+			// after
+			// the FileOutputStream has been closed.
+			FileOutputStream fos3 = new FileOutputStream(f2);
+			DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
+			fos3.close();
+			try {
+				dos3.write(byteArray, 2, 3);
+				fail("IOException not thrown");
+			} catch (IOException e) {
+			}
+
+			f2.delete();
+		} catch (SecurityException e) {
+			fail("Unexpectd SecurityException during test");
+		} catch (IOException e) {
+			fail("Unexpected IOException during test");
+		}
+	}
+
+	protected void setUp() {
+		// setting up a deflater to be used
+		byte byteArray[] = { 1, 3, 4, 7, 8 };
+		int x = 0;
+		Deflater deflate = new Deflater(1);
+		deflate.setInput(byteArray);
+		while (!(deflate.needsInput())) {
+			x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
+		}
+		deflate.finish();
+		while (!(deflate.finished())) {
+			x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
+		}
+		deflate.end();
+	}
+
+	protected void tearDown() {
+
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java?rev=397192&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java Wed Apr 26 06:04:19 2006
@@ -0,0 +1,1193 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.archive.tests.java.util.zip;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.Adler32;
+import java.util.zip.DataFormatException;
+import java.util.zip.Deflater;
+import java.util.zip.Inflater;
+
+import java.io.UnsupportedEncodingException;
+
+import tests.support.resource.Support_Resources;
+
+public class DeflaterTest extends junit.framework.TestCase {
+
+	class MyDeflater extends java.util.zip.Deflater {
+		MyDeflater() {
+			super();
+		}
+
+		MyDeflater(int lvl) {
+			super(lvl);
+		}
+
+		MyDeflater(int lvl, boolean noHeader) {
+			super(lvl, noHeader);
+		}
+
+		void myFinalize() {
+			finalize();
+		}
+
+		int getDefCompression() {
+			return DEFAULT_COMPRESSION;
+		}
+
+		int getDefStrategy() {
+			return DEFAULT_STRATEGY;
+		}
+
+		int getHuffman() {
+			return HUFFMAN_ONLY;
+		}
+
+		int getFiltered() {
+			return FILTERED;
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#deflate(byte[])
+	 */
+	public void test_deflate$B() {
+		// test method of java.util.zip.deflater.deflate(byte)
+		byte outPutBuf[] = new byte[50];
+		byte byteArray[] = { 1, 3, 4, 7, 8 };
+		byte outPutInf[] = new byte[50];
+		int x = 0;
+
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			x += defl.deflate(outPutBuf);
+		assertEquals("Deflater at end of stream, should return 0", 0, defl
+				.deflate(outPutBuf));
+		int totalOut = defl.getTotalOut();
+		int totalIn = defl.getTotalIn();
+		assertTrue(
+				"The total number of bytes from deflate did not equal getTotalOut",
+				x == totalOut);
+		assertTrue(
+				"The number of input bytes from the array did not correspond with getTotalIn: Was "
+						+ totalIn + " Should Be " + byteArray.length,
+				totalIn == byteArray.length);
+		defl.end();
+
+		Inflater infl = new Inflater();
+		try {
+			infl.setInput(outPutBuf);
+			while (!infl.finished())
+				infl.inflate(outPutInf);
+		} catch (DataFormatException e) {
+			fail("Invalid input to be decompressed");
+		}
+		assertTrue(
+				"Inflates getTotalOut() did not correspond with deflates getTotalIn()",
+				infl.getTotalOut() == totalIn);
+		assertTrue(
+				"Inflates getTotalIn() did not correspond with deflates getTotalOut()",
+				infl.getTotalIn() == totalOut);
+		for (int i = 0; i < byteArray.length; i++)
+			assertTrue(
+					"Final decompressed data does not equal the original data",
+					byteArray[i] == outPutInf[i]);
+		assertEquals("Final decompressed data contained more bytes than original",
+				0, outPutInf[byteArray.length]);
+		infl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#deflate(byte[], int, int)
+	 */
+	public void test_deflate$BII() {
+		// test method of java.util.zip.deflater.deflate(byte,int,int)
+		byte outPutBuf[] = new byte[50];
+		byte byteArray[] = { 5, 2, 3, 7, 8 };
+		byte outPutInf[] = new byte[50];
+		int offSet = 1;
+		int length = outPutBuf.length - 1;
+		int x = 0;
+
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			x += defl.deflate(outPutBuf, offSet, length);
+		assertEquals("Deflater at end of stream, should return 0", 0, defl.deflate(
+				outPutBuf, offSet, length));
+		int totalOut = defl.getTotalOut();
+		int totalIn = defl.getTotalIn();
+		assertTrue(
+				"The total number of bytes from deflate did not equal getTotalOut",
+				totalOut == x);
+		assertTrue(
+				"The number of input bytes from the array did not correspond with getTotalIn - side effect of deflate()",
+				totalIn == byteArray.length);
+		defl.end();
+
+		Inflater infl = new Inflater();
+		try {
+			infl.setInput(outPutBuf, offSet, length);
+			while (!infl.finished())
+				infl.inflate(outPutInf);
+		} catch (DataFormatException e) {
+			fail("Invalid input to be decompressed");
+		}
+		assertTrue(
+				"inflates getTotalOut() did not correspond with deflates getTotalIn()",
+				infl.getTotalOut() == totalIn);
+		assertTrue(
+				"inflates getTotalIn() did not correspond with deflates getTotalOut()",
+				infl.getTotalIn() == totalOut);
+		for (int i = 0; i < byteArray.length; i++)
+			assertTrue(
+					"Final decompressed data does not equal the original data",
+					byteArray[i] == outPutInf[i]);
+		assertEquals("Final decompressed data contained more bytes than original",
+				0, outPutInf[byteArray.length]);
+		infl.end();
+
+		// Set of tests testing the boundaries of the offSet/length
+		defl = new Deflater();
+		outPutBuf = new byte[100];
+		defl.setInput(byteArray);
+		for (int i = 0; i < 2; i++) {
+			if (i == 0) {
+				offSet = outPutBuf.length + 1;
+				length = outPutBuf.length;
+			} else {
+				offSet = 0;
+				length = outPutBuf.length + 1;
+			}
+			try {
+				defl.deflate(outPutBuf, offSet, length);
+				fail("Test " + i
+						+ ": ArrayIndexOutOfBoundsException not thrown");
+			} catch (ArrayIndexOutOfBoundsException e) {
+			}
+		}
+		defl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#end()
+	 */
+	public void test_end() {
+		// test method java.util.zip.deflater.end();
+
+		byte byteArray[] = { 5, 2, 3, 7, 8 };
+		byte outPutBuf[] = new byte[100];
+
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		defl.end();
+		helper_end_test(defl, "end");
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#finalize()
+	 */
+	public void test_finalize() {
+		// test method java.util.zip.deflater.finalize()
+		MyDeflater mdefl = new MyDeflater();
+		mdefl.myFinalize();
+		System.gc();
+		helper_end_test(mdefl, "finalize");
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#finish()
+	 */
+	public void test_finish() {
+		// test method java.util.zip.deflater.finish()
+		// This test already here, its the same as test_deflate()
+		byte byteArray[] = { 5, 2, 3, 7, 8 };
+		byte outPutBuf[] = new byte[100];
+		byte outPutInf[] = new byte[100];
+		int x = 0;
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray);
+		defl.finish();
+
+		// needsInput should never return true after finish() is called
+		if (System.getProperty("java.vendor").startsWith("IBM"))
+			assertTrue(
+					"needsInput() should return false after finish() is called",
+					!defl.needsInput());
+
+		while (!defl.finished())
+			x += defl.deflate(outPutBuf);
+		int totalOut = defl.getTotalOut();
+		int totalIn = defl.getTotalIn();
+		assertTrue(
+				"The total number of bytes from deflate did not equal getTotalOut",
+				x == totalOut);
+		assertTrue(
+				"The number of input bytes from the array did not correspond with getTotalIn",
+				totalIn == byteArray.length);
+		defl.end();
+
+		Inflater infl = new Inflater();
+		try {
+			infl.setInput(outPutBuf);
+			while (!infl.finished())
+				infl.inflate(outPutInf);
+		} catch (DataFormatException e) {
+			fail("Invalid input to be decompressed");
+		}
+		assertTrue(
+				"Inflates getTotalOut() did not correspond with deflates getTotalIn()",
+				infl.getTotalOut() == totalIn);
+		assertTrue(
+				"Inflates getTotalIn() did not correspond with deflates getTotalOut()",
+				infl.getTotalIn() == totalOut);
+		for (int i = 0; i < byteArray.length; i++)
+			assertTrue(
+					"Final decompressed data does not equal the original data",
+					byteArray[i] == outPutInf[i]);
+		assertEquals("Final decompressed data contained more bytes than original",
+				0, outPutInf[byteArray.length]);
+		infl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#finished()
+	 */
+	public void test_finished() {
+		// test method java.util.zip.deflater.finish()
+		byte byteArray[] = { 5, 2, 3, 7, 8 };
+		byte outPutBuf[] = new byte[100];
+		Deflater defl = new Deflater();
+		assertTrue("Test 1: Deflater should not be finished.", !defl.finished());
+		defl.setInput(byteArray);
+		assertTrue("Test 2: Deflater should not be finished.", !defl.finished());
+		defl.finish();
+		assertTrue("Test 3: Deflater should not be finished.", !defl.finished());
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		assertTrue("Test 4: Deflater should be finished.", defl.finished());
+		defl.end();
+		assertTrue("Test 5: Deflater should be finished.", defl.finished());
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#getAdler()
+	 */
+	public void test_getAdler() {
+		// test method for java.util.zip.Deflater.getAdler()
+		byte byteArray[] = { 'a', 'b', 'c', 1, 2, 3 };
+		byte outPutBuf[] = new byte[100];
+		Deflater defl = new Deflater();
+
+		// getting the checkSum value using the Adler
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		long checkSumD = defl.getAdler();
+		defl.end();
+
+		// getting the checkSum value through the Adler32 class
+		Adler32 adl = new Adler32();
+		adl.update(byteArray);
+		long checkSumR = adl.getValue();
+		assertTrue(
+				"The checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
+				checkSumR == checkSumD);
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#getTotalIn()
+	 */
+	public void test_getTotalIn() {
+		// test method java.util.zip.deflater.getTotalIn()
+		byte outPutBuf[] = new byte[5];
+		byte byteArray[] = { 1, 3, 4, 7, 8 };
+
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		assertTrue(
+				"The number of input byte from the array did not correspond with getTotalIn",
+				defl.getTotalIn() == byteArray.length);
+		defl.end();
+
+		defl = new Deflater();
+		int offSet = 2;
+		int length = 3;
+		outPutBuf = new byte[5];
+		defl.setInput(byteArray, offSet, length);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		assertTrue(
+				"The number of input byte sent to setInputBII() did not corrsepond with getTotalIn",
+				defl.getTotalIn() == length);
+		defl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#getTotalOut()
+	 */
+	public void test_getTotalOut() {
+		// test method java.util.zip.deflater.getTotalOut()
+		// the getTotalOut should equal the sum of value returned by deflate()
+		byte outPutBuf[] = new byte[5];
+		byte byteArray[] = { 5, 2, 3, 7, 8 };
+		int x = 0;
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			x += defl.deflate(outPutBuf);
+		assertTrue(
+				"The total number of bytes from deflate() did not equal getTotalOut",
+				x == defl.getTotalOut());
+		defl.end();
+
+		x = 0;
+		int offSet = 2;
+		int length = 3;
+		defl = new Deflater();
+		outPutBuf = new byte[5];
+		defl.setInput(byteArray, offSet, length);
+		defl.finish();
+		while (!defl.finished())
+			x += defl.deflate(outPutBuf);
+		assertTrue(
+				"The total number of bytes from deflateBII() did not equal getTotalOut",
+				x == defl.getTotalOut());
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#needsInput()
+	 */
+	public void test_needsInput() {
+		// test method of java.util.zip.deflater.needsInput()
+		Deflater defl = new Deflater();
+		assertTrue(
+				"needsInput give the wrong boolean value as a result of no input buffer",
+				defl.needsInput());
+		byte byteArray[] = { 1, 2, 3 };
+		defl.setInput(byteArray);
+		assertTrue(
+				"needsInput give wrong boolean value as a result of a full input buffer",
+				!defl.needsInput());
+		byte[] outPutBuf = new byte[50];
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		byte emptyByteArray[] = new byte[0];
+		defl.setInput(emptyByteArray);
+		assertTrue(
+				"needsInput give wrong boolean value as a result of an empty input buffer",
+				defl.needsInput());
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		// needsInput should NOT return true after finish() has been
+		// called.
+		if (System.getProperty("java.vendor").startsWith("IBM"))
+			assertTrue(
+					"needsInput gave wrong boolean value as a result of finish() being called",
+					!defl.needsInput());
+		defl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#reset()
+	 */
+	public void test_reset() {
+		// test method of java.util.zip.deflater.reset()
+		byte outPutBuf[] = new byte[100];
+		byte outPutInf[] = new byte[100];
+		byte curArray[] = new byte[5];
+		byte byteArray[] = { 1, 3, 4, 7, 8 };
+		byte byteArray2[] = { 8, 7, 4, 3, 1 };
+		int x = 0;
+		int orgValue = 0;
+		Deflater defl = new Deflater();
+
+		for (int i = 0; i < 3; i++) {
+			if (i == 0)
+				curArray = byteArray;
+			else if (i == 1)
+				curArray = byteArray2;
+			else
+				defl.reset();
+
+			defl.setInput(curArray);
+			defl.finish();
+			while (!defl.finished())
+				x += defl.deflate(outPutBuf);
+
+			if (i == 0)
+				assertTrue(
+						"The total number of bytes from deflate did not equal getTotalOut",
+						x == defl.getTotalOut());
+			else if (i == 1)
+				assertTrue(
+						"The total number of bytes from deflate should still be the same ("
+								+ x + ")", x == orgValue);
+			else
+				assertTrue(
+						"The total number of bytes from deflate should be doubled ("
+								+ orgValue * 2 + ")", x == orgValue * 2);
+
+			if (i == 0)
+				orgValue = x;
+
+			try {
+				Inflater infl = new Inflater();
+				infl.setInput(outPutBuf);
+				while (!infl.finished())
+					infl.inflate(outPutInf);
+				infl.end();
+			} catch (DataFormatException e) {
+				fail("Test " + i + ": Invalid input to be decompressed");
+			}
+
+			if (i == 1)
+				curArray = byteArray;
+
+			for (int j = 0; j < curArray.length; j++)
+				assertTrue(
+						"Test "
+								+ i
+								+ ": Final decompressed data does not equal the original data",
+						curArray[j] == outPutInf[j]);
+			assertTrue(
+					"Test "
+							+ i
+							+ ": Final decompressed data contained more bytes than original",
+					outPutInf[curArray.length] == 0);
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#setDictionary(byte[])
+	 */
+	public void test_setDictionary$B() {
+		// test method of java.util.zip.deflater.setDictionary(byte[])
+		// This test is very close to getAdler()
+		byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3 };
+		byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
+				'w', 'r' };
+		byte outPutBuf[] = new byte[100];
+
+		Deflater defl = new Deflater();
+		long deflAdler = defl.getAdler();
+		assertEquals("No dictionary set, no data deflated, getAdler should return 1",
+				1, deflAdler);
+		defl.setDictionary(dictionaryArray);
+		deflAdler = defl.getAdler();
+
+		// getting the checkSum value through the Adler32 class
+		Adler32 adl = new Adler32();
+		adl.update(dictionaryArray);
+		long realAdler = adl.getValue();
+		assertTrue(
+				"Dictionary is set, getAdler() should equal the adler value of the dictionaryArray",
+				deflAdler == realAdler);
+
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		deflAdler = defl.getAdler();
+		adl = new Adler32();
+		adl.update(byteArray);
+		realAdler = adl.getValue();
+		// Deflate is finished and there were bytes deflated that did not occur
+		// in the dictionaryArray, therefore a new dictionary was automatically
+		// set.
+		assertTrue("getAdler() returned " + deflAdler + " should be "
+				+ realAdler, deflAdler == realAdler);
+		defl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#setDictionary(byte[], int, int)
+	 */
+	public void test_setDictionary$BII() {
+		// test method of java.util.zip.deflater.setDictionary(byte)
+		// This test is very close to getAdler()
+		byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3, 'o', 't' };
+		byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
+				'w', 'r', 't', 'u', 'i', 'o', 4, 5, 6, 7 };
+		byte outPutBuf[] = new byte[500];
+
+		int offSet = 4;
+		int length = 5;
+
+		Deflater defl = new Deflater();
+		long deflAdler = defl.getAdler();
+		assertEquals("No dictionary set, no data deflated, getAdler should return 1",
+				1, deflAdler);
+		defl.setDictionary(dictionaryArray, offSet, length);
+		deflAdler = defl.getAdler();
+
+		// getting the checkSum value through the Adler32 class
+		Adler32 adl = new Adler32();
+		adl.update(dictionaryArray, offSet, length);
+		long realAdler = adl.getValue();
+		assertTrue(
+				"Dictionary is set, getAdler() should equal the adler value of the dictionaryArray",
+				deflAdler == realAdler);
+
+		defl.setInput(byteArray);
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		deflAdler = defl.getAdler();
+		adl = new Adler32();
+		adl.update(byteArray);
+		realAdler = adl.getValue();
+		// Deflate is finished and there were bytes deflated that did not occur
+		// in the dictionaryArray, therefore a new dictionary was automatically
+		// set.
+		assertTrue("getAdler() returned " + deflAdler + " should be "
+				+ realAdler, deflAdler == realAdler);
+		defl.end();
+
+		// boundary check
+		defl = new Deflater();
+		for (int i = 0; i < 2; i++) {
+			if (i == 0) {
+				offSet = 0;
+				length = dictionaryArray.length + 1;
+			} else {
+				offSet = dictionaryArray.length + 1;
+				length = 1;
+			}
+			try {
+				defl.setDictionary(dictionaryArray, offSet, length);
+				fail(
+						"Test "
+								+ i
+								+ ": boundary check for setDictionary failed for offset "
+								+ offSet + " and length " + length);
+			} catch (ArrayIndexOutOfBoundsException e) {
+			}
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#setInput(byte[])
+	 */
+	public void test_setInput$B() {
+		// test method of java.util.zip.Deflater.setInput(byte)
+		byte[] byteArray = { 1, 2, 3 };
+		byte[] outPutBuf = new byte[50];
+		byte[] outPutInf = new byte[50];
+
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray);
+		assertTrue("the array buffer in setInput() is empty", !defl
+				.needsInput());
+		// The second setInput() should be ignored since needsInput() return
+		// false
+		defl.setInput(byteArray);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		defl.end();
+
+		Inflater infl = new Inflater();
+		try {
+			infl.setInput(outPutBuf);
+			while (!infl.finished())
+				infl.inflate(outPutInf);
+		} catch (DataFormatException e) {
+			fail("Invalid input to be decompressed");
+		}
+		for (int i = 0; i < byteArray.length; i++)
+			assertTrue(
+					"Final decompressed data does not equal the original data",
+					byteArray[i] == outPutInf[i]);
+		assertTrue(
+				"Inflater.getTotalOut should have been equal to the length of the input",
+				infl.getTotalOut() == byteArray.length);
+		infl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#setInput(byte[], int, int)
+	 */
+	public void test_setInput$BII() {
+		// test methods of java.util.zip.Deflater.setInput(byte,int,int)
+		byte[] byteArray = { 1, 2, 3, 4, 5 };
+		byte[] outPutBuf = new byte[50];
+		byte[] outPutInf = new byte[50];
+		int offSet = 1;
+		int length = 3;
+
+		Deflater defl = new Deflater();
+		defl.setInput(byteArray, offSet, length);
+		assertTrue("the array buffer in setInput() is empty", !defl
+				.needsInput());
+		// The second setInput() should be ignored since needsInput() return
+		// false
+		defl.setInput(byteArray, offSet, length);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		defl.end();
+
+		Inflater infl = new Inflater();
+		try {
+			infl.setInput(outPutBuf);
+			while (!infl.finished())
+				infl.inflate(outPutInf);
+		} catch (DataFormatException e) {
+			fail("Invalid input to be decompressed");
+		}
+		for (int i = 0; i < length; i++)
+			assertTrue(
+					"Final decompressed data does not equal the original data",
+					byteArray[i + offSet] == outPutInf[i]);
+		assertTrue(
+				"Inflater.getTotalOut should have been equal to the length of the input",
+				infl.getTotalOut() == length);
+		infl.end();
+
+		// boundary check
+		defl = new Deflater();
+		for (int i = 0; i < 2; i++) {
+			if (i == 0) {
+				offSet = 0;
+				length = byteArray.length + 1;
+			} else {
+				offSet = byteArray.length + 1;
+				length = 1;
+			}
+			try {
+				defl.setInput(byteArray, offSet, length);
+				fail("Test " + i
+						+ ": boundary check for setInput failed for offset "
+						+ offSet + " and length " + length);
+			} catch (ArrayIndexOutOfBoundsException e) {
+			}
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#setLevel(int)
+	 */
+	public void test_setLevelI() {
+		// test methods of java.util.zip.deflater.setLevel(int)
+		// Very similar to test_Constructor(int)
+		byte[] byteArray = new byte[100];
+		try {
+			InputStream inFile = Support_Resources
+					.getStream("hyts_checkInput.txt");
+			inFile.read(byteArray);
+			inFile.close();
+		} catch (IOException e) {
+			fail("Unexpected IOException " + e + " during test");
+		}
+
+		byte[] outPutBuf;
+		int totalOut;
+		for (int i = 0; i < 10; i++) {
+			Deflater defl = new Deflater();
+			defl.setLevel(i);
+			outPutBuf = new byte[500];
+			defl.setInput(byteArray);
+			while (!defl.needsInput())
+				defl.deflate(outPutBuf);
+			defl.finish();
+			while (!defl.finished())
+				defl.deflate(outPutBuf);
+			totalOut = defl.getTotalOut();
+			defl.end();
+
+			outPutBuf = new byte[500];
+			defl = new Deflater(i);
+			defl.setInput(byteArray);
+			while (!defl.needsInput())
+				defl.deflate(outPutBuf);
+			defl.finish();
+			while (!defl.finished())
+				defl.deflate(outPutBuf);
+			assertTrue(
+					"getTotalOut() not equal comparing two Deflaters with same compression level.",
+					defl.getTotalOut() == totalOut);
+			defl.end();
+		}
+
+		// testing boundaries
+		try {
+			Deflater boundDefl = new Deflater();
+			// Level must be between 0-9
+			boundDefl.setLevel(-2);
+			fail(
+					"IllegalArgumentException not thrown when setting level to a number < 0.");
+		} catch (IllegalArgumentException e) {
+		}
+		try {
+			Deflater boundDefl = new Deflater();
+			boundDefl.setLevel(10);
+			fail(
+					"IllegalArgumentException not thrown when setting level to a number > 9.");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#setStrategy(int)
+	 */
+	public void test_setStrategyI() {
+		// test method of java.util.zip.deflater.setStrategy(int)
+		byte[] byteArray = new byte[100];
+		try {
+			InputStream inFile = Support_Resources
+					.getStream("hyts_checkInput.txt");
+			inFile.read(byteArray);
+			inFile.close();
+		} catch (IOException e) {
+			fail("Unexpected IOException " + e + " during test.");
+		}
+
+		for (int i = 0; i < 3; i++) {
+			byte outPutBuf[] = new byte[500];
+			MyDeflater mdefl = new MyDeflater();
+
+			if (i == 0)
+				mdefl.setStrategy(mdefl.getDefStrategy());
+			else if (i == 1)
+				mdefl.setStrategy(mdefl.getHuffman());
+			else
+				mdefl.setStrategy(mdefl.getFiltered());
+
+			mdefl.setInput(byteArray);
+			while (!mdefl.needsInput())
+				mdefl.deflate(outPutBuf);
+			mdefl.finish();
+			while (!mdefl.finished())
+				mdefl.deflate(outPutBuf);
+
+			if (i == 0) {
+				// System.out.println(mdefl.getTotalOut());
+				// ran JDK and found that getTotalOut() = 86 for this particular
+				// file
+				assertEquals("getTotalOut() for the default strategy did not correspond with JDK",
+						86, mdefl.getTotalOut());
+			} else if (i == 1) {
+				// System.out.println(mdefl.getTotalOut());
+				// ran JDK and found that getTotalOut() = 100 for this
+				// particular file
+				assertEquals("getTotalOut() for the Huffman strategy did not correspond with JDK",
+						100, mdefl.getTotalOut());
+			} else {
+				// System.out.println(mdefl.getTotalOut());
+				// ran JDK and found that totalOut = 93 for this particular file
+				assertEquals("Total Out for the Filtered strategy did not correspond with JDK",
+						93, mdefl.getTotalOut());
+			}
+			mdefl.end();
+		}
+
+		// Attempting to setStrategy to an invalid value
+		try {
+			Deflater defl = new Deflater();
+			defl.setStrategy(-412);
+			fail(
+					"IllegalArgumentException not thrown when setting strategy to an invalid value.");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#Deflater()
+	 */
+	public void test_Constructor() {
+		// test methods of java.util.zip.Deflater()
+		byte[] byteArray = new byte[100];
+		try {
+
+			InputStream inFile = Support_Resources
+					.getStream("hyts_checkInput.txt");
+			inFile.read(byteArray);
+			inFile.close();
+		} catch (IOException e) {
+			fail("Unexpected IOException " + e + " during test");
+		}
+
+		Deflater defl = new Deflater();
+		byte[] outPutBuf = new byte[500];
+		defl.setInput(byteArray);
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		int totalOut = defl.getTotalOut();
+		defl.end();
+
+		// creating a Deflater using the DEFAULT_COMPRESSION as the int
+		MyDeflater mdefl = new MyDeflater();
+		mdefl = new MyDeflater(mdefl.getDefCompression());
+		outPutBuf = new byte[500];
+		mdefl.setInput(byteArray);
+		while (!mdefl.needsInput())
+			mdefl.deflate(outPutBuf);
+		mdefl.finish();
+		while (!mdefl.finished())
+			mdefl.deflate(outPutBuf);
+		assertTrue(
+				"getTotalOut() not equal comparing two Deflaters with same compression level.",
+				mdefl.getTotalOut() == totalOut);
+		mdefl.end();
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#Deflater(int, boolean)
+	 */
+	public void test_ConstructorIZ() {
+		// test methods of java.util.zip.deflater(int,bool)
+		byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
+				'w', 'r' };
+
+		Deflater defl = new Deflater();
+		byte outPutBuf[] = new byte[500];
+		defl.setLevel(2);
+		defl.setInput(byteArray);
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		int totalOut = defl.getTotalOut();
+		defl.end();
+
+		outPutBuf = new byte[500];
+		defl = new Deflater(2, false);
+		defl.setInput(byteArray);
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		assertTrue(
+				"getTotalOut() not equal comparing two Deflaters with same compression level.",
+				defl.getTotalOut() == totalOut);
+		defl.end();
+
+		outPutBuf = new byte[500];
+		defl = new Deflater(2, true);
+		defl.setInput(byteArray);
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		assertTrue(
+				"getTotalOut() should not be equal comparing two Deflaters with different header options.",
+				defl.getTotalOut() != totalOut);
+		defl.end();
+
+		byte outPutInf[] = new byte[500];
+		Inflater infl = new Inflater(true);
+		try {
+			while (!infl.finished()) {
+				if (infl.needsInput())
+					infl.setInput(outPutBuf);
+				infl.inflate(outPutInf);
+			}
+		} catch (DataFormatException e) {
+			fail(
+					"invalid input to inflate - called in test constructorIZ");
+		}
+		for (int i = 0; i < byteArray.length; i++)
+			assertTrue(
+					"Final decompressed data does not equal the original data",
+					byteArray[i] == outPutInf[i]);
+		assertEquals("final decompressed data contained more bytes than original - construcotrIZ",
+				0, outPutInf[byteArray.length]);
+		infl.end();
+
+		infl = new Inflater(false);
+		outPutInf = new byte[500];
+		int r = 0;
+		try {
+			while (!infl.finished()) {
+				if (infl.needsInput())
+					infl.setInput(outPutBuf);
+				infl.inflate(outPutInf);
+			}
+		} catch (DataFormatException e) {
+			r = 1;
+		}
+		assertEquals("header option did not correspond", 1, r);
+
+		// testing boundaries
+		try {
+			Deflater boundDefl = new Deflater();
+			// Level must be between 0-9
+			boundDefl.setLevel(-2);
+			fail(
+					"IllegalArgumentException not thrown when setting level to a number < 0.");
+		} catch (IllegalArgumentException e) {
+		}
+		try {
+			Deflater boundDefl = new Deflater();
+			boundDefl.setLevel(10);
+			fail(
+					"IllegalArgumentException not thrown when setting level to a number > 9.");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.Deflater#Deflater(int)
+	 */
+	public void test_ConstructorI() {
+		// test methods of java.util.zip.Deflater(int)
+		byte[] byteArray = new byte[100];
+		try {
+			InputStream inFile = Support_Resources
+					.getStream("hyts_checkInput.txt");
+			inFile.read(byteArray);
+			inFile.close();
+		} catch (IOException e) {
+			fail("Unexpected IOException " + e + " during test");
+		}
+
+		byte outPutBuf[] = new byte[500];
+		Deflater defl = new Deflater(3);
+		defl.setInput(byteArray);
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		int totalOut = defl.getTotalOut();
+		defl.end();
+
+		// test to see if the compression ratio is the same as setting the level
+		// on a deflater
+		outPutBuf = new byte[500];
+		defl = new Deflater();
+		defl.setLevel(3);
+		defl.setInput(byteArray);
+		while (!defl.needsInput())
+			defl.deflate(outPutBuf);
+		defl.finish();
+		while (!defl.finished())
+			defl.deflate(outPutBuf);
+		assertTrue(
+				"getTotalOut() not equal comparing two Deflaters with same compression level.",
+				defl.getTotalOut() == totalOut);
+		defl.end();
+
+		// testing boundaries
+		try {
+			Deflater boundDefl = new Deflater();
+			// Level must be between 0-9
+			boundDefl.setLevel(-2);
+			fail(
+					"IllegalArgumentException not thrown when setting level to a number < 0.");
+		} catch (IllegalArgumentException e) {
+		}
+		try {
+			Deflater boundDefl = new Deflater();
+			boundDefl.setLevel(10);
+			fail(
+					"IllegalArgumentException not thrown when setting level to a number > 9.");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	private void helper_end_test(Deflater defl, String desc) {
+		// Help tests for test_end() and test_reset().
+		byte byteArray[] = { 5, 2, 3, 7, 8 };
+
+		// Methods where we expect IllegalStateException or NullPointerException
+		// to be thrown
+		try {
+			defl.getTotalOut();
+			fail("defl.getTotalOut() can still be used after " + desc
+					+ " is called in test_" + desc);
+		} catch (IllegalStateException e) {
+		} catch (NullPointerException e) {
+		}
+		try {
+			defl.getTotalIn();
+			fail("defl.getTotalIn() can still be used after " + desc
+					+ " is called in test_" + desc);
+		} catch (IllegalStateException e) {
+		} catch (NullPointerException e) {
+		}
+		try {
+			defl.getAdler();
+			fail("defl.getAdler() can still be used after " + desc
+					+ " is called in test_" + desc);
+		} catch (IllegalStateException e) {
+		} catch (NullPointerException e) {
+		}
+		try {
+			byte[] dict = { 'a', 'b', 'c' };
+			defl.setDictionary(dict);
+			fail("defl.setDictionary() can still be used after " + desc
+					+ " is called in test_" + desc);
+		} catch (IllegalStateException e) {
+		} catch (NullPointerException e) {
+		}
+		try {
+			defl.getTotalIn();
+			fail("defl.getTotalIn() can still be used after " + desc
+					+ " is called in test_" + desc);
+		} catch (IllegalStateException e) {
+		} catch (NullPointerException e) {
+		}
+		try {
+			defl.getTotalIn();
+			fail("defl.getTotalIn() can still be used after " + desc
+					+ " is called in test_" + desc);
+		} catch (IllegalStateException e) {
+		} catch (NullPointerException e) {
+		}
+		try {
+			defl.deflate(byteArray);
+			fail("defl.deflate() can still be used after " + desc
+					+ " is called in test_" + desc);
+		} catch (IllegalStateException e) {
+		} catch (NullPointerException e) {
+		}
+
+		// Methods where we expect NullPointerException to be thrown
+		try {
+			defl.reset();
+			fail("defl.reset() 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
+		try {
+			defl.needsInput();
+		} catch (Exception e) {
+			fail("Test 1: No exception should have been thrown: " + e
+					+ " in test_" + desc);
+		}
+		try {
+			defl.setStrategy(1);
+		} catch (IllegalStateException e) {
+			fail("Test 2: No exception should have been thrown: " + e
+					+ " in test_" + desc);
+		}
+		try {
+			defl.setLevel(1);
+		} catch (IllegalStateException e) {
+			fail("Test 3: No exception should have been thrown: " + e
+					+ " in test_" + desc);
+		}
+		try {
+			defl.end();
+		} catch (Exception e) {
+			fail("Test 4: No exception should have been thrown: " + e
+					+ " in test_" + desc);
+		}
+
+		// Methods where exceptions should be thrown
+		String vendor = System.getProperty("java.vendor");
+		if (vendor.indexOf("IBM") != -1) {
+			try {
+				defl.setInput(byteArray);
+				fail("defl.setInput() can still be used after " + desc
+						+ " is called in test_" + desc);
+			} catch (IllegalStateException e) {
+			}
+		}
+	}
+
+    /**
+     * @tests java.util.zip.Deflater()
+     */
+    public void test_needsDictionary() {
+        Deflater inf = new Deflater();
+        assertEquals(0, inf.getTotalIn());
+        assertEquals(0, inf.getTotalOut());
+        assertEquals(0, inf.getBytesRead());
+        assertEquals(0, inf.getBytesWritten());
+    }
+    
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+
+    /**
+     * @throws DataFormatException
+     * @throws UnsupportedEncodingException
+     * @tests java.util.zip.Deflater#getBytesRead()
+     */
+    public void test_getBytesRead() throws DataFormatException,
+            UnsupportedEncodingException {
+        // Regression test for HARMONY-158
+        Deflater def = new Deflater();
+        assertEquals(0, def.getTotalIn());
+        assertEquals(0, def.getTotalOut());
+        assertEquals(0, def.getBytesRead());
+        // Encode a String into bytes
+        String inputString = "blahblahblah??";
+        byte[] input = inputString.getBytes("UTF-8");
+
+        // Compress the bytes
+        byte[] output = new byte[100];
+        def.setInput(input);
+        def.finish();
+        int compressedDataLength = def.deflate(output);
+        assertEquals(14, def.getTotalIn());
+        assertEquals(compressedDataLength, def.getTotalOut());
+        assertEquals(14, def.getBytesRead());
+    }
+
+    /**
+     * @throws DataFormatException
+     * @throws UnsupportedEncodingException
+     * @tests java.util.zip.Deflater#getBytesRead()
+     */
+    public void test_getBytesWritten() throws DataFormatException,
+            UnsupportedEncodingException {
+        // Regression test for HARMONY-158
+        Deflater def = new Deflater();
+        assertEquals(0, def.getTotalIn());
+        assertEquals(0, def.getTotalOut());
+        assertEquals(0, def.getBytesWritten());
+        // Encode a String into bytes
+        String inputString = "blahblahblah??";
+        byte[] input = inputString.getBytes("UTF-8");
+
+        // Compress the bytes
+        byte[] output = new byte[100];
+        def.setInput(input);
+        def.finish();
+        int compressedDataLength = def.deflate(output);
+        assertEquals(14, def.getTotalIn());
+        assertEquals(compressedDataLength, def.getTotalOut());
+        assertEquals(compressedDataLength, def.getBytesWritten());
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java?rev=397192&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java Wed Apr 26 06:04:19 2006
@@ -0,0 +1,239 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.archive.tests.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.zip.Checksum;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import tests.support.resource.Support_Resources;
+
+public class GZIPInputStreamTest extends junit.framework.TestCase {
+	File resources;
+
+	class TestGZIPInputStream extends GZIPInputStream {
+		TestGZIPInputStream(InputStream in) throws IOException {
+			super(in);
+		}
+
+		TestGZIPInputStream(InputStream in, int size) throws IOException {
+			super(in, size);
+		}
+
+		Checksum getChecksum() {
+			return crc;
+		}
+
+		boolean endofInput() {
+			return eos;
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPInputStream#GZIPInputStream(java.io.InputStream)
+	 */
+	public void test_ConstructorLjava_io_InputStream() {
+		// test method java.util.zip.GZIPInputStream.constructor
+		try {
+			Support_Resources.copyFile(resources, "GZIPInputStream",
+					"hyts_gInput.txt");
+			final URL gInput = new File(resources.toString()
+					+ "/GZIPInputStream/hyts_gInput.txt").toURL();
+			TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
+					.openConnection().getInputStream());
+			assertNotNull("the constructor for GZIPInputStream is null",
+					inGZIP);
+			assertEquals("the CRC value of the inputStream is not zero", 0, inGZIP
+					.getChecksum().getValue());
+			inGZIP.close();
+		} catch (IOException e) {
+			fail(
+					"an IO error occured while trying to open the input file");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPInputStream#GZIPInputStream(java.io.InputStream,
+	 *        int)
+	 */
+	public void test_ConstructorLjava_io_InputStreamI() {
+		// test method java.util.zip.GZIPInputStream.constructorI
+		try {
+			Support_Resources.copyFile(resources, "GZIPInputStream",
+					"hyts_gInput.txt");
+			final URL gInput = new File(resources.toString()
+					+ "/GZIPInputStream/hyts_gInput.txt").toURL();
+			TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
+					.openConnection().getInputStream(), 200);
+			assertNotNull("the constructor for GZIPInputStream is null",
+					inGZIP);
+			assertEquals("the CRC value of the inputStream is not zero", 0, inGZIP
+					.getChecksum().getValue());
+			inGZIP.close();
+		} catch (IOException e) {
+			fail(
+					"an IO error occured while trying to open the input file");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPInputStream#read(byte[], int, int)
+	 */
+	public void test_read$BII() {
+		// test method java.util.zip.GZIPInputStream.readBII
+		byte orgBuf[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
+		byte outBuf[] = new byte[100];
+		try {
+			int result = 0;
+			Support_Resources.copyFile(resources, "GZIPInputStream",
+					"hyts_gInput.txt");
+			String resPath = resources.toString();
+			if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\')
+				resPath = resPath.substring(1);
+			final URL gInput = new URL("file:/" + resPath
+					+ "/GZIPInputStream/hyts_gInput.txt");
+			TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
+					.openConnection().getInputStream());
+			while (!(inGZIP.endofInput())) {
+				result += inGZIP.read(outBuf, result, outBuf.length - result);
+			}
+			assertEquals("the checkSum value of the compressed and decompressed data does not equal",
+					3097700292L, inGZIP.getChecksum().getValue());
+			for (int i = 0; i < orgBuf.length; i++) {
+				assertTrue(
+						"the decompressed data does not equal the orginal data decompressed",
+						orgBuf[i] == outBuf[i]);
+				// System.out.println(orgBuf[i] + " " + outBuf[i]);
+			}
+			int r = 0;
+			try {
+				inGZIP.read(outBuf, 100, 1);
+			} catch (ArrayIndexOutOfBoundsException e) {
+				r = 1;
+			}
+			inGZIP.close();
+			assertEquals("Boundary Check was not present", 1, r);
+		} catch (IOException e) {
+			e.printStackTrace();
+			fail("unexpected: " + e);
+		}
+
+		try {
+			// Create compressed data which is exactly 512 bytes (after the
+			// header),
+			// the size of the InflaterStream internal buffer
+			byte[] test = new byte[507];
+			for (int i = 0; i < 256; i++)
+				test[i] = (byte) i;
+			for (int i = 256; i < test.length; i++)
+				test[i] = (byte) (256 - i);
+			ByteArrayOutputStream bout = new ByteArrayOutputStream();
+			GZIPOutputStream out = new GZIPOutputStream(bout);
+			out.write(test);
+			out.close();
+			byte[] comp = bout.toByteArray();
+			GZIPInputStream gin2 = new GZIPInputStream(
+					new ByteArrayInputStream(comp), 512);
+			int result, total = 0;
+			while ((result = gin2.read(test)) != -1)
+				total += result;
+			assertEquals("Should return -1", -1, gin2.read());
+			gin2.close();
+			assertTrue("Incorrectly decompressed", total == test.length);
+
+			gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
+			total = 0;
+			while ((result = gin2.read(new byte[200])) != -1) {
+				total += result;
+			}
+			assertEquals("Should return -1", -1, gin2.read());
+			gin2.close();
+			assertTrue("Incorrectly decompressed", total == test.length);
+
+			gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 516);
+			total = 0;
+			while ((result = gin2.read(new byte[200])) != -1) {
+				total += result;
+			}
+			assertEquals("Should return -1", -1, gin2.read());
+			gin2.close();
+			assertTrue("Incorrectly decompressed", total == test.length);
+
+			comp[40] = 0;
+			gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
+			boolean exception = false;
+			try {
+				while (gin2.read(test) != -1)
+					;
+			} catch (IOException e) {
+				exception = true;
+			}
+			assertTrue("Exception expected", exception);
+		} catch (IOException e) {
+			fail("Unexpected: " + e);
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPInputStream#close()
+	 */
+	public void test_close() {
+		// test method java.util.zip.GZIPInputStream.close
+		byte outBuf[] = new byte[100];
+		try {
+			int result = 0;
+			Support_Resources.copyFile(resources, "GZIPInputStream",
+					"hyts_gInput.txt");
+			String resPath = resources.toString();
+			if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\')
+				resPath = resPath.substring(1);
+			final URL gInput = new URL("file:/" + resPath
+					+ "/GZIPInputStream/hyts_gInput.txt");
+			TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
+					.openConnection().getInputStream());
+			while (!(inGZIP.endofInput())) {
+				result += inGZIP.read(outBuf, result, outBuf.length - result);
+			}
+			assertEquals("the checkSum value of the compressed and decompressed data does not equal",
+					3097700292L, inGZIP.getChecksum().getValue());
+			inGZIP.close();
+			int r = 0;
+			try {
+				inGZIP.read(outBuf, 0, 1);
+			} catch (IOException e) {
+				r = 1;
+			}
+			assertEquals("GZIPInputStream can still be used after close is called",
+					1, r);
+		} catch (IOException e) {
+			e.printStackTrace();
+			fail("unexpected: " + e);
+		}
+	}
+
+	protected void setUp() {
+		resources = Support_Resources.createTempFolder();
+	}
+
+	protected void tearDown() {
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java?rev=397192&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java Wed Apr 26 06:04:19 2006
@@ -0,0 +1,177 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.archive.tests.java.util.zip;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.Checksum;
+import java.util.zip.GZIPOutputStream;
+
+public class GZIPOutputStreamTest extends junit.framework.TestCase {
+
+	class TestGZIPOutputStream extends GZIPOutputStream {
+		TestGZIPOutputStream(OutputStream out) throws IOException {
+			super(out);
+		}
+
+		TestGZIPOutputStream(OutputStream out, int size) throws IOException {
+			super(out, size);
+		}
+
+		Checksum getChecksum() {
+			return crc;
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPOutputStream#GZIPOutputStream(java.io.OutputStream)
+	 */
+	public void test_ConstructorLjava_io_OutputStream() {
+		try {
+			FileOutputStream outFile = new FileOutputStream("GZIPOutCon.txt");
+			TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
+			assertNotNull("the constructor for GZIPOutputStream is null",
+					outGZIP);
+			assertEquals("the CRC value of the outputStream is not zero", 0, outGZIP
+					.getChecksum().getValue());
+			outGZIP.close();
+		} catch (IOException e) {
+			fail(
+					"an IO error occured while trying to find the output file or creating GZIP constructor");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPOutputStream#GZIPOutputStream(java.io.OutputStream,
+	 *        int)
+	 */
+	public void test_ConstructorLjava_io_OutputStreamI() {
+		try {
+			FileOutputStream outFile = new FileOutputStream("GZIPOutCon.txt");
+			TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile,
+					100);
+			assertNotNull("the constructor for GZIPOutputStream is null",
+					outGZIP);
+			assertEquals("the CRC value of the outputStream is not zero", 0, outGZIP
+					.getChecksum().getValue());
+			outGZIP.close();
+		} catch (IOException e) {
+			fail(
+					"an IO error occured while trying to find the output file or creating GZIP constructor");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPOutputStream#finish()
+	 */
+	public void test_finish() {
+		// test method java.util.zip.GZIPOutputStream.finish()
+		byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
+		try {
+			FileOutputStream outFile = new FileOutputStream("GZIPOutFinish.txt");
+			TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
+
+			outGZIP.finish();
+			int r = 0;
+			try {
+				outGZIP.write(byteArray, 0, 1);
+			} catch (IOException e) {
+				r = 1;
+			}
+
+			assertEquals("GZIP instance can still be used after finish is called",
+					1, r);
+			outGZIP.close();
+		} catch (IOException e) {
+			fail(
+					"an IO error occured while trying to find the output file or creating GZIP constructor");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPOutputStream#close()
+	 */
+	public void test_close() {
+		// test method java.util.zip.GZIPOutputStream.close()
+		byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
+		try {
+			FileOutputStream outFile = new FileOutputStream("GZIPOutClose2.txt");
+			TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
+			outGZIP.close();
+			int r = 0;
+			try {
+				outGZIP.write(byteArray, 0, 1);
+			} catch (IOException e) {
+				r = 1;
+			}
+			assertEquals("GZIP instance can still be used after close is called",
+					1, r);
+		} catch (IOException e) {
+			fail(
+					"an IO error occured while trying to find the output file or creating GZIP constructor");
+		}
+	}
+
+	/**
+	 * @tests java.util.zip.GZIPOutputStream#write(byte[], int, int)
+	 */
+	public void test_write$BII() {
+		// test method java.util.zip.GZIPOutputStream.writeBII
+		byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
+		try {
+			FileOutputStream outFile = new FileOutputStream("GZIPOutWrite.txt");
+			TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
+			outGZIP.write(byteArray, 0, 10);
+			// ran JDK and found this CRC32 value is 3097700292
+			// System.out.print(outGZIP.getChecksum().getValue());
+			assertEquals("the checksum value was incorrect result of write from GZIP",
+					3097700292L, outGZIP.getChecksum().getValue());
+
+			// test for boundary check
+			int r = 0;
+			try {
+				outGZIP.write(byteArray, 0, 11);
+			} catch (ArrayIndexOutOfBoundsException e) {
+				r = 1;
+			}
+			assertEquals("out of bounds exception is not present", 1, r);
+			outGZIP.close();
+		} catch (IOException e) {
+			fail(
+					"an IO error occured while trying to find the output file or creating GZIP constructor");
+		}
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+
+		try {
+			File dFile = new File("GZIPOutCon.txt");
+			dFile.delete();
+			/*
+			 * File dFile2 = new File("GZIPOutFinish.txt"); dFile2.delete();
+			 * File dFile3 = new File("GZIPOutClose.txt"); dFile3.delete(); File
+			 * dFile4 = new File("GZIPOutWrite.txt"); dFile4.delete();
+			 */
+		} catch (SecurityException e) {
+			fail("Cannot delete file for security reasons");		
+		}
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message