harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386058 [2/49] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/archive/make/common/ modules/archive/src/test/java/tests/ modules/archive/src/test/java/tests/api/ modules/archive/src/test/java/tests/api/java/ modules/archive/s...
Date Wed, 15 Mar 2006 11:47:39 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarFileTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarFileTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarFileTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarFileTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,405 @@
+/* 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 tests.api.java.util.jar;
+
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.cert.Certificate;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import tests.support.Support_PlatformFile;
+import tests.support.resource.Support_Resources;
+
+public class JarFileTest extends junit.framework.TestCase {
+
+	java.util.zip.ZipEntry zipEntry;
+
+	java.util.jar.JarEntry jarEntry;
+
+	java.util.jar.JarFile jarFile;
+
+	final String jarName = "hyts_patch.jar"; // a 'normal' jar file
+
+	// same as patch.jar but without a manifest file
+	final String jarName2 = "hyts_patch2.jar"; 
+
+	final String jarName3 = "hyts_manifest1.jar";
+
+	final String jarName4 = "hyts_signed.jar";
+
+	final String entryName = "foo/bar/A.class";
+
+	final String entryName2 = "Blah.txt";
+
+	final String entryName3 = "coucou/FileAccess.class";
+
+	File resources;
+
+	/**
+	 * @tests java.util.jar.JarFile#JarFile(java.io.File)
+	 */
+	public void test_ConstructorLjava_io_File() {
+		// Test for method java.util.jar.JarFile(java.io.File)
+		/*
+		 * try { assertTrue("Error in created file", new JarFile(new
+		 * java.io.File(jarName)).getEntry(entryName).getName().equals(entryName)); }
+		 * catch (Exception e) { fail("Exception during test: " +
+		 * e.toString()); }
+		 */
+	}
+
+	/**
+	 * @tests java.util.jar.JarFile#JarFile(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.util.jar.JarFile(java.lang.String)
+		/*
+		 * try { assertTrue("Error in created file", new
+		 * JarFile(jarName).getEntry(entryName).getName().equals(entryName)); }
+		 * catch (Exception e) { fail("Exception during test: " +
+		 * e.toString()); }
+		 */
+	}
+
+	/**
+	 * @tests java.util.jar.JarFile#entries()
+	 */
+	public void test_entries() {
+		// Test for method java.util.Enumeration java.util.jar.JarFile.entries()
+
+		/*
+		 * Note only (and all of) the following should be contained in the file
+		 * META-INF/ META-INF/MANIFEST.MF foo/ foo/bar/ foo/bar/A.class Blah.txt
+		 */
+
+		try {
+			Support_Resources.copyFile(resources, null, jarName);
+			JarFile jarFile = new JarFile(new File(resources, jarName));
+			Enumeration e = jarFile.entries();
+			int i = 0;
+			while (e.hasMoreElements()) {
+				i++;
+				e.nextElement();
+			}
+			jarFile.close();
+			assertTrue("Wrong number of elements--wanted 6, got: " + i, i == 6);
+		} catch (Exception e) {
+			fail("Exception during test: " + e.toString());
+		}
+
+		System.out.println("start");
+		System.out.flush();
+
+		try {
+			Support_Resources.copyFile(resources, null, jarName);
+			JarFile jarFile = new JarFile(new File(resources, jarName));
+			Enumeration enumeration = jarFile.entries();
+			jarFile.close();
+			boolean pass = false;
+			try {
+				enumeration.hasMoreElements();
+			} catch (IllegalStateException e) {
+				pass = true;
+			}
+			assertTrue("hasMoreElements did not detect closed jar file", pass);
+			Support_Resources.copyFile(resources, null, jarName);
+			jarFile = new JarFile(new File(resources, jarName));
+			enumeration = jarFile.entries();
+			jarFile.close();
+			pass = false;
+			try {
+				enumeration.nextElement();
+			} catch (IllegalStateException e) {
+				pass = true;
+			}
+			assertTrue("nextElement did not detect closed jar file", pass);
+		} catch (Exception e) {
+			fail("Exception during entries test: " + e.toString());
+		}
+		System.out.println("finish");
+		System.out.flush();
+
+	}
+
+	/**
+	 * @tests java.util.jar.JarFile#getJarEntry(java.lang.String)
+	 */
+	public void test_getJarEntryLjava_lang_String() {
+		// Test for method java.util.jar.JarEntry
+		// java.util.jar.JarFile.getJarEntry(java.lang.String)
+		try {
+			Support_Resources.copyFile(resources, null, jarName);
+			JarFile jarFile = new JarFile(new File(resources, jarName));
+			assertTrue("Error in returned entry", jarFile.getEntry(entryName)
+					.getSize() == 311);
+			jarFile.close();
+		} catch (Exception e) {
+			fail("Exception during test: " + e.toString());
+		}
+
+		// tests for signed jars
+		// test all signed jars in the /Testres/Internal/SignedJars directory
+		String jarDirUrl = Support_Resources
+				.getResourceURL("/../internalres/signedjars");
+		Vector signedJars = new Vector();
+		try {
+			InputStream is = new URL(jarDirUrl + "/jarlist.txt").openStream();
+			while (is.available() > 0) {
+				StringBuffer linebuff = new StringBuffer(80); // Typical line
+				// length
+				done: while (true) {
+					int nextByte = is.read();
+					switch (nextByte) {
+					case -1:
+						break done;
+					case (byte) '\r':
+						if (linebuff.length() == 0) {
+							// ignore
+						}
+						break done;
+					case (byte) '\n':
+						if (linebuff.length() == 0) {
+							// ignore
+						}
+						break done;
+					default:
+						linebuff.append((char) nextByte);
+					}
+				}
+				if (linebuff.length() == 0) {
+					break;
+				}
+				String line = linebuff.toString();
+				signedJars.add(line);
+			}
+			is.close();
+		} catch (IOException e) {
+			// no list of jars found
+		}
+
+		for (int i = 0; i < signedJars.size(); i++) {
+			String jarName = (String) signedJars.get(i);
+			try {
+				File file = Support_Resources.getExternalLocalFile(jarDirUrl
+						+ "/" + jarName);
+				JarFile jarFile = new JarFile(file, true);
+				boolean foundCerts = false;
+				Enumeration e = jarFile.entries();
+				while (e.hasMoreElements()) {
+					JarEntry entry = (JarEntry) e.nextElement();
+					InputStream is = jarFile.getInputStream(entry);
+					is.skip(100000);
+					is.close();
+					Certificate[] certs = entry.getCertificates();
+					if (certs != null && certs.length > 0) {
+						foundCerts = true;
+						break;
+					}
+				}
+				assertTrue(
+						"No certificates found during signed jar test for jar \""
+								+ jarName + "\"", foundCerts);
+			} catch (IOException e) {
+				fail("Exception during signed jar test for jar \""
+						+ jarName + "\": " + e.toString());
+			}
+		}
+	}
+
+	/**
+	 * @tests java.util.jar.JarFile#getManifest()
+	 */
+	public void test_getManifest() {
+		// Test for method java.util.jar.Manifest
+		// java.util.jar.JarFile.getManifest()
+		try {
+			Support_Resources.copyFile(resources, null, jarName);
+			JarFile jarFile = new JarFile(new File(resources, jarName));
+			assertTrue("Error--Manifest not returned",
+					jarFile.getManifest() != null);
+			jarFile.close();
+		} catch (Exception e) {
+			fail("Exception during 1st test: " + e.toString());
+		}
+		try {
+			Support_Resources.copyFile(resources, null, jarName2);
+			JarFile jarFile = new JarFile(new File(resources, jarName2));
+			assertTrue("Error--should have returned null", jarFile
+					.getManifest() == null);
+			jarFile.close();
+		} catch (Exception e) {
+			fail("Exception during 2nd test: " + e.toString());
+		}
+
+		try {
+			// jarName3 was created using the following test
+			Support_Resources.copyFile(resources, null, jarName3);
+			JarFile jarFile = new JarFile(new File(resources, jarName3));
+			assertTrue("Should find manifest without verifying", jarFile
+					.getManifest() != null);
+			jarFile.close();
+		} catch (Exception e) {
+			fail("Exception during 3rd test: " + e.toString());
+		}
+
+		try {
+			// this is used to create jarName3 used in the previous test
+			Manifest manifest = new Manifest();
+			Attributes attributes = manifest.getMainAttributes();
+			attributes.put(new Attributes.Name("Manifest-Version"), "1.0");
+			ByteArrayOutputStream manOut = new ByteArrayOutputStream();
+			manifest.write(manOut);
+			byte[] manBytes = manOut.toByteArray();
+			File file = new File(Support_PlatformFile.getNewPlatformFile(
+					"hyts_manifest1", ".jar"));
+			JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(
+					file.getAbsolutePath()));
+			ZipEntry entry = new ZipEntry("META-INF/");
+			entry.setSize(0);
+			jarOut.putNextEntry(entry);
+			entry = new ZipEntry(JarFile.MANIFEST_NAME);
+			entry.setSize(manBytes.length);
+			jarOut.putNextEntry(entry);
+			jarOut.write(manBytes);
+			entry = new ZipEntry("myfile");
+			entry.setSize(1);
+			jarOut.putNextEntry(entry);
+			jarOut.write(65);
+			jarOut.close();
+			JarFile jar = new JarFile(file.getAbsolutePath(), false);
+			assertTrue("Should find manifest without verifying", jar
+					.getManifest() != null);
+			jar.close();
+			file.delete();
+		} catch (IOException e) {
+			fail("IOException 3");
+		}
+	}
+
+	/**
+	 * @tests java.util.jar.JarFile#getInputStream(java.util.zip.ZipEntry)
+	 */
+	public void test_getInputStreamLjava_util_jar_JarEntry() {
+		File localFile = null;
+		try {
+			Support_Resources.copyFile(resources, null, jarName);
+			localFile = new File(resources, jarName);
+		} catch (Exception e) {
+			fail("Failed to create local file: " + e);
+		}
+
+		byte[] b = new byte[1024];
+		try {
+			JarFile jf = new JarFile(localFile);
+			java.io.InputStream is = jf.getInputStream(jf.getEntry(entryName));
+			jf.close();
+			assertTrue("Returned invalid stream", is.available() > 0);
+			int r = is.read(b, 0, 1024);
+			is.close();
+			StringBuffer sb = new StringBuffer(r);
+			for (int i = 0; i < r; i++) {
+				sb.append((char) (b[i] & 0xff));
+			}
+			String contents = sb.toString();
+			assertTrue("Incorrect stream read", contents.indexOf("bar") > 0);
+		} catch (Exception e) {
+			fail("Exception during test: " + e.toString());
+		}
+
+		try {
+			JarFile jf = new JarFile(localFile);
+			InputStream in = jf.getInputStream(new JarEntry("invalid"));
+			assertTrue("Got stream for non-existent entry", in == null);
+		} catch (Exception e) {
+			fail("Exception during test 2: " + e);
+		}
+	}
+
+	/**
+	 * @tests java.util.jar.JarFile#getInputStream(java.util.zip.ZipEntry)
+	 */
+	public void test_getInputStreamLjava_util_jar_JarEntry_subtest0() {
+		File signedFile = null;
+		try {
+			Support_Resources.copyFile(resources, null, jarName4);
+			signedFile = new File(resources, jarName4);
+		} catch (Exception e) {
+			fail("Failed to create local file 2: " + e);
+		}
+
+		try {
+			JarFile jar = new JarFile(signedFile);
+			JarEntry entry = new JarEntry(entryName3);
+			InputStream in = jar.getInputStream(entry);
+			in.read();
+		} catch (Exception e) {
+			fail("Exception during test 3: " + e);
+		}
+
+		try {
+			JarFile jar = new JarFile(signedFile);
+			JarEntry entry = new JarEntry(entryName3);
+			InputStream in = jar.getInputStream(entry);
+			in.read(new byte[1077]);
+			assertTrue("found certificates", entry.getCertificates() == null);
+		} catch (Exception e) {
+			fail("Exception during test 4: " + e);
+		}
+
+		boolean exception = false;
+		try {
+			JarFile jar = new JarFile(signedFile);
+			JarEntry entry = new JarEntry(entryName3);
+			entry.setSize(1076);
+			InputStream in = jar.getInputStream(entry);
+			in.read(new byte[2048]);
+		} catch (SecurityException e) {
+			exception = true;
+		} catch (Exception e) {
+			fail("Exception during test 5: " + e);
+		}
+		assertTrue("Failed to throw SecurityException", exception);
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		resources = Support_Resources.createTempFolder();
+
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarInputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,133 @@
+/* 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 tests.api.java.util.jar;
+
+
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import tests.support.resource.Support_Resources;
+
+public class JarInputStreamTest extends junit.framework.TestCase {
+	// a 'normal' jar file
+	String jarName;
+
+	// same as patch.jar but without a manifest file
+	String jarName2;
+
+	final String entryName = "foo/bar/A.class";
+
+	final String entryName2 = "Blah.txt";
+
+	/**
+	 * @tests java.util.jar.JarInputStream#JarInputStream(java.io.InputStream)
+	 */
+	public void test_ConstructorLjava_io_InputStream() {
+		// Test for method java.util.jar.JarInputStream(java.io.InputStream)
+		try {
+			java.io.InputStream is = new URL(jarName).openConnection()
+					.getInputStream();
+			boolean hasCorrectEntry = false;
+			JarInputStream jis = new JarInputStream(is);
+			assertTrue("The jar input stream should have a manifest", jis
+					.getManifest() != null);
+			JarEntry je = jis.getNextJarEntry();
+			while (je != null) {
+				if (je.getName().equals(entryName))
+					hasCorrectEntry = true;
+				je = jis.getNextJarEntry();
+			}
+			assertTrue(
+					"The jar input stream does not contain the correct entries",
+					hasCorrectEntry);
+		} catch (Exception e) {
+			fail("Exception during test: " + e.toString());
+		}
+
+	}
+
+	/**
+	 * @tests java.util.jar.JarInputStream#getManifest()
+	 */
+	public void test_getManifest() {
+		// Test for method java.util.jar.Manifest
+		// java.util.jar.JarInputStream.getManifest()
+		try {
+			Manifest m;
+
+			java.io.InputStream is = new URL(jarName2).openConnection()
+					.getInputStream();
+			JarInputStream jis = new JarInputStream(is);
+			m = jis.getManifest();
+			assertTrue("The jar input stream should not have a manifest",
+					m == null);
+
+			is = new URL(jarName).openConnection().getInputStream();
+			jis = new JarInputStream(is);
+			m = jis.getManifest();
+			assertTrue("The jar input stream should have a manifest", m != null);
+		} catch (Exception e) {
+			fail("Exception during test: " + e.toString());
+		}
+
+	}
+
+	/**
+	 * @tests java.util.jar.JarInputStream#getNextJarEntry()
+	 */
+	public void test_getNextJarEntry() {
+		// Test for method java.util.jar.JarEntry
+		// java.util.jar.JarInputStream.getNextJarEntry()
+		final Set desired = new HashSet(Arrays.asList(new String[] { "foo/",
+				"foo/bar/", "foo/bar/A.class", "Blah.txt" }));
+		Set actual = new HashSet();
+		try {
+			java.io.InputStream is = new URL(jarName).openConnection()
+					.getInputStream();
+			JarInputStream jis = new JarInputStream(is);
+			JarEntry je = jis.getNextJarEntry();
+			while (je != null) {
+				actual.add(je.toString());
+				je = jis.getNextJarEntry();
+			}
+		} catch (Exception e) {
+			fail("Exception during test: " + e.toString());
+		}
+		assertTrue("Set of entries is not correct", actual.equals(desired));
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		jarName = Support_Resources.getURL("morestuff/hyts_patch.jar");
+		jarName2 = Support_Resources.getURL("morestuff/hyts_patch2.jar");
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarOutputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/JarOutputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,115 @@
+/* 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 tests.api.java.util.jar;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import tests.support.Support_Exec;
+import tests.support.resource.Support_Resources;
+
+public class JarOutputStreamTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.jar.JarOutputStream#putNextEntry(java.util.zip.ZipEntry)
+	 */
+	public void test_putNextEntryLjava_util_zip_ZipEntry() {
+		// testClass file`s actual extension is .class, since having .class
+		// extension files in source dir causes
+		// problems on eclipse, the extension is changed into .ser or it can be
+		// anything. The file is being
+		// read by inputstream and being written to other file,
+		// as long as the content of the file is not changed, the extension does
+		// not matter
+		final String testClass = "hyts_mainClass.ser";
+		final String entryName = "foo/bar/execjartest/MainClass.class";
+
+		// test whether specifying the main class in the manifest
+		// works using either /'s or .'s as a separator
+		final String[] manifestMain = { "foo.bar.execjartest.MainClass",
+				"foo/bar/execjartest/MainClass" };
+
+		for (int i = 0; i < manifestMain.length; i++) {
+
+			// create the manifest
+			Manifest newman = new Manifest();
+			Attributes att = newman.getMainAttributes();
+			att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+			att.put(Attributes.Name.MAIN_CLASS, manifestMain[i]);
+
+			File outputJar = null;
+			JarOutputStream jout = null;
+
+			try {
+				// open the output jarfile
+				outputJar = File.createTempFile("hyts_", ".jar");
+				jout = new JarOutputStream(new FileOutputStream(outputJar),
+						newman);
+				jout.putNextEntry(new JarEntry(entryName));
+			} catch (Exception e) {
+				fail("Error creating JarOutputStream: " + e);
+			}
+			File resources = Support_Resources.createTempFolder();
+			try {
+				// read in the class file, and output it to the jar
+				Support_Resources.copyFile(resources, null, testClass);
+				URL jarURL = new URL((new File(resources, testClass)).toURL()
+						.toString());
+				InputStream jis = jarURL.openStream();
+
+				byte[] bytes = new byte[1024];
+				int len;
+				while ((len = jis.read(bytes)) != -1)
+					jout.write(bytes, 0, len);
+
+				jout.flush();
+				jout.close();
+				jis.close();
+			} catch (Exception e) {
+				fail("Error writing JAR file for testing: " + e);
+			}
+			String res = null;
+			// set up the VM parameters
+			String[] args = new String[2];
+			args[0] = "-jar";
+			args[1] = outputJar.getAbsolutePath();
+
+			try {
+				// execute the JAR and read the result
+				res = Support_Exec.execJava(args, null, true);
+			} catch (Exception e) {
+				fail("Exception executing test JAR: " + e);
+			}
+
+			assertTrue("Error executing JAR test on: " + manifestMain[i]
+					+ ". Result returned was incorrect.", res
+					.startsWith("TEST"));
+			outputJar.delete();
+		}
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/ManifestTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/ManifestTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/ManifestTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/jar/ManifestTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,189 @@
+/* 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 tests.api.java.util.jar;
+
+
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import tests.support.resource.Support_Resources;
+
+public class ManifestTest extends junit.framework.TestCase {
+
+	final String jarName = "hyts_patch.jar";
+
+	final String attJarName = "hyts_att.jar";
+
+	Manifest m, m2;
+
+	File resources;
+
+	/**
+	 * @tests java.util.jar.Manifest#Manifest()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.jar.Manifest()
+		Manifest emptyManifest = new Manifest();
+		assertTrue("Should have no entries", emptyManifest.getEntries()
+				.isEmpty());
+		assertTrue("Should have no main attributes", emptyManifest
+				.getMainAttributes().isEmpty());
+	}
+
+	/**
+	 * @tests java.util.jar.Manifest#Manifest(java.io.InputStream)
+	 */
+	public void test_ConstructorLjava_io_InputStream() {
+		// Test for method java.util.jar.Manifest(java.io.InputStream)
+		/*
+		 * ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		 * m2.write(baos); InputSteam is = new ByteArrayInputStream
+		 * (baos.toByteArray()); Manifest myManifest = new Manifest (is);
+		 * assertTrue("Manifests should be equal", myManifest.equals(m2));
+		 */
+
+		Manifest manifest = null;
+		try {
+			manifest = new Manifest(new URL(Support_Resources
+					.getURL("manifest/hyts_MANIFEST.MF")).openStream());
+		} catch (MalformedURLException e) {
+			fail("Malformed URL");
+		} catch (IOException e) {
+			fail("IOException");
+		}
+		Attributes main = manifest.getMainAttributes();
+		assertTrue("Bundle-Name not correct", main.getValue("Bundle-Name")
+				.equals("ClientSupport"));
+		assertTrue(
+				"Bundle-Description not correct",
+				main
+						.getValue("Bundle-Description")
+						.equals(
+								"Provides SessionService, AuthenticationService. Extends RegistryService."));
+		assertTrue("Bundle-Activator not correct", main.getValue(
+				"Bundle-Activator").equals(
+				"com.ibm.ive.eccomm.client.support.ClientSupportActivator"));
+		assertTrue(
+				"Import-Package not correct",
+				main
+						.getValue("Import-Package")
+						.equals(
+								"com.ibm.ive.eccomm.client.services.log,com.ibm.ive.eccomm.client.services.registry,com.ibm.ive.eccomm.service.registry; specification-version=1.0.0,com.ibm.ive.eccomm.service.session; specification-version=1.0.0,com.ibm.ive.eccomm.service.framework; specification-version=1.2.0,org.osgi.framework; specification-version=1.0.0,org.osgi.service.log; specification-version=1.0.0,com.ibm.ive.eccomm.flash; specification-version=1.2.0,com.ibm.ive.eccomm.client.xml,com.ibm.ive.eccomm.client.http.common,com.ibm.ive.eccomm.client.http.client"));
+		assertTrue(
+				"Import-Service not correct",
+				main
+						.getValue("Import-Service")
+						.equals(
+								"org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService"));
+		assertTrue(
+				"Export-Package not correct",
+				main
+						.getValue("Export-Package")
+						.equals(
+								"com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.common; specification-version=1.0.0,com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0"));
+		assertTrue(
+				"Export-Service not correct",
+				main
+						.getValue("Export-Service")
+						.equals(
+								"com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService"));
+		assertTrue("Bundle-Vendor not correct", main.getValue("Bundle-Vendor")
+				.equals("IBM"));
+		assertTrue("Bundle-Version not correct", main
+				.getValue("Bundle-Version").equals("1.2.0"));
+	}
+
+	/**
+	 * @tests java.util.jar.Manifest#clear()
+	 */
+	public void test_clear() {
+		// Test for method void java.util.jar.Manifest.clear()
+		m2.clear();
+		assertTrue("Should have no entries", m2.getEntries().isEmpty());
+		assertTrue("Should have no main attributes", m2.getMainAttributes()
+				.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.jar.Manifest#getAttributes(java.lang.String)
+	 */
+	public void test_getAttributesLjava_lang_String() {
+		// Test for method java.util.jar.Attributes
+		// java.util.jar.Manifest.getAttributes(java.lang.String)
+		assertTrue("Should not exist",
+				m2.getAttributes("Doesn't Exist") == null);
+		assertTrue("Should exist", m2.getAttributes("HasAttributes.txt").get(
+				new Attributes.Name("MyAttribute")).equals("OK"));
+	}
+
+	/**
+	 * @tests java.util.jar.Manifest#getEntries()
+	 */
+	public void test_getEntries() {
+		// Test for method java.util.Map java.util.jar.Manifest.getEntries()
+		Map myMap = m2.getEntries();
+		assertTrue("Shouldn't exist", myMap.get("Doesn't exist") == null);
+		assertTrue("Should exist",
+				((Attributes) myMap.get("HasAttributes.txt")).get(
+						new Attributes.Name("MyAttribute")).equals("OK"));
+
+	}
+
+	/**
+	 * @tests java.util.jar.Manifest#getMainAttributes()
+	 */
+	public void test_getMainAttributes() {
+		// Test for method java.util.jar.Attributes
+		// java.util.jar.Manifest.getMainAttributes()
+		Attributes a = m.getMainAttributes();
+		assertTrue("Manifest_Version should return 1.0", a.get(
+				Attributes.Name.MANIFEST_VERSION).equals("1.0"));
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		resources = Support_Resources.createTempFolder();
+		try {
+			Support_Resources.copyFile(resources, null, jarName);
+			JarFile jarFile = new JarFile(new File(resources, jarName));
+			m = jarFile.getManifest();
+			jarFile.close();
+			Support_Resources.copyFile(resources, null, attJarName);
+			jarFile = new JarFile(new File(resources, attJarName));
+			m2 = jarFile.getManifest();
+			jarFile.close();
+		} catch (Exception e) {
+			fail("Exception during setup: " + e.toString());
+		}
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/Adler32Test.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/Adler32Test.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/Adler32Test.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/Adler32Test.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,178 @@
+/* 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 tests.api.java.util.zip;
+
+
+
+import java.util.zip.Adler32;
+
+public class Adler32Test extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.zip.Adler32#Adler32()
+	 */
+	public void test_Constructor() {
+		// test method of java.util.zip.Adler32()
+		Adler32 adl = new Adler32();
+		assertTrue("Constructor of adl32 failed", adl.getValue() == 1);
+	}
+
+	/**
+	 * @tests java.util.zip.Adler32#getValue()
+	 */
+	public void test_getValue() {
+		// test methods of java.util.zip.getValue()
+		Adler32 adl = new Adler32();
+		assertTrue(
+				"GetValue should return a zero as a result of construction an object of Adler32",
+				adl.getValue() == 1);
+
+		adl.reset();
+		adl.update(1);
+		// System.out.print("value of adl"+adl.getValue());
+		// The value of the adl should be 131074
+		assertTrue(
+				"update(int) failed to update the checksum to the correct value ",
+				adl.getValue() == 131074);
+		adl.reset();
+		assertTrue("reset failed to reset the checksum value to zero", adl
+				.getValue() == 1);
+
+		adl.reset();
+		adl.update(Integer.MIN_VALUE);
+		// System.out.print("value of adl " + adl.getValue());
+		// The value of the adl should be 65537
+		assertTrue(
+				"update(min) failed to update the checksum to the correct value ",
+				adl.getValue() == 65537L);
+	}
+
+	/**
+	 * @tests java.util.zip.Adler32#reset()
+	 */
+	public void test_reset() {
+		// test methods of java.util.zip.reset()
+		Adler32 adl = new Adler32();
+		adl.update(1);
+		// System.out.print("value of adl"+adl.getValue());
+		// The value of the adl should be 131074
+		assertTrue(
+				"update(int) failed to update the checksum to the correct value ",
+				adl.getValue() == 131074);
+		adl.reset();
+		assertTrue("reset failed to reset the checksum value to zero", adl
+				.getValue() == 1);
+	}
+
+	/**
+	 * @tests java.util.zip.Adler32#update(int)
+	 */
+	public void test_updateI() {
+		// test methods of java.util.zip.update(int)
+		Adler32 adl = new Adler32();
+		adl.update(1);
+		// The value of the adl should be 131074
+		assertTrue(
+				"update(int) failed to update the checksum to the correct value ",
+				adl.getValue() == 131074);
+
+		adl.reset();
+		adl.update(Integer.MAX_VALUE);
+		// System.out.print("value of adl " + adl.getValue());
+		// The value of the adl should be 16777472
+		assertTrue(
+				"update(max) failed to update the checksum to the correct value ",
+				adl.getValue() == 16777472L);
+
+		adl.reset();
+		adl.update(Integer.MIN_VALUE);
+		// System.out.print("value of adl " + adl.getValue());
+		// The value of the adl should be 65537
+		assertTrue(
+				"update(min) failed to update the checksum to the correct value ",
+				adl.getValue() == 65537L);
+
+	}
+
+	/**
+	 * @tests java.util.zip.Adler32#update(byte[])
+	 */
+	public void test_update$B() {
+		// test method of java.util.zip.update(byte[])
+		byte byteArray[] = { 1, 2 };
+		Adler32 adl = new Adler32();
+		adl.update(byteArray);
+		// System.out.print("value of adl"+adl.getValue());
+		// The value of the adl should be 393220
+		assertTrue(
+				"update(byte[]) failed to update the checksum to the correct value ",
+				adl.getValue() == 393220);
+
+		adl.reset();
+		byte byteEmpty[] = new byte[10000];
+		adl.update(byteEmpty);
+		// System.out.print("value of adl"+adl.getValue());
+		// The value of the adl should be 655360001
+		assertTrue(
+				"update(byte[]) failed to update the checksum to the correct value ",
+				adl.getValue() == 655360001L);
+
+	}
+
+	/**
+	 * @tests java.util.zip.Adler32#update(byte[], int, int)
+	 */
+	public void test_update$BII() {
+		// test methods of java.util.zip.update(byte[],int,int)
+		byte[] byteArray = { 1, 2, 3 };
+		Adler32 adl = new Adler32();
+		int off = 2;// accessing the 2nd element of byteArray
+		int len = 1;
+		int lenError = 3;
+		int offError = 4;
+		adl.update(byteArray, off, len);
+		// System.out.print("value of adl"+adl.getValue());
+		// The value of the adl should be 262148
+		assertTrue(
+				"update(byte[],int,int) failed to update the checksum to the correct value ",
+				adl.getValue() == 262148);
+		int r = 0;
+
+		try {
+			adl.update(byteArray, off, lenError);
+		} catch (ArrayIndexOutOfBoundsException e) {
+			r = 1;
+		}
+		assertTrue(
+				"update(byte[],int,int) failed b/c lenError>byte[].length-off",
+				r == 1);
+
+		try {
+			adl.update(byteArray, offError, len);
+		} catch (ArrayIndexOutOfBoundsException e) {
+			r = 2;
+		}
+		assertTrue("update(byte[],int,int) failed b/c offError>byte[].length",
+				r == 2);
+
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,50 @@
+/* Copyright 2004 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 tests.api.java.util.zip;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for java.util.zip package.
+ */
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("Tests for java.util.zip");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(Adler32Test.class);
+		suite.addTestSuite(CheckedInputStreamTest.class);
+		suite.addTestSuite(CheckedOutputStreamTest.class);
+		suite.addTestSuite(CRC32Test.class);
+		suite.addTestSuite(DeflaterTest.class);
+		suite.addTestSuite(DeflaterOutputStreamTest.class);
+		suite.addTestSuite(GZIPInputStreamTest.class);
+		suite.addTestSuite(GZIPOutputStreamTest.class);
+		suite.addTestSuite(InflaterTest.class);
+		suite.addTestSuite(InflaterInputStreamTest.class);
+		suite.addTestSuite(ZipEntryTest.class);
+		suite.addTestSuite(ZipFileTest.class);
+		suite.addTestSuite(ZipInputStreamTest.class);
+		suite.addTestSuite(ZipOutputStreamTest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CRC32Test.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CRC32Test.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CRC32Test.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CRC32Test.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,195 @@
+/* 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 tests.api.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();
+		assertTrue("Constructor of CRC32 failed", crc.getValue() == 0);
+	}
+
+	/**
+	 * @tests java.util.zip.CRC32#getValue()
+	 */
+	public void test_getValue() {
+		// test methods of java.util.zip.crc32.getValue()
+		CRC32 crc = new CRC32();
+		assertTrue(
+				"getValue() should return a zero as a result of constructing a CRC32 instance",
+				crc.getValue() == 0);
+
+		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
+		assertTrue(
+				"update(max) failed to update the checksum to the correct value ",
+				crc.getValue() == 4278190080L);
+
+		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
+		assertTrue(
+				"update(byte[]) failed to update the checksum to the correct value ",
+				crc.getValue() == 1295764014L);
+
+		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
+		// assertTrue("update(int) failed to update the checksum to the correct
+		// value ",crc.getValue() == 2768625435L);
+		crc.reset();
+		assertTrue("reset failed to reset the checksum value to zero", crc
+				.getValue() == 0);
+	}
+
+	/**
+	 * @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
+		assertTrue(
+				"update(int) failed to update the checksum to the correct value ",
+				crc.getValue() == 2768625435L);
+		crc.reset();
+		assertTrue("reset failed to reset the checksum value to zero", crc
+				.getValue() == 0);
+
+	}
+
+	/**
+	 * @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
+		assertTrue(
+				"update(1) failed to update the checksum to the correct value ",
+				crc.getValue() == 2768625435L);
+
+		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
+		assertTrue(
+				"update(max) failed to update the checksum to the correct value ",
+				crc.getValue() == 4278190080L);
+
+		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
+		assertTrue(
+				"update(min) failed to update the checksum to the correct value ",
+				crc.getValue() == 3523407757L);
+	}
+
+	/**
+	 * @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
+		assertTrue(
+				"update(byte[]) failed to update the checksum to the correct value ",
+				crc.getValue() == 3066839698L);
+
+		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
+		assertTrue(
+				"update(byte[]) failed to update the checksum to the correct value ",
+				crc.getValue() == 1295764014L);
+	}
+
+	/**
+	 * @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
+		assertTrue(
+				"update(byte[],int,int) failed to update the checksum to the correct value ",
+				crc.getValue() == 1259060791L);
+		int r = 0;
+		try {
+			crc.update(byteArray, off, lenError);
+		} catch (ArrayIndexOutOfBoundsException e) {
+			r = 1;
+		}
+		assertTrue(
+				"update(byte[],int,int) failed b/c lenError>byte[].length-off",
+				r == 1);
+
+		try {
+			crc.update(byteArray, offError, len);
+		} catch (ArrayIndexOutOfBoundsException e) {
+			r = 2;
+		}
+		assertTrue("update(byte[],int,int) failed b/c offError>byte[].length",
+				r == 2);
+	}
+
+	protected void setUp() {
+
+	}
+
+	protected void tearDown() {
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedInputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedInputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,141 @@
+/* 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 tests.api.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());
+			assertTrue("constructor of checkedInputStream has failed", checkIn
+					.getChecksum().getValue() == 0);
+			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) {
+			}
+			assertTrue("the checkSum value of an empty file is not zero",
+					checkEmpty.getChecksum().getValue() == 0);
+			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());
+			assertTrue("the checksum value is incorrect", checkIn.getChecksum()
+					.getValue() == 2036203193);
+			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());
+			assertTrue("the checksum value is incorrect", checkIn2
+					.getChecksum().getValue() == 2235765342L);
+			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());
+			assertTrue("checkSum value is not correct", checkIn.getChecksum()
+					.getValue() == 2235765342L);
+			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");
+		}
+
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedOutputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/CheckedOutputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,149 @@
+/* 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 tests.api.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());
+			assertTrue("the checkSum value of the constructor is not 0", chkOut
+					.getChecksum().getValue() == 0);
+			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());
+
+			assertTrue("the checkSum value for writeI is incorrect", chkOut
+					.getChecksum().getValue() == 7536755);
+			chkOut.getChecksum().reset();
+			chkOut.write(byteArray, 5, 4);
+			// ran JDK and found that checkSum value is 51708133
+			// System.out.print(" " +chkOut.getChecksum().getValue());
+
+			assertTrue("the checkSum value for writeBII is incorrect ", chkOut
+					.getChecksum().getValue() == 51708133);
+			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;
+			}
+			assertTrue("boundary check is not performed", r == 1);
+			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");
+		}
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/DeflaterOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/DeflaterOutputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/DeflaterOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/tests/api/java/util/zip/DeflaterOutputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,457 @@
+/* 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 tests.api.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.
+			assertTrue("Incorrect Buffer Size",
+					dos.getProtectedBuf().length == 512);
+
+			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.
+			assertTrue("Incorrect Buffer Size",
+					dos.getProtectedBuf().length == 512);
+
+			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);
+			assertTrue("Incorrect Buffer Size",
+					dos.getProtectedBuf().length == 5);
+
+			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.
+			assertTrue("Incorrect Byte Returned.", iis.read() == 1);
+			assertTrue("Incorrect Byte Returned.", iis.read() == 3);
+			assertTrue("Incorrect Byte Returned.", iis.read() == 4);
+			assertTrue("Incorrect Byte Returned.", iis.read() == 6);
+			assertTrue("Incorrect Byte Returned.", iis.read() == -1);
+			assertTrue("Incorrect Byte Returned.", iis.read() == -1);
+			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);
+			assertTrue("Incorrect Byte Returned (EOF).", iis.read() == -1);
+			assertTrue("Incorrect Byte Returned (EOF).", iis.read() == -1);
+			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);
+			assertTrue("Incorrect Byte Returned.", iis.read() == 4);
+			assertTrue("Incorrect Byte Returned.", iis.read() == 7);
+			assertTrue("Incorrect Byte Returned.", iis.read() == 8);
+			assertTrue("Incorrect Byte Returned (EOF).", iis.read() == -1);
+			assertTrue("Incorrect Byte Returned (EOF).", iis.read() == -1);
+			iis.close();
+			f1.delete();
+
+			// Test for trying to write more bytes than availble 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() {
+
+	}
+
+}



Mime
View raw message