Path: blob/master/test/jdk/java/awt/FontClass/TextRequiresLayoutTest.java
41149 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 814632426* @summary Test Font.textRequiresLayout27*/2829import java.awt.Font;3031public class TextRequiresLayoutTest {3233public static void main(String args[]) {3435String simpleStr = "Hello World";36String complexStr = "\u0641\u0642\u0643";37char[] simpleChars = simpleStr.toCharArray();38char[] complexChars = complexStr.toCharArray();3940if (Font.textRequiresLayout(simpleChars, 0, simpleChars.length)) {41throw new RuntimeException("Simple text should not need layout");42}4344if (!Font.textRequiresLayout(complexChars, 0, complexChars.length)) {45throw new RuntimeException("Complex text should need layout");46}4748if (Font.textRequiresLayout(complexChars, 0, 0)) {49throw new RuntimeException("Empty text should not need layout");50}5152boolean except = false;53try {54Font.textRequiresLayout(null, 0, 0);55} catch (NullPointerException npe) {56except = true;57}58if (!except) {59throw new RuntimeException("No expected IllegalArgumentException");60}6162except = false;63try {64Font.textRequiresLayout(complexChars, -1, 0);65} catch (ArrayIndexOutOfBoundsException aioobe) {66except = true;67}68if (!except) {69throw new70RuntimeException("No expected ArrayIndexOutOfBoundsException");71}7273except = false;74try {75Font.textRequiresLayout(complexChars, 0, complexChars.length+1);76} catch (ArrayIndexOutOfBoundsException aioobe) {77except = true;78}79if (!except) {80throw new81RuntimeException("No expected ArrayIndexOutOfBoundsException");82}83}84}858687