3623N/A/*
3623N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3623N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3623N/A *
3623N/A * This code is free software; you can redistribute it and/or modify it
3623N/A * under the terms of the GNU General Public License version 2 only, as
3623N/A * published by the Free Software Foundation.
3623N/A *
3623N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3623N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3623N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3623N/A * version 2 for more details (a copy is included in the LICENSE file that
3623N/A * accompanied this code).
3623N/A *
3623N/A * You should have received a copy of the GNU General Public License version
3623N/A * 2 along with this work; if not, write to the Free Software Foundation,
3623N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3623N/A *
3623N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3623N/A * or visit www.oracle.com if you need additional information or have any
3623N/A * questions.
3623N/A */
3623N/A
3623N/A/*
3623N/A * @test
3623N/A * @bug 6623219
3623N/A * @summary Test canDisplayUpTo with supplementary characters.
3623N/A */
3623N/A
3623N/Aimport java.awt.*;
3623N/Aimport java.text.*;
3623N/A
3623N/Apublic class SupplementaryCanDisplayUpToTest {
3623N/A // Lists consisting of a font name, test text, and its expected
3623N/A // return value. Test text uses private area code point U+F0000
3623N/A // (\udb80\udc00).
3623N/A private static String[][] DATA = {
3623N/A // Windows
3623N/A { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80\udc00", "4" },
3623N/A { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80Z", "4" },
3623N/A { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80", "4" },
3623N/A { "Meiryo", "\ud87e\udd45\ud87e\udd47\udc00", "4" },
3623N/A { "Meiryo", "\ud87e\udd45\ud87e\udd47", "-1" },
3623N/A
3623N/A // Linux
3623N/A { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },
3623N/A { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },
3623N/A { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },
3623N/A { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },
3623N/A { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b", "-1" },
3623N/A
3623N/A // Solaris
3623N/A { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },
3623N/A { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },
3623N/A { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },
3623N/A { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },
3623N/A { "FZMingTi", "\ud87e\udc25\ud87e\udc3b", "-1" },
3623N/A };
3623N/A private static int errorcount = 0;
3623N/A
3623N/A public static void main(String[] args) {
3623N/A for (String[] data : DATA) {
3623N/A String fontname = data[0];
3623N/A Font font = new Font(fontname, Font.PLAIN, 16);
3623N/A if (font.getFamily().equals(Font.DIALOG)) {
3623N/A // Skip any unavailable fonts.
3623N/A continue;
3623N/A }
3623N/A
3623N/A System.out.printf("Testing with font '%s'... ", fontname);
3623N/A int errors = 0;
3623N/A String text = data[1];
3623N/A int expected = Integer.parseInt(data[2]);
3623N/A
3623N/A int result = font.canDisplayUpTo(text);
3623N/A if (result != expected) {
3623N/A System.err.println("canDisplayUpTo(String) returns " + result);
3623N/A errors++;
3623N/A }
3623N/A
3623N/A result = font.canDisplayUpTo(text.toCharArray(), 0, text.length());
3623N/A if (result != expected) {
3623N/A System.err.println("canDisplayUpTo(char[], int, int) returns " + result);
3623N/A errors++;
3623N/A }
3623N/A
3623N/A CharacterIterator iter = new StringCharacterIterator(text);
3623N/A result = font.canDisplayUpTo(iter, iter.getBeginIndex(), iter.getEndIndex());
3623N/A if (result != expected) {
3623N/A System.err.println("canDisplayUpTo(CharacterIterator, int, int) returns " + result);
3623N/A errors++;
3623N/A }
3623N/A
3623N/A if (errors == 0) {
3623N/A System.out.println("passed");
3623N/A } else {
3623N/A System.out.println("failed");
3623N/A errorcount += errors;
3623N/A }
3623N/A }
3623N/A if (errorcount > 0) {
3623N/A throw new RuntimeException("SupplementaryCanDisplayUpToTest: failed");
3623N/A }
3623N/A }
3623N/A}