From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25238 invoked by alias); 4 Mar 2006 16:09:52 -0000 Received: (qmail 25225 invoked by uid 22791); 4 Mar 2006 16:09:50 -0000 X-Spam-Check-By: sourceware.org Received: from mail.gmx.net (HELO mail.gmx.net) (213.165.64.20) by sourceware.org (qpsmtpd/0.31) with SMTP; Sat, 04 Mar 2006 16:09:48 +0000 Received: (qmail invoked by alias); 04 Mar 2006 16:09:45 -0000 Received: from e178197041.adsl.alicedsl.de (EHLO [10.11.11.10]) [85.178.197.41] by mail.gmx.net (mp028) with SMTP; 04 Mar 2006 17:09:45 +0100 X-Authenticated: #17532834 Message-ID: <4409BBD1.40106@gmx.net> Date: Sat, 04 Mar 2006 16:09:00 -0000 From: Robert Schuster User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7.12) Gecko/20051208 MIME-Version: 1.0 To: mauve-patches@sources.redhat.com Subject: FYI: PlainDocument.insertString test - cleanups and more tests Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigB002096F2738D3FB6C02740E" X-Y-GMX-Trusted: 0 X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2006/txt/msg00193.txt.bz2 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigB002096F2738D3FB6C02740E Content-Type: multipart/mixed; boundary="------------090800040908010805050703" This is a multi-part message in MIME format. --------------090800040908010805050703 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-length: 891 Hi, I cleaned up the insertString tests a bit: A nasty exception in Classpath prevented that further tests could be executed. I made the test case more robust against that problem. Furthermore I added more tests for the insertString method: Stuff I had trouble with when trying in beanshell. They all pass on the JDK but Classpath gives us 12 errors now. 2006-03-04 Robert Schuster * gnu/testlet/javax/swing/text/PlainDocument/insertString.java: (testModifications): New test method. (testNewLine): Added checkpoint name. (testFilterNewLine): Added checkpoint name. (testArguments): Changed catch-clause to Exception, added instanceof for previous exception type. (prepare): Added new helper method. (checkElement): Added new helper method. (insert): Added new helper method. cya Robert --------------090800040908010805050703 Content-Type: text/x-patch; name="mauve-plaindocument-insertstring.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mauve-plaindocument-insertstring.diff" Content-length: 6149 Index: gnu/testlet/javax/swing/text/PlainDocument/insertString.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/PlainDocument/insertString.java,v retrieving revision 1.2 diff -u -r1.2 insertString.java --- gnu/testlet/javax/swing/text/PlainDocument/insertString.java 25 Jan 2006 18:15:10 -0000 1.2 +++ gnu/testlet/javax/swing/text/PlainDocument/insertString.java 4 Mar 2006 16:01:48 -0000 @@ -51,6 +51,8 @@ testFilterNewline(harness); testArguments(harness); testPositions(harness); + + testModifications(harness); } /** @@ -61,6 +63,8 @@ */ private void testNewline(TestHarness harness) { + harness.checkPoint("testNewline"); + PlainDocument doc = new PlainDocument(); try { @@ -93,6 +97,8 @@ */ private void testFilterNewline(TestHarness harness) { + harness.checkPoint("testFilterNewline"); + PlainDocument doc = new PlainDocument(); doc.putProperty("filterNewlines", Boolean.TRUE); try @@ -123,9 +129,9 @@ { d.insertString(-1, "XYZ", SimpleAttributeSet.EMPTY); } - catch (BadLocationException e) + catch (Exception e) { - pass = true; + pass = e instanceof BadLocationException; } harness.check(pass); @@ -200,4 +206,151 @@ } } + // Helper for testModifications. + PlainDocument prepare(String initialContent) + { + PlainDocument pd = new PlainDocument(); + + try + { + pd.insertString(0, initialContent, null); + + return pd; + } + catch (BadLocationException ble) + { + return pd; + } + } + + // Helper for testModifications. + void checkElement(TestHarness harness, + PlainDocument doc, + int elementIndex, + int startOffset, + int endOffset, + String text) + { + Element e = doc.getDefaultRootElement(); + Element child = e.getElement(elementIndex); + + harness.check(child.getStartOffset(), startOffset); + harness.check(child.getEndOffset(), endOffset); + + String retrievedText = null; + try + { + retrievedText = doc.getText(startOffset, endOffset-startOffset); + } + catch (BadLocationException ble) + { + } + harness.check(retrievedText, text); + } + + // Helper for testModifications. + void insert(PlainDocument doc, int index, String text) + { + try + { + doc.insertString(index, text, null); + } + catch(BadLocationException ble) + { + } + } + + void testModifications(TestHarness h) + { + // Test 1: Insert an "a" into before a "\n". + h.checkPoint("modifications-insert char 1-pre"); + PlainDocument doc = new PlainDocument();; + + // Checks whether there is an Element at index 0 which has the + // starting offset 0, end offset 1 and contains the text "\n". + checkElement(h, doc, 0, 0, 1, "\n"); + + h.checkPoint("modifications-insert char 1-post"); + insert(doc, 0, "a"); + checkElement(h, doc, 0, 0, 2, "a\n"); + + // Test 2: Insert a newline after the first a in "abc\nbla\n". + h.checkPoint("modifications-insert newline 1-pre"); + doc = prepare("abc\nbla\n"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 8, "bla\n"); + + h.checkPoint("modifications-insert newline 1-post"); + insert(doc, 1, "\n"); + checkElement(h, doc, 0, 0, 2, "a\n"); + checkElement(h, doc, 1, 2, 5, "bc\n"); + checkElement(h, doc, 2, 5, 9, "bla\n"); + + // Test 3: Insert a newline after the c in "abc\n". + h.checkPoint("modifications-insert newline 2-pre"); + doc = prepare("abc\nbla\n"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + + h.checkPoint("modifications-insert newline 2-post"); + insert(doc, 3, "\n"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 5, "\n"); + + // Test 4: Type a char after "abc\n". + h.checkPoint("modifications-insert char 2-pre"); + doc = prepare("abc\n"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + + h.checkPoint("modifications-insert char 2-post"); + insert(doc, 4, "d"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 6, "d\n"); + + // Test 5: Insert "foo\nbaz\nbar" after "ab" in "abc\ndef\n". + h.checkPoint("modifications-insert multi-line string 1-pre"); + doc = prepare("abc\ndef\n"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 8, "def\n"); + + h.checkPoint("modifications-insert multi-line string 1-post"); + insert(doc, 2, "foo\nbaz\nbar"); + checkElement(h, doc, 0, 0, 6, "abfoo\n"); + checkElement(h, doc, 1, 6, 10, "baz\n"); + checkElement(h, doc, 2, 10, 15, "barc\n"); + checkElement(h, doc, 3, 15, 19, "def\n"); + + // Test 6: Insert "foo" after first newline in "abc\ndef\n" + h.checkPoint("modifications-insert single-line string-pre"); + doc = prepare("abc\ndef\n"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 8, "def\n"); + + h.checkPoint("modifications-insert single-line string-post"); + insert(doc, 4, "foo"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 11, "foodef\n"); + + // Test 7: Insert "foo\nbaz\nbar" after first newline in "abc\ndef\n". + h.checkPoint("modifications-insert multi-line string 2-pre"); + doc = prepare("abc\ndef\n"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 8, "def\n"); + + h.checkPoint("modifications-insert multi-line string 2-post"); + insert(doc, 4, "foo\nbaz\nbar"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + checkElement(h, doc, 1, 4, 8, "foo\n"); + checkElement(h, doc, 2, 8, 12, "baz\n"); + checkElement(h, doc, 3, 12, 19, "bardef\n"); + + // Test 8: Type char after a in "ac\n". + h.checkPoint("modifications-insert char 3-pre"); + doc = prepare("ac\n"); + checkElement(h, doc, 0, 0, 3, "ac\n"); + + h.checkPoint("modifications-insert char 3-post"); + insert(doc, 1, "b"); + checkElement(h, doc, 0, 0, 4, "abc\n"); + } + } --------------090800040908010805050703-- --------------enigB002096F2738D3FB6C02740E Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-length: 252 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFECbvRG9cfwmwwEtoRAv6SAJ9RNJWtRdc02krDShrAkg3mf9u8ZwCfbvQl 1wEhpk3wN+0TAu2yTmQOsik= =H2wp -----END PGP SIGNATURE----- --------------enigB002096F2738D3FB6C02740E--