ReadOnlyFloatBufferTest.java revision e5fea3d504609d22337a5311d3ce0e72314bceee
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 */ 16package org.apache.harmony.tests.java.nio; 17 18import java.nio.FloatBuffer; 19import java.nio.ReadOnlyBufferException; 20 21public class ReadOnlyFloatBufferTest extends FloatBufferTest { 22 protected void setUp() throws Exception { 23 super.setUp(); 24 buf = buf.asReadOnlyBuffer(); 25 baseBuf = buf; 26 } 27 28 protected void tearDown() throws Exception { 29 super.tearDown(); 30 } 31 32 public void testIsReadOnly() { 33 assertTrue(buf.isReadOnly()); 34 } 35 36 public void testHasArray() { 37 assertFalse(buf.hasArray()); 38 } 39 40 public void testArray() { 41 try { 42 buf.array(); 43 fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$ 44 } catch (ReadOnlyBufferException e) { 45 //expected 46 } 47 } 48 49 public void testHashCode() { 50 FloatBuffer duplicate = buf.duplicate(); 51 assertEquals(buf.hashCode(), duplicate.hashCode()); 52 } 53 54 public void testArrayOffset() { 55 try { 56 buf.arrayOffset(); 57 fail("Should throw Exception"); //$NON-NLS-1$ 58 } catch (UnsupportedOperationException e) { 59 //expected 60 } 61 } 62 63 public void testCompact() { 64 try { 65 buf.compact(); 66 fail("Should throw Exception"); //$NON-NLS-1$ 67 } catch (ReadOnlyBufferException e) { 68 // expected 69 } 70 } 71 72 public void testPutfloat() { 73 try { 74 buf.put(0); 75 fail("Should throw Exception"); //$NON-NLS-1$ 76 } catch (ReadOnlyBufferException e) { 77 // expected 78 } 79 } 80 81 public void testPutfloatArray() { 82 float array[] = new float[1]; 83 try { 84 buf.put(array); 85 fail("Should throw Exception"); //$NON-NLS-1$ 86 } catch (ReadOnlyBufferException e) { 87 // expected 88 } 89 try { 90 buf.put((float[]) null); 91 fail("Should throw Exception"); //$NON-NLS-1$ 92 } catch (NullPointerException e) { 93 // expected 94 } 95 } 96 97 public void testPutfloatArrayintint() { 98 float array[] = new float[1]; 99 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, 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 testPutFloatBuffer() { 126 FloatBuffer other = FloatBuffer.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((FloatBuffer) 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 testPutintfloat() { 148 try { 149 buf.put(0, (float) 0); 150 fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$ 151 } catch (ReadOnlyBufferException e) { 152 // expected 153 } 154 try { 155 buf.put(-1, (float) 0); 156 fail("Should throw ReadOnlyBufferException"); //$NON-NLS-1$ 157 } catch (ReadOnlyBufferException e) { 158 // expected 159 } 160 } 161} 162