Pack200 - more tests

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk@997338 13f79535-47bb-0310-9956-ffa450edef68
master
Sian January 14 years ago
parent a2730622e5
commit 83a450f372
  1. 22
      src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
  2. 10
      src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
  3. 38
      src/test/java/org/apache/harmony/pack200/tests/PackingOptionsTest.java
  4. 89
      src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
  5. 2
      src/test/java/org/apache/harmony/unpack200/tests/SegmentTest.java
  6. BIN
      src/test/resources/org/apache/harmony/pack200/tests/annotations.jar
  7. BIN
      src/test/resources/org/apache/harmony/pack200/tests/annotationsRI.jar
  8. BIN
      src/test/resources/org/apache/harmony/pack200/tests/annotationsRI.pack.gz
  9. BIN
      src/test/resources/org/apache/harmony/pack200/tests/p200WithUnknownAttributes.jar
  10. BIN
      src/test/resources/org/apache/harmony/pack200/tests/p200WithUnknownAttributes2.jar

@ -19,6 +19,7 @@ package org.apache.harmony.pack200.tests;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -28,6 +29,7 @@ import java.net.URISyntaxException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
import junit.framework.TestCase;
@ -125,7 +127,21 @@ public class ArchiveTest extends TestCase {
compareFiles(jarFile, jarFile2);
}
public void testLargeClass() throws IOException, Pack200Exception, URISyntaxException {
public void testAlternativeConstructor() throws FileNotFoundException,
IOException, URISyntaxException, Pack200Exception {
JarInputStream inStream = new JarInputStream(new FileInputStream(
new File(Archive.class.getResource(
"/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI())));
file = File.createTempFile("sql", ".pack.gz");
file.deleteOnExit();
out = new FileOutputStream(file);
new Archive(inStream, out, null).pack();
inStream.close();
out.close();
}
public void testLargeClass() throws IOException, Pack200Exception,
URISyntaxException {
in = new JarFile(new File(Archive.class.getResource(
"/org/apache/harmony/pack200/tests/largeClassUnpacked.jar")
.toURI()));
@ -217,7 +233,7 @@ public class ArchiveTest extends TestCase {
in = new JarFile(new File(Archive.class.getResource(
"/org/apache/harmony/pack200/tests/annotations.jar").toURI()));
file = File.createTempFile("annotations", ".pack");
// file.deleteOnExit();
file.deleteOnExit();
out = new FileOutputStream(file);
PackingOptions options = new PackingOptions();
options.setGzip(false);
@ -228,7 +244,7 @@ public class ArchiveTest extends TestCase {
// now unpack
InputStream in2 = new FileInputStream(file);
File file2 = File.createTempFile("annotationsout", ".jar");
// file2.deleteOnExit();
file2.deleteOnExit();
JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(
in2, out2);

@ -26,7 +26,6 @@ import org.apache.harmony.pack200.BHSDCodec;
import org.apache.harmony.pack200.CanonicalCodecFamilies;
import org.apache.harmony.pack200.Codec;
import org.apache.harmony.pack200.Pack200Exception;
import org.apache.harmony.pack200.RunCodec;
/**
*
@ -205,6 +204,15 @@ public class CodecTest extends TestCase {
checkAscendingCardinalities(CanonicalCodecFamilies.deltaUnsignedCodecs3);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaUnsignedCodecs4);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaUnsignedCodecs5);
checkAscendingCardinalities(CanonicalCodecFamilies.nonDeltaSignedCodecs1);
checkAscendingCardinalities(CanonicalCodecFamilies.nonDeltaSignedCodecs2);
checkAscendingCardinalities(CanonicalCodecFamilies.nonDeltaDoubleSignedCodecs1);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaSignedCodecs1);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaSignedCodecs2);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaSignedCodecs3);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaSignedCodecs4);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaSignedCodecs5);
checkAscendingCardinalities(CanonicalCodecFamilies.deltaDoubleSignedCodecs1);
}
private void checkAscendingCardinalities(BHSDCodec[] family) {

@ -504,6 +504,44 @@ public class PackingOptionsTest extends TestCase {
// compareFiles(jarFile, jarFile2);
}
public void testNewAttributes2() throws Exception {
in = new JarFile(
new File(
Archive.class
.getResource(
"/org/apache/harmony/pack200/tests/p200WithUnknownAttributes.jar")
.toURI()));
file = File.createTempFile("unknown", ".pack");
file.deleteOnExit();
out = new FileOutputStream(file);
PackingOptions options = new PackingOptions();
options.addFieldAttributeAction("Pack200", "I");
options.addMethodAttributeAction("Pack200", "I");
options.addCodeAttributeAction("Pack200", "I");
Archive ar = new Archive(in, out, options);
ar.pack();
in.close();
out.close();
// unpack and check this was done right
InputStream in2 = new FileInputStream(file);
File file2 = File.createTempFile("unknown", ".jar");
file2.deleteOnExit();
JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
org.apache.harmony.unpack200.Archive u2archive = new org.apache.harmony.unpack200.Archive(
in2, out2);
u2archive.unpack();
// compare with original
File compareFile = new File(Archive.class.getResource(
"/org/apache/harmony/pack200/tests/p200WithUnknownAttributes.jar").toURI());
JarFile jarFile = new JarFile(file2);
JarFile jarFile2 = new JarFile(compareFile);
assertEquals(jarFile2.size(), jarFile.size());
compareJarEntries(jarFile, jarFile2);
}
public void testErrorAttributes() throws Exception {
in = new JarFile(
new File(

@ -16,8 +16,11 @@
*/
package org.apache.harmony.unpack200.tests;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
@ -27,6 +30,7 @@ import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import junit.framework.TestCase;
@ -117,6 +121,16 @@ public class ArchiveTest extends TestCase {
}
}
public void testAlternativeConstructor() throws Exception {
String inputFile = new File(Archive.class
.getResource("/org/apache/harmony/pack200/tests/sql.pack.gz").toURI()).getPath();
file = File.createTempFile("sql", ".jar");
file.deleteOnExit();
String outputFile = file.getPath();
Archive archive = new Archive(inputFile, outputFile);
archive.unpack();
}
// Test with an archive containing Harmony's Pack200 module, packed with -E1
public void testWithPack200E1() throws Exception {
in = Archive.class
@ -179,6 +193,58 @@ public class ArchiveTest extends TestCase {
archive.unpack();
}
public void testRemovePackFile() throws Exception {
File original = new File(Archive.class.getResource(
"/org/apache/harmony/pack200/tests/sql.pack.gz").toURI());
File copy = File.createTempFile("sqlcopy", ".pack.gz");
BufferedInputStream inputStream = new BufferedInputStream(
new FileInputStream(original));
BufferedOutputStream outputStream = new BufferedOutputStream(
new FileOutputStream(copy));
byte[] bytes = new byte[256];
int read = inputStream.read(bytes);
while (read > 0) {
outputStream.write(bytes, 0, read);
read = inputStream.read(bytes);
}
inputStream.close();
outputStream.close();
String inputFile = copy.getPath();
file = File.createTempFile("sqlout", ".jar");
file.deleteOnExit();
String outputFile = file.getPath();
Archive archive = new Archive(inputFile, outputFile);
archive.setRemovePackFile(true);
archive.unpack();
assertFalse(copy.exists());
}
public void testDeflateHint() throws Exception {
in = Archive.class
.getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
file = File.createTempFile("sql", ".jar");
file.deleteOnExit();
out = new JarOutputStream(new FileOutputStream(file));
Archive archive = new Archive(in, out);
archive.setDeflateHint(true);
archive.unpack();
JarFile jarFile = new JarFile(file);
assertEquals(ZipEntry.DEFLATED, jarFile.getEntry("bin/test/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.class").getMethod());
in = Archive.class
.getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
file = File.createTempFile("sql", ".jar");
file.deleteOnExit();
out = new JarOutputStream(new FileOutputStream(file));
archive = new Archive(in, out);
archive.setDeflateHint(false);
archive.unpack();
jarFile = new JarFile(file);
assertEquals(ZipEntry.STORED, jarFile.getEntry("bin/test/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.class").getMethod());
}
protected void tearDown() throws Exception {
super.tearDown();
if (in != null) {
@ -235,6 +301,29 @@ public class ArchiveTest extends TestCase {
assertTrue(reader.ready());
reader.close();
// test append option
long length = logFile.length();
in = Archive.class
.getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
file = File.createTempFile("logtest", ".jar");
file.deleteOnExit();
out = new JarOutputStream(new FileOutputStream(file));
archive = new Archive(in, out);
archive.setLogFile(logFile.getPath(), true);
archive.setVerbose(true);
archive.unpack();
assertTrue(logFile.length() > length);
in = Archive.class
.getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
file = File.createTempFile("logtest", ".jar");
file.deleteOnExit();
out = new JarOutputStream(new FileOutputStream(file));
archive = new Archive(in, out);
archive.setLogFile(logFile.getPath(), false);
archive.setVerbose(true);
archive.unpack();
assertTrue(logFile.length() == length);
// test setting quiet explicitly
in = Archive.class
.getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");

@ -80,13 +80,13 @@ public class SegmentTest extends TestCase {
in = Segment.class
.getResourceAsStream("/org/apache/harmony/pack200/tests/HelloWorld.pack");
file = File.createTempFile("hello", "world.jar");
file.deleteOnExit();
out = new JarOutputStream(new FileOutputStream(file));
Segment segment = new Segment();
segment.unpack(in, out);
out.close();
out = null;
JarFile jarFile = new JarFile(file);
file.deleteOnExit();
JarEntry entry = jarFile
.getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");

Loading…
Cancel
Save