jdk/test/tools/jlink/plugins/SignatureParserTest.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 36511 9d0388c6b336
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary Test SignatureParser
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @author Jean-Francois Denise
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.jimage.decompressor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @run main SignatureParserTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.Objects;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import jdk.internal.jimage.decompressor.SignatureParser;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
public class SignatureParserTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
    private int passed = 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
    private int failed = 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
    public static void main(String[] args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
        new SignatureParserTest().test();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    private void test() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        test("[Ljava/lang/String;", "[L;", "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        test("[[[[[[[[[[Ljava/lang/String;", "[[[[[[[[[[L;", "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        test("<T:Ljava/lang/Object;:Ljava/lang/Comparable<-TT;>;>" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
                        "(Ljava/lang/String;Ljava/lang/Class<TT;>;TT;Ljava/lang/Comparable<-TT;>;" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
                        "Ljava/lang/Comparable<-TT;>;ZZ)V",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
                "<T:L;:L<-TT;>;>(L;L<TT;>;TT;L<-TT;>;L<-TT;>;ZZ)V",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
                "java/lang/Object", "java/lang/Comparable", "java/lang/String",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
                "java/lang/Class", "java/lang/Comparable", "java/lang/Comparable");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        test("(Ljava/lang/String;ZLjava/util/EventListener;TTK;)V",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                "(L;ZL;TTK;)V",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                "java/lang/String", "java/util/EventListener");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        test("<Y:Ljava/lang/String;>", "<Y:L;>", "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        test("<Y:Ljava/lang/String;Z::Ljava/util/EventListener;>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
                "<Y:L;Z::L;>", "java/lang/String",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                "java/util/EventListener");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        test("<Y:Ljava/lang/String;Z::Ljava/util/EventListener;O::Ljava/lang/Comparable<Ljava/lang/String;>;>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                "<Y:L;Z::L;O::L<L;>;>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                "java/lang/String", "java/util/EventListener", "java/lang/Comparable", "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        test("<Y:Ljava/lang/String;O::Ljava/lang/Comparable<Ljava/lang/String;Ljava/lang/Float;>;>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                "<Y:L;O::L<L;L;>;>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                "java/lang/String", "java/lang/Comparable", "java/lang/String", "java/lang/Float");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        test("<Y:Ljava/lang/String;O::Ljava/lang/Comparable<Ljava/lang/String;Ljava/lang/Float<Ljava/lang/Object;>;>;>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                "<Y:L;O::L<L;L<L;>;>;>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
                "java/lang/String", "java/lang/Comparable", "java/lang/String", "java/lang/Float", "java/lang/Object");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        test("Ljava/util/Set;", "L;", "java/util/Set");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        test("Ljavaapplication20/Titi<[Ljava/lang/String;Ljava/lang/Integer;>;", "L<[L;L;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                "javaapplication20/Titi",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                "java/lang/String", "java/lang/Integer");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        test("Ljava/lang/Comparable<TK;>;", "L<TK;>;", "java/lang/Comparable");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        test("Ljava/io/Serializable;Ljava/lang/Comparable<TK;>;", "L;L<TK;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                "java/io/Serializable", "java/lang/Comparable");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        test("<Y:Ljava/lang/String;Z::Ljava/util/EventListener;K::Ljava/util/EventListener;O::"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                + "Ljava/lang/Comparable<Ljava/lang/String;>;>"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                + "Ljavaapplication20/Titi<[Ljava/lang/String;Ljava/lang/Integer;TZ;>;"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                + "Ljava/io/Serializable;Ljava/lang/Comparable<TK;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                "<Y:L;Z::L;K::L;O::L<L;>;>L<[L;L;TZ;>;L;L<TK;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                "java/lang/String", "java/util/EventListener", "java/util/EventListener", "java/lang/Comparable",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                "java/lang/String", "javaapplication20/Titi", "java/lang/String", "java/lang/Integer",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
                "java/io/Serializable", "java/lang/Comparable");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        test("<PO:Ljava/lang/Object;>(Ljava/lang/Integer;TPO;)Ljava/lang/Integer;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                "<PO:L;>(L;TPO;)L;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                "java/lang/Object", "java/lang/Integer", "java/lang/Integer");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        test("<PO:Ljava/lang/Object;>(Ljava/lang/Integer;TPO;)TPO;", "<PO:L;>(L;TPO;)TPO;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                "java/lang/Object", "java/lang/Integer");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        test("<T::Ljava/util/EventListener;>(Ljava/lang/Class<TT;>;)[TT;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                "<T::L;>(L<TT;>;)[TT;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                "java/util/EventListener", "java/lang/Class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        test("<PO:LTiti;>(Ljava/lang/Integer;ITPO;)Z", "<PO:L;>(L;ITPO;)Z",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                "Titi", "java/lang/Integer");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        test("<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                "<K:L;V:L;>L;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                "java/lang/Object", "java/lang/Object", "java/lang/Object");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        test("Ljava/util/LinkedHashMap<TK;TV;>.LinkedHashIterator;Ljava/util/Iterator<TV;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                "L<TK;TV;>.L;L<TV;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                "java/util/LinkedHashMap",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                "inkedHashIterator",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                "java/util/Iterator");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        test("LToto<Ljava/lang/String;>;", "L<L;>;", "Toto",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        test("Ljavaapplication20/Titi<[Ljava/lang/String;Ljava/lang/Integer<LToto;>;TZ;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                "L<[L;L<L;>;TZ;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                "javaapplication20/Titi", "java/lang/String", "java/lang/Integer", "Toto");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        test("LX<[LQ;LW<LToto;>;TZ;>;", "L<[L;L<L;>;TZ;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                "X", "Q", "W", "Toto");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        test("Ljava/lang/String<*>;", "L<*>;", "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        test("Ljava/util/List<[B>;", "L<[B>;", "java/util/List");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        test("<T:Ljava/lang/Object;T_NODE::Ljava/util/stream/Node<TT;>;>Ljava/lang/Object;Ljava/util/stream/Node<TT;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                "<T:L;T_NODE::L<TT;>;>L;L<TT;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                "java/lang/Object", "java/util/stream/Node", "java/lang/Object", "java/util/stream/Node");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        test("Ljavaapplication20/Titi<[Ljava/lang/String;>;", "L<[L;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                "javaapplication20/Titi", "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        test("<A::Ljava/lang/annotation/Annotation;"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                        + "W::Lcom/sun/codemodel/internal/JAnnotationWriter<TA;>;>"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                        + "Ljava/lang/Object;Ljava/lang/reflect/InvocationHandler;"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                        + "Lcom/sun/codemodel/internal/JAnnotationWriter<TA;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                "<A::L;W::L<TA;>;>L;L;L<TA;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                "java/lang/annotation/Annotation", "com/sun/codemodel/internal/JAnnotationWriter",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                "java/lang/Object", "java/lang/reflect/InvocationHandler", "com/sun/codemodel/internal/JAnnotationWriter");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        test("<W::Lcom/sun/codemodel/internal/JAnnotationWriter<*>;>(Ljava/lang/Class<TW;>;" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                "Lcom/sun/codemodel/internal/JAnnotatable;)TW;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                "<W::L<*>;>(L<TW;>;L;)TW;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                "com/sun/codemodel/internal/JAnnotationWriter", "java/lang/Class", "com/sun/codemodel/internal/JAnnotatable");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        test("Ljava/util/Set<Lcom/sun/tools/jdeps/JdepsTask$DotGraph<TT;>.Edge;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                "L<L<TT;>.Edge;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                "java/util/Set",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                "com/sun/tools/jdeps/JdepsTask$DotGraph");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        test("<E::Lcom/sun/xml/internal/rngom/ast/om/ParsedElementAnnotation;" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                "L::Lcom/sun/xml/internal/rngom/ast/om/Location;" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                "CL::Lcom/sun/xml/internal/rngom/ast/builder/CommentList<TL;>;>Ljava/lang/Object;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                "<E::L;L::L;CL::L<TL;>;>L;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                "com/sun/xml/internal/rngom/ast/om/ParsedElementAnnotation",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                "",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                "com/sun/xml/internal/rngom/ast/om/Location",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                "",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                "com/sun/xml/internal/rngom/ast/builder/CommentList",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                "",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                "java/lang/Object");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        test("(Ljava/util/List<Lcom/sun/xml/internal/rngom/nc/NameClass;>;TL;TA;)" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                "Lcom/sun/xml/internal/rngom/nc/NameClass;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                "(L<L;>;TL;TA;)L;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                "java/util/List",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                "com/sun/xml/internal/rngom/nc/NameClass",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                "",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                "com/sun/xml/internal/rngom/nc/NameClass");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        test("[Ljava/util/List;", "[L;", "java/util/List");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        test("[Ljava/util/List<+Lcom/sun/jdi/request/EventRequest;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                "[L<+L;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                "java/util/List", "com/sun/jdi/request/EventRequest");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        test("Lcom/sun/xml/internal/bind/v2/util/QNameMap<TV;>.HashIterator" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                "<Lcom/sun/xml/internal/bind/v2/util/QNameMap$Entry<TV;>;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                "L<TV;>.HashIterator<L<TV;>;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                "com/sun/xml/internal/bind/v2/util/QNameMap", "com/sun/xml/internal/bind/v2/util/QNameMap$Entry");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        test("[Ljava/lang/String;", "[L;", "java/lang/String");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        test("[Ljava/lang/String<Ljava/lang/Toto<Ljava/lang/Titi;>;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                "[L<L<L;>;>;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                "java/lang/String", "java/lang/Toto", "java/lang/Titi");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        test("<T::Ljava/util/EventListener;K:Ljava/util/BOO;>(ZCLjava/lang/Class<TT;>;IJS)[TT;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                "<T::L;K:L;>(ZCL<TT;>;IJS)[TT;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                "java/util/EventListener", "java/util/BOO", "java/lang/Class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        test("<T:Ljava/lang/Object;>(TT;ILjava/lang/Long;)TT;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                "<T:L;>(TT;IL;)TT;", "java/lang/Object", "java/lang/Long");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        test("<T:Ljava/lang/Object;>(TT;ILjava/lang/Long;)TT;^TT;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                "<T:L;>(TT;IL;)TT;^TT;", "java/lang/Object", "java/lang/Long");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        test("<T:Ljava/lang/Object;>(TT;ILjava/lang/Long;)TT;^TT;^Ljava/lang/Exception;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                "<T:L;>(TT;IL;)TT;^TT;^L;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                "java/lang/Object", "java/lang/Long", "java/lang/Exception");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        if (passed + failed == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            throw new AssertionError("No tests were run");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        String message = String.format("Passed: %d, failed: %d, total: %d", passed, failed, passed + failed);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        if (failed > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
            throw new AssertionError("Test failed: " + message);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
            System.err.println(message);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
    private void test(String type, String formatted, String...classNames) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
            SignatureParser.ParseResult result = SignatureParser.parseSignatureDescriptor(type);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
            String[] parsedNames = parse(classNames);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            assertEquals(result.formatted, formatted, "Input: '" + type + "', checking 'formatted'");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
            assertEquals(result.types.size(), 2 * classNames.length,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                    "Input: '" + type + "', checking the length of 'types':" +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                            "\nexpected: " + Arrays.toString(parsedNames) +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                            "\n     got: " + result.types);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
            for (int i = 0; i < result.types.size(); ++i) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                assertEquals(result.types.get(i), parsedNames[i],
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                        "Input: '" + type + "', checking 'packageName' at index " + i / 2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                ++i;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                assertEquals(result.types.get(i), parsedNames[i],
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                        "Input: '" + type + "', checking 'simpleName' at index " + i / 2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
            String reconstructed = SignatureParser.reconstruct(result.formatted, result.types);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
            assertEquals(reconstructed, type, "Input: '" + type + "', checking reconstruction from: "
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
                    + result.formatted + " " + result.types);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
            ++passed;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        } catch (Exception | AssertionError e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
            e.printStackTrace();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
            ++failed;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    private void assertEquals(Object actual, Object expected, String message) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        if (!Objects.equals(actual, expected)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            throw new AssertionError(message + ": expected: " + expected + ", actual: " + actual);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
    private String[] parse(String[] classNames) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        String[] result = new String[2 * classNames.length];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        for (int i = 0; i < classNames.length; ++i) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
            int index = classNames[i].lastIndexOf("/");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
            result[2 * i] = index == -1 ? "" : classNames[i].substring(0, index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            result[2 *i + 1] = classNames[i].substring(index + 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        return result;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
}