harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r785527 - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/NewAttributeBands.java test/java/org/apache/harmony/pack200/tests/NewAttributeBandsTest.java
Date Wed, 17 Jun 2009 09:44:00 GMT
Author: sjanuary
Date: Wed Jun 17 09:43:59 2009
New Revision: 785527

URL: http://svn.apache.org/viewvc?rev=785527&view=rev
Log:
Pack200 - more tests for unknown attributes and a bug fix

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

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java?rev=785527&r1=785526&r2=785527&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
Wed Jun 17 09:43:59 2009
@@ -499,9 +499,12 @@
         public void addAttributeToBand(NewAttribute attribute,
                 InputStream stream) {
             countElement.addAttributeToBand(attribute, stream);
-            for (Iterator iterator = layoutElements.iterator(); iterator.hasNext();) {
-                AttributeLayoutElement layoutElement = (AttributeLayoutElement) iterator.next();
-                layoutElement.addAttributeToBand(attribute, stream);
+            int count = countElement.latestValue();
+            for (int i = 0; i < count; i++) {
+                for (Iterator iterator = layoutElements.iterator(); iterator.hasNext();)
{
+                    AttributeLayoutElement layoutElement = (AttributeLayoutElement) iterator.next();
+                    layoutElement.addAttributeToBand(attribute, stream);
+                }
             }
         }
 
@@ -837,6 +840,9 @@
                 throw new RuntimeException("Error reading unknown attribute");
             }
         }
+        // use casting to preserve sign
+        if(i == 1) result = (byte) result;
+        if(i == 2) result = (short) result;
         return result;
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/NewAttributeBandsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/NewAttributeBandsTest.java?rev=785527&r1=785526&r2=785527&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/NewAttributeBandsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/NewAttributeBandsTest.java
Wed Jun 17 09:43:59 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.harmony.pack200.tests;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.List;
 
@@ -23,8 +25,11 @@
 
 import org.apache.harmony.pack200.AttributeDefinitionBands;
 import org.apache.harmony.pack200.CPUTF8;
+import org.apache.harmony.pack200.Codec;
 import org.apache.harmony.pack200.CpBands;
+import org.apache.harmony.pack200.NewAttribute;
 import org.apache.harmony.pack200.NewAttributeBands;
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.SegmentHeader;
 import org.apache.harmony.pack200.AttributeDefinitionBands.AttributeDefinition;
 import org.apache.harmony.pack200.NewAttributeBands.Call;
@@ -197,6 +202,51 @@
         assertEquals(secondCallable, call.getCallable());
     }
 
+    public void testAddAttributes() throws IOException, Pack200Exception {
+        CPUTF8 name = new CPUTF8("TestAttribute");
+        CPUTF8 layout = new CPUTF8("B");
+        MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
+                null, null, new AttributeDefinition(35,
+                        AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
+        newAttributeBands.addAttribute(new NewAttribute(null, "TestAttribute", "B", new byte[]
{27}, null, 0, null));
+        newAttributeBands.addAttribute(new NewAttribute(null, "TestAttribute", "B", new byte[]
{56}, null, 0, null));
+        newAttributeBands.addAttribute(new NewAttribute(null, "TestAttribute", "B", new byte[]
{3}, null, 0, null));
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        newAttributeBands.pack(out);
+        // BYTE1 is used for B layouts so we don't need to unpack to test the results
+        byte[] bytes = out.toByteArray();
+        assertEquals(3, bytes.length);
+        assertEquals(27, bytes[0]);
+        assertEquals(56, bytes[1]);
+        assertEquals(3, bytes[2]);
+    }
+
+    public void testAddAttributesWithReplicationLayout() throws IOException, Pack200Exception
{
+        CPUTF8 name = new CPUTF8("TestAttribute");
+        CPUTF8 layout = new CPUTF8("NB[SH]");
+        MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
+                null, null, new AttributeDefinition(35,
+                        AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
+        newAttributeBands.addAttribute(new NewAttribute(null, "TestAttribute", "B", new byte[]
{1, 0, 100}, null, 0, null));
+        short s = -50;
+        byte b1 = (byte)(s>>>8);
+        byte b2 = (byte)s;
+        newAttributeBands.addAttribute(new NewAttribute(null, "TestAttribute", "B", new byte[]
{3, 0, 5, 0, 25, b1, b2}, null, 0, null));
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        newAttributeBands.pack(out);
+        byte[] bytes = out.toByteArray();
+        assertEquals(1, bytes[0]);
+        assertEquals(3, bytes[1]);
+        byte[] band = new byte[bytes.length - 2];
+        System.arraycopy(bytes, 2, band, 0, band.length);
+        int[] decoded = Codec.SIGNED5.decodeInts(4, new ByteArrayInputStream(band));
+        assertEquals(4, decoded.length);
+        assertEquals(100, decoded[0]);
+        assertEquals(5, decoded[1]);
+        assertEquals(25, decoded[2]);
+        assertEquals(-50, decoded[3]);
+    }
+
     private class MockNewAttributeBands extends NewAttributeBands {
 
         public MockNewAttributeBands(int effort, CpBands cpBands,



Mime
View raw message