summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.jni/directbuffer.c
blob: 3d32aba01fbd9d2e1cc139e1c59020e3fdd2a80c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
}