1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.annotation.*;
import java.lang.reflect.*;
/*
* @test
* @bug 8054307
* @summary Tests the correct encoding of latin1/UTF16 Strings used in annotations.
*/
public class TestAnnotatedStringEncoding {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface Test {
String str();
int index();
}
public static void main(String[] args) throws Exception {
new TestAnnotatedStringEncoding().run();
}
public void run() {
// Iterate over annotated methods and retrieve the string
for (Method m : this.getClass().getMethods()) {
if (m.isAnnotationPresent(Test.class)) {
// Check if string equals expected value
Test test = m.getAnnotation(Test.class);
String str = test.str();
int index = test.index();
if (!str.equals(strValue[index])) {
throw new RuntimeException(m.getName() + " failed: \"" + str + "\" (0x" + Integer.toHexString(str.charAt(0)) +
") does not equal \"" + strValue[index] + "\" (0x" + Integer.toHexString(strValue[index].charAt(0)) + ") .");
}
}
}
System.out.println("Test passed.");
}
public static String[] strValue = {
"\u0000", "\u0020", "\u0021", "\u0080",
"\u00FF", "\u0100", "\u017F", "\u01FF",
"\u07FF", "\u0800", "\uC280", "\uC2BF",
"\uC380", "\uC3BF", "\uC5BF", "\uFFFF",
"\u10000", "\u1FFFFF", "\u200000",
"\u3FFFFFF", "\u4000000", "\u7FFFFFFF",
"ab\uff23\uff24ef\uff27", "\uff21\uff22cd\uff25g", "\u00FF\u00FF\u00FF", "\u00A1\u00A1\u00A1\u00A1", ""};
@Test(str = "\u0000", index = 0)
public static void check0() { }
@Test(str = "\u0020", index = 1)
public static void check1() { }
@Test(str = "\u0021", index = 2)
public static void check2() { }
@Test(str = "\u0080", index = 3)
public static void check3() { }
@Test(str = "\u00FF", index = 4)
public static void check4() { }
@Test(str = "\u0100", index = 5)
public static void check5() { }
@Test(str = "\u017F", index = 6)
public static void check6() { }
@Test(str = "\u01FF", index = 7)
public static void check7() { }
@Test(str = "\u07FF", index = 8)
public static void check8() { }
@Test(str = "\u0800", index = 9)
public static void check9() { }
@Test(str = "\uC280", index = 10)
public static void check10() { }
@Test(str = "\uC2BF", index = 11)
public static void check11() { }
@Test(str = "\uC380", index = 12)
public static void check12() { }
@Test(str = "\uC3BF", index = 13)
public static void check13() { }
@Test(str = "\uC5BF", index = 14)
public static void check14() { }
@Test(str = "\uFFFF", index = 15)
public static void check15() { }
@Test(str = "\u10000", index = 16)
public static void check16() { }
@Test(str = "\u1FFFFF", index = 17)
public static void check17() { }
@Test(str = "\u200000", index = 18)
public static void check18() { }
@Test(str = "\u3FFFFFF", index = 19)
public static void check19() { }
@Test(str = "\u4000000", index = 20)
public static void check20() { }
@Test(str = "\u7FFFFFFF", index = 21)
public static void check21() { }
@Test(str = "ab\uff23\uff24ef\uff27", index = 22)
public static void check22() { }
@Test(str = "\uff21\uff22cd\uff25g", index = 23)
public static void check23() { }
@Test(str = "\u00FF\u00FF\u00FF", index = 24)
public static void check24() { }
@Test(str = "\u00A1\u00A1\u00A1\u00A1", index = 25)
public static void check25() { }
@Test(str = "", index = 26)
public static void check26() { }
}
|