This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton-j.git

commit 4907d3a5b662675f0aa6c552dbaa89b7917c1391
Author: Robbie Gemmell <rob...@apache.org>
AuthorDate: Thu May 30 18:13:39 2019 +0100

    PROTON-2059: handle the char type during array decoding
---
 .../org/apache/qpid/proton/codec/ArrayType.java    | 16 +++++++++++++++
 .../qpid/proton/codec/ArrayTypeCodecTest.java      | 24 +++++++++++++++-------
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java 
b/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java
index 7d4de49..3104486 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/ArrayType.java
@@ -1112,6 +1112,10 @@ public class ArrayType implements PrimitiveType<Object[]>
             {
                 return 
decodeDoubleArray((DoubleType.DoubleEncoding)constructor, count);
             }
+            else if(constructor instanceof CharacterType.CharacterEncoding)
+            {
+                return 
decodeCharArray((CharacterType.CharacterEncoding)constructor, count);
+            }
             else
             {
                 throw new ClassCastException("Unexpected class " + 
constructor.getClass().getName());
@@ -1206,5 +1210,17 @@ public class ArrayType implements PrimitiveType<Object[]>
 
         return array;
     }
+
+    private static char[] decodeCharArray(CharacterType.CharacterEncoding 
constructor, final int count)
+    {
+        char[] array = new char[count];
+
+        for(int i = 0; i < count; i++)
+        {
+            array[i] = constructor.readPrimitiveValue();
+        }
+
+        return array;
+    }
 }
 
diff --git 
a/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java 
b/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java
index c82ecb7..9a85216 100644
--- 
a/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java
+++ 
b/proton-j/src/test/java/org/apache/qpid/proton/codec/ArrayTypeCodecTest.java
@@ -1023,24 +1023,24 @@ public class ArrayTypeCodecTest extends 
CodecTestSupport {
     }
 
     @Test
-    public void testEncodeCharArray25() throws Throwable {
+    public void testEncodeDecodeCharArray25() throws Throwable {
         // char array8 less than 128 bytes
-        doEncodeCharArrayTestImpl(25);
+        doEncodeDecodeCharArrayTestImpl(25);
     }
 
     @Test
-    public void testEncodeCharArray50() throws Throwable {
+    public void testEncodeDecodeCharArray50() throws Throwable {
         // char array8 greater than 128 bytes
-        doEncodeCharArrayTestImpl(50);
+        doEncodeDecodeCharArrayTestImpl(50);
     }
 
     @Test
-    public void testEncodeCharArray384() throws Throwable {
+    public void testEncodeDecodeCharArray384() throws Throwable {
         // char array32
-        doEncodeCharArrayTestImpl(384);
+        doEncodeDecodeCharArrayTestImpl(384);
     }
 
-    private void doEncodeCharArrayTestImpl(int count) throws Throwable {
+    private void doEncodeDecodeCharArrayTestImpl(int count) throws Throwable {
         char[] source = createPayloadArrayChars(count);
 
         try {
@@ -1084,6 +1084,16 @@ public class ArrayTypeCodecTest extends CodecTestSupport 
{
             assertFalse("Should have drained the encoder buffer contents", 
buffer.hasRemaining());
 
             assertArrayEquals("Unexpected actual array encoding", 
expectedEncoding, actualEncoding);
+
+            // Now verify against the decoding
+            buffer.flip();
+            Object decoded = decoder.readObject();
+            assertNotNull(decoded);
+            assertTrue(decoded.getClass().isArray());
+            assertTrue(decoded.getClass().getComponentType().isPrimitive());
+            assertEquals(char.class, decoded.getClass().getComponentType());
+
+            assertArrayEquals("Unexpected decoding", source, (char[]) decoded);
         }
         catch (Throwable t) {
             System.err.println("Error during test, source array: " + 
Arrays.toString(source));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to