harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r986626 - in /harmony/enhanced/java/trunk/classlib/modules/pack200/src: main/java/org/apache/harmony/pack200/ test/java/org/apache/harmony/pack200/tests/ test/resources/org/apache/harmony/pack200/tests/
Date Wed, 18 Aug 2010 11:30:50 GMT
Author: sjanuary
Date: Wed Aug 18 11:30:50 2010
New Revision: 986626

URL: http://svn.apache.org/viewvc?rev=986626&view=rev
Log:
Pack200 - new tests and some accompanying bug fixes

Added:
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/RunCodecTest.java
  (with props)
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/annotations.jar
  (with props)
Modified:
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
    harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
Wed Aug 18 11:30:50 2010
@@ -1328,22 +1328,22 @@ public class ClassBands extends BandSet 
             boolean visible, List nameRU, List t, List values, List caseArrayN, List nestTypeRS,
List nestNameRU, List nestPairN) {
         if(visible) {
             method_RVPA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
-            Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+            Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
             if((flag.intValue() & (1<<23)) != 0) {
                 method_RVPA_bands.incrementAnnoN();
             } else {
                 method_RVPA_bands.newEntryInAnnoN();
             }
-            tempMethodFlags.add(new Integer(flag.intValue() | (1<<23)));
+            tempMethodFlags.add(new Long(flag.longValue() | (1<<23)));
         } else {
             method_RIPA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
-            Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
-            if((flag.intValue() & (1<<24)) != 0) {
+            Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+            if((flag.longValue() & (1<<24)) != 0) {
                 method_RIPA_bands.incrementAnnoN();
             } else {
                 method_RIPA_bands.newEntryInAnnoN();
             }
-            tempMethodFlags.add(new Integer(flag.intValue() | (1<<24)));
+            tempMethodFlags.add(new Long(flag.longValue() | (1<<24)));
         }
     }
 

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
Wed Aug 18 11:30:50 2010
@@ -268,7 +268,7 @@ public class MetadataBandGroup extends B
             } else if (tag.equals("J")) {
                 Long value = (Long)valuesIterator.next();
                 caseJ_KJ.add(cpBands.getConstant(value));
-            } else if (tag.equals("C")) {
+            } else if (tag.equals("c")) {
                 String value = (String)valuesIterator.next();
                 casec_RS.add(cpBands.getCPSignature(value));
             } else if (tag.equals("e")) {

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingUtils.java
Wed Aug 18 11:30:50 2010
@@ -86,7 +86,7 @@ public class PackingUtils {
     }
 
     /**
-     * When effort is 0, the packer copys through the original jar input stream
+     * When effort is 0, the packer copies through the original jar input stream
      * without compression
      * 
      * @param jarInputStream

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java
Wed Aug 18 11:30:50 2010
@@ -151,11 +151,16 @@ public class PopulationCodec extends Cod
     }
 
     public byte[] encode(int[] favoured, int[] tokens, int[] unfavoured) throws Pack200Exception
{
-        byte[] favouredEncoded = favouredCodec.encode(favoured);
+        int[] favoured2 = new int[favoured.length + 1];
+        System.arraycopy(favoured, 0, favoured2, 0, favoured.length);
+        favoured2[favoured2.length - 1] = favoured[favoured.length - 1]; // repeat last value;
+        byte[] favouredEncoded = favouredCodec.encode(favoured2);
         byte[] tokensEncoded = tokenCodec.encode(tokens);
         byte[] unfavouredEncoded = unfavouredCodec.encode(unfavoured);
         byte[] band = new byte[favouredEncoded.length + tokensEncoded.length + unfavouredEncoded.length];
-
+        System.arraycopy(favouredEncoded, 0, band, 0, favouredEncoded.length);
+        System.arraycopy(tokensEncoded, 0, band, favouredEncoded.length, tokensEncoded.length);
+        System.arraycopy(unfavouredEncoded, 0, band, favouredEncoded.length + tokensEncoded.length,
unfavouredEncoded.length);
         return band;
     }
 

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
Wed Aug 18 11:30:50 2010
@@ -135,13 +135,11 @@ public class RunCodec extends Codec {
     }
 
     public byte[] encode(int value, int last) throws Pack200Exception {
-        // TODO Auto-generated method stub
-        return null;
+        throw new Pack200Exception("Must encode entire band at once with a RunCodec");
     }
 
     public byte[] encode(int value) throws Pack200Exception {
-        // TODO Auto-generated method stub
-        return null;
+        throw new Pack200Exception("Must encode entire band at once with a RunCodec");
     }
 
     public int getK() {

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
Wed Aug 18 11:30:50 2010
@@ -458,31 +458,40 @@ public class Segment implements ClassVis
                 name = "";
             }
             nameRU.add(name);
-            values.add(value);
-            addTag(value);
+            addValueAndTag(value);
         }
 
-        private void addTag(Object value) {
+        private void addValueAndTag(Object value) {
             if(value instanceof Integer) {
                 T.add("I");
+                values.add(value);
             } else if (value instanceof Double) {
                 T.add("D");
+                values.add(value);
             } else if (value instanceof Float) {
                 T.add("F");
+                values.add(value);
             } else if (value instanceof Long) {
                 T.add("J");
+                values.add(value);
             } else if (value instanceof Byte) {
                 T.add("B");
+                values.add(new Integer(((Byte)value).intValue()));
             } else if (value instanceof Character) {
                 T.add("C");
+                values.add(new Integer(((Character)value).charValue()));
             } else if (value instanceof Short) {
                 T.add("S");
+                values.add(new Integer(((Short)value).intValue()));
             } else if (value instanceof Boolean) {
                 T.add("Z");
+                values.add(new Integer(((Boolean)value).booleanValue() ? 1 : 0));
             } else if (value instanceof String) {
                 T.add("s");
+                values.add(value);
             } else if (value instanceof Type) {
                 T.add("c");
+                values.add(((Type)value).toString());
             }
         }
 
@@ -499,8 +508,7 @@ public class Segment implements ClassVis
                     Integer numPairs = (Integer) nestPairN.remove(nestPairN.size() - 1);
                     nestPairN.add(new Integer(numPairs.intValue() + 1));
                     nestNameRU.add(name);
-                    values.add(value);
-                    addTag(value);
+                    addValueAndTag(value);
                 }
 
                 public AnnotationVisitor visitAnnotation(String arg0,
@@ -543,8 +551,7 @@ public class Segment implements ClassVis
                         name = "";
                     }
                     nameRU.add(name);
-                    values.add(value);
-                    addTag(value);
+                    addValueAndTag(value);
                 }
 
                 public AnnotationVisitor visitAnnotation(String arg0,

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Wed Aug 18 11:30:50 2010
@@ -344,6 +344,20 @@ public class ArchiveTest extends TestCas
 
         compareFiles(jarFile, jarFile2);
     }
+    
+    public void testAnnotations2() throws IOException, Pack200Exception,
+            URISyntaxException {
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/annotations.jar").toURI()));
+        file = File.createTempFile("annotations", ".pack");
+        file.deleteOnExit();
+        out = new FileOutputStream(file);
+        PackingOptions options = new PackingOptions();
+        options.setGzip(false);
+        new Archive(in, out, options).pack();
+        in.close();
+        out.close();
+    }
 
     public void testE0() throws Pack200Exception, IOException, URISyntaxException {
         File f1 = new File(Archive.class.getResource(

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java
Wed Aug 18 11:30:50 2010
@@ -165,23 +165,6 @@ public class CodecTest extends TestCase 
         assertFalse(byte2s.encodes(256));
     }
 
-    public void testRunCodec() throws Exception {
-        RunCodec runCodec = new RunCodec(1, Codec.UNSIGNED5, Codec.BYTE1);
-        ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {
-                (byte) 192, 0, (byte) 192, 0 });
-        assertEquals(192, runCodec.decode(bais));
-        assertEquals(192, runCodec.decode(bais));
-        assertEquals(0, runCodec.decode(bais));
-        assertEquals(0, bais.available());
-        runCodec = new RunCodec(1, Codec.BYTE1, Codec.UNSIGNED5);
-        bais = new ByteArrayInputStream(new byte[] { (byte) 192, 0, (byte) 192,
-                0 });
-        assertEquals(192, runCodec.decode(bais));
-        assertEquals(0, runCodec.decode(bais));
-        assertEquals(192, runCodec.decode(bais));
-        assertEquals(0, bais.available());
-    }
-
     public void testUnsigned5() throws Exception {
         decode(Codec.UNSIGNED5, new byte[] { 1 }, 1, 0);
         decode(Codec.UNSIGNED5, new byte[] { (byte) 191 }, 191, 0);

Modified: harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java?rev=986626&r1=986625&r2=986626&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java
Wed Aug 18 11:30:50 2010
@@ -22,6 +22,7 @@ import java.io.InputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.pack200.BHSDCodec;
 import org.apache.harmony.pack200.Codec;
 import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.PopulationCodec;
@@ -63,5 +64,20 @@ public class PopulationCodecTest extends
         }
         assertEquals(0, in.available());
     }
+    
+    public void testEncodeSingleValue() {
+        try {
+            new PopulationCodec(BHSDCodec.SIGNED5, BHSDCodec.SIGNED5, BHSDCodec.UDELTA5).encode(5);
+            fail("Should not allow a single value to be encoded as we don't know which codec
to use");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+        try {
+            new PopulationCodec(BHSDCodec.SIGNED5, BHSDCodec.SIGNED5, BHSDCodec.UDELTA5).encode(5,
8);
+            fail("Should not allow a single value to be encoded as we don't know which codec
to use");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+    }
 
 }

Added: harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/RunCodecTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/RunCodecTest.java?rev=986626&view=auto
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/RunCodecTest.java
(added)
+++ harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/RunCodecTest.java
Wed Aug 18 11:30:50 2010
@@ -0,0 +1,166 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 org.apache.harmony.pack200.tests;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.pack200.BHSDCodec;
+import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
+import org.apache.harmony.pack200.PopulationCodec;
+import org.apache.harmony.pack200.RunCodec;
+
+/**
+ * Test for RunCodec
+ */
+public class RunCodecTest extends TestCase {
+
+    public void testRunCodec() {
+        try {
+            new RunCodec(0, BHSDCodec.SIGNED5, BHSDCodec.UDELTA5);
+            fail("Should not allow a k value of 0");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+        try {
+            new RunCodec(10, null, BHSDCodec.UDELTA5);
+            fail("Should not allow a null codec");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+        try {
+            new RunCodec(10, BHSDCodec.UDELTA5, null);
+            fail("Should not allow a null codec");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+        try {
+            new RunCodec(10, null, null);
+            fail("Should not allow a null codec");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+    }
+
+    public void testDecode() throws Exception {
+        RunCodec runCodec = new RunCodec(1, Codec.UNSIGNED5, Codec.BYTE1);
+        ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {
+                (byte) 192, 0, (byte) 192, 0 });
+        assertEquals(192, runCodec.decode(bais));
+        assertEquals(192, runCodec.decode(bais));
+        assertEquals(0, runCodec.decode(bais));
+        assertEquals(0, bais.available());
+        runCodec = new RunCodec(1, Codec.BYTE1, Codec.UNSIGNED5);
+        bais = new ByteArrayInputStream(new byte[] { (byte) 192, 0, (byte) 192,
+                0 });
+        assertEquals(192, runCodec.decode(bais));
+        assertEquals(0, runCodec.decode(bais));
+        assertEquals(192, runCodec.decode(bais));
+        assertEquals(0, bais.available());
+    }
+
+    public void testDecodeInts() throws Exception {
+        int[] band = new int[] { 1, -2, -3, 1000, 55, 5, 10, 20 };
+        // first 5 of band to be encoded with DELTA5
+        byte[] bytes1 = Codec.DELTA5.encode(new int[] { 1, -2, -3, 1000, 55 });
+        // rest of band to be encoded with UNSIGNED5
+        byte[] bytes2 = Codec.UNSIGNED5.encode(new int[] { 5, 10, 20 });
+        byte[] bandEncoded = new byte[bytes1.length + bytes2.length];
+        System.arraycopy(bytes1, 0, bandEncoded, 0, bytes1.length);
+        System.arraycopy(bytes2, 0, bandEncoded, bytes1.length, bytes2.length);
+        RunCodec runCodec = new RunCodec(5, Codec.DELTA5, Codec.UNSIGNED5);
+        int[] bandDecoded = runCodec.decodeInts(8, new ByteArrayInputStream(
+                bandEncoded));
+        assertEquals(band.length, bandDecoded.length);
+        for (int i = 0; i < band.length; i++) {
+            assertEquals(band[i], bandDecoded[i]);
+        }
+    }
+
+    public void testNestedPopulationCodec() throws Exception {
+        int[] band = new int[] { 11, 12, 33, 4000, -555, 5, 10, 20, 10, 3, 20,
+                20, 20, 10, 10, 999, 20, 789, 10, 10, 355, 12345 };
+        // first 5 of band to be encoded with DELTA5
+        byte[] bytes1 = Codec.DELTA5
+                .encode(new int[] { 11, 12, 33, 4000, -555 });
+        // rest of band to be encoded with a PopulationCodec
+        PopulationCodec popCodec = new PopulationCodec(Codec.UNSIGNED5,
+                Codec.BYTE1, Codec.UNSIGNED5);
+        byte[] bytes2 = popCodec.encode(new int[] { 10, 20 }, new int[] { 0, 1,
+                2, 1, 0, 2, 2, 2, 1, 1, 0, 2, 0, 1, 1, 0, 0 }, new int[] { 5,
+                3, 999, 789, 355, 12345 });
+        byte[] bandEncoded = new byte[bytes1.length + bytes2.length];
+        System.arraycopy(bytes1, 0, bandEncoded, 0, bytes1.length);
+        System.arraycopy(bytes2, 0, bandEncoded, bytes1.length, bytes2.length);
+        RunCodec runCodec = new RunCodec(5, Codec.DELTA5, new PopulationCodec(
+                Codec.UNSIGNED5, Codec.BYTE1, Codec.UNSIGNED5));
+        int[] bandDecoded = runCodec.decodeInts(band.length,
+                new ByteArrayInputStream(bandEncoded));
+        assertEquals(band.length, bandDecoded.length);
+        for (int i = 0; i < band.length; i++) {
+            assertEquals(band[i], bandDecoded[i]);
+        }
+    }
+
+    public void testNestedRunCodec() throws Exception {
+        int[] band = new int[] { 1, 2, 3, 10, 20, 30, 100, 200, 300 };
+        // first 3 of band to be encoded with UDELTA5
+        byte[] bytes1 = Codec.UDELTA5.encode(new int[] { 1, 2, 3 });
+        // rest of band to be encoded with a RunCodec
+        byte[] bytes2 = Codec.BYTE1.encode(new int[] { 10, 20, 30 });
+        byte[] bytes3 = Codec.UNSIGNED5.encode(new int[] { 100, 200, 300 });
+        byte[] bandEncoded = new byte[bytes1.length + bytes2.length
+                + bytes3.length];
+        System.arraycopy(bytes1, 0, bandEncoded, 0, bytes1.length);
+        System.arraycopy(bytes2, 0, bandEncoded, bytes1.length, bytes2.length);
+        System.arraycopy(bytes3, 0, bandEncoded, bytes1.length + bytes2.length,
+                bytes3.length);
+        RunCodec runCodec = new RunCodec(3, Codec.UDELTA5, new RunCodec(3,
+                Codec.BYTE1, Codec.UNSIGNED5));
+        int[] bandDecoded = runCodec.decodeInts(9, new ByteArrayInputStream(
+                bandEncoded));
+        assertEquals(band.length, bandDecoded.length);
+        for (int i = 0; i < band.length; i++) {
+            assertEquals(band[i], bandDecoded[i]);
+        }
+    }
+
+    public void testToString() throws Pack200Exception {
+        RunCodec runCodec = new RunCodec(3, Codec.UNSIGNED5, Codec.BYTE1);
+        assertEquals(
+                "RunCodec[k=" + 3 + ";aCodec=" + Codec.UNSIGNED5.toString()
+                        + "bCodec=" + Codec.BYTE1.toString() + "]",
+                runCodec.toString());
+    }
+
+    public void testEncodeSingleValue() {
+        try {
+            new RunCodec(10, BHSDCodec.SIGNED5, BHSDCodec.UDELTA5).encode(5);
+            fail("Should not allow a single value to be encoded as we don't know which codec
to use");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+        try {
+            new RunCodec(10, BHSDCodec.SIGNED5, BHSDCodec.UDELTA5).encode(5, 8);
+            fail("Should not allow a single value to be encoded as we don't know which codec
to use");
+        } catch (Pack200Exception e) {
+            // pass
+        }
+    }
+}

Propchange: harmony/enhanced/java/trunk/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/RunCodecTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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



Mime
View raw message