summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java (renamed from luni/src/test/java/libcore/java/util/zip/GzipTest.java)31
-rw-r--r--luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java50
-rw-r--r--support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gzbin42 -> 0 bytes
3 files changed, 63 insertions, 18 deletions
diff --git a/luni/src/test/java/libcore/java/util/zip/GzipTest.java b/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java
index f7e03dc..a28fae5 100644
--- a/luni/src/test/java/libcore/java/util/zip/GzipTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java
@@ -27,23 +27,25 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import junit.framework.TestCase;
-public final class GzipTest extends TestCase {
-
- public void testRoundtripShortMessage() throws IOException {
- byte[] data = gzip(("Hello World").getBytes("UTF-8"));
- assertTrue(Arrays.equals(data, gunzip(gzip(data))));
+public final class GZIPInputStreamTest extends TestCase {
+ public void testShortMessage() throws IOException {
+ byte[] data = new byte[] {
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -13, 72, -51, -55, -55, 87, 8, -49,
+ 47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0
+ };
+ assertEquals("Hello World", new String(gunzip(data), "UTF-8"));
}
- public void testRoundtripLongMessage() throws IOException {
+ public void testLongMessage() throws IOException {
byte[] data = new byte[1024 * 1024];
new Random().nextBytes(data);
- assertTrue(Arrays.equals(data, gunzip(gzip(data))));
+ assertTrue(Arrays.equals(data, gunzip(GZIPOutputStreamTest.gzip(data))));
}
/** http://b/3042574 GzipInputStream.skip() causing CRC failures */
public void testSkip() throws IOException {
byte[] data = new byte[1024 * 1024];
- byte[] gzipped = gzip(data);
+ byte[] gzipped = GZIPOutputStreamTest.gzip(data);
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(gzipped));
long totalSkipped = 0;
@@ -53,19 +55,11 @@ public final class GzipTest extends TestCase {
totalSkipped += count;
} while (count > 0);
-
assertEquals(data.length, totalSkipped);
+ in.close();
}
- public byte[] gzip(byte[] bytes) throws IOException {
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
- OutputStream gzippedOut = new GZIPOutputStream(bytesOut);
- gzippedOut.write(bytes);
- gzippedOut.close();
- return bytesOut.toByteArray();
- }
-
- public byte[] gunzip(byte[] bytes) throws IOException {
+ public static byte[] gunzip(byte[] bytes) throws IOException {
InputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
@@ -73,6 +67,7 @@ public final class GzipTest extends TestCase {
while ((count = in.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
+ in.close();
return out.toByteArray();
}
}
diff --git a/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java
new file mode 100644
index 0000000..a61880f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import junit.framework.TestCase;
+
+public final class GZIPOutputStreamTest extends TestCase {
+ public void testShortMessage() throws IOException {
+ byte[] data = gzip(("Hello World").getBytes("UTF-8"));
+ assertEquals("[31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -13, 72, -51, -55, -55, 87, 8, -49, " +
+ "47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0]", Arrays.toString(data));
+ }
+
+ public void testLongMessage() throws IOException {
+ byte[] data = new byte[1024 * 1024];
+ new Random().nextBytes(data);
+ assertTrue(Arrays.equals(data, GZIPInputStreamTest.gunzip(gzip(data))));
+ }
+
+ public static byte[] gzip(byte[] bytes) throws IOException {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ OutputStream gzippedOut = new GZIPOutputStream(bytesOut);
+ gzippedOut.write(bytes);
+ gzippedOut.close();
+ return bytesOut.toByteArray();
+ }
+}
diff --git a/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz b/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz
deleted file mode 100644
index e0f5a00..0000000
--- a/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz
+++ /dev/null
Binary files differ