OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / org / apache / harmony / nio / tests / java / nio / WrappedFloatBufferTest.java
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.apache.harmony.nio.tests.java.nio;
17
18 import dalvik.annotation.TestLevel;
19 import dalvik.annotation.TestTargetNew;
20 import dalvik.annotation.TestTargetClass;
21
22 import java.nio.FloatBuffer;
23
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]);
29         loadTestData1(buf);
30         baseBuf = buf;
31     }
32
33     protected void tearDown() throws Exception {
34         baseBuf = null;
35         buf = null;
36     }
37
38     /**
39      * @tests java.nio.CharBuffer#allocate(char[],int,int)
40      *
41      */
42     @TestTargetNew(
43         level = TestLevel.PARTIAL_COMPLETE,
44         notes = "",
45         method = "wrap",
46         args = {float[].class, int.class, int.class}
47     )
48     public void testWrappedFloatBuffer_IllegalArg() {
49         float array[] = new float[20];
50         try {
51             FloatBuffer.wrap(array, -1, 0);
52             fail("Should throw Exception");
53         } catch (IndexOutOfBoundsException e) {
54             // expected
55         }
56         try {
57             FloatBuffer.wrap(array, 21, 0);
58             fail("Should throw Exception");
59         } catch (IndexOutOfBoundsException e) {
60             // expected
61         }
62         try {
63             FloatBuffer.wrap(array, 0, -1);
64             fail("Should throw Exception");
65         } catch (IndexOutOfBoundsException e) {
66             // expected
67         }
68         try {
69             FloatBuffer.wrap(array, 0, 21);
70             fail("Should throw Exception");
71         } catch (IndexOutOfBoundsException e) {
72             // expected
73         }
74         try {
75             FloatBuffer.wrap(array, Integer.MAX_VALUE, 1);
76             fail("Should throw Exception");
77         } catch (IndexOutOfBoundsException e) {
78             // expected
79         }
80         try {
81             FloatBuffer.wrap(array, 1, Integer.MAX_VALUE);
82             fail("Should throw Exception");
83         } catch (IndexOutOfBoundsException e) {
84             // expected
85         }
86         try {
87             FloatBuffer.wrap((float[])null, -1, 0);
88             fail("Should throw NPE");
89         } catch (NullPointerException e) {
90         }
91
92         FloatBuffer buf = FloatBuffer.wrap(array, 2, 16);
93         assertEquals(buf.position(), 2);
94         assertEquals(buf.limit(), 18);
95         assertEquals(buf.capacity(), 20);
96     }
97 }