Path: blob/master/test/hotspot/jtreg/runtime/Annotations/TestAnnotatedStringEncoding.java
40948 views
/*1* Copyright (c) 2015, 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*/2223import java.lang.annotation.*;24import java.lang.reflect.*;2526/*27* @test28* @bug 805430729* @summary Tests the correct encoding of latin1/UTF16 Strings used in annotations.30*/31public class TestAnnotatedStringEncoding {32@Retention(RetentionPolicy.RUNTIME)33@Target(ElementType.METHOD)34@interface Test {35String str();36int index();37}3839public static void main(String[] args) throws Exception {40new TestAnnotatedStringEncoding().run();41}4243public void run() {44// Iterate over annotated methods and retrieve the string45for (Method m : this.getClass().getMethods()) {46if (m.isAnnotationPresent(Test.class)) {47// Check if string equals expected value48Test test = m.getAnnotation(Test.class);49String str = test.str();50int index = test.index();51if (!str.equals(strValue[index])) {52throw new RuntimeException(m.getName() + " failed: \"" + str + "\" (0x" + Integer.toHexString(str.charAt(0)) +53") does not equal \"" + strValue[index] + "\" (0x" + Integer.toHexString(strValue[index].charAt(0)) + ") .");54}55}56}57System.out.println("Test passed.");58}5960public static String[] strValue = {61"\u0000", "\u0020", "\u0021", "\u0080",62"\u00FF", "\u0100", "\u017F", "\u01FF",63"\u07FF", "\u0800", "\uC280", "\uC2BF",64"\uC380", "\uC3BF", "\uC5BF", "\uFFFF",65"\u10000", "\u1FFFFF", "\u200000",66"\u3FFFFFF", "\u4000000", "\u7FFFFFFF",67"ab\uff23\uff24ef\uff27", "\uff21\uff22cd\uff25g", "\u00FF\u00FF\u00FF", "\u00A1\u00A1\u00A1\u00A1", ""};6869@Test(str = "\u0000", index = 0)70public static void check0() { }7172@Test(str = "\u0020", index = 1)73public static void check1() { }7475@Test(str = "\u0021", index = 2)76public static void check2() { }7778@Test(str = "\u0080", index = 3)79public static void check3() { }8081@Test(str = "\u00FF", index = 4)82public static void check4() { }8384@Test(str = "\u0100", index = 5)85public static void check5() { }8687@Test(str = "\u017F", index = 6)88public static void check6() { }8990@Test(str = "\u01FF", index = 7)91public static void check7() { }9293@Test(str = "\u07FF", index = 8)94public static void check8() { }9596@Test(str = "\u0800", index = 9)97public static void check9() { }9899@Test(str = "\uC280", index = 10)100public static void check10() { }101102@Test(str = "\uC2BF", index = 11)103public static void check11() { }104105@Test(str = "\uC380", index = 12)106public static void check12() { }107108@Test(str = "\uC3BF", index = 13)109public static void check13() { }110111@Test(str = "\uC5BF", index = 14)112public static void check14() { }113114@Test(str = "\uFFFF", index = 15)115public static void check15() { }116117@Test(str = "\u10000", index = 16)118public static void check16() { }119120@Test(str = "\u1FFFFF", index = 17)121public static void check17() { }122123@Test(str = "\u200000", index = 18)124public static void check18() { }125126@Test(str = "\u3FFFFFF", index = 19)127public static void check19() { }128129@Test(str = "\u4000000", index = 20)130public static void check20() { }131132@Test(str = "\u7FFFFFFF", index = 21)133public static void check21() { }134135@Test(str = "ab\uff23\uff24ef\uff27", index = 22)136public static void check22() { }137138@Test(str = "\uff21\uff22cd\uff25g", index = 23)139public static void check23() { }140141@Test(str = "\u00FF\u00FF\u00FF", index = 24)142public static void check24() { }143144@Test(str = "\u00A1\u00A1\u00A1\u00A1", index = 25)145public static void check25() { }146147@Test(str = "", index = 26)148public static void check26() { }149}150151152