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 / WrappedCharBufferTest1.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
17 package org.apache.harmony.nio.tests.java.nio;
18
19 import dalvik.annotation.TestLevel;
20 import dalvik.annotation.TestTargetNew;
21 import dalvik.annotation.TestTargetClass;
22
23 import java.nio.CharBuffer;
24
25 @TestTargetClass(java.nio.CharBuffer.class)
26 public class WrappedCharBufferTest1 extends CharBufferTest {
27
28     protected void setUp() throws Exception {
29         capacity = BUFFER_LENGTH;
30         buf = CharBuffer.wrap(new char[BUFFER_LENGTH]);
31         loadTestData1(buf);
32         baseBuf = buf;
33     }
34
35     protected void tearDown() throws Exception {
36         baseBuf = null;
37         buf = null;
38     }
39
40     /**
41      * @tests java.nio.CharBuffer#allocate(char[],int,int)
42      *
43      */
44     @TestTargetNew(
45         level = TestLevel.PARTIAL_COMPLETE,
46         notes = "Verifies IndexOutOfBoundsException, NullPointerException.",
47         method = "wrap",
48         args = {java.lang.CharSequence.class, int.class, int.class}
49     )
50     public void testWrappedCharBuffer_IllegalArg() {
51         char array[] = new char[BUFFER_LENGTH];
52         try {
53             CharBuffer.wrap(array, -1, 0);
54             fail("Should throw Exception");
55         } catch (IndexOutOfBoundsException e) {
56             // expected
57         }
58         try {
59             CharBuffer.wrap(array, BUFFER_LENGTH + 1, 0);
60             fail("Should throw Exception");
61         } catch (IndexOutOfBoundsException e) {
62             // expected
63         }
64         try {
65             CharBuffer.wrap(array, 0, -1);
66             fail("Should throw Exception");
67         } catch (IndexOutOfBoundsException e) {
68             // expected
69         }
70         try {
71             CharBuffer.wrap(array, 0, BUFFER_LENGTH + 1);
72             fail("Should throw Exception");
73         } catch (IndexOutOfBoundsException e) {
74             // expected
75         }
76         try {
77             CharBuffer.wrap(array, Integer.MAX_VALUE, 1);
78             fail("Should throw Exception");
79         } catch (IndexOutOfBoundsException e) {
80             // expected
81         }
82         try {
83             CharBuffer.wrap(array, 1, Integer.MAX_VALUE);
84             fail("Should throw Exception");
85         } catch (IndexOutOfBoundsException e) {
86             // expected
87         }
88         try {
89             CharBuffer.wrap((char[])null, -1, 0);
90             fail("Should throw NPE");
91         } catch (NullPointerException e) {
92         }
93     }
94 }