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