harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r519069 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/GapContent.java test/api/java/common/javax/swing/text/GapContent_GapVectorTest.java
Date Fri, 16 Mar 2007 17:17:31 GMT
Author: ayza
Date: Fri Mar 16 10:17:30 2007
New Revision: 519069

URL: http://svn.apache.org/viewvc?view=rev&rev=519069
Log:
Committing patches from HARMONY-2198 ([classlib][swing] compatibility: j.s.text.GapContent.replace
is not compatible with RI)

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/GapContent.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/GapContent_GapVectorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/GapContent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/GapContent.java?view=diff&rev=519069&r1=519068&r2=519069
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/GapContent.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/GapContent.java
Fri Mar 16 10:17:30 2007
@@ -364,9 +364,13 @@
     }
 
     final void insertItems(final int where, final Object addItems,
-                             final int addSize)
+                           final int addSize)
         throws BadLocationException {
 
+        if (addSize == 0) {
+            return;
+        }
+
         if (where < 0 || where > length()) {
             throw new BadLocationException(Messages.getString("swing.8E"), where); //$NON-NLS-1$
         }
@@ -399,6 +403,10 @@
         if (where < 0 || where + nitems >= length()) {
 
             throw new BadLocationException(Messages.getString("swing.7F"), where); //$NON-NLS-1$
+        }
+
+        if (nitems == 0) {
+            return;
         }
 
         if (where + nitems == gapStart) {

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/GapContent_GapVectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/GapContent_GapVectorTest.java?view=diff&rev=519069&r1=519068&r2=519069
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/GapContent_GapVectorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/GapContent_GapVectorTest.java
Fri Mar 16 10:17:30 2007
@@ -16,6 +16,8 @@
  */
 package javax.swing.text;
 
+import javax.swing.BasicSwingTestCase;
+
 import junit.framework.TestCase;
 
 public class GapContent_GapVectorTest extends TestCase {
@@ -87,6 +89,37 @@
         }
     }
 
+    public void testInsertStringNull() throws BadLocationException {
+        try {
+            gv.insertString(0, null);
+            fail("NullPointerException is expected");
+        } catch (NullPointerException e) { }
+        assertEquals(10, gv.getGapStart());
+        assertEquals(19, gv.getGapEnd());
+    }
+
+    public void testInsertStringEmpty() throws BadLocationException {
+        gv.insertString(0, "");
+        assertEquals(10, gv.getGapStart());
+        assertEquals(19, gv.getGapEnd());
+    }
+
+    public void testInsertStringInvalidNull() {
+        try {
+            gv.insertString(-1, null);
+
+            fail("NullPointerException or BadLocationException must be thrown");
+        } catch (NullPointerException e) {
+            if (!BasicSwingTestCase.isHarmony()) {
+                fail("Unexpected NullPointerException");
+            }
+        } catch (BadLocationException e) {
+            if (BasicSwingTestCase.isHarmony()) {
+                fail("Unexpected BadLocationException");
+            }
+        }
+    }
+
     public void testRemoveValid() throws BadLocationException {
         gv.remove(1, 7);
         assertEquals(1, gv.getGapStart());
@@ -110,6 +143,24 @@
         }
     }
 
+    public void testRemoveEmpty() throws BadLocationException {
+        gv.remove(1, 0);
+
+        assertEquals(10, gv.getGapStart());
+        assertEquals(19, gv.getGapEnd());
+    }
+
+    public void testRemoveEmptyInvalid() {
+        try {
+            gv.remove(-1, 0);
+
+            fail("BadLocationException should be thrown");
+        } catch (BadLocationException e) { }
+
+        assertEquals(10, gv.getGapStart());
+        assertEquals(19, gv.getGapEnd());
+    }
+
     public void testReplace() throws BadLocationException {
         char[] charArray = { 'z', 'y', 'x', 'w', 'v' };
         gv.replace(3, 5, charArray, 3);
@@ -121,6 +172,74 @@
         }
         for (int i = gv.getGapEnd(), j = 0; j < chars2.length; i++, j++) {
             assertEquals("2 @ " + i, chars2[j], array[i]);
+        }
+    }
+
+    // HARMONY-1809
+    public void testReplaceInvalidRemovePosition() throws Exception {
+        gv.replace(-2, 2, null, 0);
+        if (BasicSwingTestCase.isHarmony()) {
+            // Harmony just ignores the operation
+            // because GapContent.removeItems throws BadLocationException;
+            assertEquals("abcdefghij\n", gv.getString(0, gv.length()));
+        } else {
+            assertEquals("cdefghij\n", gv.getString(0, gv.length()));
+        }
+    }
+
+    // HARMONY-1809
+    public void testReplaceInvalidRemoveLength() throws Exception {
+        gv.replace(5, 6, null, 0);
+        if (BasicSwingTestCase.isHarmony()) {
+            // Harmony just ignores the operation
+            // because GapContent.removeItems throws BadLocationException;
+            assertEquals("abcdefghij\n", gv.getString(0, gv.length()));
+        } else {
+            assertEquals("abcde", gv.getString(0, gv.length()));
+        }
+    }
+
+    // HARMONY-1809
+    public void testReplaceNullInsert() throws Exception {
+        gv.replace(0, 0, null, 0);
+        assertEquals(10, gv.getGapStart());
+        assertEquals(19, gv.getGapEnd());
+        assertEquals("abcdefghij\n", gv.getString(0, gv.length()));
+    }
+
+    // HARMONY-1809
+    public void testReplaceInvalidInsertLength() throws Exception {
+        try {
+            gv.replace(0, 0, new char[] {'1'}, 2);
+            fail("ArrayIndexOutOfBounds is expected");
+        } catch (ArrayIndexOutOfBoundsException e) { }
+
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(0, gv.getGapStart());
+            assertEquals(9, gv.getGapEnd());
+            assertEquals("abcdefghij\n", gv.getString(0, gv.length()));
+        } else {
+            assertEquals(2, gv.getGapStart());
+            assertEquals(9, gv.getGapEnd());
+            assertEquals("ababcdefghij\n", gv.getString(0, gv.length()));
+        }
+    }
+
+    // HARMONY-1809
+    public void testReplaceInvalidInsertLengthNegative() throws Exception {
+        try {
+            gv.replace(0, 0, new char[] {'1'}, -1);
+            fail("ArrayIndexOutOfBounds is expected");
+        } catch (ArrayIndexOutOfBoundsException e) { }
+
+        if (BasicSwingTestCase.isHarmony()) {
+            assertEquals(0, gv.getGapStart());
+            assertEquals(9, gv.getGapEnd());
+            assertEquals("abcdefghij\n", gv.getString(0, gv.length()));
+        } else {
+            assertEquals(-1, gv.getGapStart());
+            assertEquals(9, gv.getGapEnd());
+            assertEquals("bcdefghij\n", gv.getString(0, gv.length()));
         }
     }
 



Mime
View raw message