if (swap) {
swapShorts(src_ + offset, length);
}
- memcpy((jbyte *)pointer, src_ + offset, length);
+ memcpy((jbyte *)pointer, (jbyte *)src_ + offset, length);
if (swap) {
swapShorts(src_ + offset, length);
}
*/
static void harmony_nio_putIntsImpl(JNIEnv *_env, jobject _this,
jint pointer, jintArray src, jint offset, jint length, jboolean swap) {
-
+
offset = offset << 2;
length = length << 2;
if (swap) {
swapInts(src_ + offset, length);
}
- memcpy((jbyte *)pointer, src_ + offset, length);
+ memcpy((jbyte *)pointer, (jbyte *)src_ + offset, length);
if (swap) {
swapInts(src_ + offset, length);
}
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.IntBuffer;
@TestTargetClass(java.nio.IntBuffer.class)
public class DirectIntBufferTest extends IntBufferTest {
baseBuf = null;
}
+ /**
+ * Regression for http://code.google.com/p/android/issues/detail?id=3279
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "put",
+ args = {int[].class, int.class, int.class}
+ )
+ public void testPutWhenOffsetIsNonZero() {
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
+ byteBuffer.order(ByteOrder.nativeOrder());
+ IntBuffer intBuffer = byteBuffer.asIntBuffer();
+
+ int[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ intBuffer.put(source, 2, 2);
+ intBuffer.put(source, 4, 2);
+ assertEquals(4, intBuffer.get(0));
+ assertEquals(5, intBuffer.get(1));
+ assertEquals(6, intBuffer.get(2));
+ assertEquals(7, intBuffer.get(3));
+ }
+
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies hasArray method for direct IntBuffer.",
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
+import java.nio.IntBuffer;
@TestTargetClass(java.nio.ShortBuffer.class)
public class DirectShortBufferTest extends ShortBufferTest {
baseBuf = null;
}
+ /**
+ * Regression for http://code.google.com/p/android/issues/detail?id=3279
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "put",
+ args = {short[].class, int.class, int.class}
+ )
+ public void testPutWhenOffsetIsNonZero() {
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
+ byteBuffer.order(ByteOrder.nativeOrder());
+ ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
+
+ short[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ shortBuffer.put(source, 2, 2);
+ shortBuffer.put(source, 4, 2);
+ assertEquals(4, shortBuffer.get(0));
+ assertEquals(5, shortBuffer.get(1));
+ assertEquals(6, shortBuffer.get(2));
+ assertEquals(7, shortBuffer.get(3));
+ }
+
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies hasArray method for direct ShortBuffer.",