1dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes/* Licensed to the Apache Software Foundation (ASF) under one or more
2dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * contributor license agreements.  See the NOTICE file distributed with
3dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * this work for additional information regarding copyright ownership.
4dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0
5dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * (the "License"); you may not use this file except in compliance with
6dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * the License.  You may obtain a copy of the License at
7dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes *
8dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes *     http://www.apache.org/licenses/LICENSE-2.0
9dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes *
10dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * Unless required by applicable law or agreed to in writing, software
11dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * See the License for the specific language governing permissions and
14dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes * limitations under the License.
15dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes */
16e5fea3d504609d22337a5311d3ce0e72314bceeeNarayan Kamathpackage org.apache.harmony.tests.java.nio;
17dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes
18dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughesimport java.nio.ShortBuffer;
19dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes
20dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughespublic class WrappedShortBufferTest extends ShortBufferTest {
21dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes    protected void setUp() throws Exception {
22dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        super.setUp();
23dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        buf = ShortBuffer.wrap(new short[BUFFER_LENGTH]);
24dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        loadTestData1(buf);
25dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        baseBuf = buf;
26dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes    }
27dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes
28dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes    protected void tearDown() throws Exception {
29dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        super.tearDown();
30dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        baseBuf = null;
31dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        buf = null;
32dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes    }
33dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes
34dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes    /**
35dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes     * @tests java.nio.CharBuffer#allocate(char[],int,int)
36dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes     *
37dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes     */
38dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes    public void testWrappedShortBuffer_IllegalArg() {
39dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        short array[] = new short[20];
40dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        try {
41dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            ShortBuffer.wrap(array, -1, 0);
42dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            fail("Should throw Exception"); //$NON-NLS-1$
43dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        } catch (IndexOutOfBoundsException e) {
44dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            // expected
45dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        }
46dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        try {
47dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            ShortBuffer.wrap(array, 21, 0);
48dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            fail("Should throw Exception"); //$NON-NLS-1$
49dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        } catch (IndexOutOfBoundsException e) {
50dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            // expected
51dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        }
52dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        try {
53dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            ShortBuffer.wrap(array, 0, -1);
54dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            fail("Should throw Exception"); //$NON-NLS-1$
55dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        } catch (IndexOutOfBoundsException e) {
56dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            // expected
57dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        }
58dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        try {
59dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            ShortBuffer.wrap(array, 0, 21);
60dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            fail("Should throw Exception"); //$NON-NLS-1$
61dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        } catch (IndexOutOfBoundsException e) {
62dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            // expected
63dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        }
64dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        try {
65dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            ShortBuffer.wrap(array, Integer.MAX_VALUE, 1);
66dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            fail("Should throw Exception"); //$NON-NLS-1$
67dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        } catch (IndexOutOfBoundsException e) {
68dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            // expected
69dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        }
70dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        try {
71dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            ShortBuffer.wrap(array, 1, Integer.MAX_VALUE);
72dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            fail("Should throw Exception"); //$NON-NLS-1$
73dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        } catch (IndexOutOfBoundsException e) {
74dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            // expected
75dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        }
76dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        try {
77dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            ShortBuffer.wrap((short[])null, -1, 0);
78dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes            fail("Should throw NPE"); //$NON-NLS-1$
79dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        } catch (NullPointerException e) {
80dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        }
81dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes
82dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        ShortBuffer buf = ShortBuffer.wrap(array, 2, 16);
83dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        assertEquals(buf.position(), 2);
84dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        assertEquals(buf.limit(), 18);
85dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes        assertEquals(buf.capacity(), 20);
86dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes    }
87dce2b2fa9d6b26414a8d5a55918e4d7ca2ab1baaElliott Hughes}
88