01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.drlvm.tests.regression.h0000;
19:
20: import java.nio.Buffer;
21: import java.nio.ByteBuffer;
22: import junit.framework.TestCase;
23:
24: public class DirectByteBufferTest extends TestCase {
25:
26: static {
27: System.loadLibrary("DirectByteBufferTest");
28: }
29:
30: public static void main(String[] args) {
31: new DirectByteBufferTest().testValidBuffer();
32: }
33:
34: private static native String tryDirectBuffer();
35:
36: private static native String checkSameDirectStorage(Buffer b1,
37: Buffer b2);
38:
39: private static void assertView(String message, ByteBuffer b1,
40: Buffer b2, int capacityRatio) {
41: assertEquals(message + ":capacity", b1.capacity()
42: / capacityRatio, b2.capacity());
43: String err = checkSameDirectStorage(b1, b2);
44: assertNull(message + " : " + err, err);
45: }
46:
47: public void testValidBuffer() {
48: String err = tryDirectBuffer();
49: assertNull(err, err);
50: }
51:
52: /**
53: * A regression test for HARMONY-3591:
54: * JNI operations fail on non-byte views of a direct buffer.
55: */
56: public void testBufferView() {
57: ByteBuffer b = ByteBuffer.allocateDirect(100);
58: assertTrue(b.isDirect());
59: assertView("duplicate", b, b.duplicate(), 1);
60: assertView("char view", b, b.asCharBuffer(), 2);
61: assertView("short view", b, b.asShortBuffer(), 2);
62: assertView("int view", b, b.asIntBuffer(), 4);
63: assertView("float view", b, b.asFloatBuffer(), 4);
64: assertView("double view", b, b.asDoubleBuffer(), 8);
65: assertView("long view", b, b.asLongBuffer(), 8);
66: }
67: }
|