gcc/libjava/testsuite/libjava.jni/directbuffer.c
Michael Koch d2ba8a75ef re PR libgcj/18115 (JNI nio buffer functions only work with byte buffers)
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.

From-SVN: r93046
2005-01-07 11:32:07 +00:00

76 lines
1.9 KiB
C

#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);
}