Index: api/java/common/java/awt/FontTest.java =================================================================== --- api/java/common/java/awt/FontTest.java (revision 0) +++ api/java/common/java/awt/FontTest.java (revision 0) @@ -0,0 +1,68 @@ +/* + * Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package java.awt; + +import java.awt.font.TextAttribute; +import java.text.AttributedString; + +import junit.framework.TestCase; + +public class FontTest extends TestCase { + + private final Font f = new Font("dialog", Font.PLAIN, 12); + + /** + * Checks Font.getLineMetrics() methods if FontRenderContext parameter is NULL. + * + */ + public void test_Font_getLineMetrics_WithNullFRC(){ + // // regression test for Harmony-1465 + final String str = "test"; + try{ + f.getLineMetrics(str, null); + fail("NullPointerException expected but wasn't thrown!"); + }catch (NullPointerException e) { + // as expected + } + + try{ + f.getLineMetrics(str, 1, 3, null); + fail("NullPointerException expected but wasn't thrown!"); + }catch (NullPointerException e) { + // as expected + } + + try{ + f.getLineMetrics(str.toCharArray(), 1, 3, null); + fail("NullPointerException expected but wasn't thrown!"); + }catch (NullPointerException e) { + // as expected + } + + try{ + AttributedString as = new AttributedString("test"); + as.addAttribute(TextAttribute.FONT, f, 0, 2 ); + + f.getLineMetrics(as.getIterator(), 1, 3, null); + fail("NullPointerException expected but wasn't thrown!"); + }catch (NullPointerException e) { + // as expected + } + + } + +} Index: api/java/common/java/awt/font/TextLayoutTest.java =================================================================== --- api/java/common/java/awt/font/TextLayoutTest.java (revision 442249) +++ api/java/common/java/awt/font/TextLayoutTest.java (working copy) @@ -29,6 +29,9 @@ import java.awt.geom.*; import java.text.AttributedString; import java.text.AttributedCharacterIterator; +import java.text.AttributedCharacterIterator.Attribute; +import java.util.HashMap; +import java.util.Map; public class TextLayoutTest extends TestCase { @@ -642,6 +645,76 @@ assertEquals(TextHitInfo.leading(5), i); } + public void testTextLayoutConstructorConstraints() throws Exception{ + // regression test for Harmony-1464 + try{ + new TextLayout(null, (Font)null, null); + } catch (IllegalArgumentException e) { + // expected + } + + try{ + new TextLayout(null, f, null); + } catch (IllegalArgumentException e) { + // expected + } + + try{ + new TextLayout("", f, null); + } catch (IllegalArgumentException e) { + // expected + } + + try{ + new TextLayout("aa", f, null); + } catch (NullPointerException e) { + // expected + } + + try{ + new TextLayout(null, null); + } catch (IllegalArgumentException e) { + // expected + } + + AttributedString as = new AttributedString("test"); + as.addAttribute(TextAttribute.FONT, f, 0, 2 ); + + try{ + new TextLayout(as.getIterator(), null); + } catch (NullPointerException e) { + // expected + } + + try { + new TextLayout(null, (Map)null, (FontRenderContext) null); + } catch (IllegalArgumentException e) { + System.out.println("success: " + e.getMessage()); + // as expected + } + + try { + new TextLayout(null, (Map)new HashMap(), (FontRenderContext) null); + } catch (IllegalArgumentException e) { + // as expected + } + + try { + new TextLayout("aa", (Map)new HashMap(), (FontRenderContext) null); + } catch (NullPointerException e) { + // as expected + } + + + try{ + new TextLayout("", (Map)new HashMap(), (FontRenderContext) null); + } catch (IllegalArgumentException e) { + // as expected + System.out.println("success: " + e.getMessage()); + } + + } + public static Test suite() { return new TestSuite(TextLayoutTest.class);