001: /* Licensed to the Apache Software Foundation (ASF) under one or more
002: * contributor license agreements. See the NOTICE file distributed with
003: * this work for additional information regarding copyright ownership.
004: * The ASF licenses this file to You under the Apache License, Version 2.0
005: * (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.harmony.nio.tests.java.nio;
017:
018: import java.nio.IntBuffer;
019: import java.nio.ReadOnlyBufferException;
020:
021: public class ReadOnlyIntBufferTest extends IntBufferTest {
022: protected void setUp() throws Exception {
023: super .setUp();
024: buf = buf.asReadOnlyBuffer();
025: baseBuf = buf;
026: }
027:
028: protected void tearDown() throws Exception {
029: super .tearDown();
030: }
031:
032: public void testIsReadOnly() {
033: assertTrue(buf.isReadOnly());
034: }
035:
036: public void testHasArray() {
037: assertFalse(buf.hasArray());
038: }
039:
040: public void testArray() {
041: try {
042: buf.array();
043: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
044: } catch (ReadOnlyBufferException e) {
045: //expected
046: }
047: }
048:
049: public void testHashCode() {
050: IntBuffer duplicate = buf.duplicate();
051: assertEquals(buf.hashCode(), duplicate.hashCode());
052: }
053:
054: public void testArrayOffset() {
055: try {
056: buf.arrayOffset();
057: fail("Should throw Exception"); //$NON-NLS-1$
058: } catch (UnsupportedOperationException e) {
059: //expected
060: }
061: }
062:
063: public void testCompact() {
064: try {
065: buf.compact();
066: fail("Should throw Exception"); //$NON-NLS-1$
067: } catch (ReadOnlyBufferException e) {
068: // expected
069: }
070: }
071:
072: public void testPutint() {
073: try {
074: buf.put(0);
075: fail("Should throw Exception"); //$NON-NLS-1$
076: } catch (ReadOnlyBufferException e) {
077: // expected
078: }
079: }
080:
081: public void testPutintArray() {
082: int array[] = new int[1];
083: try {
084: buf.put(array);
085: fail("Should throw Exception"); //$NON-NLS-1$
086: } catch (ReadOnlyBufferException e) {
087: // expected
088: }
089: try {
090: buf.put((int[]) null);
091: fail("Should throw Exception"); //$NON-NLS-1$
092: } catch (NullPointerException e) {
093: // expected
094: }
095: }
096:
097: public void testPutintArrayintint() {
098: int array[] = new int[1];
099: try {
100: buf.put(array, 0, array.length);
101: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
102: } catch (ReadOnlyBufferException e) {
103: // expected
104: }
105: try {
106: buf.put((int[]) null, -1, 1);
107: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
108: } catch (ReadOnlyBufferException e) {
109: // expected
110: }
111: try {
112: buf.put(new int[buf.capacity() + 1], 0, buf.capacity() + 1);
113: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
114: } catch (ReadOnlyBufferException e) {
115: // expected
116: }
117: try {
118: buf.put(array, -1, array.length);
119: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
120: } catch (ReadOnlyBufferException e) {
121: // expected
122: }
123: }
124:
125: public void testPutIntBuffer() {
126: IntBuffer other = IntBuffer.allocate(1);
127: try {
128: buf.put(other);
129: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
130: } catch (ReadOnlyBufferException e) {
131: // expected
132: }
133: try {
134: buf.put((IntBuffer) null);
135: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
136: } catch (ReadOnlyBufferException e) {
137: // expected
138: }
139: try {
140: buf.put(buf);
141: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
142: } catch (ReadOnlyBufferException e) {
143: // expected
144: }
145: }
146:
147: public void testPutintint() {
148: try {
149: buf.put(0, (int) 0);
150: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
151: } catch (ReadOnlyBufferException e) {
152: // expected
153: }
154: try {
155: buf.put(-1, (int) 0);
156: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
157: } catch (ReadOnlyBufferException e) {
158: // expected
159: }
160: }
161: }
|