harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r687671 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/test: java/org/apache/harmony/unpack200/tests/ resources/org/apache/harmony/pack200/tests/
Date Thu, 21 Aug 2008 09:42:54 GMT
Author: sjanuary
Date: Thu Aug 21 02:42:52 2008
New Revision: 687671

URL: http://svn.apache.org/viewvc?rev=687671&view=rev
Log:
Pack200 - fix tests so they don't rely on javap any more and compare class files directly
instead

Added:
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/hw.jar
  (with props)
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpacked.jar
  (with props)
Removed:
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/HelloWorldJavap.out
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlJavap.out
Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/SegmentTest.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java?rev=687671&r1=687670&r2=687671&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
Thu Aug 21 02:42:52 2008
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Enumeration;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
@@ -69,51 +70,42 @@
         archive.unpack();
         JarFile jarFile = new JarFile(file);
         file.deleteOnExit();
-        JarEntry entry = jarFile
-                .getJarEntry("bin/test/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest$BaseRowSetImpl.class");
-        assertNotNull(entry);
-        try {
-            Process process2 = Runtime
-                .getRuntime()
-                .exec(
-                        "javap -c -verbose -classpath "
-                                + file.getName()
-                                + " bin/test/org.apache.harmony.sql.tests.javax.sql.rowset.BaseRowSetTest$BaseRowSetImpl",
-                        new String[] {}, file.getParentFile());
-
-            BufferedReader reader1 = new BufferedReader(new InputStreamReader(
-                    process2.getInputStream()));
-            InputStream javapCompareFile = Archive.class
-                    .getResourceAsStream("/org/apache/harmony/pack200/tests/sqlJavap.out");
+
+        JarFile jarFile2 = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
+
+        Enumeration entries = jarFile.entries();
+        Enumeration entries2 = jarFile2.entries();
+        while(entries.hasMoreElements() && entries2.hasMoreElements()) {
+
+            JarEntry entry = (JarEntry) entries.nextElement();
+            assertNotNull(entry);
+            String name = entry.getName();
+
+            JarEntry entry2 = (JarEntry) entries2.nextElement();
+            assertNotNull(entry2);
+            String name2 = entry2.getName();
+
+            assertEquals(name, name2);
+
+            InputStream ours = jarFile.getInputStream(entry);
+            InputStream expected = jarFile2.getInputStream(entry2);
+
+            BufferedReader reader1 = new BufferedReader(new InputStreamReader(ours));
             BufferedReader reader2 = new BufferedReader(new InputStreamReader(
-                    javapCompareFile));
-            String line1 = readNextLine(reader1);
-            String line2 = readNextLine(reader2);
+                    expected));
+            String line1 = reader1.readLine();
+            String line2 = reader2.readLine();
             int i = 1;
             while (line1 != null || line2 != null) {
-                assertEquals(line2, line1);
-                line1 = readNextLine(reader1);
-                line2 = readNextLine(reader2);
+                assertEquals("Unpacked class files differ for " + name, line2, line1);
+                line1 = reader1.readLine();
+                line2 = reader2.readLine();
                 i++;
             }
             reader1.close();
             reader2.close();
-        } catch (IOException e) {
-            String message = e.getMessage();
-            if (message.startsWith("Unable to start program") || message.startsWith("The
creation of the Process has just failed")) {
-                System.out.println("Warning: org.apache.harmony.unpack200.tests.ArchiveTest.testWithSql()
was not completed as javap could not be found");
-            } else {
-                throw e;
-            }
-        }
-    }
-
-    private String readNextLine(BufferedReader reader) throws IOException {
-        String line = reader.readLine();
-        while ("".equals(line)) {
-            line = reader.readLine();
         }
-        return line;
     }
 
     // Test with an archive containing Harmony's Pack200 module, packed with -E1

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/SegmentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/SegmentTest.java?rev=687671&r1=687670&r2=687671&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/SegmentTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/SegmentTest.java
Thu Aug 21 02:42:52 2008
@@ -87,56 +87,80 @@
         out = null;
         JarFile jarFile = new JarFile(file);
         file.deleteOnExit();
+
         JarEntry entry = jarFile
                 .getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
         assertNotNull(entry);
+        InputStream ours = jarFile.getInputStream(entry);
+
+        JarFile jarFile2 = new JarFile(new File(Segment.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
+        JarEntry entry2 = jarFile2
+                .getJarEntry("org/apache/harmony/archive/tests/internal/pack200/HelloWorld.class");
+        assertNotNull(entry2);
 
-        try {
-            Process process = Runtime
-                    .getRuntime()
-                    .exec(
-                            "java -cp "
-                                    + file.getName()
-                                    + " org.apache.harmony.archive.tests.internal.pack200.HelloWorld",
-                            new String[] {}, file.getParentFile());
-            BufferedReader reader = new BufferedReader(new InputStreamReader(
-                    process.getInputStream()));
-            String line = reader.readLine();
-            assertEquals("Hello world", line);
-            reader.close();
-
-            Process process2 = Runtime
-                    .getRuntime()
-                    .exec(
-                            "javap -c -verbose -classpath "
-                                    + file.getName()
-                                    + " org.apache.harmony.archive.tests.internal.pack200.HelloWorld",
-                            new String[] {}, file.getParentFile());
-            BufferedReader reader1 = new BufferedReader(new InputStreamReader(process2
-                    .getInputStream()));
-            InputStream javapCompareFile = Segment.class
-                    .getResourceAsStream("/org/apache/harmony/pack200/tests/HelloWorldJavap.out");
-            BufferedReader reader2 = new BufferedReader(new InputStreamReader(
-                    javapCompareFile));
-            String line1 = readNextLine(reader1);
-            String line2 = readNextLine(reader2);
-            int i = 1;
-            while (line1 != null || line2 != null) {
-                assertEquals(line2, line1);
-                line1 = readNextLine(reader1);
-                line2 = readNextLine(reader2);
-                i++;
-            }
-            reader1.close();
-            reader2.close();
-        } catch (IOException e) {
-            String message = e.getMessage();
-            if (message.startsWith("Unable to start program") || message.startsWith("The
creation of the Process has just failed")) {
-                System.out.println("Warning: org.apache.harmony.unpack200.tests.SegmentTest.testHelloWorld()
was not completed as java or javap could not be found");
-            } else {
-                throw e;
-            }
+        InputStream expected = jarFile2.getInputStream(entry2);
+
+        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 class files differ", line2, line1);
+            line1 = reader1.readLine();
+            line2 = reader2.readLine();
+            i++;
         }
+        reader1.close();
+        reader2.close();
+
+//        try {
+//            Process process = Runtime
+//                    .getRuntime()
+//                    .exec(
+//                            "java -cp "
+//                                    + file.getName()
+//                                    + " org.apache.harmony.archive.tests.internal.pack200.HelloWorld",
+//                            new String[] {}, file.getParentFile());
+//            BufferedReader reader = new BufferedReader(new InputStreamReader(
+//                    process.getInputStream()));
+//            String line = reader.readLine();
+//            assertEquals("Hello world", line);
+//            reader.close();
+//
+//            Process process2 = Runtime
+//                    .getRuntime()
+//                    .exec(
+//                            "javap -c -verbose -classpath "
+//                                    + file.getName()
+//                                    + " org.apache.harmony.archive.tests.internal.pack200.HelloWorld",
+//                            new String[] {}, file.getParentFile());
+//            BufferedReader reader1 = new BufferedReader(new InputStreamReader(process2
+//                    .getInputStream()));
+//            InputStream javapCompareFile = Segment.class
+//                    .getResourceAsStream("/org/apache/harmony/pack200/tests/HelloWorldJavap.out");
+//            BufferedReader reader2 = new BufferedReader(new InputStreamReader(
+//                    javapCompareFile));
+//            String line1 = readNextLine(reader1);
+//            String line2 = readNextLine(reader2);
+//            int i = 1;
+//            while (line1 != null || line2 != null) {
+//                assertEquals(line2, line1);
+//                line1 = readNextLine(reader1);
+//                line2 = readNextLine(reader2);
+//                i++;
+//            }
+//            reader1.close();
+//            reader2.close();
+//        } catch (IOException e) {
+//            String message = e.getMessage();
+//            if (message.startsWith("Unable to start program") || message.startsWith("The
creation of the Process has just failed")) {
+//                System.out.println("Warning: org.apache.harmony.unpack200.tests.SegmentTest.testHelloWorld()
was not completed as java or javap could not be found");
+//            } else {
+//                throw e;
+//            }
+//        }
     }
 
     private String readNextLine(BufferedReader reader) throws IOException {

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/hw.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/hw.jar?rev=687671&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/hw.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpacked.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpacked.jar?rev=687671&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpacked.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message