1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.apache.harmony.nio.tests.java.nio;
18 import dalvik.annotation.TestLevel;
19 import dalvik.annotation.TestTargetNew;
20 import dalvik.annotation.TestTargetClass;
22 import java.nio.BufferOverflowException;
23 import java.nio.ByteBuffer;
24 import java.nio.ByteOrder;
25 import java.nio.IntBuffer;
27 @TestTargetClass(java.nio.IntBuffer.class)
28 public class DirectIntBufferTest extends IntBufferTest {
30 capacity = BUFFER_LENGTH;
31 buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*4).asIntBuffer();
36 public void tearDown(){
42 * Regression for http://code.google.com/p/android/issues/detail?id=3279
45 level = TestLevel.PARTIAL_COMPLETE,
48 args = {int[].class, int.class, int.class}
50 public void testPutWhenOffsetIsNonZero() {
51 ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
52 byteBuffer.order(ByteOrder.nativeOrder());
53 IntBuffer intBuffer = byteBuffer.asIntBuffer();
55 int[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
57 intBuffer.put(source, 2, 2);
58 intBuffer.put(source, 4, 2);
59 assertEquals(4, intBuffer.get(0));
60 assertEquals(5, intBuffer.get(1));
61 assertEquals(6, intBuffer.get(2));
62 assertEquals(7, intBuffer.get(3));
66 level = TestLevel.PARTIAL_COMPLETE,
67 notes = "Verifies hasArray method for direct IntBuffer.",
71 public void testHasArray() {
72 assertFalse(buf.hasArray());
76 level = TestLevel.PARTIAL_COMPLETE,
77 notes = "Verifies array method for direct IntBuffer.",
81 public void testArray() {
84 fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
85 } catch (UnsupportedOperationException e) {
90 level = TestLevel.PARTIAL_COMPLETE,
91 notes = "Verifies arrayOffset method for direct IntBuffer.",
92 method = "arrayOffset",
95 public void testArrayOffset() {
98 fail("Should throw UnsupportedOperationException"); //$NON-NLS-1$
99 } catch (UnsupportedOperationException e) {
105 level = TestLevel.PARTIAL_COMPLETE,
106 notes = "Verifies isDirect method for direct IntBuffer.",
110 public void testIsDirect() {
111 assertTrue(buf.isDirect());
115 level = TestLevel.PARTIAL_COMPLETE,
116 notes = "Verifies order method for direct IntBuffer.",
120 public void testOrder() {
121 assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
125 level = TestLevel.PARTIAL_COMPLETE,
126 notes = "Regression test for IntToByteBufferAdapter",
127 clazz = ByteBuffer.class,
128 method = "asIntBuffer",
131 public void testRangeChecks() {
132 int[] myInts = new int[BUFFER_LENGTH];
134 for (int i = 0; i < BUFFER_LENGTH; i++) {
135 myInts[i] = 1000 + i;
139 buf.put(myInts, 0, BUFFER_LENGTH);
141 buf.put(myInts, 0, BUFFER_LENGTH);
144 buf.put(myInts, 0, 1); // should fail
145 fail("BufferOverflowException expected but not thrown");
146 } catch (BufferOverflowException boe) {
152 buf.put(myInts, 0, BUFFER_LENGTH + 1); // should fail
153 fail("BufferOverflowException expected but not thrown");
154 } catch (IndexOutOfBoundsException ioobe) {
159 buf.position(BUFFER_LENGTH - 1);
160 buf.put(myInts, 0, 2); // should fail
161 fail("BufferOverflowException expected but not thrown");
162 } catch (BufferOverflowException boe) {