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.FloatBuffer;
019: import java.nio.ReadOnlyBufferException;
020:
021: public class ReadOnlyFloatBufferTest extends FloatBufferTest {
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: FloatBuffer 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 testPutfloat() {
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 testPutfloatArray() {
082: float array[] = new float[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((float[]) null);
091: fail("Should throw Exception"); //$NON-NLS-1$
092: } catch (NullPointerException e) {
093: // expected
094: }
095: }
096:
097: public void testPutfloatArrayintint() {
098: float array[] = new float[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((float[]) null, 0, 1);
107: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
108: } catch (ReadOnlyBufferException e) {
109: // expected
110: }
111: try {
112: buf.put(new float[buf.capacity() + 1], 0,
113: buf.capacity() + 1);
114: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
115: } catch (ReadOnlyBufferException e) {
116: // expected
117: }
118: try {
119: buf.put(array, -1, array.length);
120: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
121: } catch (ReadOnlyBufferException e) {
122: // expected
123: }
124: }
125:
126: public void testPutFloatBuffer() {
127: FloatBuffer other = FloatBuffer.allocate(1);
128: try {
129: buf.put(other);
130: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
131: } catch (ReadOnlyBufferException e) {
132: // expected
133: }
134: try {
135: buf.put((FloatBuffer) null);
136: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
137: } catch (ReadOnlyBufferException e) {
138: // expected
139: }
140: try {
141: buf.put(buf);
142: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
143: } catch (ReadOnlyBufferException e) {
144: // expected
145: }
146: }
147:
148: public void testPutintfloat() {
149: try {
150: buf.put(0, (float) 0);
151: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
152: } catch (ReadOnlyBufferException e) {
153: // expected
154: }
155: try {
156: buf.put(-1, (float) 0);
157: fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$
158: } catch (ReadOnlyBufferException e) {
159: // expected
160: }
161: }
162: }
|