Path: blob/master/test/jdk/java/awt/FontClass/SurrogateTest/SupplementaryCanDisplayUpToTest.java
41154 views
/*1* Copyright (c) 2011, 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 662321926* @summary Test canDisplayUpTo with supplementary characters.27*/2829import java.awt.*;30import java.text.*;3132public class SupplementaryCanDisplayUpToTest {33// Lists consisting of a font name, test text, and its expected34// return value. Test text uses private area code point U+F000035// (\udb80\udc00).36private static String[][] DATA = {37// Windows38{ "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80\udc00", "4" },39{ "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80Z", "4" },40{ "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80", "4" },41{ "Meiryo", "\ud87e\udd45\ud87e\udd47\udc00", "4" },42{ "Meiryo", "\ud87e\udd45\ud87e\udd47", "-1" },4344// Linux45{ "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },46{ "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },47{ "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },48{ "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },49{ "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b", "-1" },5051// Solaris52{ "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },53{ "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },54{ "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },55{ "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },56{ "FZMingTi", "\ud87e\udc25\ud87e\udc3b", "-1" },57};58private static int errorcount = 0;5960public static void main(String[] args) {61for (String[] data : DATA) {62String fontname = data[0];63Font font = new Font(fontname, Font.PLAIN, 16);64if (font.getFamily().equals(Font.DIALOG)) {65// Skip any unavailable fonts.66continue;67}6869System.out.printf("Testing with font '%s'... ", fontname);70int errors = 0;71String text = data[1];72int expected = Integer.parseInt(data[2]);7374int result = font.canDisplayUpTo(text);75if (result != expected) {76System.err.println("canDisplayUpTo(String) returns " + result);77errors++;78}7980result = font.canDisplayUpTo(text.toCharArray(), 0, text.length());81if (result != expected) {82System.err.println("canDisplayUpTo(char[], int, int) returns " + result);83errors++;84}8586CharacterIterator iter = new StringCharacterIterator(text);87result = font.canDisplayUpTo(iter, iter.getBeginIndex(), iter.getEndIndex());88if (result != expected) {89System.err.println("canDisplayUpTo(CharacterIterator, int, int) returns " + result);90errors++;91}9293if (errors == 0) {94System.out.println("passed");95} else {96System.out.println("failed");97errorcount += errors;98}99}100if (errorcount > 0) {101throw new RuntimeException("SupplementaryCanDisplayUpToTest: failed");102}103}104}105106107