summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2013-12-19 17:52:47 +0000
committerNarayan Kamath <narayan@google.com>2013-12-20 10:14:20 +0000
commitef809d09cf0d28d999ac69969e4506d8afa4624d (patch)
tree326627b033a42a39261310054edd8ebea087df39 /test
parent7a761d8cdcc960d2198277a89396a0e24b8bb10b (diff)
downloadart-ef809d09cf0d28d999ac69969e4506d8afa4624d.tar.gz
art-ef809d09cf0d28d999ac69969e4506d8afa4624d.tar.bz2
art-ef809d09cf0d28d999ac69969e4506d8afa4624d.zip
JNI: NewDirectByteBuffer should allow 0 length buffers.
This makes the implementation symmetric with direct buffers allocated from java. - GetDirectBufferAddress returns the address of the buffer passed in to NewDirectByteBuffer (and not NULL). - GetDirectBufferCapaticy returns 0. bug: https://code.google.com/p/android/issues/detail?id=63055 Change-Id: I55b24623ec4f7670972fed898ea097934c6c0b5f
Diffstat (limited to 'test')
-rw-r--r--test/JniTest/JniTest.java3
-rw-r--r--test/JniTest/jni_test.cc12
2 files changed, 15 insertions, 0 deletions
diff --git a/test/JniTest/JniTest.java b/test/JniTest/JniTest.java
index 9194da581f..d53cf5e564 100644
--- a/test/JniTest/JniTest.java
+++ b/test/JniTest/JniTest.java
@@ -23,6 +23,7 @@ class JniTest {
testFindFieldOnAttachedNativeThread();
testCallStaticVoidMethodOnSubClass();
testGetMirandaMethod();
+ testZeroLengthByteBuffers();
}
private static native void testFindClassOnAttachedNativeThread();
@@ -67,6 +68,8 @@ class JniTest {
}
}
+ private static native void testZeroLengthByteBuffers();
+
private static abstract class testGetMirandaMethod_MirandaAbstract implements testGetMirandaMethod_MirandaInterface {
public boolean inAbstract() {
return true;
diff --git a/test/JniTest/jni_test.cc b/test/JniTest/jni_test.cc
index d15e180c02..33af94b2ab 100644
--- a/test/JniTest/jni_test.cc
+++ b/test/JniTest/jni_test.cc
@@ -17,6 +17,7 @@
#include <assert.h>
#include <stdio.h>
#include <pthread.h>
+#include <vector>
#include "jni.h"
@@ -125,3 +126,14 @@ extern "C" JNIEXPORT jobject JNICALL Java_JniTest_testGetMirandaMethodNative(JNI
assert(miranda_method != NULL);
return env->ToReflectedMethod(abstract_class, miranda_method, JNI_FALSE);
}
+
+// https://code.google.com/p/android/issues/detail?id=63055
+extern "C" void JNICALL Java_JniTest_testZeroLengthByteBuffers(JNIEnv* env, jclass) {
+ std::vector<uint8_t> buffer(1);
+ jobject byte_buffer = env->NewDirectByteBuffer(&buffer[0], 0);
+ assert(byte_buffer != NULL);
+ assert(!env->ExceptionCheck());
+
+ assert(env->GetDirectBufferAddress(byte_buffer) == &buffer[0]);
+ assert(env->GetDirectBufferCapacity(byte_buffer) == 0);
+}