summaryrefslogtreecommitdiffstats
path: root/archive
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-02-18 17:20:15 -0800
committerElliott Hughes <enh@google.com>2010-02-19 10:35:06 -0800
commit7ee3a061452c5a7e5c8e661219a1f08a14171858 (patch)
treef995fb4c053e4c68a86909aa72aee284cb39133a /archive
parent1d1f9244611a8ba3be65795d4ea6e84bcecdb89d (diff)
downloadlibcore-7ee3a061452c5a7e5c8e661219a1f08a14171858.zip
libcore-7ee3a061452c5a7e5c8e661219a1f08a14171858.tar.gz
libcore-7ee3a061452c5a7e5c8e661219a1f08a14171858.tar.bz2
Resync a load of tests with upstream, make our build faster.
I started off with a mission to remove uses of dalvik.annotation.* (stuff like @TestTargetNew and other useless junk that just makes it harder to stay in sync with upstream). I wrote a script to go through tests showing me the diff between what we have and what upstream has, thinking that in cases where upstream has also added tests, I may as well pull them in at the same time... ...but I didn't realize how close we were to having dx fill its 1.5GiB heap. After trying various alternatives, I decided to bite the bullet and break core-tests up into one .jar per module. This adds parallelism back into this, the slowest part of our build. (I can do even better, but I'll do that in a separate patch, preferably after we've merged recent changes from master.) Only a couple of dependencies were problematic: the worthless TestSuiteFactory which already contained a comment suggesting we get rid of it, and the fact that some tests -- most notably the concurrent ones -- also contained main methods that started the JUnit tty-based TestRunner. (In the long run, we want to be running the harmony tests directly from a pristine "svn co" of upstream, using DalvikRunner. But this will be a big help in the meantime, and starts the work of getting our current copy of the tests into a state where we can start to extract any meaningful changes/additions we've made.)
Diffstat (limited to 'archive')
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java7
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java339
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java7
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java372
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java142
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java86
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java1815
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java281
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java353
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java581
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java1361
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java1035
-rw-r--r--archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java109
-rw-r--r--archive/src/test/java/tests/archive/AllTests.java7
14 files changed, 2771 insertions, 3724 deletions
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java
index 13fe019..7b39de6 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java
@@ -24,13 +24,8 @@ import junit.framework.TestSuite;
* Test suite for java.util.jar package.
*/
public class AllTests {
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
public static Test suite() {
- TestSuite suite = tests.TestSuiteFactory.createTestSuite(
+ TestSuite suite = new TestSuite(
"Suite org.apache.harmony.archive.tests.java.util.jar");
suite.addTestSuite(AttributesNameTest.class);
suite.addTestSuite(AttributesTest.class);
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java
index 532a3a6..7290ac2 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java
@@ -14,211 +14,156 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.util.zip.Adler32;
-@TestTargetClass(Adler32.class)
public class Adler32Test extends junit.framework.TestCase {
- /**
- * @tests java.util.zip.Adler32#Adler32()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Adler32",
- args = {}
- )
- public void test_Constructor() {
- // test method of java.util.zip.Adler32()
- Adler32 adl = new Adler32();
- assertEquals("Constructor of adl32 failed", 1, adl.getValue());
- }
-
- /**
- * @tests java.util.zip.Adler32#getValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getValue",
- args = {}
- )
- public void test_getValue() {
- // test methods of java.util.zip.getValue()
- Adler32 adl = new Adler32();
- assertEquals(
- "GetValue should return a zero as a result of construction an object of Adler32",
- 1, adl.getValue());
-
- adl.reset();
- adl.update(1);
- // System.out.print("value of adl"+adl.getValue());
- // The value of the adl should be 131074
- assertEquals(
- "update(int) failed to update the checksum to the correct value ",
- 131074, adl.getValue());
- adl.reset();
- assertEquals("reset failed to reset the checksum value to zero", 1, adl
- .getValue());
-
- adl.reset();
- adl.update(Integer.MIN_VALUE);
- // System.out.print("value of adl " + adl.getValue());
- // The value of the adl should be 65537
- assertEquals(
- "update(min) failed to update the checksum to the correct value ",
- 65537L, adl.getValue());
- }
-
- /**
- * @tests java.util.zip.Adler32#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- 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
- assertEquals(
- "update(int) failed to update the checksum to the correct value ",
- 131074, adl.getValue());
- adl.reset();
- assertEquals("reset failed to reset the checksum value to zero", 1, adl
- .getValue());
- }
-
- /**
- * @tests java.util.zip.Adler32#update(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "update",
- args = {int.class}
- )
- 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
- assertEquals(
- "update(int) failed to update the checksum to the correct value ",
- 131074, adl.getValue());
-
- adl.reset();
- adl.update(Integer.MAX_VALUE);
- // System.out.print("value of adl " + adl.getValue());
- // The value of the adl should be 16777472
- assertEquals(
- "update(max) failed to update the checksum to the correct value ",
- 16777472L, adl.getValue());
-
- adl.reset();
- adl.update(Integer.MIN_VALUE);
- // System.out.print("value of adl " + adl.getValue());
- // The value of the adl should be 65537
- assertEquals(
- "update(min) failed to update the checksum to the correct value ",
- 65537L, adl.getValue());
-
- }
-
- /**
- * @tests java.util.zip.Adler32#update(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "update",
- args = {byte[].class}
- )
- 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
- assertEquals(
- "update(byte[]) failed to update the checksum to the correct value ",
- 393220, adl.getValue());
-
- 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
- assertEquals(
- "update(byte[]) failed to update the checksum to the correct value ",
- 655360001L, adl.getValue());
-
- }
-
- /**
- * @tests java.util.zip.Adler32#update(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "update",
- args = {byte[].class, int.class, int.class}
- )
- 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
- assertEquals(
- "update(byte[],int,int) failed to update the checksum to the correct value ",
- 262148, adl.getValue());
- int r = 0;
-
- try {
- adl.update(byteArray, off, lenError);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals(
- "update(byte[],int,int) failed b/c lenError>byte[].length-off",
- 1, r);
-
- try {
- adl.update(byteArray, offError, len);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 2;
- }
- assertEquals(
- "update(byte[],int,int) failed b/c offError>byte[].length", 2,
- r);
-
- }
-
- @Override
+ /**
+ * @tests java.util.zip.Adler32#Adler32()
+ */
+ public void test_Constructor() {
+ // test method of java.util.zip.Adler32()
+ Adler32 adl = new Adler32();
+ assertEquals("Constructor of adl32 failed", 1, adl.getValue());
+ }
+
+ /**
+ * @tests java.util.zip.Adler32#getValue()
+ */
+ public void test_getValue() {
+ // test methods of java.util.zip.getValue()
+ Adler32 adl = new Adler32();
+ assertEquals("GetValue should return a zero as a result of construction an object of Adler32",
+ 1, adl.getValue());
+
+ adl.reset();
+ adl.update(1);
+ // System.out.print("value of adl"+adl.getValue());
+ // The value of the adl should be 131074
+ assertEquals("update(int) failed to update the checksum to the correct value ",
+ 131074, adl.getValue());
+ adl.reset();
+ assertEquals("reset failed to reset the checksum value to zero", 1, adl
+ .getValue());
+
+ adl.reset();
+ adl.update(Integer.MIN_VALUE);
+ // System.out.print("value of adl " + adl.getValue());
+ // The value of the adl should be 65537
+ assertEquals("update(min) failed to update the checksum to the correct value ",
+ 65537L, adl.getValue());
+ }
+
+ /**
+ * @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
+ assertEquals("update(int) failed to update the checksum to the correct value ",
+ 131074, adl.getValue());
+ adl.reset();
+ assertEquals("reset failed to reset the checksum value to zero", 1, adl
+ .getValue());
+ }
+
+ /**
+ * @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
+ assertEquals("update(int) failed to update the checksum to the correct value ",
+ 131074, adl.getValue());
+
+ adl.reset();
+ adl.update(Integer.MAX_VALUE);
+ // System.out.print("value of adl " + adl.getValue());
+ // The value of the adl should be 16777472
+ assertEquals("update(max) failed to update the checksum to the correct value ",
+ 16777472L, adl.getValue());
+
+ adl.reset();
+ adl.update(Integer.MIN_VALUE);
+ // System.out.print("value of adl " + adl.getValue());
+ // The value of the adl should be 65537
+ assertEquals("update(min) failed to update the checksum to the correct value ",
+ 65537L, adl.getValue());
+
+ }
+
+ /**
+ * @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
+ assertEquals("update(byte[]) failed to update the checksum to the correct value ",
+ 393220, adl.getValue());
+
+ 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
+ assertEquals("update(byte[]) failed to update the checksum to the correct value ",
+ 655360001L, adl.getValue());
+
+ }
+
+ /**
+ * @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
+ assertEquals("update(byte[],int,int) failed to update the checksum to the correct value ",
+ 262148, adl.getValue());
+ int r = 0;
+
+ try {
+ adl.update(byteArray, off, lenError);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ r = 1;
+ }
+ assertEquals("update(byte[],int,int) failed b/c lenError>byte[].length-off",
+ 1, r);
+
+ try {
+ adl.update(byteArray, offError, len);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ r = 2;
+ }
+ assertEquals("update(byte[],int,int) failed b/c offError>byte[].length",
+ 2, r);
+
+ }
+
+ @Override
protected void setUp() {
- }
+ }
- @Override
+ @Override
protected void tearDown() {
- }
+ }
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java
index acde889..562b396 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java
@@ -24,13 +24,8 @@ 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 = tests.TestSuiteFactory.createTestSuite(
+ TestSuite suite = new TestSuite(
"Suite org.apache.harmony.archive.tests.java.util.zip");
// $JUnit-BEGIN$
suite.addTestSuite(Adler32Test.class);
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java
index 805cab3..7eb0566 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java
@@ -14,229 +14,173 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.util.zip.CRC32;
-@TestTargetClass(CRC32.class)
public class CRC32Test extends junit.framework.TestCase {
- /**
- * @tests java.util.zip.CRC32#CRC32()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "CRC32",
- args = {}
- )
- 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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getValue",
- args = {}
- )
- 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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "update",
- args = {int.class}
- )
- 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[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "update",
- args = {byte[].class}
- )
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "update",
- args = {byte[].class, int.class, int.class}
- )
- 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);
- }
-
- @Override
+ /**
+ * @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);
+ }
+
+ @Override
protected void setUp() {
- }
+ }
- @Override
+ @Override
protected void tearDown() {
- }
+ }
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
index 4450bdf..393923d 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
@@ -14,139 +14,99 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
+import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
+
import junit.framework.TestCase;
import tests.support.resource.Support_Resources;
-
-@TestTargetClass(CheckedInputStream.class)
public class CheckedInputStreamTest extends TestCase {
+
+ @Override
+ protected void tearDown() {
+ try {
+ File deletedFile = new File("empty.txt");
+ deletedFile.delete();
+ } catch (SecurityException e) {
+ fail("Cannot delete file for security reasons");
+ }
- /**
- * @tests java.util.zip.CheckedInputStream#CheckedInputStream(java.io.InputStream,
- * java.util.zip.Checksum)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "CheckedInputStream",
- args = {java.io.InputStream.class, java.util.zip.Checksum.class}
- )
- public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum()
- throws Exception {
- InputStream checkInput = Support_Resources
- .getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput,
- new CRC32());
- assertEquals("constructor of checkedInputStream has failed", 0, checkIn
- .getChecksum().getValue());
+ }
+
+ /**
+ * @tests java.util.zip.CheckedInputStream#CheckedInputStream(java.io.InputStream,
+ * java.util.zip.Checksum)
+ */
+ public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum() throws Exception {
+ InputStream 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();
}
- /**
- * @tests java.util.zip.CheckedInputStream#getChecksum()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getChecksum",
- args = {}
- )
- public void test_getChecksum() throws Exception {
+ /**
+ * @tests java.util.zip.CheckedInputStream#getChecksum()
+ */
+ public void test_getChecksum() throws Exception {
byte outBuf[] = new byte[100];
// testing getChecksum for an empty file
- File empty = File.createTempFile("empty", ".txt");
- empty.deleteOnExit();
- FileOutputStream outEmp = new FileOutputStream(empty);
+ FileOutputStream outEmp = new FileOutputStream("empty.txt");
outEmp.close();
- InputStream inEmp = new FileInputStream(empty);
- CheckedInputStream checkEmpty = new CheckedInputStream(inEmp,
- new CRC32());
+ 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());
+ assertEquals("the checkSum value of an empty file is not zero", 0, checkEmpty
+ .getChecksum().getValue());
inEmp.close();
// testing getChecksum for the file checkInput
- InputStream checkInput = Support_Resources
- .getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput,
- new CRC32());
+ InputStream 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());
+ 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());
+ 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());
+ assertEquals("the checksum value is incorrect", 2235765342L, checkIn2.getChecksum()
+ .getValue());
checkInput.close();
}
- /**
- * @tests java.util.zip.CheckedInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws Exception {
+ /**
+ * @tests java.util.zip.CheckedInputStream#skip(long)
+ */
+ public void test_skipJ() throws Exception {
// testing that the return by skip is valid
- InputStream checkInput = Support_Resources
- .getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput,
- new CRC32());
+ InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+ CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
long skipValue = 5;
- assertEquals(
- "the value returned by skip(n) is not the same as its parameter",
+ assertEquals("the value returned by skip(n) is not the same as its parameter",
skipValue, checkIn.skip(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());
+ assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
+ .getValue());
checkInput.close();
- try {
- checkInput.skip(33);
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
}
- /**
- * @tests java.util.zip.CheckedInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
public void test_read() throws Exception {
// testing that the return by skip is valid
InputStream checkInput = Support_Resources
@@ -161,16 +121,9 @@ public class CheckedInputStreamTest extends TestCase {
} catch (IOException ee) {
// expected
}
- long skipValue = 5;
checkInput.close();
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$byteII() throws Exception {
// testing that the return by skip is valid
InputStream checkInput = Support_Resources
@@ -186,7 +139,6 @@ public class CheckedInputStreamTest extends TestCase {
} catch (IOException ee) {
// expected
}
- long skipValue = 5;
checkInput.close();
}
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
index 738f610..be28774 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
@@ -17,11 +17,6 @@
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
@@ -34,7 +29,6 @@ import java.util.zip.InflaterInputStream;
import junit.framework.TestCase;
-@TestTargetClass(DeflaterOutputStream.class)
public class DeflaterOutputStreamTest extends TestCase {
private class MyDeflaterOutputStream extends DeflaterOutputStream {
@@ -64,10 +58,6 @@ public class DeflaterOutputStreamTest extends TestCase {
boolean getDaflateFlag() {
return deflateFlag;
}
-
- void cleanDaflateFlag() {
- deflateFlag = false;
- }
}
private byte outPutBuf[] = new byte[500];
@@ -75,7 +65,7 @@ public class DeflaterOutputStreamTest extends TestCase {
@Override
protected void setUp() {
// setting up a deflater to be used
- byte byteArray[] = {1, 3, 4, 7, 8};
+ byte byteArray[] = { 1, 3, 4, 7, 8 };
int x = 0;
Deflater deflate = new Deflater(1);
deflate.setInput(byteArray);
@@ -93,16 +83,9 @@ public class DeflaterOutputStreamTest extends TestCase {
* @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
* java.util.zip.Deflater)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "DeflaterOutputStream",
- args = {java.io.OutputStream.class, java.util.zip.Deflater.class}
- )
- public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Deflater()
- throws Exception {
- byte byteArray[] = {1, 3, 4, 7, 8};
- File f1 = File.createTempFile("hyts_Constru_OD", ".tst");
+ public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Deflater() throws Exception {
+ 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;
@@ -127,14 +110,8 @@ public class DeflaterOutputStreamTest extends TestCase {
/**
* @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "DeflaterOutputStream",
- args = {java.io.OutputStream.class}
- )
public void test_ConstructorLjava_io_OutputStream() throws Exception {
- File f1 = File.createTempFile("hyts_Constru_O", ".tst");
+ File f1 = new File("hyts_Constru(O).tst");
FileOutputStream fos = new FileOutputStream(f1);
MyDeflaterOutputStream dos = new MyDeflaterOutputStream(fos);
@@ -151,19 +128,13 @@ public class DeflaterOutputStreamTest extends TestCase {
* @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
* java.util.zip.Deflater, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "DeflaterOutputStream",
- args = {java.io.OutputStream.class, java.util.zip.Deflater.class, int.class}
- )
public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_DeflaterI()
throws Exception {
int buf = 5;
int negBuf = -5;
int zeroBuf = 0;
- byte byteArray[] = {1, 3, 4, 7, 8, 3, 6};
- File f1 = File.createTempFile("hyts_Constru_ODI", ".tst");
+ 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;
@@ -203,12 +174,6 @@ public class DeflaterOutputStreamTest extends TestCase {
/**
* @tests java.util.zip.DeflaterOutputStream#close()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException can not be checked.",
- method = "close",
- args = {}
- )
public void test_close() throws Exception {
File f1 = File.createTempFile("close", ".tst");
@@ -268,20 +233,14 @@ public class DeflaterOutputStreamTest extends TestCase {
/**
* @tests java.util.zip.DeflaterOutputStream#finish()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "finish",
- args = {}
- )
public void test_finish() throws Exception {
// Need test to see if method finish() actually finishes
// Only testing possible errors, not if it actually works
- File f1 = File.createTempFile("finish", ".tst");
+ File f1 = new File("finish.tst");
FileOutputStream fos1 = new FileOutputStream(f1);
DeflaterOutputStream dos = new DeflaterOutputStream(fos1);
- byte byteArray[] = {1, 3, 4, 6};
+ byte byteArray[] = { 1, 3, 4, 6 };
dos.write(byteArray);
dos.finish();
@@ -325,14 +284,8 @@ public class DeflaterOutputStreamTest extends TestCase {
/**
* @tests java.util.zip.DeflaterOutputStream#write(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
public void test_writeI() throws Exception {
- File f1 = File.createTempFile("writeI1", ".tst");
+ File f1 = new File("writeI1.tst");
FileOutputStream fos = new FileOutputStream(f1);
DeflaterOutputStream dos = new DeflaterOutputStream(fos);
for (int i = 0; i < 3; i++) {
@@ -367,17 +320,11 @@ public class DeflaterOutputStreamTest extends TestCase {
/**
* @tests java.util.zip.DeflaterOutputStream#write(byte[], int, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() throws Exception {
- byte byteArray[] = {1, 3, 4, 7, 8, 3, 6};
+ byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
// Test to see if the correct bytes are saved.
- File f1 = File.createTempFile("writeBII", ".tst");
+ File f1 = new File("writeBII.tst");
FileOutputStream fos1 = new FileOutputStream(f1);
DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1);
dos1.write(byteArray, 2, 3);
@@ -393,7 +340,7 @@ public class DeflaterOutputStreamTest extends TestCase {
f1.delete();
// Test for trying to write more bytes than available from the array
- File f2 = File.createTempFile("writeBII", ".tst");
+ File f2 = new File("writeBII2.tst");
FileOutputStream fos2 = new FileOutputStream(f2);
DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
try {
@@ -441,13 +388,6 @@ public class DeflaterOutputStreamTest extends TestCase {
f2.delete();
}
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "deflate",
- args = {}
- )
public void test_deflate() throws Exception {
File f1 = File.createTempFile("writeI1", ".tst");
FileOutputStream fos = new FileOutputStream(f1);
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
index ae77450..93fe710 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
@@ -17,15 +17,9 @@
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.zip.Adler32;
-
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
@@ -33,447 +27,376 @@ import java.util.zip.Inflater;
import junit.framework.TestCase;
import tests.support.resource.Support_Resources;
-@TestTargetClass(Deflater.class)
public class DeflaterTest extends TestCase {
- class MyDeflater extends 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[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "deflate",
- args = {byte[].class}
- )
- public void test_deflate$B() {
- 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()) {
+ class MyDeflater extends 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() {
+ 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));
+ assertEquals("Deflater at end of stream, should return 0", 0, defl
+ .deflate(outPutBuf));
int totalOut = defl.getTotalOut();
int totalIn = defl.getTotalIn();
assertEquals(x, totalOut);
assertEquals(byteArray.length, totalIn);
- defl.end();
+ defl.end();
- Inflater infl = new Inflater();
- try {
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
+ Inflater infl = new Inflater();
+ try {
+ infl.setInput(outPutBuf);
+ while (!infl.finished()) {
infl.inflate(outPutInf);
}
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
+ } catch (DataFormatException e) {
+ fail("Invalid input to be decompressed");
+ }
assertEquals(totalIn, infl.getTotalOut());
assertEquals(totalOut, infl.getTotalIn());
- for (int i = 0; i < byteArray.length; i++) {
+ for (int i = 0; i < byteArray.length; i++) {
assertEquals(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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "deflate",
- args = {byte[].class, int.class, int.class}
- )
- public void test_deflate$BII() {
- 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()) {
+ 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() {
+ 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();
+ assertEquals("Deflater at end of stream, should return 0", 0, defl.deflate(
+ outPutBuf, offSet, length));
+ int totalOut = defl.getTotalOut();
+ int totalIn = defl.getTotalIn();
assertEquals(x, totalOut);
assertEquals(byteArray.length, totalIn);
- defl.end();
+ defl.end();
- Inflater infl = new Inflater();
- try {
- infl.setInput(outPutBuf, offSet, length);
- while (!infl.finished()) {
+ 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");
- }
+ } catch (DataFormatException e) {
+ fail("Invalid input to be decompressed");
+ }
assertEquals(totalIn, infl.getTotalOut());
assertEquals(totalOut, infl.getTotalIn());
- for (int i = 0; i < byteArray.length; i++) {
+ for (int i = 0; i < byteArray.length; i++) {
assertEquals(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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "end",
- args = {}
- )
- public void test_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()) {
+ 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() {
+ 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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "finalize",
- args = {}
- )
- public void test_finalize() {
- MyDeflater mdefl = new MyDeflater();
- mdefl.myFinalize();
- System.gc();
- helper_end_test(mdefl, "finalize");
- }
-
- /**
- * @tests java.util.zip.Deflater#finish()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "finish",
- args = {}
- )
- public void test_finish() throws Exception {
- // 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")) {
- assertFalse(
- "needsInput() should return false after finish() is called",
- defl.needsInput());
- }
-
- while (!defl.finished()) {
+ defl.end();
+ helper_end_test(defl, "end");
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#finalize()
+ */
+ public void test_finalize() {
+ MyDeflater mdefl = new MyDeflater();
+ mdefl.myFinalize();
+ System.gc();
+ helper_end_test(mdefl, "finalize");
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#finish()
+ */
+ public void test_finish() throws Exception {
+ // 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")) {
+ assertFalse("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();
+ int totalOut = defl.getTotalOut();
+ int totalIn = defl.getTotalIn();
assertEquals(x, totalOut);
assertEquals(byteArray.length, totalIn);
- defl.end();
+ defl.end();
- Inflater infl = new Inflater();
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
+ Inflater infl = new Inflater();
+ infl.setInput(outPutBuf);
+ while (!infl.finished()) {
+ infl.inflate(outPutInf);
+ }
assertEquals(totalIn, infl.getTotalOut());
assertEquals(totalOut, infl.getTotalIn());
- for (int i = 0; i < byteArray.length; i++) {
+ for (int i = 0; i < byteArray.length; i++) {
assertEquals(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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "finished",
- args = {}
- )
- public void test_finished() {
- 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()) {
+ 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() {
+ 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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getAdler",
- args = {}
- )
- public void test_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()) {
+ 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() {
+ 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();
- assertEquals(
+ 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();
+ assertEquals(
"The checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
checkSumD, checkSumR);
- }
-
- /**
- * @tests java.util.zip.Deflater#getTotalIn()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTotalIn",
- args = {}
- )
- public void test_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()) {
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#getTotalIn()
+ */
+ public void test_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);
}
assertEquals(byteArray.length, defl.getTotalIn());
- 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.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);
}
assertEquals(length, defl.getTotalIn());
- defl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#getTotalOut()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTotalOut",
- args = {}
- )
- public void test_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()) {
+ defl.end();
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#getTotalOut()
+ */
+ public void test_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);
}
assertEquals(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()) {
+ 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);
}
assertEquals(x, defl.getTotalOut());
- }
-
- /**
- * @tests java.util.zip.Deflater#needsInput()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "needsInput",
- args = {}
- )
- public void test_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);
- assertFalse(
- "needsInput give wrong boolean value as a result of a full input buffer",
- defl.needsInput());
- byte[] outPutBuf = new byte[50];
- while (!defl.needsInput()) {
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#needsInput()
+ */
+ public void test_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);
+ assertFalse(
+ "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()) {
+ 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")) {
+ // needsInput should NOT return true after finish() has been
+ // called.
+ if (System.getProperty("java.vendor").startsWith("IBM")) {
assertFalse(
- "needsInput gave wrong boolean value as a result of finish() being called",
- defl.needsInput());
- }
- defl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- public void test_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) {
+ "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() {
+ 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;
@@ -481,13 +404,13 @@ public class DeflaterTest extends TestCase {
defl.reset();
}
- defl.setInput(curArray);
- defl.finish();
- while (!defl.finished()) {
+ defl.setInput(curArray);
+ defl.finish();
+ while (!defl.finished()) {
x += defl.deflate(outPutBuf);
}
- if (i == 0) {
+ if (i == 0) {
assertEquals(x, defl.getTotalOut());
} else if (i == 1) {
assertEquals(x, orgValue);
@@ -495,333 +418,296 @@ public class DeflaterTest extends TestCase {
assertEquals(x, orgValue * 2);
}
- if (i == 0) {
+ if (i == 0) {
orgValue = x;
}
- try {
- Inflater infl = new Inflater();
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
+ 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");
- }
+ infl.end();
+ } catch (DataFormatException e) {
+ fail("Test " + i + ": Invalid input to be decompressed");
+ }
- if (i == 1) {
+ if (i == 1) {
curArray = byteArray;
}
- for (int j = 0; j < curArray.length; j++) {
+ for (int j = 0; j < curArray.length; j++) {
assertEquals(curArray[j], outPutInf[j]);
}
assertEquals(0, outPutInf[curArray.length]);
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#setDictionary(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setDictionary",
- args = {byte[].class}
- )
- public void test_setDictionary$B() {
- // 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();
+ }
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#setDictionary(byte[])
+ */
+ public void test_setDictionary$B() {
+ // 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();
assertEquals(deflAdler, realAdler);
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
+ 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.
+ 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.
assertEquals(realAdler, deflAdler);
- defl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#setDictionary(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setDictionary",
- args = {byte[].class, int.class, int.class}
- )
- public void test_setDictionary$BII() {
- // 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();
+ defl.end();
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#setDictionary(byte[], int, int)
+ */
+ public void test_setDictionary$BII() {
+ // 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();
assertEquals(deflAdler, realAdler);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
+ 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.
+ 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.
assertEquals(realAdler, deflAdler);
- 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[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setInput",
- args = {byte[].class}
- )
- public void test_setInput$B() {
- 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.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() {
+ 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();
+ defl.end();
- Inflater infl = new Inflater();
- try {
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
+ 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++) {
+ } catch (DataFormatException e) {
+ fail("Invalid input to be decompressed");
+ }
+ for (int i = 0; i < byteArray.length; i++) {
assertEquals(byteArray[i], outPutInf[i]);
}
- assertEquals(byteArray.length, infl.getTotalOut());
- infl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#setInput(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setInput",
- args = {byte[].class, int.class, int.class}
- )
- public void test_setInput$BII() throws Exception {
- 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);
- assertFalse("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()) {
+ assertEquals(byteArray.length, infl.getTotalOut());
+ infl.end();
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#setInput(byte[], int, int)
+ */
+ public void test_setInput$BII() throws Exception {
+ 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);
+ assertFalse("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();
+ defl.end();
- Inflater infl = new Inflater();
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
- for (int i = 0; i < length; i++) {
+ Inflater infl = new Inflater();
+ infl.setInput(outPutBuf);
+ while (!infl.finished()) {
+ infl.inflate(outPutInf);
+ }
+ for (int i = 0; i < length; i++) {
assertEquals(byteArray[i + offSet], outPutInf[i]);
}
- assertEquals(length, infl.getTotalOut());
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLevel",
- args = {int.class}
- )
- public void test_setLevelI() throws Exception {
- // Very similar to test_Constructor(int)
- byte[] byteArray = new byte[100];
- InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
- inFile.read(byteArray);
- inFile.close();
-
- 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()) {
+ assertEquals(length, infl.getTotalOut());
+ 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() throws Exception {
+ // Very similar to test_Constructor(int)
+ byte[] byteArray = new byte[100];
+ InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
+ inFile.read(byteArray);
+ inFile.close();
+
+ 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.finish();
+ while (!defl.finished()) {
defl.deflate(outPutBuf);
}
- totalOut = defl.getTotalOut();
- defl.end();
+ totalOut = defl.getTotalOut();
+ defl.end();
- outPutBuf = new byte[500];
- defl = new Deflater(i);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
+ outPutBuf = new byte[500];
+ defl = new Deflater(i);
+ defl.setInput(byteArray);
+ while (!defl.needsInput()) {
defl.deflate(outPutBuf);
}
- defl.finish();
- while (!defl.finished()) {
+ defl.finish();
+ while (!defl.finished()) {
defl.deflate(outPutBuf);
}
- assertEquals(totalOut, defl.getTotalOut());
- 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setStrategy",
- args = {int.class}
- )
- public void test_setStrategyI() throws Exception {
- byte[] byteArray = new byte[100];
- InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
- inFile.read(byteArray);
- inFile.close();
-
- for (int i = 0; i < 3; i++) {
- byte outPutBuf[] = new byte[500];
- MyDeflater mdefl = new MyDeflater();
-
- if (i == 0) {
+ assertEquals(totalOut, defl.getTotalOut());
+ 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() throws Exception {
+ byte[] byteArray = new byte[100];
+ InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
+ inFile.read(byteArray);
+ inFile.close();
+
+ 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());
@@ -829,335 +715,325 @@ public class DeflaterTest extends TestCase {
mdefl.setStrategy(mdefl.getFiltered());
}
- mdefl.setInput(byteArray);
- while (!mdefl.needsInput()) {
+ mdefl.setInput(byteArray);
+ while (!mdefl.needsInput()) {
mdefl.deflate(outPutBuf);
}
- mdefl.finish();
- while (!mdefl.finished()) {
+ 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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Deflater",
- args = {}
- )
- public void test_Constructor() throws Exception {
- byte[] byteArray = new byte[100];
- InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
- inFile.read(byteArray);
- inFile.close();
-
- Deflater defl = new Deflater();
- byte[] outPutBuf = new byte[500];
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
+ 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() throws Exception {
+ byte[] byteArray = new byte[100];
+ InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
+ inFile.read(byteArray);
+ inFile.close();
+
+ Deflater defl = new Deflater();
+ byte[] outPutBuf = new byte[500];
+ defl.setInput(byteArray);
+ while (!defl.needsInput()) {
defl.deflate(outPutBuf);
}
- defl.finish();
- while (!defl.finished()) {
+ 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()) {
+ 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.finish();
+ while (!mdefl.finished()) {
mdefl.deflate(outPutBuf);
}
- assertEquals(totalOut, mdefl.getTotalOut());
- mdefl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#Deflater(int, boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Deflater",
- args = {int.class, boolean.class}
- )
- public void test_ConstructorIZ() throws Exception {
- 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()) {
+ assertEquals(totalOut, mdefl.getTotalOut());
+ mdefl.end();
+ }
+
+ /**
+ * @tests java.util.zip.Deflater#Deflater(int, boolean)
+ */
+ public void test_ConstructorIZ() throws Exception {
+ 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.finish();
+ while (!defl.finished()) {
defl.deflate(outPutBuf);
}
- int totalOut = defl.getTotalOut();
- defl.end();
+ int totalOut = defl.getTotalOut();
+ defl.end();
- outPutBuf = new byte[500];
- defl = new Deflater(2, false);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
+ outPutBuf = new byte[500];
+ defl = new Deflater(2, false);
+ defl.setInput(byteArray);
+ while (!defl.needsInput()) {
defl.deflate(outPutBuf);
}
- defl.finish();
- while (!defl.finished()) {
+ defl.finish();
+ while (!defl.finished()) {
defl.deflate(outPutBuf);
}
- assertEquals(totalOut, defl.getTotalOut());
- defl.end();
+ assertEquals(totalOut, defl.getTotalOut());
+ defl.end();
- outPutBuf = new byte[500];
- defl = new Deflater(2, true);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
+ outPutBuf = new byte[500];
+ defl = new Deflater(2, true);
+ defl.setInput(byteArray);
+ while (!defl.needsInput()) {
defl.deflate(outPutBuf);
}
- defl.finish();
- while (!defl.finished()) {
+ 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);
- while (!infl.finished()) {
- if (infl.needsInput()) {
- infl.setInput(outPutBuf);
- }
- infl.inflate(outPutInf);
- }
- for (int i = 0; i < byteArray.length; i++) {
+ 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);
+ while (!infl.finished()) {
+ if (infl.needsInput()) {
+ infl.setInput(outPutBuf);
+ }
+ infl.inflate(outPutInf);
+ }
+ for (int i = 0; i < byteArray.length; i++) {
assertEquals(byteArray[i], outPutInf[i]);
}
- assertEquals(
- "final decompressed data contained more bytes than original - constructorIZ",
- 0, outPutInf[byteArray.length]);
- infl.end();
-
- infl = new Inflater(false);
- outPutInf = new byte[500];
- int r = 0;
- try {
- while (!infl.finished()) {
- if (infl.needsInput()) {
+ assertEquals("final decompressed data contained more bytes than original - constructorIZ",
+ 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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Deflater",
- args = {int.class}
- )
- public void test_ConstructorI() throws Exception {
- byte[] byteArray = new byte[100];
+ 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() throws Exception {
+ byte[] byteArray = new byte[100];
InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
inFile.read(byteArray);
inFile.close();
- byte outPutBuf[] = new byte[500];
- Deflater defl = new Deflater(3);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
+ 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.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()) {
+ 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.finish();
+ while (!defl.finished()) {
defl.deflate(outPutBuf);
}
- assertEquals(totalOut, defl.getTotalOut());
- defl.end();
+ assertEquals(totalOut, defl.getTotalOut());
+ defl.end();
- // testing boundaries
- try {
+ // 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 {
+ }
+ 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
+ defl.needsInput();
+ defl.setStrategy(1);
+ defl.setLevel(1);
+ defl.end();
+
+ // 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) {
+ }
+ }
+ }
- 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
- defl.needsInput();
- defl.setStrategy(1);
- defl.setLevel(1);
- defl.end();
-
- // 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());
}
/**
@@ -1165,12 +1041,6 @@ public class DeflaterTest extends TestCase {
* @throws UnsupportedEncodingException
* @tests java.util.zip.Deflater#getBytesRead()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getBytesRead",
- args = {}
- )
public void test_getBytesRead() throws DataFormatException,
UnsupportedEncodingException {
// Regression test for HARMONY-158
@@ -1197,12 +1067,6 @@ public class DeflaterTest extends TestCase {
* @throws UnsupportedEncodingException
* @tests java.util.zip.Deflater#getBytesRead()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getBytesWritten",
- args = {}
- )
public void test_getBytesWritten() throws DataFormatException,
UnsupportedEncodingException {
// Regression test for HARMONY-158
@@ -1223,21 +1087,16 @@ public class DeflaterTest extends TestCase {
assertEquals(compressedDataLength, def.getTotalOut());
assertEquals(compressedDataLength, def.getBytesWritten());
}
-
- // BEGIN android-removed
- // We use different default settings for deflating, so our output won't be
- // the
- // same.
- // //Regression Test for HARMONY-2481
- // public void test_deflate_beforeSetInput() throws Exception {
- // Deflater deflater = new Deflater();
- // deflater.finish();
- // byte[] buffer = new byte[1024];
- // assertEquals(8, deflater.deflate(buffer));
- // byte[] expectedBytes = { 120, -100, 3, 0, 0, 0, 0, 1 };
- // for (int i = 0; i < expectedBytes.length; i++) {
- // assertEquals(expectedBytes[i], buffer[i]);
- // }
- // }
- // END android-removed
+
+ //Regression Test for HARMONY-2481
+ public void test_deflate_beforeSetInput() throws Exception {
+ Deflater deflater = new Deflater();
+ deflater.finish();
+ byte[] buffer = new byte[1024];
+ assertEquals(8, deflater.deflate(buffer));
+ byte[] expectedBytes = { 120, -100, 3, 0, 0, 0, 0, 1 };
+ for (int i = 0; i < expectedBytes.length; i++) {
+ assertEquals(expectedBytes[i], buffer[i]);
+ }
+ }
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
index 1e8ddb4..3431510 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
@@ -14,14 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -31,127 +25,85 @@ 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;
-@TestTargetClass(GZIPInputStream.class)
public class GZIPInputStreamTest extends junit.framework.TestCase {
- File resources;
+ File resources;
- class TestGZIPInputStream extends GZIPInputStream {
- TestGZIPInputStream(InputStream in) throws IOException {
- super(in);
- }
+ class TestGZIPInputStream extends GZIPInputStream {
+ TestGZIPInputStream(InputStream in) throws IOException {
+ super(in);
+ }
- TestGZIPInputStream(InputStream in, int size) throws IOException {
- super(in, size);
- }
+ TestGZIPInputStream(InputStream in, int size) throws IOException {
+ super(in, size);
+ }
- Checksum getChecksum() {
- return crc;
- }
+ Checksum getChecksum() {
+ return crc;
+ }
- boolean endofInput() {
- return eos;
- }
- }
+ boolean endofInput() {
+ return eos;
+ }
+ }
- /**
- * @tests java.util.zip.GZIPInputStream#GZIPInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "GZIPInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() {
- // test method java.util.zip.GZIPInputStream.constructor
- try {
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- final URL gInput = new File(resources.toString()
- + "/GZIPInputStream/hyts_gInput.txt.gz").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)
+ */
+ public void test_ConstructorLjava_io_InputStream() {
+ // test method java.util.zip.GZIPInputStream.constructor
+ try {
+ Support_Resources.copyFile(resources, "GZIPInputStream",
+ "hyts_gInput.txt.gz");
+ final URL gInput = new File(resources.toString()
+ + "/GZIPInputStream/hyts_gInput.txt.gz").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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "GZIPInputStream",
- args = {java.io.InputStream.class, int.class}
- )
- public void test_ConstructorLjava_io_InputStreamI() {
- // test method java.util.zip.GZIPInputStream.constructorI
- try {
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- final URL gInput = new File(resources.toString()
- + "/GZIPInputStream/hyts_gInput.txt.gz").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");
- }
- try {
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- final URL gInput = new File(resources.toString()
- + "/GZIPInputStream/hyts_gInput.txt.gz").toURL();
- TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
- .openConnection().getInputStream(), 0);
- fail("Expected IllegalArgumentException");
- } catch (IOException e) {
- fail("an IO error occured while trying to open the input file");
- } catch (IllegalArgumentException ee) {
- // expected
- }
- try {
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- final URL gInput = new File(resources.toString()
- + "/GZIPInputStream/hyts_gInput.txt.gz").toURL();
- TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
- .openConnection().getInputStream(), -1);
- fail("Expected IllegalArgumentException");
- } catch (IOException e) {
- fail("an IO error occured while trying to open the input file");
- } catch (IllegalArgumentException ee) {
- // expected
- }
- }
+ /**
+ * @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.gz");
+ final URL gInput = new File(resources.toString()
+ + "/GZIPInputStream/hyts_gInput.txt.gz").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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- // test method java.util.zip.GZIPInputStream.readBII
- byte orgBuf[] = {'3', '5', '2', 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
+ /**
+ * @tests java.util.zip.GZIPInputStream#read(byte[], int, int)
+ */
+ public void test_read$BII() throws IOException {
+ // test method java.util.zip.GZIPInputStream.readBII
+ byte orgBuf[] = { '3', '5', '2', 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
byte outBuf[] = new byte[100];
int result = 0;
Support_Resources.copyFile(resources, "GZIPInputStream",
@@ -240,14 +192,13 @@ public class GZIPInputStreamTest extends junit.framework.TestCase {
exception = true;
}
assertTrue("Exception expected", exception);
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream zipout = new GZIPOutputStream(baos);
zipout.write(test);
zipout.close();
outBuf = new byte[530];
- GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(baos
- .toByteArray()));
+ GZIPInputStream in= new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));
try {
in.read(outBuf, 530, 1);
fail("Test failed IOOBE was not thrown");
@@ -256,7 +207,7 @@ public class GZIPInputStreamTest extends junit.framework.TestCase {
while (true) {
result = in.read(outBuf, 0, 5);
if (result == -1) {
- // "EOF was reached";
+ //"EOF was reached";
break;
}
}
@@ -264,64 +215,50 @@ public class GZIPInputStreamTest extends junit.framework.TestCase {
result = in.read(null, 100, 1);
result = in.read(outBuf, -100, 1);
result = in.read(outBuf, -1, 1);// 100, 1);
- }
+ }
- /**
- * @tests java.util.zip.GZIPInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- 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.gz");
- String resPath = resources.toString();
- if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') {
+ /**
+ * @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.gz");
+ 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.gz");
- 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",
- 2074883667L, 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);
- }
- }
+ final URL gInput = new URL("file:/" + resPath
+ + "/GZIPInputStream/hyts_gInput.txt.gz");
+ 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",
+ 2074883667L, 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);
+ }
+ }
/**
* Regression test for HARMONY-3703.
* @tests java.util.zip.GZIPInputStream#read()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class}
- )
public void test_read() throws IOException {
GZIPInputStream gis = null;
int result = 0;
@@ -350,11 +287,11 @@ public class GZIPInputStreamTest extends junit.framework.TestCase {
@Override
protected void setUp() {
- resources = Support_Resources.createTempFolder();
- }
+ resources = Support_Resources.createTempFolder();
+ }
- @Override
+ @Override
protected void tearDown() {
- }
+ }
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
index b71ce63..fdcc3fa 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
@@ -14,14 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -29,213 +23,160 @@ import java.io.OutputStream;
import java.util.zip.Checksum;
import java.util.zip.GZIPOutputStream;
-@TestTargetClass(GZIPOutputStream.class)
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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "GZIPOutputStream",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() {
- try {
- FileOutputStream outFile = new FileOutputStream(
- File.createTempFile("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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "GZIPOutputStream",
- args = {java.io.OutputStream.class, int.class}
- )
- public void test_ConstructorLjava_io_OutputStreamI() {
- try {
- FileOutputStream outFile = new FileOutputStream(
- File.createTempFile("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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "finish",
- args = {}
- )
- public void test_finish() {
- // test method java.util.zip.GZIPOutputStream.finish()
- byte byteArray[] = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
- TestGZIPOutputStream outGZIP = null;
- FileOutputStream outFile = null;
- try {
- outFile = new FileOutputStream(
- File.createTempFile("GZIPOutCon", ".txt"));
- 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");
- }
- try {
- outFile = new FileOutputStream("GZIPOutFinish.txt");
- outGZIP = new TestGZIPOutputStream(outFile);
- outFile.close();
-
- outGZIP.finish();
- fail("Expected IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.GZIPOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "close",
- args = {}
- )
- 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(
- File.createTempFile("GZIPOutCon", ".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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() {
- // test method java.util.zip.GZIPOutputStream.writeBII
- byte byteArray[] = {3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w'};
- TestGZIPOutputStream outGZIP = null;
- try {
- FileOutputStream outFile = new FileOutputStream(
- File.createTempFile("GZIPOutCon", ".txt"));
- 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 (IndexOutOfBoundsException ee) {
- 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");
- }
- try {
- outGZIP.write(byteArray, 0, 10);
- fail("Expected IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- @Override
+ 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 (IndexOutOfBoundsException 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");
+ }
+ }
+
+ @Override
protected void setUp() {
- }
+ }
- @Override
+ @Override
protected void tearDown() {
- try {
- File dFile = new File("GZIPOutCon.txt");
- dFile.delete();
- File dFile2 = new File("GZIPOutFinish.txt");
+ try {
+ File dFile = new File("GZIPOutCon.txt");
+ dFile.delete();
+ File dFile2 = new File("GZIPOutFinish.txt");
dFile2.delete();
- File dFile3 = new File("GZIPOutWrite.txt");
+ File dFile3 = new File("GZIPOutWrite.txt");
dFile3.delete();
- File dFile4 = new File("GZIPOutClose2.txt");
- dFile4.delete();
- } catch (SecurityException e) {
- fail("Cannot delete file for security reasons");
- }
- }
+ File dFile4 = new File("GZIPOutClose2.txt");
+ dFile4.delete();
+ } catch (SecurityException e) {
+ fail("Cannot delete file for security reasons");
+ }
+ }
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
index 707f13b..3ab7a64 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
@@ -14,139 +14,107 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import junit.framework.TestCase;
-
-import tests.support.resource.Support_Resources;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.FileOutputStream;
-import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
-@TestTargetClass(InflaterInputStream.class)
-public class InflaterInputStreamTest extends TestCase {
-
- // files hyts_constru(O),hyts_constru(OD),hyts_constru(ODI) needs to be
- // included as resources
- byte outPutBuf[] = new byte[500];
-
- class MyInflaterInputStream extends InflaterInputStream {
- MyInflaterInputStream(InputStream in) {
- super(in);
- }
-
- MyInflaterInputStream(InputStream in, Inflater infl) {
- super(in, infl);
- }
-
- MyInflaterInputStream(InputStream in, Inflater infl, int size) {
- super(in, infl, size);
- }
-
- void myFill() throws IOException {
- fill();
- }
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InflaterInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- byte byteArray[] = new byte[100];
- InputStream infile = Support_Resources.getStream("hyts_constru_OD.txt");
- InflaterInputStream inflatIP = new InflaterInputStream(infile);
-
- inflatIP.read(byteArray, 0, 5);// only suppose to read in 5 bytes
- inflatIP.close();
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream,
- * java.util.zip.Inflater)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InflaterInputStream",
- args = {java.io.InputStream.class, java.util.zip.Inflater.class}
- )
- public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Inflater()
- throws IOException {
- byte byteArray[] = new byte[100];
- InputStream infile = Support_Resources.getStream("hyts_constru_OD.txt");
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate);
-
- inflatIP.read(byteArray, 0, 5);// only suppose to read in 5 bytes
- inflatIP.close();
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream,
- * java.util.zip.Inflater, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IllegalArgumentException checking missed.",
- method = "InflaterInputStream",
- args = {java.io.InputStream.class, java.util.zip.Inflater.class, int.class}
- )
- public void test_ConstructorLjava_io_InputStreamLjava_util_zip_InflaterI()
- throws IOException {
- int result = 0;
- int buffer[] = new int[500];
- InputStream infile = Support_Resources
- .getStream("hyts_constru_ODI.txt");
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate,
- 1);
-
- int i = 0;
- while ((result = inflatIP.read()) != -1) {
- buffer[i] = result;
- i++;
- }
- inflatIP.close();
+import junit.framework.TestCase;
+import tests.support.resource.Support_Resources;
- try {
- inflatIP = new InflaterInputStream(infile, inflate, -1);
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException ee) {
- // expected
- }
+public class InflaterInputStreamTest extends TestCase {
- }
+ // files hyts_constru(O),hyts_constru(OD),hyts_constru(ODI) needs to be
+ // included as resources
+ // android-changed: we removed the parentheses for the benefit of our broken build system.
+ byte outPutBuf[] = new byte[500];
+
+ class MyInflaterInputStream extends InflaterInputStream {
+ MyInflaterInputStream(InputStream in) {
+ super(in);
+ }
+
+ MyInflaterInputStream(InputStream in, Inflater infl) {
+ super(in, infl);
+ }
+
+ MyInflaterInputStream(InputStream in, Inflater infl, int size) {
+ super(in, infl, size);
+ }
+
+ void myFill() throws IOException {
+ fill();
+ }
+ }
+
+ /**
+ * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream)
+ */
+ public void test_ConstructorLjava_io_InputStream() throws IOException {
+ //FIXME This test doesn't pass in Harmony classlib or Sun 5.0_7 RI
+ /*
+ int result = 0;
+ int buffer[] = new int[500];
+ InputStream infile = Support_Resources
+ .getStream("hyts_constru_O.txt"); // android-changed
+
+ InflaterInputStream inflatIP = new InflaterInputStream(infile);
+
+ int i = 0;
+ while ((result = inflatIP.read()) != -1) {
+ buffer[i] = result;
+ i++;
+ }
+ inflatIP.close();
+ */
+ }
+
+ /**
+ * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream,
+ * java.util.zip.Inflater)
+ */
+ public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Inflater() throws IOException {
+ byte byteArray[] = new byte[100];
+ InputStream infile = Support_Resources.getStream("hyts_constru_OD.txt"); // android-changed
+ Inflater inflate = new Inflater();
+ InflaterInputStream inflatIP = new InflaterInputStream(infile,
+ inflate);
+
+ inflatIP.read(byteArray, 0, 5);// only suppose to read in 5 bytes
+ inflatIP.close();
+ }
+
+ /**
+ * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream,
+ * java.util.zip.Inflater, int)
+ */
+ public void test_ConstructorLjava_io_InputStreamLjava_util_zip_InflaterI() throws IOException {
+ int result = 0;
+ int buffer[] = new int[500];
+ InputStream infile = Support_Resources.getStream("hyts_constru_ODI.txt"); // android-changed
+ Inflater inflate = new Inflater();
+ InflaterInputStream inflatIP = new InflaterInputStream(infile,
+ inflate, 1);
+
+ int i = 0;
+ while ((result = inflatIP.read()) != -1) {
+ buffer[i] = result;
+ i++;
+ }
+ inflatIP.close();
+ }
/**
* @tests java.util.zip.InflaterInputStream#mark(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "mark",
- args = {int.class}
- )
public void test_markI() {
InputStream is = new ByteArrayInputStream(new byte[10]);
InflaterInputStream iis = new InflaterInputStream(is);
@@ -159,12 +127,6 @@ public class InflaterInputStreamTest extends TestCase {
/**
* @tests java.util.zip.InflaterInputStream#markSupported()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "markSupported",
- args = {}
- )
public void test_markSupported() {
InputStream is = new ByteArrayInputStream(new byte[10]);
InflaterInputStream iis = new InflaterInputStream(is);
@@ -172,43 +134,32 @@ public class InflaterInputStreamTest extends TestCase {
assertTrue(is.markSupported());
}
- /**
+ /**
* @tests java.util.zip.InflaterInputStream#read()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- int result = 0;
- int buffer[] = new int[500];
- byte orgBuffer[] = {1, 3, 4, 7, 8};
- InputStream infile = Support_Resources.getStream("hyts_constru_OD.txt");
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate);
-
- int i = 0;
- while ((result = inflatIP.read()) != -1) {
- buffer[i] = result;
- i++;
- }
- inflatIP.close();
-
- for (int j = 0; j < orgBuffer.length; j++) {
- assertTrue(
- "original compressed data did not equal decompressed data",
- buffer[j] == orgBuffer[j]);
- }
- inflatIP.close();
- try {
- inflatIP.read();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected.
- }
- }
+ public void test_read() throws IOException {
+ int result = 0;
+ int buffer[] = new int[500];
+ byte orgBuffer[] = { 1, 3, 4, 7, 8 };
+ InputStream infile = Support_Resources
+ .getStream("hyts_constru_OD.txt"); // android-changed
+ Inflater inflate = new Inflater();
+ InflaterInputStream inflatIP = new InflaterInputStream(infile,
+ inflate);
+
+ int i = 0;
+ while ((result = inflatIP.read()) != -1) {
+ buffer[i] = result;
+ i++;
+ }
+ inflatIP.close();
+
+ for (int j = 0; j < orgBuffer.length; j++) {
+ assertTrue(
+ "original compressed data did not equal decompressed data",
+ buffer[j] == orgBuffer[j]);
+ }
+ }
public void testAvailableNonEmptySource() throws Exception {
// this byte[] is a deflation of these bytes: { 1, 3, 4, 6 }
@@ -246,24 +197,10 @@ public class InflaterInputStreamTest extends TestCase {
assertEquals(0, in.available());
}
- /**
- * @tests java.util.zip.InflaterInputStream#read(byte[], int, int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException & ZipException checking missed. Additional tests for fill method is not needed.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException & ZipException checking missed. Additional tests for fill method is not needed.",
- method = "fill",
- args = {}
- )
- })
- public void test_read$BII() throws IOException {
+ /**
+ * @tests java.util.zip.InflaterInputStream#read(byte[], int, int)
+ */
+ public void test_read$BII() throws IOException{
byte[] test = new byte[507];
for (int i = 0; i < 256; i++) {
test[i] = (byte) i;
@@ -282,7 +219,7 @@ public class InflaterInputStreamTest extends TestCase {
while (true) {
result = iis.read(outBuf, 0, 5);
if (result == -1) {
- // "EOF was reached";
+ //"EOF was reached";
break;
}
}
@@ -292,26 +229,8 @@ public class InflaterInputStreamTest extends TestCase {
} catch (IndexOutOfBoundsException e) {
// expected;
}
- iis.close();
- }
+ }
- /**
- * @tests java.util.zip.InflaterInputStream#read(byte[], int, int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "fill",
- args = {}
- )
- })
public void test_read$BII2() throws IOException {
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
@@ -329,20 +248,6 @@ public class InflaterInputStreamTest extends TestCase {
}
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "fill",
- args = {}
- )
- })
public void test_read$BII3() throws IOException {
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
@@ -362,12 +267,6 @@ public class InflaterInputStreamTest extends TestCase {
/**
* @tests java.util.zip.InflaterInputStream#reset()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
public void test_reset() {
InputStream is = new ByteArrayInputStream(new byte[10]);
InflaterInputStream iis = new InflaterInputStream(is);
@@ -378,135 +277,110 @@ public class InflaterInputStreamTest extends TestCase {
// correct
}
}
-
- /**
- * @tests java.util.zip.InflaterInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- InputStream is = Support_Resources.getStream("hyts_available.tst");
- InflaterInputStream iis = new InflaterInputStream(is);
-
- // Tests for skipping a negative number of bytes.
- try {
- iis.skip(-3);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
+
+ /**
+ * @tests java.util.zip.InflaterInputStream#skip(long)
+ */
+ public void test_skipJ() throws IOException {
+ InputStream is = Support_Resources.getStream("hyts_available.tst");
+ InflaterInputStream iis = new InflaterInputStream(is);
+
+ // Tests for skipping a negative number of bytes.
+ try {
+ iis.skip(-3);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
// Expected
- }
- assertEquals("Incorrect Byte Returned.", 5, iis.read());
+ }
+ assertEquals("Incorrect Byte Returned.", 5, iis.read());
- try {
- iis.skip(Integer.MIN_VALUE);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
+ try {
+ iis.skip(Integer.MIN_VALUE);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
// Expected
- }
- assertEquals("Incorrect Byte Returned.", 4, iis.read());
+ }
+ assertEquals("Incorrect Byte Returned.", 4, iis.read());
- // Test to make sure the correct number of bytes were skipped
- assertEquals("Incorrect Number Of Bytes Skipped.", 3, iis.skip(3));
+ // Test to make sure the correct number of bytes were skipped
+ assertEquals("Incorrect Number Of Bytes Skipped.", 3, iis.skip(3));
- // Test to see if the number of bytes skipped returned is true.
- assertEquals("Incorrect Byte Returned.", 7, iis.read());
+ // Test to see if the number of bytes skipped returned is true.
+ assertEquals("Incorrect Byte Returned.", 7, iis.read());
- assertEquals("Incorrect Number Of Bytes Skipped.", 0, iis.skip(0));
- assertEquals("Incorrect Byte Returned.", 0, iis.read());
+ assertEquals("Incorrect Number Of Bytes Skipped.", 0, iis.skip(0));
+ assertEquals("Incorrect Byte Returned.", 0, iis.read());
- // Test for skipping more bytes than available in the stream
- assertEquals("Incorrect Number Of Bytes Skipped.", 2, iis.skip(4));
- assertEquals("Incorrect Byte Returned.", -1, iis.read());
- iis.close();
- }
+ // Test for skipping more bytes than available in the stream
+ assertEquals("Incorrect Number Of Bytes Skipped.", 2, iis.skip(4));
+ assertEquals("Incorrect Byte Returned.", -1, iis.read());
+ iis.close();
+ }
- /**
- * @tests java.util.zip.InflaterInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException checking missed.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ2() throws IOException {
- int result = 0;
- int buffer[] = new int[100];
- byte orgBuffer[] = {1, 3, 4, 7, 8};
+ /**
+ * @tests java.util.zip.InflaterInputStream#skip(long)
+ */
+ public void test_skipJ2() throws IOException {
+ int result = 0;
+ int buffer[] = new int[100];
+ byte orgBuffer[] = { 1, 3, 4, 7, 8 };
// testing for negative input to skip
- InputStream infile = Support_Resources.getStream("hyts_constru_OD.txt");
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile, inflate,
- 10);
- long skip;
- try {
- skip = inflatIP.skip(Integer.MIN_VALUE);
- fail("Expected IllegalArgumentException when skip() is called with negative parameter");
- } catch (IllegalArgumentException e) {
+ InputStream infile = Support_Resources
+ .getStream("hyts_constru_OD.txt"); // android-changed
+ Inflater inflate = new Inflater();
+ InflaterInputStream inflatIP = new InflaterInputStream(infile,
+ inflate, 10);
+ long skip;
+ try {
+ skip = inflatIP.skip(Integer.MIN_VALUE);
+ fail("Expected IllegalArgumentException when skip() is called with negative parameter");
+ } catch (IllegalArgumentException e) {
// Expected
- }
- inflatIP.close();
-
- // testing for number of bytes greater than input.
- InputStream infile2 = Support_Resources
- .getStream("hyts_constru_OD.txt");
- InflaterInputStream inflatIP2 = new InflaterInputStream(infile2);
-
- // looked at how many bytes the skip skipped. It is
- // 5 and its supposed to be the entire input stream.
-
- skip = inflatIP2.skip(Integer.MAX_VALUE);
- // System.out.println(skip);
- assertEquals("method skip() returned wrong number of bytes skipped", 5,
- skip);
-
- // test for skipping of 2 bytes
- InputStream infile3 = Support_Resources
- .getStream("hyts_constru_OD.txt");
- InflaterInputStream inflatIP3 = new InflaterInputStream(infile3);
- skip = inflatIP3.skip(2);
- assertEquals(
- "the number of bytes returned by skip did not correspond with its input parameters",
- 2, skip);
- int i = 0;
- result = 0;
- while ((result = inflatIP3.read()) != -1) {
- buffer[i] = result;
- i++;
- }
- inflatIP2.close();
-
- for (int j = 2; j < orgBuffer.length; j++) {
- assertTrue(
- "original compressed data did not equal decompressed data",
- buffer[j - 2] == orgBuffer[j]);
- }
-
- try {
- inflatIP2.skip(4);
- fail("IOException expected.");
- } catch (IOException ee) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- InputStream is = Support_Resources.getStream("hyts_available.tst");
- InflaterInputStream iis = new InflaterInputStream(is);
+ }
+ inflatIP.close();
+
+ // testing for number of bytes greater than input.
+ InputStream infile2 = Support_Resources
+ .getStream("hyts_constru_OD.txt"); // android-changed
+ InflaterInputStream inflatIP2 = new InflaterInputStream(infile2);
+
+ // looked at how many bytes the skip skipped. It is
+ // 5 and its supposed to be the entire input stream.
+
+ skip = inflatIP2.skip(Integer.MAX_VALUE);
+ // System.out.println(skip);
+ assertEquals("method skip() returned wrong number of bytes skipped",
+ 5, skip);
+
+ // test for skipping of 2 bytes
+ InputStream infile3 = Support_Resources
+ .getStream("hyts_constru_OD.txt"); // android-changed
+ InflaterInputStream inflatIP3 = new InflaterInputStream(infile3);
+ skip = inflatIP3.skip(2);
+ assertEquals("the number of bytes returned by skip did not correspond with its input parameters",
+ 2, skip);
+ int i = 0;
+ result = 0;
+ while ((result = inflatIP3.read()) != -1) {
+ buffer[i] = result;
+ i++;
+ }
+ inflatIP2.close();
+
+ for (int j = 2; j < orgBuffer.length; j++) {
+ assertTrue(
+ "original compressed data did not equal decompressed data",
+ buffer[j - 2] == orgBuffer[j]);
+ }
+ }
+
+ /**
+ * @tests java.util.zip.InflaterInputStream#available()
+ */
+ public void test_available() throws IOException {
+ InputStream is = Support_Resources.getStream("hyts_available.tst");
+ InflaterInputStream iis = new InflaterInputStream(is);
int available;
for (int i = 0; i < 11; i++) {
@@ -519,31 +393,24 @@ public class InflaterInputStreamTest extends TestCase {
}
}
- iis.close();
- try {
- iis.available();
- fail("available after close should throw IOException.");
- } catch (IOException e) {
+ iis.close();
+ try {
+ iis.available();
+ fail("available after close should throw IOException.");
+ } catch (IOException e) {
// Expected
- }
- }
+ }
+ }
- /**
- * @tests java.util.zip.InflaterInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException can not be tested.",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- InflaterInputStream iin = new InflaterInputStream(
- new ByteArrayInputStream(new byte[0]));
- iin.close();
+ /**
+ * @tests java.util.zip.InflaterInputStream#close()
+ */
+ public void test_close() throws IOException {
+ InflaterInputStream iin = new InflaterInputStream(
+ new ByteArrayInputStream(new byte[0]));
+ iin.close();
// test for exception
- iin.close();
-
- }
+ iin.close();
+ }
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
index cd5d538..49be8d0 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
@@ -14,17 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.Arrays;
import java.util.zip.Adler32;
import java.io.UnsupportedEncodingException;
import java.util.zip.DataFormatException;
@@ -34,345 +29,292 @@ import java.util.zip.ZipException;
import tests.support.resource.Support_Resources;
-@TestTargetClass(Inflater.class)
public class InflaterTest extends junit.framework.TestCase {
- byte outPutBuff1[] = new byte[500];
-
- byte outPutDiction[] = new byte[500];
-
- /**
- * @tests java.util.zip.Inflater#end()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "end",
- args = {}
- )
- public void test_end() {
- // test method of java.util.zip.inflater.end()
- byte byteArray[] = {5, 2, 3, 7, 8};
-
- int r = 0;
- Inflater inflate = new Inflater();
- inflate.setInput(byteArray);
- inflate.end();
- try {
- inflate.reset();
- inflate.setInput(byteArray);
- } catch (NullPointerException e) {
- r = 1;
- }
- assertEquals("inflate can still be used after end is called", 1, r);
-
- Inflater i = new Inflater();
- i.end();
- // check for exception
- i.end();
- }
-
- /**
- * @tests java.util.zip.Inflater#finished()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "finished",
- args = {}
- )
- public void test_finished() {
- // test method of java.util.zip.inflater.finished()
- byte byteArray[] = {1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5'};
- Inflater inflate = new Inflater(false);
- byte outPutInf[] = new byte[500];
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
-
- inflate.inflate(outPutInf);
- }
- assertTrue(
- "the method finished() returned false when no more data needs to be decompressed",
- inflate.finished());
- } 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]);
- }
- assertEquals(
- "final decompressed data contained more bytes than original - finished()",
- 0, outPutInf[byteArray.length]);
- }
-
- /**
- * @tests java.util.zip.Inflater#getAdler()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getAdler",
- args = {}
- )
- public void test_getAdler() {
- // test method of java.util.zip.inflater.getAdler()
- byte dictionaryArray[] = {'e', 'r', 't', 'a', 'b', 2, 3};
-
- Inflater inflateDiction = new Inflater();
- inflateDiction.setInput(outPutDiction);
- if (inflateDiction.needsDictionary() == true) {
- // getting the checkSum value through the Adler32 class
- Adler32 adl = new Adler32();
- adl.update(dictionaryArray);
- 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 == inflateDiction.getAdler());
- }
- }
+ byte outPutBuff1[] = new byte[500];
+
+ byte outPutDiction[] = new byte[500];
+
+ /**
+ * @tests java.util.zip.Inflater#end()
+ */
+ public void test_end() {
+ // test method of java.util.zip.inflater.end()
+ byte byteArray[] = { 5, 2, 3, 7, 8 };
+
+ int r = 0;
+ Inflater inflate = new Inflater();
+ inflate.setInput(byteArray);
+ inflate.end();
+ try {
+ inflate.reset();
+ inflate.setInput(byteArray);
+ } catch (NullPointerException e) {
+ r = 1;
+ }
+ assertEquals("inflate can still be used after end is called", 1, r);
+
+ Inflater i = new Inflater();
+ i.end();
+ // check for exception
+ i.end();
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#finished()
+ */
+ public void test_finished() {
+ // test method of java.util.zip.inflater.finished()
+ byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
+ Inflater inflate = new Inflater(false);
+ byte outPutInf[] = new byte[500];
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuff1);
+ }
+
+ inflate.inflate(outPutInf);
+ }
+ assertTrue(
+ "the method finished() returned false when no more data needs to be decompressed",
+ inflate.finished());
+ } 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]);
+ }
+ assertEquals("final decompressed data contained more bytes than original - finished()",
+ 0, outPutInf[byteArray.length]);
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#getAdler()
+ */
+ public void test_getAdler() {
+ // test method of java.util.zip.inflater.getAdler()
+ byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3 };
+
+ Inflater inflateDiction = new Inflater();
+ inflateDiction.setInput(outPutDiction);
+ if (inflateDiction.needsDictionary() == true) {
+ // getting the checkSum value through the Adler32 class
+ Adler32 adl = new Adler32();
+ adl.update(dictionaryArray);
+ 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 == inflateDiction.getAdler());
+ }
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#getRemaining()
+ */
+ public void test_getRemaining() {
+ // test method of java.util.zip.inflater.getRemaining()
+ byte byteArray[] = { 1, 3, 5, 6, 7 };
+ Inflater inflate = new Inflater();
+ assertEquals("upon creating an instance of inflate, getRemaining returned a non zero value",
+ 0, inflate.getRemaining());
+ inflate.setInput(byteArray);
+ assertTrue(
+ "getRemaining returned zero when there is input in the input buffer",
+ inflate.getRemaining() != 0);
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#getTotalIn()
+ */
+ public void test_getTotalIn() {
+ // test method of java.util.zip.inflater.getTotalIn()
+ // creating the decompressed data
+ byte outPutBuf[] = new byte[500];
+ byte byteArray[] = { 1, 3, 4, 7, 8 };
+ byte outPutInf[] = new byte[500];
+ 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);
+ }
+
+ Inflater inflate = new Inflater();
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuf);
+ }
+
+ inflate.inflate(outPutInf);
+ }
+ } catch (DataFormatException e) {
+ fail("Input to inflate is invalid or corrupted - getTotalIn");
+ }
+ // System.out.print(deflate.getTotalOut() + " " + inflate.getTotalIn());
+ assertTrue(
+ "the total byte in outPutBuf did not equal the byte returned in getTotalIn",
+ inflate.getTotalIn() == deflate.getTotalOut());
+
+ Inflater inflate2 = new Inflater();
+ int offSet = 0;// seems only can start as 0
+ int length = 4;
+ try {
+ // seems no while loops allowed
+ if (inflate2.needsInput()) {
+ inflate2.setInput(outPutBuff1, offSet, length);
+ }
+
+ inflate2.inflate(outPutInf);
+
+ } catch (DataFormatException e) {
+ fail("Input to inflate is invalid or corrupted - getTotalIn");
+ }
+ // System.out.print(inflate2.getTotalIn() + " " + length);
+ assertTrue(
+ "total byte dictated by length did not equal byte returned in getTotalIn",
+ inflate2.getTotalIn() == length);
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#getTotalOut()
+ */
+ public void test_getTotalOut() {
+ // test method of java.util.zip.inflater.Inflater()
+ // creating the decompressed data
+ byte outPutBuf[] = new byte[500];
+ byte byteArray[] = { 1, 3, 4, 7, 8 };
+ int y = 0;
+ 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);
+ }
+
+ Inflater inflate = new Inflater();
+ byte outPutInf[] = new byte[500];
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuf);
+ }
+
+ y += inflate.inflate(outPutInf);
+ }
+ } catch (DataFormatException e) {
+ fail("Input to inflate is invalid or corrupted - getTotalIn");
+ }
+
+ assertTrue(
+ "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
+ y == inflate.getTotalOut());
+ assertTrue(
+ "the total number of bytes to be compressed does not equal the total bytes decompressed",
+ inflate.getTotalOut() == deflate.getTotalIn());
+
+ // testing inflate(byte,int,int)
+ inflate.reset();
+ y = 0;
+ int offSet = 0;// seems only can start as 0
+ int length = 4;
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuf);
+ }
+
+ y += inflate.inflate(outPutInf, offSet, length);
+ }
+ } catch (DataFormatException e) {
+ System.out
+ .println("Input to inflate is invalid or corrupted - getTotalIn");
+ }
+ assertTrue(
+ "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
+ y == inflate.getTotalOut());
+ assertTrue(
+ "the total number of bytes to be compressed does not equal the total bytes decompressed",
+ inflate.getTotalOut() == deflate.getTotalIn());
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#inflate(byte[])
+ */
+ public void test_inflate$B() {
+ // test method of java.util.zip.inflater.inflate(byte)
+
+ byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
+ byte outPutInf[] = new byte[500];
+ Inflater inflate = new Inflater();
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuff1);
+ }
+ inflate.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]);
+ }
+ assertEquals("final decompressed data contained more bytes than original - inflateB",
+ 0, outPutInf[byteArray.length]);
+ // testing for an empty input array
+ byte outPutBuf[] = new byte[500];
+ byte emptyArray[] = new byte[11];
+ int x = 0;
+ Deflater defEmpty = new Deflater(3);
+ defEmpty.setInput(emptyArray);
+ while (!(defEmpty.needsInput())) {
+ x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
+ }
+ defEmpty.finish();
+ while (!(defEmpty.finished())) {
+ x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
+ }
+ assertTrue(
+ "the total number of byte from deflate did not equal getTotalOut - inflate(byte)",
+ x == defEmpty.getTotalOut());
+ assertTrue(
+ "the number of input byte from the array did not correspond with getTotalIn - inflate(byte)",
+ defEmpty.getTotalIn() == emptyArray.length);
+ Inflater infEmpty = new Inflater();
+ try {
+ while (!(infEmpty.finished())) {
+ if (infEmpty.needsInput()) {
+ infEmpty.setInput(outPutBuf);
+ }
+ infEmpty.inflate(outPutInf);
+ }
+ } catch (DataFormatException e) {
+ fail("Invalid input to be decompressed");
+ }
+ for (int i = 0; i < emptyArray.length; i++) {
+ assertTrue(
+ "Final decompressed data does not equal the original data",
+ emptyArray[i] == outPutInf[i]);
+ assertEquals("Final decompressed data does not equal zero",
+ 0, outPutInf[i]);
+ }
+ assertEquals("Final decompressed data contains more element than original data",
+ 0, outPutInf[emptyArray.length]);
+ }
- /**
- * @tests java.util.zip.Inflater#getRemaining()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getRemaining",
- args = {}
- )
- public void test_getRemaining() {
- // test method of java.util.zip.inflater.getRemaining()
- byte byteArray[] = {1, 3, 5, 6, 7};
- Inflater inflate = new Inflater();
- assertEquals(
- "upon creating an instance of inflate, getRemaining returned a non zero value",
- 0, inflate.getRemaining());
- inflate.setInput(byteArray);
- assertTrue(
- "getRemaining returned zero when there is input in the input buffer",
- inflate.getRemaining() != 0);
- }
-
- /**
- * @tests java.util.zip.Inflater#getTotalIn()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTotalIn",
- args = {}
- )
- public void test_getTotalIn() {
- // test method of java.util.zip.inflater.getTotalIn()
- // creating the decompressed data
- byte outPutBuf[] = new byte[500];
- byte byteArray[] = {1, 3, 4, 7, 8};
- byte outPutInf[] = new byte[500];
- 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);
- }
-
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuf);
- }
-
- inflate.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Input to inflate is invalid or corrupted - getTotalIn");
- }
- // System.out.print(deflate.getTotalOut() + " " + inflate.getTotalIn());
- assertTrue(
- "the total byte in outPutBuf did not equal the byte returned in getTotalIn",
- inflate.getTotalIn() == deflate.getTotalOut());
-
- Inflater inflate2 = new Inflater();
- int offSet = 0;// seems only can start as 0
- int length = 4;
- try {
- // seems no while loops allowed
- if (inflate2.needsInput()) {
- inflate2.setInput(outPutBuff1, offSet, length);
- }
-
- inflate2.inflate(outPutInf);
-
- } catch (DataFormatException e) {
- fail("Input to inflate is invalid or corrupted - getTotalIn");
- }
- // System.out.print(inflate2.getTotalIn() + " " + length);
- assertTrue(
- "total byte dictated by length did not equal byte returned in getTotalIn",
- inflate2.getTotalIn() == length);
- }
-
- /**
- * @tests java.util.zip.Inflater#getTotalOut()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTotalOut",
- args = {}
- )
- public void test_getTotalOut() {
- // test method of java.util.zip.inflater.Inflater()
- // creating the decompressed data
- byte outPutBuf[] = new byte[500];
- byte byteArray[] = {1, 3, 4, 7, 8};
- int y = 0;
- 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);
- }
-
- Inflater inflate = new Inflater();
- byte outPutInf[] = new byte[500];
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuf);
- }
-
- y += inflate.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Input to inflate is invalid or corrupted - getTotalIn");
- }
-
- assertTrue(
- "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
- y == inflate.getTotalOut());
- assertTrue(
- "the total number of bytes to be compressed does not equal the total bytes decompressed",
- inflate.getTotalOut() == deflate.getTotalIn());
-
- // testing inflate(byte,int,int)
- inflate.reset();
- y = 0;
- int offSet = 0;// seems only can start as 0
- int length = 4;
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuf);
- }
-
- y += inflate.inflate(outPutInf, offSet, length);
- }
- } catch (DataFormatException e) {
- System.out
- .println("Input to inflate is invalid or corrupted - getTotalIn");
- }
- assertTrue(
- "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
- y == inflate.getTotalOut());
- assertTrue(
- "the total number of bytes to be compressed does not equal the total bytes decompressed",
- inflate.getTotalOut() == deflate.getTotalIn());
- }
-
- /**
- * @tests java.util.zip.Inflater#inflate(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "DataFormatException checking missed.",
- method = "inflate",
- args = {byte[].class}
- )
- public void test_inflate$B() {
- // test method of java.util.zip.inflater.inflate(byte)
-
- byte byteArray[] = {1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5'};
- byte outPutInf[] = new byte[500];
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- inflate.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]);
- }
- assertEquals(
- "final decompressed data contained more bytes than original - inflateB",
- 0, outPutInf[byteArray.length]);
- // testing for an empty input array
- byte outPutBuf[] = new byte[500];
- byte emptyArray[] = new byte[11];
- int x = 0;
- Deflater defEmpty = new Deflater(3);
- defEmpty.setInput(emptyArray);
- while (!(defEmpty.needsInput())) {
- x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- defEmpty.finish();
- while (!(defEmpty.finished())) {
- x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- assertTrue(
- "the total number of byte from deflate did not equal getTotalOut - inflate(byte)",
- x == defEmpty.getTotalOut());
- assertTrue(
- "the number of input byte from the array did not correspond with getTotalIn - inflate(byte)",
- defEmpty.getTotalIn() == emptyArray.length);
- Inflater infEmpty = new Inflater();
- try {
- while (!(infEmpty.finished())) {
- if (infEmpty.needsInput()) {
- infEmpty.setInput(outPutBuf);
- }
- infEmpty.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < emptyArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- emptyArray[i] == outPutInf[i]);
- assertEquals("Final decompressed data does not equal zero", 0,
- outPutInf[i]);
- }
- assertEquals(
- "Final decompressed data contains more element than original data",
- 0, outPutInf[emptyArray.length]);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "inflate",
- args = {byte[].class}
- )
public void test_inflate$B1() {
byte codedData[] = {
120, -38, 75, -54, 73, -52, 80, 40, 46, 41, -54, -52, 75, 87,
@@ -408,82 +350,53 @@ public class InflaterTest extends junit.framework.TestCase {
infl2.end();
}
- /**
- * @tests java.util.zip.Inflater#Inflater()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Inflater",
- args = {}
- )
- public void test_Constructor() {
- // test method of java.util.zip.inflater.Inflater()
- Inflater inflate = new Inflater();
- assertNotNull("failed to create the instance of inflater",
- inflate);
- }
-
- /**
- * @tests java.util.zip.Inflater#inflate(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "DataFormatException checking missed.",
- method = "inflate",
- args = {byte[].class, int.class, int.class}
- )
- public void test_inflate$BII() {
- // test method of java.util.zip.inflater.inflate(byte,int,int)
-
- byte byteArray[] = {1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5'};
- byte outPutInf[] = new byte[100];
- int y = 0;
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- y += inflate.inflate(outPutInf, y, outPutInf.length - y);
- }
- } 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]);
- }
- assertEquals(
- "final decompressed data contained more bytes than original - inflateB",
- 0, outPutInf[byteArray.length]);
-
- // test boundary checks
- inflate.reset();
- int r = 0;
- int offSet = 0;
- int lengthError = 101;
- try {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- inflate.inflate(outPutInf, offSet, lengthError);
-
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("out of bounds error did not get caught", 1, r);
- }
+ /**
+ * @tests java.util.zip.Inflater#inflate(byte[], int, int)
+ */
+ public void test_inflate$BII() {
+ // test method of java.util.zip.inflater.inflate(byte,int,int)
+
+ byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
+ byte outPutInf[] = new byte[100];
+ int y = 0;
+ Inflater inflate = new Inflater();
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuff1);
+ }
+ y += inflate.inflate(outPutInf, y, outPutInf.length - y);
+ }
+ } 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]);
+ }
+ assertEquals("final decompressed data contained more bytes than original - inflateB",
+ 0, outPutInf[byteArray.length]);
+
+ // test boundary checks
+ inflate.reset();
+ int r = 0;
+ int offSet = 0;
+ int lengthError = 101;
+ try {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuff1);
+ }
+ inflate.inflate(outPutInf, offSet, lengthError);
+
+ } catch (DataFormatException e) {
+ fail("Invalid input to be decompressed");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ r = 1;
+ }
+ assertEquals("out of bounds error did not get caught", 1, r);
+ }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "inflate",
- args = {byte[].class, int.class, int.class}
- )
public void test_inflate$BII1() {
byte codedData[] = {
120, -38, 75, -54, 73, -52, 80, 40, 46, 41, -54, -52, 75, 87,
@@ -519,271 +432,292 @@ public class InflaterTest extends junit.framework.TestCase {
infl2.end();
}
- /**
- * @tests java.util.zip.Inflater#Inflater(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Inflater",
- args = {boolean.class}
- )
- public void test_ConstructorZ() {
- // test method of java.util.zip.inflater.Inflater(boolean)
- // note does not throw exception if deflater has a header, but inflater
- // doesn't or vice versa.
- byte byteArray[] = {1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5'};
- Inflater inflate = new Inflater(true);
- assertNotNull("failed to create the instance of inflater", inflate);
- byte outPutInf[] = new byte[500];
- int r = 0;
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
-
- inflate.inflate(outPutInf);
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertEquals(
- "the output array from inflate should contain 0 because the header of inflate and deflate did not match, but this failed",
- 0, outPutBuff1[i]);
- }
- } catch (DataFormatException e) {
- r = 1;
- }
- assertEquals(
- "Error: exception should be thrown because of header inconsistency",
- 1, r);
-
- }
-
- /**
- * @tests java.util.zip.Inflater#needsDictionary()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "needsDictionary",
- args = {}
- )
- public void test_needsDictionary() {
- // test method of java.util.zip.inflater.needsDictionary()
- // note: this flag is set after inflate is called
- byte outPutInf[] = new byte[500];
-
- // testing with dictionary set.
- Inflater inflateDiction = new Inflater();
- if (inflateDiction.needsInput()) {
- inflateDiction.setInput(outPutDiction);
- }
- try {
- assertEquals("should return 0 because needs dictionary", 0,
- inflateDiction.inflate(outPutInf));
- } catch (DataFormatException e) {
- fail("Should not cause exception");
- }
- assertTrue(
- "method needsDictionary returned false when dictionary was used in deflater",
- inflateDiction.needsDictionary());
-
- // testing without dictionary
- Inflater inflate = new Inflater();
- try {
- inflate.setInput(outPutBuff1);
- inflate.inflate(outPutInf);
- assertFalse(
- "method needsDictionary returned true when dictionary was not used in deflater",
- inflate.needsDictionary());
- } catch (DataFormatException e) {
- fail("Input to inflate is invalid or corrupted - needsDictionary");
- }
+ /**
+ * @tests java.util.zip.Inflater#Inflater()
+ */
+ public void test_Constructor() {
+ // test method of java.util.zip.inflater.Inflater()
+ Inflater inflate = new Inflater();
+ assertNotNull("failed to create the instance of inflater",
+ inflate);
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#Inflater(boolean)
+ */
+ public void test_ConstructorZ() {
+ // test method of java.util.zip.inflater.Inflater(boolean)
+ // note does not throw exception if deflater has a header, but inflater
+ // doesn't or vice versa.
+ byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
+ Inflater inflate = new Inflater(true);
+ assertNotNull("failed to create the instance of inflater", inflate);
+ byte outPutInf[] = new byte[500];
+ int r = 0;
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuff1);
+ }
+
+ inflate.inflate(outPutInf);
+ }
+ for (int i = 0; i < byteArray.length; i++) {
+ assertEquals("the output array from inflate should contain 0 because the header of inflate and deflate did not match, but this failed",
+ 0, outPutBuff1[i]);
+ }
+ } catch (DataFormatException e) {
+ r = 1;
+ }
+ assertEquals("Error: exception should be thrown because of header inconsistency",
+ 1, r);
+
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#needsDictionary()
+ */
+ public void test_needsDictionary() {
+ // test method of java.util.zip.inflater.needsDictionary()
+ // note: this flag is set after inflate is called
+ byte outPutInf[] = new byte[500];
+
+ // testing with dictionary set.
+ Inflater inflateDiction = new Inflater();
+ if (inflateDiction.needsInput()) {
+ inflateDiction.setInput(outPutDiction);
+ }
+ try {
+ assertEquals("should return 0 because needs dictionary",
+ 0, inflateDiction.inflate(outPutInf));
+ } catch (DataFormatException e) {
+ fail("Should not cause exception");
+ }
+ assertTrue(
+ "method needsDictionary returned false when dictionary was used in deflater",
+ inflateDiction.needsDictionary());
+
+ // testing without dictionary
+ Inflater inflate = new Inflater();
+ try {
+ inflate.setInput(outPutBuff1);
+ inflate.inflate(outPutInf);
+ assertFalse(
+ "method needsDictionary returned true when dictionary was not used in deflater",
+ inflate.needsDictionary());
+ } catch (DataFormatException e) {
+ fail(
+ "Input to inflate is invalid or corrupted - needsDictionary");
+ }
// Regression test for HARMONY-86
Inflater inf = new Inflater();
assertFalse(inf.needsDictionary());
- assertEquals(0, inf.getTotalIn());
- assertEquals(0, inf.getTotalOut());
- assertEquals(0, inf.getBytesRead());
- assertEquals(0, inf.getBytesWritten());
- }
-
- /**
- * @tests java.util.zip.Inflater#needsInput()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "needsInput",
- args = {}
- )
- public void test_needsInput() {
- // test method of java.util.zip.inflater.needsInput()
- Inflater inflate = new Inflater();
- assertTrue(
- "needsInput give the wrong boolean value as a result of no input buffer",
- inflate.needsInput());
-
- byte byteArray[] = {2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9};
- inflate.setInput(byteArray);
- assertFalse(
- "methodNeedsInput returned true when the input buffer is full",
- inflate.needsInput());
-
- inflate.reset();
- byte byteArrayEmpty[] = new byte[0];
- inflate.setInput(byteArrayEmpty);
- assertTrue(
- "needsInput give wrong boolean value as a result of an empty input buffer",
- inflate.needsInput());
- }
-
- /**
- * @tests java.util.zip.Inflater#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // test method of java.util.zip.inflater.reset()
- byte byteArray[] = {1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5'};
- byte outPutInf[] = new byte[100];
- int y = 0;
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- y += inflate.inflate(outPutInf, y, outPutInf.length - y);
- }
- } 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]);
- }
- assertEquals(
- "final decompressed data contained more bytes than original - reset",
- 0, outPutInf[byteArray.length]);
-
- // testing that resetting the inflater will also return the correct
- // decompressed data
-
- inflate.reset();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- inflate.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]);
- }
- assertEquals(
- "final decompressed data contained more bytes than original - reset",
- 0, outPutInf[byteArray.length]);
-
- }
-
-
- /**
- * @tests java.util.zip.Inflater#setInput(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setInput",
- args = {byte[].class}
- )
- public void test_setInput$B() {
- // test method of java.util.zip.inflater.setInput(byte)
- byte byteArray[] = {2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9};
- Inflater inflate = new Inflater();
- inflate.setInput(byteArray);
- assertTrue("setInputB did not deliver any byte to the input buffer",
- inflate.getRemaining() != 0);
- }
-
- /**
- * @tests java.util.zip.Inflater#setInput(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setInput",
- args = {byte[].class, int.class, int.class}
- )
- public void test_setInput$BII() {
- // test method of java.util.zip.inflater.setInput(byte,int,int)
- byte byteArray[] = {2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9};
- int offSet = 6;
- int length = 6;
- Inflater inflate = new Inflater();
- inflate.setInput(byteArray, offSet, length);
- assertTrue(
- "setInputBII did not deliver the right number of bytes to the input buffer",
- inflate.getRemaining() == length);
- // boundary check
- inflate.reset();
- int r = 0;
- try {
- inflate.setInput(byteArray, 100, 100);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("boundary check is not present for setInput", 1, r);
- }
-
- @Override
+ assertEquals(0,inf.getTotalIn());
+ assertEquals(0,inf.getTotalOut());
+ assertEquals(0,inf.getBytesRead());
+ assertEquals(0,inf.getBytesWritten());
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#needsInput()
+ */
+ public void test_needsInput() {
+ // test method of java.util.zip.inflater.needsInput()
+ Inflater inflate = new Inflater();
+ assertTrue(
+ "needsInput give the wrong boolean value as a result of no input buffer",
+ inflate.needsInput());
+
+ byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
+ inflate.setInput(byteArray);
+ assertFalse(
+ "methodNeedsInput returned true when the input buffer is full",
+ inflate.needsInput());
+
+ inflate.reset();
+ byte byteArrayEmpty[] = new byte[0];
+ inflate.setInput(byteArrayEmpty);
+ assertTrue(
+ "needsInput give wrong boolean value as a result of an empty input buffer",
+ inflate.needsInput());
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#reset()
+ */
+ public void test_reset() {
+ // test method of java.util.zip.inflater.reset()
+ byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
+ byte outPutInf[] = new byte[100];
+ int y = 0;
+ Inflater inflate = new Inflater();
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuff1);
+ }
+ y += inflate.inflate(outPutInf, y, outPutInf.length - y);
+ }
+ } 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]);
+ }
+ assertEquals("final decompressed data contained more bytes than original - reset",
+ 0, outPutInf[byteArray.length]);
+
+ // testing that resetting the inflater will also return the correct
+ // decompressed data
+
+ inflate.reset();
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutBuff1);
+ }
+ inflate.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]);
+ }
+ assertEquals("final decompressed data contained more bytes than original - reset",
+ 0, outPutInf[byteArray.length]);
+
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#setDictionary(byte[])
+ */
+ public void test_setDictionary$B() {
+ //FIXME This test doesn't pass in Harmony classlib or Sun 5.0_7 RI
+ /*
+ // test method of java.util.zip.inflater.setDictionary(byte)
+ 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 outPutInf[] = new byte[100];
+
+ // trying to inflate without setting a dictionary
+
+ Inflater inflateWO = new Inflater();
+ byte outPutInf2[] = new byte[100];
+ int r = 0;
+ try {
+ while (!(inflateWO.finished())) {
+ if (inflateWO.needsInput()) {
+ inflateWO.setInput(outPutDiction);
+ }
+ inflateWO.inflate(outPutInf2);
+ }
+ } catch (DataFormatException e) {
+ r = 1;
+ }
+ assertEquals("invalid input to be decompressed due to dictionary not set",
+ 1, r);
+ // now setting the dictionary in inflater
+ Inflater inflate = new Inflater();
+ try {
+ while (!(inflate.finished())) {
+ if (inflate.needsInput()) {
+ inflate.setInput(outPutDiction);
+ }
+ if (inflate.needsDictionary()) {
+ inflate.setDictionary(dictionaryArray);
+ }
+ inflate.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]);
+ }
+ assertEquals("final decompressed data contained more bytes than original - deflateB",
+ 0, outPutInf[byteArray.length]);
+ */
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#setInput(byte[])
+ */
+ public void test_setInput$B() {
+ // test method of java.util.zip.inflater.setInput(byte)
+ byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
+ Inflater inflate = new Inflater();
+ inflate.setInput(byteArray);
+ assertTrue("setInputB did not deliver any byte to the input buffer",
+ inflate.getRemaining() != 0);
+ }
+
+ /**
+ * @tests java.util.zip.Inflater#setInput(byte[], int, int)
+ */
+ public void test_setInput$BII() {
+ // test method of java.util.zip.inflater.setInput(byte,int,int)
+ byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
+ int offSet = 6;
+ int length = 6;
+ Inflater inflate = new Inflater();
+ inflate.setInput(byteArray, offSet, length);
+ assertTrue(
+ "setInputBII did not deliver the right number of bytes to the input buffer",
+ inflate.getRemaining() == length);
+ // boundary check
+ inflate.reset();
+ int r = 0;
+ try {
+ inflate.setInput(byteArray, 100, 100);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ r = 1;
+ }
+ assertEquals("boundary check is not present for setInput", 1, r);
+ }
+
+ @Override
protected void setUp() {
- try {
- java.io.InputStream infile = Support_Resources
- .getStream("hyts_compressD.txt");
- BufferedInputStream inflatIP = new BufferedInputStream(infile);
- inflatIP.read(outPutBuff1, 0, outPutBuff1.length);
- inflatIP.close();
-
- java.io.InputStream infile2 = Support_Resources
- .getStream("hyts_compDiction.txt");
- BufferedInputStream inflatIP2 = new BufferedInputStream(infile2);
- inflatIP2.read(outPutDiction, 0, outPutDiction.length);
- inflatIP2.close();
-
- } catch (FileNotFoundException e) {
- fail("input file to test InflaterInputStream constructor is not found");
- } catch (ZipException e) {
- fail("read() threw an zip exception while testing constructor");
- } catch (IOException e) {
- fail("read() threw an exception while testing constructor");
- }
- }
-
- @Override
+ try {
+ java.io.InputStream infile = Support_Resources
+ .getStream("hyts_compressD.txt");
+ BufferedInputStream inflatIP = new BufferedInputStream(infile);
+ inflatIP.read(outPutBuff1, 0, outPutBuff1.length);
+ inflatIP.close();
+
+ java.io.InputStream infile2 = Support_Resources
+ .getStream("hyts_compDiction.txt");
+ BufferedInputStream inflatIP2 = new BufferedInputStream(infile2);
+ inflatIP2.read(outPutDiction, 0, outPutDiction.length);
+ inflatIP2.close();
+
+ } catch (FileNotFoundException e) {
+ fail(
+ "input file to test InflaterInputStream constructor is not found");
+ } catch (ZipException e) {
+ fail(
+ "read() threw an zip exception while testing constructor");
+ } catch (IOException e) {
+ fail("read() threw an exception while testing constructor");
+ }
+ }
+
+ @Override
protected void tearDown() {
- }
-
+ }
+
/**
* @tests java.util.zip.Deflater#getBytesRead()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getBytesRead",
- args = {}
- )
public void test_getBytesRead() throws DataFormatException,
UnsupportedEncodingException {
// Regression test for HARMONY-158
@@ -802,23 +736,16 @@ public class InflaterTest extends junit.framework.TestCase {
def.finish();
def.deflate(output);
inf.setInput(output);
- int compressedDataLength = inf.inflate(input);
+ int compressedDataLength =inf.inflate(input);
assertEquals(16, inf.getTotalIn());
assertEquals(compressedDataLength, inf.getTotalOut());
assertEquals(16, inf.getBytesRead());
}
-
+
/**
* @tests java.util.zip.Deflater#getBytesRead()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getBytesWritten",
- args = {}
- )
- public void test_getBytesWritten() throws DataFormatException,
- UnsupportedEncodingException {
+ public void test_getBytesWritten() throws DataFormatException, UnsupportedEncodingException {
// Regression test for HARMONY-158
Deflater def = new Deflater();
Inflater inf = new Inflater();
@@ -835,7 +762,7 @@ public class InflaterTest extends junit.framework.TestCase {
def.finish();
def.deflate(output);
inf.setInput(output);
- int compressedDataLength = inf.inflate(input);
+ int compressedDataLength =inf.inflate(input);
assertEquals(16, inf.getTotalIn());
assertEquals(compressedDataLength, inf.getTotalOut());
assertEquals(14, inf.getBytesWritten());
@@ -844,14 +771,8 @@ public class InflaterTest extends junit.framework.TestCase {
/**
* @tests java.util.zip.Deflater#inflate(byte[], int, int)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test",
- method = "inflate",
- args = {byte[].class, int.class, int.class}
- )
public void testInflate() throws Exception {
- // Regression for HARMONY-81
+ // Regression for HARMONY-81
Inflater inf = new Inflater();
int res = inf.inflate(new byte[0], 0, 0);
@@ -862,30 +783,32 @@ public class InflaterTest extends junit.framework.TestCase {
byte[] b = new byte[1024];
assertEquals(0, inflater.inflate(b));
inflater.end();
- }
- /**
- * @tests java.util.zip.Deflater#inflate(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Can not be checked. Should be tested in DX test package.",
- method = "finalize",
- args = {}
- )
- public void testFinalize() throws Exception {
+ // Regression for HARMONY-2510
+ inflater = new Inflater();
+ inflater.setInput(new byte[] { -1 });
+ try {
+ inflater.inflate(b);
+
+ // The RI detects malformed data on the malformed input { -1 }. Both
+ // this implementation and the native zlib API return "need input"
+ // on that data. This is an error if the stream is exhausted, but
+ // not one that results in an exception in the Inflater API.
+ assertTrue(inflater.needsInput());
+ } catch (DataFormatException e) {
+ // expected
+ }
+
+ inflater = new Inflater();
+ inflater.setInput(new byte[] { -1, -1, -1 });
+ try {
+ inflater.inflate(b);
+ } catch (DataFormatException e) {
+ // expected
+ }
}
- /**
- * @tests java.util.zip.Inflater#setDictionary(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Checks setDictionary. Can be splitted for 2 separate tests for Deflater & Inflater. Can be used as a base for setDictionary with additional params.",
- method = "setDictionary",
- args = {byte[].class}
- )
- public void testsetDictionary$B() throws Exception {
+ public void testSetDictionary$B() throws Exception {
int i = 0;
String inputString = "blah string contains blahblahblahblah and blah";
String dictionary1 = "blah";
@@ -1003,16 +926,7 @@ public class InflaterTest extends junit.framework.TestCase {
infl1.end();
}
- /**
- * @tests java.util.zip.Inflater#setDictionary(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Checks setDictionary. Can be splitted for 2 separate tests for Deflater & Inflater. Can be used as a base for setDictionary with additional params.",
- method = "setDictionary",
- args = {byte[].class, int.class, int.class}
- )
- public void testsetDictionary$BII() throws Exception {
+ public void testSetDictionary$BII() throws Exception {
int i = 0;
String inputString = "blah string contains blahblahblahblah and blah";
String dictionary1 = "blah";
@@ -1113,4 +1027,5 @@ public class InflaterTest extends junit.framework.TestCase {
assertEquals(inputString, new String(result, 0, decLen));
}
+
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
index ee7aceb..be5d0c6 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
@@ -14,27 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import tests.support.resource.Support_Resources;
-
+import java.util.TimeZone;
+import java.util.zip.ZipEntry;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.util.TimeZone;
-import java.util.zip.ZipEntry;
-@TestTargetClass(ZipEntry.class)
+import tests.support.resource.Support_Resources;
+
public class ZipEntryTest extends junit.framework.TestCase {
- // BEGIN android-added
public byte[] getAllBytesFromStream(InputStream is) throws IOException {
ByteArrayOutputStream bs = new ByteArrayOutputStream();
byte[] buf = new byte[512];
@@ -47,601 +38,463 @@ public class ZipEntryTest extends junit.framework.TestCase {
return bs.toByteArray();
}
- // END android-added
-
- // zip file hyts_ZipFile.zip must be included as a resource
- java.util.zip.ZipEntry zentry;
-
- java.util.zip.ZipFile zfile;
-
- private static final String platformId = System.getProperty(
- "com.ibm.oti.configuration", "JDK")
- + System.getProperty("java.vm.version");
-
- static final String tempFileName = platformId + "zipentrytest.zip";
-
- long orgSize;
-
- long orgCompressedSize;
-
- long orgCrc;
-
- long orgTime;
-
- String orgComment;
-
- /**
- * @tests java.util.zip.ZipEntry#ZipEntry(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ZipEntry",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.util.zip.ZipEntry(java.lang.String)
- zentry = zfile.getEntry("File3.txt");
- assertNotNull("Failed to create ZipEntry", zentry);
- try {
- zentry = zfile.getEntry(null);
- fail("NullPointerException not thrown");
- } catch (NullPointerException e) {
- }
- StringBuffer s = new StringBuffer();
- for (int i = 0; i < 65535; i++) {
- s.append('a');
- }
- try {
- zentry = new ZipEntry(s.toString());
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException During Test.");
- }
- try {
- s.append('a');
- zentry = new ZipEntry(s.toString());
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- try {
- String n = null;
- zentry = new ZipEntry(n);
- fail("NullPointerException not thrown");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getComment()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getComment",
- args = {}
- )
- public void test_getComment() {
- // Test for method java.lang.String java.util.zip.ZipEntry.getComment()
- ZipEntry zipEntry = new ZipEntry("zippy.zip");
- assertNull("Incorrect Comment Returned.", zipEntry.getComment());
- zipEntry.setComment("This Is A Comment");
- assertEquals("Incorrect Comment Returned.", "This Is A Comment",
- zipEntry.getComment());
- }
+ // zip file hyts_ZipFile.zip must be included as a resource
+ java.util.zip.ZipEntry zentry;
- /**
- * @tests java.util.zip.ZipEntry#getCompressedSize()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCompressedSize",
- args = {}
- )
- public void test_getCompressedSize() {
- // Test for method long java.util.zip.ZipEntry.getCompressedSize()
- assertTrue("Incorrect compressed size returned", zentry
- .getCompressedSize() == orgCompressedSize);
- }
+ java.util.zip.ZipFile zfile;
- /**
- * @tests java.util.zip.ZipEntry#getCrc()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCrc",
- args = {}
- )
- public void test_getCrc() {
- // Test for method long java.util.zip.ZipEntry.getCrc()
- assertTrue("Failed to get Crc", zentry.getCrc() == orgCrc);
- }
+ private static final String platformId = System.getProperty(
+ "com.ibm.oti.configuration", "JDK")
+ + System.getProperty("java.vm.version");
- /**
- * @tests java.util.zip.ZipEntry#getExtra()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getExtra",
- args = {}
- )
- public void test_getExtra() {
- // Test for method byte [] java.util.zip.ZipEntry.getExtra()
- assertNull("Incorrect extra information returned", zentry.getExtra());
- byte[] ba = {'T', 'E', 'S', 'T'};
- zentry = new ZipEntry("test.tst");
- zentry.setExtra(ba);
- assertTrue("Incorrect Extra Information Returned.",
- zentry.getExtra() == ba);
- }
+ static final String tempFileName = platformId + "zfzezi.zip";
- /**
- * @tests java.util.zip.ZipEntry#getMethod()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMethod",
- args = {}
- )
- public void test_getMethod() {
- // Test for method int java.util.zip.ZipEntry.getMethod()
- zentry = zfile.getEntry("File1.txt");
- assertTrue("Incorrect compression method returned",
- zentry.getMethod() == java.util.zip.ZipEntry.STORED);
- zentry = zfile.getEntry("File3.txt");
- assertTrue("Incorrect compression method returned",
- zentry.getMethod() == java.util.zip.ZipEntry.DEFLATED);
- zentry = new ZipEntry("test.tst");
- assertEquals("Incorrect Method Returned.", -1, zentry.getMethod());
- }
+ long orgSize;
- /**
- * @tests java.util.zip.ZipEntry#getName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getName",
- args = {}
- )
- public void test_getName() {
- // Test for method java.lang.String java.util.zip.ZipEntry.getName()
- assertEquals(
- "Incorrect name returned - Note return result somewhat ambiguous in spec",
- "File1.txt", zentry.getName());
- }
+ long orgCompressedSize;
- /**
- * @tests java.util.zip.ZipEntry#getSize()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getSize",
- args = {}
- )
- public void test_getSize() {
- // Test for method long java.util.zip.ZipEntry.getSize()
- assertTrue("Incorrect size returned", zentry.getSize() == orgSize);
- }
+ long orgCrc;
- /**
- * @tests java.util.zip.ZipEntry#getTime()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTime",
- args = {}
- )
- public void test_getTime() {
- // Test for method long java.util.zip.ZipEntry.getTime()
- assertTrue("Failed to get time", zentry.getTime() == orgTime);
- }
+ long orgTime;
- /**
- * @tests java.util.zip.ZipEntry#isDirectory()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isDirectory",
- args = {}
- )
- public void test_isDirectory() {
- // Test for method boolean java.util.zip.ZipEntry.isDirectory()
- assertTrue("Entry should not answer true to isDirectory", !zentry
- .isDirectory());
- zentry = new ZipEntry("Directory/");
- assertTrue("Entry should answer true to isDirectory", zentry
- .isDirectory());
- }
+ String orgComment;
- /**
- * @tests java.util.zip.ZipEntry#setComment(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setComment",
- args = {java.lang.String.class}
- )
- public void test_setCommentLjava_lang_String() {
- // Test for method void
- // java.util.zip.ZipEntry.setComment(java.lang.String)
- zentry = zfile.getEntry("File1.txt");
- zentry.setComment("Set comment using api");
- assertEquals("Comment not correctly set", "Set comment using api",
- zentry.getComment());
- String n = null;
- zentry.setComment(n);
- assertNull("Comment not correctly set", zentry.getComment());
- StringBuffer s = new StringBuffer();
- for (int i = 0; i < 0xFFFF; i++) {
+ /**
+ * @tests java.util.zip.ZipEntry#ZipEntry(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method java.util.zip.ZipEntry(java.lang.String)
+ zentry = zfile.getEntry("File3.txt");
+ assertNotNull("Failed to create ZipEntry", zentry);
+ try {
+ zentry = zfile.getEntry(null);
+ fail("NullPointerException not thrown");
+ } catch (NullPointerException e) {
+ }
+ StringBuffer s = new StringBuffer();
+ for (int i = 0; i < 65535; i++) {
s.append('a');
}
- try {
- zentry.setComment(s.toString());
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException During Test.");
- }
- try {
+ try {
+ zentry = new ZipEntry(s.toString());
+ } catch (IllegalArgumentException e) {
+ fail("Unexpected IllegalArgumentException During Test.");
+ }
+ try {
+ s.append('a');
+ zentry = new ZipEntry(s.toString());
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ String n = null;
+ zentry = new ZipEntry(n);
+ fail("NullPointerException not thrown");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getComment()
+ */
+ public void test_getComment() {
+ // Test for method java.lang.String java.util.zip.ZipEntry.getComment()
+ ZipEntry zipEntry = new ZipEntry("zippy.zip");
+ assertNull("Incorrect Comment Returned.", zipEntry.getComment());
+ zipEntry.setComment("This Is A Comment");
+ assertEquals("Incorrect Comment Returned.",
+ "This Is A Comment", zipEntry.getComment());
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getCompressedSize()
+ */
+ public void test_getCompressedSize() {
+ // Test for method long java.util.zip.ZipEntry.getCompressedSize()
+ assertTrue("Incorrect compressed size returned", zentry
+ .getCompressedSize() == orgCompressedSize);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getCrc()
+ */
+ public void test_getCrc() {
+ // Test for method long java.util.zip.ZipEntry.getCrc()
+ assertTrue("Failed to get Crc", zentry.getCrc() == orgCrc);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getExtra()
+ */
+ public void test_getExtra() {
+ // Test for method byte [] java.util.zip.ZipEntry.getExtra()
+ assertNull("Incorrect extra information returned",
+ zentry.getExtra());
+ byte[] ba = { 'T', 'E', 'S', 'T' };
+ zentry = new ZipEntry("test.tst");
+ zentry.setExtra(ba);
+ assertTrue("Incorrect Extra Information Returned.",
+ zentry.getExtra() == ba);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getMethod()
+ */
+ public void test_getMethod() {
+ // Test for method int java.util.zip.ZipEntry.getMethod()
+ zentry = zfile.getEntry("File1.txt");
+ assertTrue("Incorrect compression method returned",
+ zentry.getMethod() == java.util.zip.ZipEntry.STORED);
+ zentry = zfile.getEntry("File3.txt");
+ assertTrue("Incorrect compression method returned",
+ zentry.getMethod() == java.util.zip.ZipEntry.DEFLATED);
+ zentry = new ZipEntry("test.tst");
+ assertEquals("Incorrect Method Returned.", -1, zentry.getMethod());
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getName()
+ */
+ public void test_getName() {
+ // Test for method java.lang.String java.util.zip.ZipEntry.getName()
+ assertEquals("Incorrect name returned - Note return result somewhat ambiguous in spec",
+ "File1.txt", zentry.getName());
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getSize()
+ */
+ public void test_getSize() {
+ // Test for method long java.util.zip.ZipEntry.getSize()
+ assertTrue("Incorrect size returned", zentry.getSize() == orgSize);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#getTime()
+ */
+ public void test_getTime() {
+ // Test for method long java.util.zip.ZipEntry.getTime()
+ assertTrue("Failed to get time", zentry.getTime() == orgTime);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#isDirectory()
+ */
+ public void test_isDirectory() {
+ // Test for method boolean java.util.zip.ZipEntry.isDirectory()
+ assertTrue("Entry should not answer true to isDirectory", !zentry
+ .isDirectory());
+ zentry = new ZipEntry("Directory/");
+ assertTrue("Entry should answer true to isDirectory", zentry
+ .isDirectory());
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#setComment(java.lang.String)
+ */
+ public void test_setCommentLjava_lang_String() {
+ // Test for method void
+ // java.util.zip.ZipEntry.setComment(java.lang.String)
+ zentry = zfile.getEntry("File1.txt");
+ zentry.setComment("Set comment using api");
+ assertEquals("Comment not correctly set",
+ "Set comment using api", zentry.getComment());
+ String n = null;
+ zentry.setComment(n);
+ assertNull("Comment not correctly set", zentry.getComment());
+ StringBuffer s = new StringBuffer();
+ for (int i = 0; i < 0xFFFF; i++) {
s.append('a');
- zentry.setComment(s.toString());
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setCompressedSize(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setCompressedSize",
- args = {long.class}
- )
- public void test_setCompressedSizeJ() {
- // Test for method void java.util.zip.ZipEntry.setCompressedSize(long)
- zentry.setCompressedSize(orgCompressedSize + 10);
- assertTrue("Set compressed size failed",
- zentry.getCompressedSize() == (orgCompressedSize + 10));
- zentry.setCompressedSize(0);
- assertEquals("Set compressed size failed", 0, zentry
- .getCompressedSize());
- zentry.setCompressedSize(-25);
- assertEquals("Set compressed size failed", -25, zentry
- .getCompressedSize());
- zentry.setCompressedSize(4294967296l);
- assertTrue("Set compressed size failed",
- zentry.getCompressedSize() == 4294967296l);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setCrc(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setCrc",
- args = {long.class}
- )
- public void test_setCrcJ() {
- // Test for method void java.util.zip.ZipEntry.setCrc(long)
- zentry.setCrc(orgCrc + 100);
- assertTrue("Failed to set Crc", zentry.getCrc() == (orgCrc + 100));
- zentry.setCrc(0);
- assertEquals("Failed to set Crc", 0, zentry.getCrc());
- try {
- zentry.setCrc(-25);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- try {
- zentry.setCrc(4294967295l);
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException during test");
- }
- try {
- zentry.setCrc(4294967296l);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setExtra(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setExtra",
- args = {byte[].class}
- )
- public void test_setExtra$B() {
- // Test for method void java.util.zip.ZipEntry.setExtra(byte [])
- zentry = zfile.getEntry("File1.txt");
- zentry.setExtra("Test setting extra information".getBytes());
- assertEquals("Extra information not written properly",
- "Test setting extra information", new String(zentry.getExtra(),
- 0, zentry.getExtra().length));
- zentry = new ZipEntry("test.tst");
- byte[] ba = new byte[0xFFFF];
- try {
- zentry.setExtra(ba);
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException during test");
- }
- try {
- ba = new byte[0xFFFF + 1];
- zentry.setExtra(ba);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
-
- // One constructor
- ZipEntry zeInput = new ZipEntry("InputZIP");
- byte[] extraB = {'a', 'b', 'd', 'e'};
- zeInput.setExtra(extraB);
- assertEquals(extraB, zeInput.getExtra());
- assertEquals(extraB[3], zeInput.getExtra()[3]);
- assertEquals(extraB.length, zeInput.getExtra().length);
-
- // test another constructor
- ZipEntry zeOutput = new ZipEntry(zeInput);
- assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]);
- assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length);
- assertEquals(extraB[3], zeOutput.getExtra()[3]);
- assertEquals(extraB.length, zeOutput.getExtra().length);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setMethod(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setMethod",
- args = {int.class}
- )
- public void test_setMethodI() {
- // Test for method void java.util.zip.ZipEntry.setMethod(int)
- zentry = zfile.getEntry("File3.txt");
- zentry.setMethod(ZipEntry.STORED);
- assertTrue("Failed to set compression method",
- zentry.getMethod() == ZipEntry.STORED);
- zentry.setMethod(ZipEntry.DEFLATED);
- assertTrue("Failed to set compression method",
- zentry.getMethod() == ZipEntry.DEFLATED);
- try {
- int error = 1;
- zentry = new ZipEntry("test.tst");
- zentry.setMethod(error);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setSize(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setSize",
- args = {long.class}
- )
- public void test_setSizeJ() {
- // Test for method void java.util.zip.ZipEntry.setSize(long)
- zentry.setSize(orgSize + 10);
- assertTrue("Set size failed", zentry.getSize() == (orgSize + 10));
- zentry.setSize(0);
- assertEquals("Set size failed", 0, zentry.getSize());
- try {
- zentry.setSize(-25);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- try {
- zentry.setCrc(4294967295l);
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException during test");
- }
- try {
- zentry.setCrc(4294967296l);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setTime(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTime",
- args = {long.class}
- )
- public void test_setTimeJ() {
- // Test for method void java.util.zip.ZipEntry.setTime(long)
- zentry.setTime(orgTime + 10000);
- assertTrue("Test 1: Failed to set time: " + zentry.getTime(), zentry
- .getTime() == (orgTime + 10000));
- zentry.setTime(orgTime - 10000);
- assertTrue("Test 2: Failed to set time: " + zentry.getTime(), zentry
- .getTime() == (orgTime - 10000));
- TimeZone zone = TimeZone.getDefault();
- try {
- TimeZone.setDefault(TimeZone.getTimeZone("EST"));
- zentry.setTime(0);
- assertTrue("Test 3: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- assertTrue("Test 3a: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315532800000L);
- zentry.setTime(0);
- TimeZone.setDefault(TimeZone.getTimeZone("EST"));
- assertTrue("Test 3b: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
-
- zentry.setTime(-25);
- assertTrue("Test 4: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
- zentry.setTime(4354837200000L);
- assertTrue("Test 5: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
- } finally {
- TimeZone.setDefault(zone);
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.util.zip.ZipEntry.toString()
- assertTrue("Returned incorrect entry name", zentry.toString().indexOf(
- "File1.txt") >= 0);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#ZipEntry(java.util.zip.ZipEntry)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ZipEntry",
- args = {java.util.zip.ZipEntry.class}
- )
- public void test_ConstructorLjava_util_zip_ZipEntry() {
- // Test for method java.util.zip.ZipEntry(util.zip.ZipEntry)
- zentry.setSize(2);
- zentry.setCompressedSize(4);
- zentry.setComment("Testing");
- ZipEntry zentry2 = new ZipEntry(zentry);
- assertEquals("ZipEntry Created With Incorrect Size.", 2, zentry2
- .getSize());
- assertEquals("ZipEntry Created With Incorrect Compressed Size.", 4,
- zentry2.getCompressedSize());
- assertEquals("ZipEntry Created With Incorrect Comment.", "Testing",
- zentry2.getComment());
- assertTrue("ZipEntry Created With Incorrect Crc.",
- zentry2.getCrc() == orgCrc);
- assertTrue("ZipEntry Created With Incorrect Time.",
- zentry2.getTime() == orgTime);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#clone()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clone",
- args = {}
- )
- public void test_clone() {
- // Test for method java.util.zip.ZipEntry.clone()
- Object obj = zentry.clone();
- assertTrue("toString()", obj.toString().equals(zentry.toString()));
- assertTrue("hashCode()", obj.hashCode() == zentry.hashCode());
-
- // One constructor
- ZipEntry zeInput = new ZipEntry("InputZIP");
- byte[] extraB = {'a', 'b', 'd', 'e'};
- zeInput.setExtra(extraB);
- assertEquals(extraB, zeInput.getExtra());
- assertEquals(extraB[3], zeInput.getExtra()[3]);
- assertEquals(extraB.length, zeInput.getExtra().length);
-
- // test Clone()
- ZipEntry zeOutput = (ZipEntry) zeInput.clone();
- assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]);
- assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length);
- assertEquals(extraB[3], zeOutput.getExtra()[3]);
- assertEquals(extraB.length, zeOutput.getExtra().length);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- try {
- zentry.hashCode();
- } catch (Exception ee) {
- fail("Unexpected exception " + ee);
}
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
-
- @Override
+ try {
+ zentry.setComment(s.toString());
+ } catch (IllegalArgumentException e) {
+ fail("Unexpected IllegalArgumentException During Test.");
+ }
+ try {
+ s.append('a');
+ zentry.setComment(s.toString());
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#setCompressedSize(long)
+ */
+ public void test_setCompressedSizeJ() {
+ // Test for method void java.util.zip.ZipEntry.setCompressedSize(long)
+ zentry.setCompressedSize(orgCompressedSize + 10);
+ assertTrue("Set compressed size failed",
+ zentry.getCompressedSize() == (orgCompressedSize + 10));
+ zentry.setCompressedSize(0);
+ assertEquals("Set compressed size failed",
+ 0, zentry.getCompressedSize());
+ zentry.setCompressedSize(-25);
+ assertEquals("Set compressed size failed",
+ -25, zentry.getCompressedSize());
+ zentry.setCompressedSize(4294967296l);
+ assertTrue("Set compressed size failed",
+ zentry.getCompressedSize() == 4294967296l);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#setCrc(long)
+ */
+ public void test_setCrcJ() {
+ // Test for method void java.util.zip.ZipEntry.setCrc(long)
+ zentry.setCrc(orgCrc + 100);
+ assertTrue("Failed to set Crc", zentry.getCrc() == (orgCrc + 100));
+ zentry.setCrc(0);
+ assertEquals("Failed to set Crc", 0, zentry.getCrc());
+ try {
+ zentry.setCrc(-25);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ zentry.setCrc(4294967295l);
+ } catch (IllegalArgumentException e) {
+ fail("Unexpected IllegalArgumentException during test");
+ }
+ try {
+ zentry.setCrc(4294967296l);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#setExtra(byte[])
+ */
+ public void test_setExtra$B() {
+ // Test for method void java.util.zip.ZipEntry.setExtra(byte [])
+ zentry = zfile.getEntry("File1.txt");
+ zentry.setExtra("Test setting extra information".getBytes());
+ assertEquals("Extra information not written properly", "Test setting extra information", new String(zentry
+ .getExtra(), 0, zentry.getExtra().length)
+ );
+ zentry = new ZipEntry("test.tst");
+ byte[] ba = new byte[0xFFFF];
+ try {
+ zentry.setExtra(ba);
+ } catch (IllegalArgumentException e) {
+ fail("Unexpected IllegalArgumentException during test");
+ }
+ try {
+ ba = new byte[0xFFFF + 1];
+ zentry.setExtra(ba);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // One constructor
+ ZipEntry zeInput = new ZipEntry("InputZIP");
+ byte[] extraB = { 'a', 'b', 'd', 'e' };
+ zeInput.setExtra(extraB);
+ assertEquals(extraB, zeInput.getExtra());
+ assertEquals(extraB[3], zeInput.getExtra()[3]);
+ assertEquals(extraB.length, zeInput.getExtra().length);
+
+ // test another constructor
+ ZipEntry zeOutput = new ZipEntry(zeInput);
+ assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]);
+ assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length);
+ assertEquals(extraB[3], zeOutput.getExtra()[3]);
+ assertEquals(extraB.length, zeOutput.getExtra().length);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#setMethod(int)
+ */
+ public void test_setMethodI() {
+ // Test for method void java.util.zip.ZipEntry.setMethod(int)
+ zentry = zfile.getEntry("File3.txt");
+ zentry.setMethod(ZipEntry.STORED);
+ assertTrue("Failed to set compression method",
+ zentry.getMethod() == ZipEntry.STORED);
+ zentry.setMethod(ZipEntry.DEFLATED);
+ assertTrue("Failed to set compression method",
+ zentry.getMethod() == ZipEntry.DEFLATED);
+ try {
+ int error = 1;
+ zentry = new ZipEntry("test.tst");
+ zentry.setMethod(error);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#setSize(long)
+ */
+ public void test_setSizeJ() {
+ // Test for method void java.util.zip.ZipEntry.setSize(long)
+ zentry.setSize(orgSize + 10);
+ assertTrue("Set size failed", zentry.getSize() == (orgSize + 10));
+ zentry.setSize(0);
+ assertEquals("Set size failed", 0, zentry.getSize());
+ try {
+ zentry.setSize(-25);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ zentry.setCrc(4294967295l);
+ } catch (IllegalArgumentException e) {
+ fail("Unexpected IllegalArgumentException during test");
+ }
+ try {
+ zentry.setCrc(4294967296l);
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#setTime(long)
+ */
+ public void test_setTimeJ() {
+ // Test for method void java.util.zip.ZipEntry.setTime(long)
+ zentry.setTime(orgTime + 10000);
+ assertTrue("Test 1: Failed to set time: " + zentry.getTime(), zentry
+ .getTime() == (orgTime + 10000));
+ zentry.setTime(orgTime - 10000);
+ assertTrue("Test 2: Failed to set time: " + zentry.getTime(), zentry
+ .getTime() == (orgTime - 10000));
+ TimeZone zone = TimeZone.getDefault();
+ try {
+ TimeZone.setDefault(TimeZone.getTimeZone("EST"));
+ zentry.setTime(0);
+ assertTrue("Test 3: Failed to set time: " + zentry.getTime(),
+ zentry.getTime() == 315550800000L);
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ assertTrue("Test 3a: Failed to set time: " + zentry.getTime(),
+ zentry.getTime() == 315532800000L);
+ zentry.setTime(0);
+ TimeZone.setDefault(TimeZone.getTimeZone("EST"));
+ assertTrue("Test 3b: Failed to set time: " + zentry.getTime(),
+ zentry.getTime() == 315550800000L);
+
+ zentry.setTime(-25);
+ assertTrue("Test 4: Failed to set time: " + zentry.getTime(),
+ zentry.getTime() == 315550800000L);
+ zentry.setTime(4354837200000L);
+ assertTrue("Test 5: Failed to set time: " + zentry.getTime(),
+ zentry.getTime() == 315550800000L);
+ } finally {
+ TimeZone.setDefault(zone);
+ }
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#toString()
+ */
+ public void test_toString() {
+ // Test for method java.lang.String java.util.zip.ZipEntry.toString()
+ assertTrue("Returned incorrect entry name", zentry.toString().indexOf(
+ "File1.txt") >= 0);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#ZipEntry(java.util.zip.ZipEntry)
+ */
+ public void test_ConstructorLjava_util_zip_ZipEntry() {
+ // Test for method java.util.zip.ZipEntry(util.zip.ZipEntry)
+ zentry.setSize(2);
+ zentry.setCompressedSize(4);
+ zentry.setComment("Testing");
+ ZipEntry zentry2 = new ZipEntry(zentry);
+ assertEquals("ZipEntry Created With Incorrect Size.",
+ 2, zentry2.getSize());
+ assertEquals("ZipEntry Created With Incorrect Compressed Size.", 4, zentry2
+ .getCompressedSize());
+ assertEquals("ZipEntry Created With Incorrect Comment.", "Testing", zentry2
+ .getComment());
+ assertTrue("ZipEntry Created With Incorrect Crc.",
+ zentry2.getCrc() == orgCrc);
+ assertTrue("ZipEntry Created With Incorrect Time.",
+ zentry2.getTime() == orgTime);
+ }
+
+ /**
+ * @tests java.util.zip.ZipEntry#clone()
+ */
+ public void test_clone() {
+ // Test for method java.util.zip.ZipEntry.clone()
+ Object obj = zentry.clone();
+ assertTrue("toString()", obj.toString().equals(zentry.toString()));
+ assertTrue("hashCode()", obj.hashCode() == zentry.hashCode());
+
+ // One constructor
+ ZipEntry zeInput = new ZipEntry("InputZIP");
+ byte[] extraB = { 'a', 'b', 'd', 'e' };
+ zeInput.setExtra(extraB);
+ assertEquals(extraB, zeInput.getExtra());
+ assertEquals(extraB[3], zeInput.getExtra()[3]);
+ assertEquals(extraB.length, zeInput.getExtra().length);
+
+ // test Clone()
+ ZipEntry zeOutput = (ZipEntry) zeInput.clone();
+ assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]);
+ assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length);
+ assertEquals(extraB[3], zeOutput.getExtra()[3]);
+ assertEquals(extraB.length, zeOutput.getExtra().length);
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+
+ @Override
protected void setUp() {
- java.io.File f = null;
- try {
- // BEGIN android-changed
- // Create a local copy of the file since some tests want to alter
- // information.
- f = File.createTempFile(tempFileName, ".zip");
- // Create absolute filename as ZipFile does not resolve using
- // user.dir
- f = new java.io.File(f.getAbsolutePath());
- f.delete();
- java.io.InputStream is = Support_Resources
- .getStream("hyts_ZipFile.zip");
- java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
+ java.io.File f = null;
+ try {
+ // Create a local copy of the file since some tests want to alter
+ // information.
+ f = new java.io.File(tempFileName);
+ // Create absolute filename as ZipFile does not resolve using
+ // user.dir
+ f = new java.io.File(f.getAbsolutePath());
+ f.delete();
+ java.io.InputStream is = Support_Resources
+ .getStream("hyts_ZipFile.zip");
+ java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
byte[] rbuf = getAllBytesFromStream(is);
- // END android-changed
- fos.write(rbuf, 0, rbuf.length);
- is.close();
- fos.close();
- zfile = new java.util.zip.ZipFile(f);
- zentry = zfile.getEntry("File1.txt");
- orgSize = zentry.getSize();
- orgCompressedSize = zentry.getCompressedSize();
- orgCrc = zentry.getCrc();
- orgTime = zentry.getTime();
- orgComment = zentry.getComment();
- } catch (Exception e) {
- System.out.println("Exception during ZipFile setup <"
- + f.getAbsolutePath() + ">: ");
- e.printStackTrace();
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
-
- @Override
+ fos.write(rbuf, 0, rbuf.length);
+ is.close();
+ fos.close();
+ zfile = new java.util.zip.ZipFile(f);
+ zentry = zfile.getEntry("File1.txt");
+ orgSize = zentry.getSize();
+ orgCompressedSize = zentry.getCompressedSize();
+ orgCrc = zentry.getCrc();
+ orgTime = zentry.getTime();
+ orgComment = zentry.getComment();
+ } catch (Exception e) {
+ System.out.println("Exception during ZipFile setup <"
+ + f.getAbsolutePath() + ">: ");
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+
+ @Override
protected void tearDown() {
- try {
- if (zfile != null) {
+ try {
+ if (zfile != null) {
zfile.close();
}
- java.io.File f = new java.io.File(tempFileName);
- f.delete();
- } catch (java.io.IOException e) {
- System.out.println("Exception during tearDown");
- }
- }
+ java.io.File f = new java.io.File(tempFileName);
+ f.delete();
+ } catch (java.io.IOException e) {
+ System.out.println("Exception during tearDown");
+ }
+ }
}
diff --git a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
index 0398f03..7adfeff 100644
--- a/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
+++ b/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
@@ -14,14 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.archive.tests.java.util.zip;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -33,27 +27,20 @@ import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
-@TestTargetClass(ZipOutputStream.class)
public class ZipOutputStreamTest extends junit.framework.TestCase {
- ZipOutputStream zos;
+ ZipOutputStream zos;
- ByteArrayOutputStream bos;
+ ByteArrayOutputStream bos;
- ZipInputStream zis;
+ ZipInputStream zis;
- static final String data = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorld";
+ static final String data = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorld";
- /**
+ /**
* @tests java.util.zip.ZipOutputStream#close()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Can not check IOException.",
- method = "close",
- args = {}
- )
- public void test_close() throws Exception {
+ public void test_close() throws Exception {
try {
zos.close();
fail("Close on empty stream failed to throw exception");
@@ -76,12 +63,6 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
/**
* @tests java.util.zip.ZipOutputStream#closeEntry()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "ZipException can not be checked.",
- method = "closeEntry",
- args = {}
- )
public void test_closeEntry() throws IOException {
ZipEntry ze = new ZipEntry("testEntry");
ze.setTime(System.currentTimeMillis());
@@ -90,25 +71,12 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
zos.closeEntry();
assertTrue("closeEntry failed to update required fields",
ze.getSize() == 11 && ze.getCompressedSize() == 13);
- ze = new ZipEntry("testEntry1");
- zos.close();
- try {
- zos.closeEntry();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
+
}
/**
* @tests java.util.zip.ZipOutputStream#finish()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "ZipException can not be checked.",
- method = "finish",
- args = {}
- )
public void test_finish() throws Exception {
ZipEntry ze = new ZipEntry("test");
zos.putNextEntry(ze);
@@ -131,12 +99,6 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
/**
* @tests java.util.zip.ZipOutputStream#putNextEntry(java.util.zip.ZipEntry)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "ZipException can not be checked.",
- method = "putNextEntry",
- args = {java.util.zip.ZipEntry.class}
- )
public void test_putNextEntryLjava_util_zip_ZipEntry() throws IOException {
ZipEntry ze = new ZipEntry("testEntry");
ze.setTime(System.currentTimeMillis());
@@ -161,12 +123,6 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
/**
* @tests java.util.zip.ZipOutputStream#setComment(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setComment",
- args = {java.lang.String.class}
- )
public void test_setCommentLjava_lang_String() {
// There is no way to get the comment back, so no way to determine if
// the comment is set correct
@@ -183,12 +139,6 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
/**
* @tests java.util.zip.ZipOutputStream#setLevel(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLevel",
- args = {int.class}
- )
public void test_setLevelI() throws IOException {
ZipEntry ze = new ZipEntry("test");
zos.putNextEntry(ze);
@@ -200,23 +150,11 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
zos.write(data.getBytes());
zos.closeEntry();
assertTrue("setLevel failed", csize <= ze.getCompressedSize());
- try {
- zos.setLevel(-9); // Max Compression
- fail("IllegalArgumentException ecpected.");
- } catch (IllegalArgumentException ee) {
- // expected
- }
}
/**
* @tests java.util.zip.ZipOutputStream#setMethod(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setMethod",
- args = {int.class}
- )
public void test_setMethodI() throws IOException {
ZipEntry ze = new ZipEntry("test");
zos.setMethod(ZipOutputStream.STORED);
@@ -233,23 +171,11 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
zos.write(data.getBytes());
zos.closeEntry();
assertTrue("setLevel failed", csize >= ze.getCompressedSize());
- try {
- zos.setMethod(-ZipOutputStream.DEFLATED);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ee) {
- // expected
- }
}
/**
* @tests java.util.zip.ZipOutputStream#write(byte[], int, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() throws IOException {
ZipEntry ze = new ZipEntry("test");
zos.putNextEntry(ze);
@@ -314,12 +240,6 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
/**
* @tests java.util.zip.ZipOutputStream#write(byte[], int, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Regression",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII_2() throws IOException {
// Regression for HARMONY-577
File f1 = File.createTempFile("testZip1", "tst");
@@ -331,7 +251,7 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
zip1.setMethod(ZipEntry.STORED);
zip1.write(new byte[2]);
-
+
try {
zip1.putNextEntry(new ZipEntry("Second"));
fail("ZipException expected");
@@ -364,18 +284,7 @@ public class ZipOutputStreamTest extends junit.framework.TestCase {
if (zis != null) {
zis.close();
}
- } catch (Exception e) {
- }
+ } catch (Exception e) {}
super.tearDown();
}
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "See setUp procedure for more info.",
- method = "ZipOutputStream",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() {
- assertTrue(true);
- }
}
diff --git a/archive/src/test/java/tests/archive/AllTests.java b/archive/src/test/java/tests/archive/AllTests.java
index a5c461c..4c1fca2 100644
--- a/archive/src/test/java/tests/archive/AllTests.java
+++ b/archive/src/test/java/tests/archive/AllTests.java
@@ -21,13 +21,8 @@ import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests {
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(AllTests.suite());
- }
-
public static Test suite() {
- TestSuite suite = tests.TestSuiteFactory.createTestSuite("All Archive test suites");
+ TestSuite suite = new TestSuite("All Archive test suites");
// $JUnit-BEGIN$
suite.addTest(org.apache.harmony.archive.tests.java.util.jar.AllTests
.suite());