Repository: qpid-proton-j
Updated Branches:
  refs/heads/master be6d9209e -> 459b84d44


PROTON-1965 Add additional equality tests for buffer slices

Adds tests for equality checks on sliced buffers with non-zero offsets.

Project: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/commit/459b84d4
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/459b84d4
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/459b84d4

Branch: refs/heads/master
Commit: 459b84d446160d75a5ca021ac349affcfe6e09d2
Parents: be6d920
Author: Timothy Bish <tabish...@gmail.com>
Authored: Mon Nov 19 18:19:35 2018 -0500
Committer: Timothy Bish <tabish...@gmail.com>
Committed: Mon Nov 19 18:19:35 2018 -0500

----------------------------------------------------------------------
 .../codec/CompositeReadableBufferTest.java      | 88 +++++++++++++++++++-
 1 file changed, 87 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/459b84d4/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
----------------------------------------------------------------------
diff --git 
a/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
 
b/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
index 1e8e731..5325f17 100644
--- 
a/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
+++ 
b/proton-j/src/test/java/org/apache/qpid/proton/codec/CompositeReadableBufferTest.java
@@ -16,7 +16,15 @@
  */
 package org.apache.qpid.proton.codec;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
@@ -3610,6 +3618,84 @@ public class CompositeReadableBufferTest {
         assertEquals(3, buffer2.position());
     }
 
+    @Test
+    public void 
testEqualsWhenContentRemainingWithDifferentlyPositionedSlicesSame() throws 
CharacterCodingException {
+        
doEqualsWhenContentRemainingWithDifferentlyPositionedSlicesSameTestImpl(false);
+    }
+
+    @Test
+    public void 
testEqualsWhenContentRemainingWithDifferentlyPositionedSlicesSameMultipleArrays()
 throws CharacterCodingException {
+        
doEqualsWhenContentRemainingWithDifferentlyPositionedSlicesSameTestImpl(true);
+    }
+
+    private void 
doEqualsWhenContentRemainingWithDifferentlyPositionedSlicesSameTestImpl(boolean 
multipleArrays) {
+        CompositeReadableBuffer buffer1 = new CompositeReadableBuffer();
+        CompositeReadableBuffer buffer2 = new CompositeReadableBuffer();
+
+        byte[] data1 = new byte[] {-1, -1, 0, 1, 2, 3, 4, 5};
+        byte[] data2 = new byte[] {-1, -1, -1, 0, 1, 2, 3, 4, 5};
+
+        buffer1.append(data1);
+        buffer1.position(2);
+
+        buffer2.append(data2);
+        buffer2.position(3);
+
+        if (multipleArrays) {
+            byte[] data3 = new byte[] { 5, 4, 3, 2, 1 };
+            buffer1.append(data3);
+            buffer2.append(data3);
+        }
+
+        buffer1 = buffer1.slice();
+        buffer2 = buffer2.slice();
+
+        assertEquals(buffer1, buffer2);
+        assertEquals(buffer2, buffer1);
+
+        assertEquals(0, buffer1.position());
+        assertEquals(0, buffer2.position());
+    }
+
+    @Test
+    public void 
testEqualsWhenContentRemainingWithDifferentlyPositionedSlicesNotSame() throws 
CharacterCodingException {
+        
doEqualsWhenContentRemainingWithDifferentlyPositionedSlicesNotSameTestImpl(false);
+    }
+
+    @Test
+    public void 
testEqualsWhenContentRemainingWithDifferentlyPositionedSlicesNotSameMultipleArrays()
 throws CharacterCodingException {
+        
doEqualsWhenContentRemainingWithDifferentlyPositionedSlicesNotSameTestImpl(true);
+    }
+
+    private void 
doEqualsWhenContentRemainingWithDifferentlyPositionedSlicesNotSameTestImpl(boolean
 multipleArrays) {
+        CompositeReadableBuffer buffer1 = new CompositeReadableBuffer();
+        CompositeReadableBuffer buffer2 = new CompositeReadableBuffer();
+
+        byte[] data1 = new byte[] {-1, -1, 0, 1, 2, 3, 4, 5};
+        byte[] data2 = new byte[] {-1, -1, -1, 0, 1, 2, 3, 4, -1};
+
+        buffer1.append(data1);
+        buffer1.position(2);
+
+        buffer2.append(data2);
+        buffer2.position(3);
+
+        if (multipleArrays) {
+            byte[] data3 = new byte[] { 5, 4, 3, 2, 1 };
+            buffer1.append(data3);
+            buffer2.append(data3);
+        }
+
+        buffer1 = buffer1.slice();
+        buffer2 = buffer2.slice();
+
+        assertNotEquals(buffer1, buffer2);
+        assertNotEquals(buffer2, buffer1);
+
+        assertEquals(0, buffer1.position());
+        assertEquals(0, buffer2.position());
+    }
+
     //----- Utility Methods 
--------------------------------------------------//
 
     private void assertContentEquals(CompositeReadableBuffer buffer, byte 
array[], int offset, int length) {


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

Reply via email to