langtools/test/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTest.java
author jjg
Thu, 31 Mar 2016 15:20:50 -0700
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
permissions -rw-r--r--
8152897: refactor ToolBox to allow reduced documented dependencies Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27126
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     1
/*
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
27126
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     4
 *
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     8
 *
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    13
 * accompanied this code).
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    14
 *
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    18
 *
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    21
 * questions.
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    22
 */
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    23
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    24
/*
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    25
 * @test
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    26
 * @summary Tests a line number table attribute for language constructions in different containers.
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    27
 * @bug 8040131
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    28
 * @library /tools/lib /tools/javac/lib ../lib
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 30846
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27126
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 30846
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.util
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 30846
diff changeset
    32
 *          jdk.jdeps/com.sun.tools.classfile
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build toolbox.ToolBox InMemoryFileManager TestBase
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    34
 * @build LineNumberTestBase Container TestCase
27126
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    35
 * @run main LineNumberTest
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    36
 */
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    37
public class LineNumberTest extends LineNumberTestBase {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    39
        new LineNumberTest().test();
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    40
    }
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    41
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    42
    public void test() throws Exception {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    43
        int failed = 0;
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    44
        for (TestData testData : TestData.values()) {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    45
            echo("[Executing test]: " + testData);
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    46
            try {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    47
                test(testData.container);
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    48
            } catch (Exception e) {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    49
                echo("[Test failed]: " + testData);
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    50
                e.printStackTrace();
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    51
                failed++;
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    52
                continue;
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    53
            }
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    54
            echo("[Test passed]: " + testData);
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    55
        }
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    56
        if (failed > 0)
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    57
            throw new RuntimeException(String.format("Failed tests %d of %d%n", failed, TestData.values().length));
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    58
    }
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    59
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    60
    enum TestData {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    61
        SimpleMethod(new MainContainer()),
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    62
        LocalClassContainer(new MainContainer()
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    63
                .insert(new LocalClassContainer())),
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    64
        LambdaContainer(new MainContainer()
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    65
                .insert(new LambdaContainer())),
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    66
        LambdaInLambdaContainer(new MainContainer()
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    67
                .insert(new LambdaContainer())
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    68
                .insert(new LambdaContainer())),
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    69
        LambdaInLocalClassContainerTest(new MainContainer()
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    70
                .insert(new LocalClassContainer())
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    71
                .insert(new LambdaContainer())),
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    72
        LocalClassInLambdaContainer(new MainContainer()
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    73
                .insert(new LambdaContainer())
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    74
                .insert(new LocalClassContainer())),
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    75
        LocalInLocalContainer(new MainContainer()
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    76
                .insert(new LocalClassContainer())
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    77
                .insert(new LocalClassContainer()));
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    78
        Container container;
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    79
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    80
        TestData(Container container) {
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    81
            this.container = container;
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    82
        }
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    83
    }
0fa6f84c1195 8040131: Implement classfile test for LineNumberTable attribute.
jjg
parents:
diff changeset
    84
}