This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This adds a comprehensive testcase for a CharBuffer that wraps a CharSequence. 2007-04-12 Roman Kennke <kennke@aicas.com> * gnu/testlet/java/nio/CharBuffer/CharSequenceWrapper.java: New testcase for testing wrapped CharSequences. /Roman -- aicas Allerton Interworks Computer Automated Systems GmbH Haid-und-Neu-StraÃe 18 * D-76131 Karlsruhe * Germany http://www.aicas.com * Tel: +49-721-663 968-0 USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe GeschÃftsfÃhrer: Dr. James J. Hunt
Index: gnu/testlet/java/nio/CharBuffer/CharSequenceWrapper.java =================================================================== RCS file: gnu/testlet/java/nio/CharBuffer/CharSequenceWrapper.java diff -N gnu/testlet/java/nio/CharBuffer/CharSequenceWrapper.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/nio/CharBuffer/CharSequenceWrapper.java 12 Apr 2007 20:31:14 -0000 @@ -0,0 +1,186 @@ +/* CharSequenceWrapper.java -- Tests the CharSequence wrapping CharBuffer + Copyright (C) 2007 Roman Kennke (kennke@aicas.com) +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK1.4 + +package gnu.testlet.java.nio.CharBuffer; + +import java.nio.CharBuffer; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * This tests the CharBuffer that wraps a CharSequence. + * + * @author Roman Kennke (kennke@aicas.com) + * + */ +public class CharSequenceWrapper implements Testlet +{ + + public void test(TestHarness harness) + { + testSlice(harness); + testDuplicate(harness); + testBasic(harness); + } + + /** + * Tests some basic properties of a char sequence wrapping char buffer. + * + * @param h the test harness + */ + private void testBasic(TestHarness h) + { + h.checkPoint("testBasic"); + StringBuilder b = new StringBuilder("Hello World"); + CharBuffer cb = CharBuffer.wrap(b, 4, 7); + try + { + cb.arrayOffset(); + h.fail("testBasic"); + } + catch (UnsupportedOperationException ex) + { + h.check(true); + } + try + { + cb.array(); + h.fail("testBasic"); + } + catch (UnsupportedOperationException ex) + { + h.check(true); + } + h.check(cb.capacity(), b.length()); + h.check(cb.hasArray(), false); + h.check(cb.hasRemaining(), true); + h.check(cb.isDirect(), false); + h.check(cb.isReadOnly(), true); + h.check(cb.length(), 3); + h.check(cb.limit(), 7); + h.check(cb.position(), 4); + h.check(cb.remaining(), 3); + try + { + cb.compact(); + h.fail("testBasic"); + } + catch (UnsupportedOperationException ex) + { + h.check(true); + } + } + + /** + * Tests how slicing affects the wrapped char buffer. + * + * @param h the test harness + */ + private void testSlice(TestHarness h) + { + StringBuilder b = new StringBuilder("Hello World"); + CharBuffer cb = CharBuffer.wrap(b); + cb.position(4); + cb.limit(7); + CharBuffer slice = cb.slice(); + + h.check(slice.capacity(), 3); + try + { + slice.arrayOffset(); + h.fail("testSlice"); + } + catch (UnsupportedOperationException ex) + { + h.check(true); + } + h.check(slice.hasArray(), false); + try + { + slice.array(); + h.fail("testSlice"); + } + catch (UnsupportedOperationException ex) + { + h.check(true); + } + h.check(slice.isDirect(), false); + h.check(slice.isReadOnly(), true); + h.check(slice.length(), 3); + h.check(slice.limit(), 3); + h.check(slice.position(), 0); + + // This shows a JDK bug.. + h.check(slice.get(), 'o'); + h.check(slice.get(), ' '); + h.check(slice.get(), 'W'); + + } + + /** + * Tests how duplicating affects the wrapped char buffer. + * + * @param h the test harness + */ + private void testDuplicate(TestHarness h) + { + StringBuilder b = new StringBuilder("Hello World"); + CharBuffer cb = CharBuffer.wrap(b); + cb.position(4); + cb.limit(7); + CharBuffer dup = cb.duplicate(); + + h.check(dup.capacity(), 11); + try + { + dup.arrayOffset(); + h.fail("testDuplicate"); + } + catch (UnsupportedOperationException ex) + { + h.check(true); + } + h.check(dup.hasArray(), false); + try + { + dup.array(); + h.fail("testSlice"); + } + catch (UnsupportedOperationException ex) + { + h.check(true); + } + h.check(dup.isDirect(), false); + h.check(dup.isReadOnly(), true); + h.check(dup.length(), 3); + h.check(dup.limit(), 7); + h.check(dup.position(), 4); + + h.check(dup.get(), 'o'); + h.check(dup.get(), ' '); + h.check(dup.get(), 'W'); + + } + +}
Attachment:
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |