harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r763572 - /harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Date Thu, 09 Apr 2009 09:20:36 GMT
Author: sjanuary
Date: Thu Apr  9 09:20:35 2009
New Revision: 763572

URL: http://svn.apache.org/viewvc?rev=763572&view=rev
Log:
Pack200 - test for a large class and two tests for zero effort pack

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=763572&r1=763571&r2=763572&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Thu Apr  9 09:20:35 2009
@@ -39,14 +39,13 @@
 
 public class ArchiveTest extends TestCase {
 
-    JarInputStream in;
+    JarFile in;
     OutputStream out;
     File file;
 
     public void testHelloWorld() throws IOException, Pack200Exception, URISyntaxException
{
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         new Archive(in, out, true).pack();
@@ -95,8 +94,8 @@
     }
 
     public void testSQL() throws IOException, Pack200Exception, URISyntaxException {
-        in = new JarInputStream(Archive.class
-                .getResourceAsStream("/org/apache/harmony/pack200/tests/sqlUnpacked.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
         file = File.createTempFile("sql", ".pack");
         out = new FileOutputStream(file);
         new Archive(in, out, false).pack();
@@ -121,9 +120,37 @@
         compareFiles(jarFile, jarFile2);
     }
 
+    public void testLargeClass() throws IOException, Pack200Exception, URISyntaxException
{
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/largeClassUnpacked.jar")
+                .toURI()));
+        file = File.createTempFile("largeClass", ".pack");
+        out = new FileOutputStream(file);
+        new Archive(in, out, false).pack();
+        in.close();
+        out.close();
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file2 = File.createTempFile("largeClassOut", ".jar");
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+        org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(in2,
out2);
+        archive.unpack();
+        JarFile jarFile = new JarFile(file2);
+        file2.deleteOnExit();
+
+        File compareFile = new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/largeClassUnpacked.jar").toURI());
+        JarFile jarFile2 = new JarFile(compareFile);
+
+        assertEquals(jarFile2.size(), jarFile.size());
+
+        compareFiles(jarFile, jarFile2);
+    }
+
     public void testJNDI() throws IOException, Pack200Exception, URISyntaxException {
-        in = new JarInputStream(Archive.class
-                .getResourceAsStream("/org/apache/harmony/pack200/tests/jndi.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/jndi.jar").toURI()));
         file = File.createTempFile("jndi", ".pack");
         out = new FileOutputStream(file);
         new Archive(in, out, false).pack();
@@ -144,11 +171,10 @@
         compareFiles(jarFile, jarFile2);
     }
 
-    public void testSegmentLimits() throws IOException, Pack200Exception {
-
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+    public void testSegmentLimits() throws IOException, Pack200Exception,
+            URISyntaxException {
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         Archive archive = new Archive(in, out, true);
@@ -157,9 +183,8 @@
         in.close();
         out.close();
 
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         archive = new Archive(in, out, true);
@@ -168,9 +193,8 @@
         in.close();
         out.close();
 
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         archive = new Archive(in, out, true);
@@ -181,8 +205,8 @@
     }
 
     public void testStripDebug() throws IOException, Pack200Exception, URISyntaxException
{
-        in = new JarInputStream(Archive.class
-                .getResourceAsStream("/org/apache/harmony/pack200/tests/sqlUnpacked.jar"));
+        in = new JarFile(new File(Archive.class
+                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
         file = File.createTempFile("sql", ".pack");
         out = new FileOutputStream(file);
         Archive archive = new Archive(in, out, false);
@@ -211,9 +235,9 @@
 
     public void testAnnotations() throws IOException, Pack200Exception,
             URISyntaxException {
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/annotationsUnpacked.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/annotationsUnpacked.jar")
+                .toURI()));
         file = File.createTempFile("annotations", ".pack");
         out = new FileOutputStream(file);
         new Archive(in, out, false).pack();
@@ -235,6 +259,56 @@
         compareFiles(jarFile, jarFile2);
     }
 
+    public void testE0() throws Pack200Exception, IOException, URISyntaxException {
+        File f1 = new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/jndi.jar").toURI());
+        in = new JarFile(f1);
+        file = File.createTempFile("jndiE0", ".pack");
+        out = new FileOutputStream(file);
+        Archive archive = new Archive(in, out, false);
+        archive.setEffort(0);
+        archive.pack();
+        in.close();
+        out.close();
+        compareFiles(new JarFile(f1), new JarFile(file));
+
+    }
+
+    public void testE0again() throws IOException, Pack200Exception, URISyntaxException {
+        JarInputStream inputStream = new JarInputStream(Archive.class.getResourceAsStream("/org/apache/harmony/pack200/tests/jndi.jar"));
+        file = File.createTempFile("jndiE0", ".pack");
+        out = new FileOutputStream(file);
+        Archive archive = new Archive(inputStream, out, false);
+        archive.setEffort(0);
+        archive.pack();
+        inputStream.close();
+        out.close();
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/jndi.jar").toURI()));
+        compareFiles(in, new JarFile(file));
+    }
+
+    public void testMultipleJars() throws URISyntaxException, IOException, Pack200Exception
{
+    	File folder = new File(Archive.class
+    			.getResource("/org/apache/harmony/pack200/tests/jars").toURI());
+    	String[] children = folder.list();
+    	for (int i = 0; i < children.length; i++) {
+			if(children[i].endsWith(".jar") && !children[i].endsWith("Unpacked.jar")) {
+				File inputFile = new File(folder, children[i]);
+				in = new JarFile(inputFile);
+				file = File.createTempFile("temp", ".pack.gz");
+		        out = new FileOutputStream(file);
+		        System.out.println("packing " + children[i]);
+		        new Archive(in, out, true).pack();
+		        in.close();
+		        out.close();
+
+		        // unpack and compare
+
+			}
+		}
+    }
+
     private void compareFiles(JarFile jarFile, JarFile jarFile2)
             throws IOException {
         Enumeration entries = jarFile.entries();
@@ -245,20 +319,25 @@
 
             String name = entry.getName();
             JarEntry entry2 = jarFile2.getJarEntry(name);
-            assertNotNull(entry2);
-            if(!name.equals("META-INF/MANIFEST.MF")) { // Manifests aren't necessarily byte-for-byte
identical
+            assertNotNull("Missing Entry: " + name, entry2);
+            if (!name.equals("META-INF/MANIFEST.MF")) { // Manifests aren't
+                                                        // necessarily
+                                                        // byte-for-byte
+                                                        // identical
 
                 InputStream ours = jarFile.getInputStream(entry);
                 InputStream expected = jarFile2.getInputStream(entry2);
 
-                BufferedReader reader1 = new BufferedReader(new InputStreamReader(ours));
-                BufferedReader reader2 = new BufferedReader(new InputStreamReader(
-                        expected));
+                BufferedReader reader1 = new BufferedReader(
+                        new InputStreamReader(ours));
+                BufferedReader reader2 = new BufferedReader(
+                        new InputStreamReader(expected));
                 String line1 = reader1.readLine();
                 String line2 = reader2.readLine();
                 int i = 1;
                 while (line1 != null || line2 != null) {
-                    assertEquals("Unpacked files differ for " + name, line2, line1);
+                    assertEquals("Unpacked files differ for " + name, line2,
+                            line1);
                     line1 = reader1.readLine();
                     line2 = reader2.readLine();
                     i++;
@@ -267,6 +346,8 @@
                 reader2.close();
             }
         }
+        jarFile.close();
+        jarFile2.close();
     }
 
 }



Mime
View raw message