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