diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-01-07 11:32:07 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-01-07 11:32:07 +0000 |
commit | 2d95c02be6e1f4db30a38b0e9322df01445b132a (patch) | |
tree | be94893c552db65c2384cd29222e07c02378c21c /libjava/testsuite | |
parent | fbbb20675404f3928d783d6655e432fd05933828 (diff) | |
download | gcc-2d95c02be6e1f4db30a38b0e9322df01445b132a.tar.gz |
2005-01-07 Michael Koch <konqueror@gmx.de>
PR libgcj/18115
* java/nio/Buffer.java (address): New field.
* java/nio/DirectByteBufferImpl.java (address): Removed.
* java/nio/MappedByteBufferImpl.java (address): Likewise.
* java/nio/CharViewBufferImpl.java (CharViewBufferImpl):
Explicitly initialize Buffer.address if needed.
* java/nio/DoubleViewBufferImpl.java (DoubleViewBufferImpl): Likewise.
* java/nio/FloatViewBufferImpl.java (FloatViewBufferImpl): Likewise.
* java/nio/IntViewBufferImpl.java (IntViewBufferImpl): Likewise.
* java/nio/LongViewBufferImpl.java (LongViewBufferImpl): Likewise.
* java/nio/ShortViewBufferImpl.java (ShortViewBufferImpl): Likewise.
* jni.cc (_Jv_JNI_GetDirectBufferAddress): Don't assume buffer is a
DirectByteBufferImpl object.
(_Jv_JNI_GetDirectBufferCapacity): Likewise.
* testsuite/libjava.jni/directbuffer.c,
testsuite/libjava.jni/directbuffer.java,
testsuite/libjava.jni/directbuffer.out,
testsuite/libjava.jni/bytebuffer.c,
testsuite/libjava.jni/bytebuffer.java,
testsuite/libjava.jni/bytebuffer.out: New files.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@93046 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/testsuite')
-rw-r--r-- | libjava/testsuite/libjava.jni/bytebuffer.c | 62 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/bytebuffer.java | 38 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/bytebuffer.out | 26 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/directbuffer.c | 75 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/directbuffer.java | 40 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/directbuffer.out | 14 |
6 files changed, 255 insertions, 0 deletions
diff --git a/libjava/testsuite/libjava.jni/bytebuffer.c b/libjava/testsuite/libjava.jni/bytebuffer.c new file mode 100644 index 00000000000..146c6a8443e --- /dev/null +++ b/libjava/testsuite/libjava.jni/bytebuffer.c @@ -0,0 +1,62 @@ +#include "bytebuffer.h" + +static void +test_buffer (JNIEnv *env, jobject buffer, const char *name) +{ + void *tmp = (*env)->GetDirectBufferAddress (env, buffer); + + if (tmp == NULL) + printf ("PASS: address of %s\n", name); + else + printf ("FAIL: address of %s\n", name); + + int tmplen = (*env)->GetDirectBufferCapacity (env, buffer); + + if (tmplen == -1) + printf ("PASS: length of %s\n", name); + else + printf ("FAIL: length of %s\n", name); +} + +JNIEXPORT void JNICALL +Java_bytebuffer_testByteBuffer (JNIEnv *env, jclass k, jobject buffer) +{ + test_buffer (env, buffer, "java.nio.ByteBuffer"); +} + +JNIEXPORT void JNICALL +Java_bytebuffer_testCharBuffer (JNIEnv *env, jclass k, jobject buffer) +{ + test_buffer (env, buffer, "java.nio.CharBuffer"); +} + +JNIEXPORT void JNICALL +Java_bytebuffer_testDoubleBuffer (JNIEnv *env, jclass k, jobject buffer) +{ + test_buffer (env, buffer, "java.nio.DoubleBuffer"); +} + +JNIEXPORT void JNICALL +Java_bytebuffer_testFloatBuffer (JNIEnv *env, jclass k, jobject buffer) +{ + test_buffer (env, buffer, "java.nio.FloatBuffer"); +} + +JNIEXPORT void JNICALL +Java_bytebuffer_testIntBuffer (JNIEnv *env, jclass k, jobject buffer) +{ + test_buffer (env, buffer, "java.nio.IntBuffer"); +} + +JNIEXPORT void JNICALL +Java_bytebuffer_testLongBuffer (JNIEnv *env, jclass k, jobject buffer) +{ + test_buffer (env, buffer, "java.nio.LongBuffer"); +} + +JNIEXPORT void JNICALL +Java_bytebuffer_testShortBuffer (JNIEnv *env, jclass k, jobject buffer) +{ + test_buffer (env, buffer, "java.nio.ShortBuffer"); +} + diff --git a/libjava/testsuite/libjava.jni/bytebuffer.java b/libjava/testsuite/libjava.jni/bytebuffer.java new file mode 100644 index 00000000000..0e541123f55 --- /dev/null +++ b/libjava/testsuite/libjava.jni/bytebuffer.java @@ -0,0 +1,38 @@ +// Test to make sure JNI implementation catches exceptions. + +import java.nio.*; + +public class bytebuffer +{ + static + { + System.loadLibrary("bytebuffer"); + } + + public static native void testByteBuffer(ByteBuffer bb); + public static native void testCharBuffer(CharBuffer b); + public static native void testDoubleBuffer(DoubleBuffer b); + public static native void testFloatBuffer(FloatBuffer b); + public static native void testIntBuffer(IntBuffer b); + public static native void testLongBuffer(LongBuffer b); + public static native void testShortBuffer(ShortBuffer b); + + public static void main(String[] args) + { + ByteBuffer bb = ByteBuffer.allocate(1024); + testByteBuffer(bb); + testCharBuffer(bb.asCharBuffer()); + testDoubleBuffer(bb.asDoubleBuffer()); + testFloatBuffer(bb.asFloatBuffer()); + testIntBuffer(bb.asIntBuffer()); + testLongBuffer(bb.asLongBuffer()); + testShortBuffer(bb.asShortBuffer()); + + testCharBuffer(CharBuffer.allocate(1024)); + testDoubleBuffer(DoubleBuffer.allocate(1024)); + testFloatBuffer(FloatBuffer.allocate(1024)); + testIntBuffer(IntBuffer.allocate(1024)); + testLongBuffer(LongBuffer.allocate(1024)); + testShortBuffer(ShortBuffer.allocate(1024)); + } +} diff --git a/libjava/testsuite/libjava.jni/bytebuffer.out b/libjava/testsuite/libjava.jni/bytebuffer.out new file mode 100644 index 00000000000..5af92e20612 --- /dev/null +++ b/libjava/testsuite/libjava.jni/bytebuffer.out @@ -0,0 +1,26 @@ +PASS: address of java.nio.ByteBuffer +PASS: length of java.nio.ByteBuffer +PASS: address of java.nio.CharBuffer +PASS: length of java.nio.CharBuffer +PASS: address of java.nio.DoubleBuffer +PASS: length of java.nio.DoubleBuffer +PASS: address of java.nio.FloatBuffer +PASS: length of java.nio.FloatBuffer +PASS: address of java.nio.IntBuffer +PASS: length of java.nio.IntBuffer +PASS: address of java.nio.LongBuffer +PASS: length of java.nio.LongBuffer +PASS: address of java.nio.ShortBuffer +PASS: length of java.nio.ShortBuffer +PASS: address of java.nio.CharBuffer +PASS: length of java.nio.CharBuffer +PASS: address of java.nio.DoubleBuffer +PASS: length of java.nio.DoubleBuffer +PASS: address of java.nio.FloatBuffer +PASS: length of java.nio.FloatBuffer +PASS: address of java.nio.IntBuffer +PASS: length of java.nio.IntBuffer +PASS: address of java.nio.LongBuffer +PASS: length of java.nio.LongBuffer +PASS: address of java.nio.ShortBuffer +PASS: length of java.nio.ShortBuffer diff --git a/libjava/testsuite/libjava.jni/directbuffer.c b/libjava/testsuite/libjava.jni/directbuffer.c new file mode 100644 index 00000000000..3d32aba01fb --- /dev/null +++ b/libjava/testsuite/libjava.jni/directbuffer.c @@ -0,0 +1,75 @@ +#include <stdlib.h> + +#include "directbuffer.h" + +#define BUFFER_SIZE 1024 + +static void *address; + +JNIEXPORT jobject JNICALL +Java_directbuffer_createDirectByteBuffer (JNIEnv *env, jclass k) +{ + address = malloc (BUFFER_SIZE); + return (*env)->NewDirectByteBuffer (env, address, 1024); +} + +static void +test_buffer (JNIEnv *env, jobject buffer, const char *name, int len) +{ + void *tmp = (*env)->GetDirectBufferAddress (env, buffer); + + if (address == tmp) + printf ("PASS: address of %s\n", name); + else + printf ("FAIL: address of %s\n", name); + + int tmplen = (*env)->GetDirectBufferCapacity (env, buffer); + + if (len == tmplen) + printf ("PASS: length of %s\n", name); + else + printf ("FAIL: length of %s\n", name); +} + +JNIEXPORT void JNICALL +Java_directbuffer_testDirectByteBuffer (JNIEnv *env, jclass k, jobject buffer, jint len) +{ + test_buffer (env, buffer, "direct java.nio.ByteBuffer", len); +} + +JNIEXPORT void JNICALL +Java_directbuffer_testCharBuffer (JNIEnv *env, jclass k, jobject buffer, jint len) +{ + test_buffer (env, buffer, "java.nio.CharBuffer view", len); +} + +JNIEXPORT void JNICALL +Java_directbuffer_testDoubleBuffer (JNIEnv *env, jclass k, jobject buffer, jint len) +{ + test_buffer (env, buffer, "java.nio.DoubleBuffer view", len); +} + +JNIEXPORT void JNICALL +Java_directbuffer_testFloatBuffer (JNIEnv *env, jclass k, jobject buffer, jint len) +{ + test_buffer (env, buffer, "java.nio.FloatBuffer view", len); +} + +JNIEXPORT void JNICALL +Java_directbuffer_testIntBuffer (JNIEnv *env, jclass k, jobject buffer, jint len) +{ + test_buffer (env, buffer, "java.nio.IntBuffer view", len); +} + +JNIEXPORT void JNICALL +Java_directbuffer_testLongBuffer (JNIEnv *env, jclass k, jobject buffer, jint len) +{ + test_buffer (env, buffer, "java.nio.LongBuffer view", len); +} + +JNIEXPORT void JNICALL +Java_directbuffer_testShortBuffer (JNIEnv *env, jclass k, jobject buffer, jint len) +{ + test_buffer (env, buffer, "java.nio.ShortBuffer view", len); +} + diff --git a/libjava/testsuite/libjava.jni/directbuffer.java b/libjava/testsuite/libjava.jni/directbuffer.java new file mode 100644 index 00000000000..ee844b9016d --- /dev/null +++ b/libjava/testsuite/libjava.jni/directbuffer.java @@ -0,0 +1,40 @@ +// Test to make sure JNI implementation catches exceptions. + +import java.nio.*; + +public class directbuffer +{ + static + { + System.loadLibrary("directbuffer"); + } + + public static native ByteBuffer createDirectByteBuffer(); + + public static native void testDirectByteBuffer(ByteBuffer bb, int len); + public static native void testCharBuffer(CharBuffer b, int len); + public static native void testDoubleBuffer(DoubleBuffer b, int len); + public static native void testFloatBuffer(FloatBuffer b, int len); + public static native void testIntBuffer(IntBuffer b, int len); + public static native void testLongBuffer(LongBuffer b, int len); + public static native void testShortBuffer(ShortBuffer b, int len); + + public static void main(String[] args) + { + ByteBuffer bb = createDirectByteBuffer(); + CharBuffer cb = bb.asCharBuffer(); + DoubleBuffer db = bb.asDoubleBuffer(); + FloatBuffer fb = bb.asFloatBuffer(); + IntBuffer ib = bb.asIntBuffer(); + LongBuffer lb = bb.asLongBuffer(); + ShortBuffer sb = bb.asShortBuffer(); + + testDirectByteBuffer(bb, 1024); + testCharBuffer(cb, 512); + testDoubleBuffer(db, 128); + testFloatBuffer(fb, 256); + testIntBuffer(ib, 256); + testLongBuffer(lb, 128); + testShortBuffer(sb, 512); + } +} diff --git a/libjava/testsuite/libjava.jni/directbuffer.out b/libjava/testsuite/libjava.jni/directbuffer.out new file mode 100644 index 00000000000..c1404b9f21f --- /dev/null +++ b/libjava/testsuite/libjava.jni/directbuffer.out @@ -0,0 +1,14 @@ +PASS: address of direct java.nio.ByteBuffer +PASS: length of direct java.nio.ByteBuffer +PASS: address of java.nio.CharBuffer view +PASS: length of java.nio.CharBuffer view +PASS: address of java.nio.DoubleBuffer view +PASS: length of java.nio.DoubleBuffer view +PASS: address of java.nio.FloatBuffer view +PASS: length of java.nio.FloatBuffer view +PASS: address of java.nio.IntBuffer view +PASS: length of java.nio.IntBuffer view +PASS: address of java.nio.LongBuffer view +PASS: length of java.nio.LongBuffer view +PASS: address of java.nio.ShortBuffer view +PASS: length of java.nio.ShortBuffer view |