Path: blob/master/test/jdk/java/lang/Character/TestNegativeCodepoint.java
41149 views
/*1* Copyright (c) 2018, 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 489938026* @summary Character.is<Property>(int codePoint) methods should return false27* for negative codepoint values. The to<CaseMap> methods should return28* the original codePoint for invalid codePoint ranges.29* @author John O'Conner30*/3132public class TestNegativeCodepoint {3334public static void main(String[] args) {3536int[] invalidCodePoints = { -1, -'a', 0x110000};37for (int x = 0; x < invalidCodePoints.length; ++x) {38int cp = invalidCodePoints[x];3940System.out.println("Testing codepoint: " + cp);41// test all of the is<Property> methods42if (Character.isLowerCase(cp) ||43Character.isUpperCase(cp) ||44Character.isTitleCase(cp) ||45Character.isISOControl(cp) ||46Character.isLetterOrDigit(cp) ||47Character.isLetter(cp) ||48Character.isDigit(cp) ||49Character.isDefined(cp) ||50Character.isJavaIdentifierStart(cp) ||51Character.isJavaIdentifierPart(cp) ||52Character.isUnicodeIdentifierStart(cp) ||53Character.isUnicodeIdentifierPart(cp) ||54Character.isIdentifierIgnorable(cp) ||55Character.isSpaceChar(cp) ||56Character.isWhitespace(cp) ||57Character.isMirrored(cp) ||5859// test the case mappings60Character.toLowerCase(cp) != cp ||61Character.toUpperCase(cp) != cp ||62Character.toTitleCase(cp) != cp ||6364// test directionality of invalid codepoints65Character.getDirectionality(cp) != Character.DIRECTIONALITY_UNDEFINED ||6667// test type68Character.getType(cp) != Character.UNASSIGNED ||6970// test numeric and digit values71Character.getNumericValue(cp) != -1 ||72Character.digit(cp, 10) != -1 ) {7374System.out.println("Failed.");75throw new RuntimeException();76}7778// test block value79Character.UnicodeBlock block = null;80try {81block = Character.UnicodeBlock.of(cp);82// if we haven't already thrown an exception because of the illegal83// arguments, then we need to throw one because of an error in the of() method84System.out.println("Failed.");85throw new RuntimeException();86}87catch(IllegalArgumentException e) {88// Since we're testing illegal values, we89// expect to land here every time. If not,90// our test has failed91}9293}94System.out.println("Passed.");95}96}979899