harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r488286 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/Font.java test/api/java/common/java/awt/FontTest.java
Date Mon, 18 Dec 2006 14:34:35 GMT
Author: apetrenko
Date: Mon Dec 18 06:34:34 2006
New Revision: 488286

URL: http://svn.apache.org/viewvc?view=rev&rev=488286
Log:
Patch for HARMONY-1591 "[classlib][awt]Compatibility: awt.Font.getStringBounds() exception
order on Harmony differs from RI"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java?view=diff&rev=488286&r1=488285&r2=488286
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java Mon
Dec 18 06:34:34 2006
@@ -701,32 +701,17 @@
 
     public Rectangle2D getStringBounds(String str, int start, int end,
             FontRenderContext frc) {
-        if (start < 0) {
-            // awt.95=Wrong start index: {0}
-            throw new IndexOutOfBoundsException(Messages.getString("awt.95", start)); //$NON-NLS-1$
-        }
-        if ( end > str.length()) {
-            // awt.96=Wrong finish index: {0}
-            throw new IndexOutOfBoundsException(Messages.getString("awt.96", end)); //$NON-NLS-1$
-        }
-        if (start > end) {
-            // awt.97=Wrong range length: {0}
-            throw new IndexOutOfBoundsException(Messages.getString("awt.97", //$NON-NLS-1$
-                    (end-start)));
-        }
 
         return this.getStringBounds((str.substring(start, end)), frc);
     }
 
     public Rectangle2D getStringBounds(char[] chars, int start, int end,
             FontRenderContext frc) {
-        int finish = chars.length;
-
         if (start < 0) {
             // awt.95=Wrong start index: {0}
             throw new IndexOutOfBoundsException(Messages.getString("awt.95", start)); //$NON-NLS-1$
         }
-        if ( end > finish) {
+        if ( end > chars.length) {
             // awt.96=Wrong finish index: {0}
             throw new IndexOutOfBoundsException(Messages.getString("awt.96", end)); //$NON-NLS-1$
         }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java?view=diff&rev=488286&r1=488285&r2=488286
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/FontTest.java
Mon Dec 18 06:34:34 2006
@@ -17,10 +17,13 @@
 
 package java.awt;
 
+import java.awt.font.FontRenderContext;
 import java.awt.font.TextAttribute;
 import java.text.AttributedString;
+import java.text.CharacterIterator;
 import java.text.AttributedCharacterIterator.Attribute;
 import java.util.Collections;
+
 import junit.framework.TestCase;
 
 public class FontTest extends TestCase {
@@ -105,6 +108,38 @@
         } catch (NullPointerException e) {
             // expected
         }
+    }
+    
+    /*
+     * Compatibility test. We check that Harmony throws same 
+     * exceptions as RI does.
+     */
+    public void test_Font_getStringBounds_WithNullTextSource() {
+        // regression test for Harmony-1591
+        Font font = new Font("dialog", Font.PLAIN, 12);
+        FontRenderContext cnt = new FontRenderContext(null, false, true);
+        try {
+            font.getStringBounds((char[]) null, -16, 1, cnt);
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            font.getStringBounds((String) null, -16, 1, cnt);
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            font.getStringBounds((CharacterIterator) null, -16, 1, cnt);
+        } catch (NullPointerException e) {
+            // expected
+        }
 
+        try {
+            font.getStringBounds((String) null, cnt);
+        } catch (NullPointerException e) {
+            // expected
+        }
     }
 }



Mime
View raw message