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.FloatBuffer;
24 @TestTargetClass(java.nio.FloatBuffer.class)
25 public class WrappedFloatBufferTest extends FloatBufferTest {
26 protected void setUp() throws Exception {
27 capacity = BUFFER_LENGTH;
28 buf = FloatBuffer.wrap(new float[BUFFER_LENGTH]);
33 protected void tearDown() throws Exception {
39 * @tests java.nio.CharBuffer#allocate(char[],int,int)
43 level = TestLevel.PARTIAL_COMPLETE,
46 args = {float[].class, int.class, int.class}
48 public void testWrappedFloatBuffer_IllegalArg() {
49 float array[] = new float[20];
51 FloatBuffer.wrap(array, -1, 0);
52 fail("Should throw Exception");
53 } catch (IndexOutOfBoundsException e) {
57 FloatBuffer.wrap(array, 21, 0);
58 fail("Should throw Exception");
59 } catch (IndexOutOfBoundsException e) {
63 FloatBuffer.wrap(array, 0, -1);
64 fail("Should throw Exception");
65 } catch (IndexOutOfBoundsException e) {
69 FloatBuffer.wrap(array, 0, 21);
70 fail("Should throw Exception");
71 } catch (IndexOutOfBoundsException e) {
75 FloatBuffer.wrap(array, Integer.MAX_VALUE, 1);
76 fail("Should throw Exception");
77 } catch (IndexOutOfBoundsException e) {
81 FloatBuffer.wrap(array, 1, Integer.MAX_VALUE);
82 fail("Should throw Exception");
83 } catch (IndexOutOfBoundsException e) {
87 FloatBuffer.wrap((float[])null, -1, 0);
88 fail("Should throw NPE");
89 } catch (NullPointerException e) {
92 FloatBuffer buf = FloatBuffer.wrap(array, 2, 16);
93 assertEquals(buf.position(), 2);
94 assertEquals(buf.limit(), 18);
95 assertEquals(buf.capacity(), 20);