test/jdk/com/sun/jdi/ArrayLengthDumpTest.java
author iignatyev
Fri, 14 Sep 2018 14:02:57 -0700
changeset 51754 594919232b8f
parent 51596 b8eea2a7569a
permissions -rw-r--r--
8210732: remove jdk.testlibrary.Utils Reviewed-by: alanb, jcbeyler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     1
/*
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     4
 *
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     7
 * published by the Free Software Foundation.
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     8
 *
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    13
 * accompanied this code).
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    14
 *
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    18
 *
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    21
 * questions.
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    22
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    24
/*
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    25
 * @test
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    26
 * @bug 4422141 4695338
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    27
 * @summary TTY: .length field for arrays in print statements in jdb not recognized
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    28
 *          TTY: dump <ArrayReference> command not implemented.
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    29
 * @comment converted from test/jdk/com/sun/jdi/ArrayLengthDumpTest.sh
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    30
 *
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    31
 * @library /test/lib
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    32
 * @build ArrayLengthDumpTest
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    33
 * @run main/othervm ArrayLengthDumpTest
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    34
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    36
import lib.jdb.JdbCommand;
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    37
import lib.jdb.JdbTest;
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    38
import jdk.test.lib.process.OutputAnalyzer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    40
import java.util.LinkedList;
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    41
import java.util.List;
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    42
import java.util.stream.Collectors;
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    43
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    44
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    45
class ArrayLengthDumpTarg {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int [] i = {0,1,2,3,4,5,6};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    String [] s = {"zero", "one", "two", "three", "four"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    String [][] t = {s, s, s, s, s, s, s, s, s, s, s};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    int length = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    51
    private void bar() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    54
    private void foo() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        ArrayLengthDumpTarg u[] = { new ArrayLengthDumpTarg(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                    new ArrayLengthDumpTarg(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                                    new ArrayLengthDumpTarg(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                                    new ArrayLengthDumpTarg(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                    new ArrayLengthDumpTarg(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                    new ArrayLengthDumpTarg() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        int k = u.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        System.out.println("        u.length is: " + k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        k = this.s.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        System.out.println("   this.s.length is: " + k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        k = this.t.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        System.out.println("   this.t.length is: " + k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        k = this.t[1].length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        System.out.println("this.t[1].length is: " + k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        k = i.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.out.println("        i.length is: " + k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        bar();                      // @1 breakpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        ArrayLengthDumpTarg my = new ArrayLengthDumpTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        my.foo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
}
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    79
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    80
public class ArrayLengthDumpTest extends JdbTest {
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    81
    public static void main(String argv[]) {
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    82
        new ArrayLengthDumpTest().run();
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    83
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    85
    public ArrayLengthDumpTest() {
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    86
        super(DEBUGGEE_CLASS);
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    87
    }
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    88
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    89
    private static final String DEBUGGEE_CLASS = ArrayLengthDumpTarg.class.getName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    91
    @Override
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    92
    protected void runCases() {
51596
b8eea2a7569a 8209604: [TEST] rewrite com/sun/jdi shell tests to java version - step2
amenkov
parents: 51402
diff changeset
    93
        setBreakpointsFromTestSource("ArrayLengthDumpTest.java", 1);
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    94
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    95
        // Run to breakpoint #1
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    96
        jdb.command(JdbCommand.run());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    98
        List<String> reply = new LinkedList<>();
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
    99
        reply.addAll(jdb.command(JdbCommand.dump("this")));
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   100
        reply.addAll(jdb.command(JdbCommand.dump("this.s.length")));
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   101
        reply.addAll(jdb.command(JdbCommand.dump("this.s")));
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   102
        reply.addAll(jdb.command(JdbCommand.dump("this.t.length")));
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   103
        reply.addAll(jdb.command(JdbCommand.dump("this.t[1].length")));
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   104
        reply.addAll(jdb.command(JdbCommand.dump("ArrayLengthDumpTarg.i.length")));
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   105
        reply.addAll(jdb.command(JdbCommand.dump("this.length")));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   107
        new OutputAnalyzer(reply.stream().collect(Collectors.joining(lineSeparator)))
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   108
                // Test the fix for 4690242:
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   109
                .shouldNotContain("No instance field or method with the name length in")
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   110
                .shouldNotContain("No static field or method with the name length")
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   111
                // Test the fix for 4695338:
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   112
                .shouldContain("\"zero\", \"one\", \"two\", \"three\", \"four\"");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
51402
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   114
        jdb.contToExit(1);
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   115
    }
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   116
bfdebb29b1e5 8209109: [TEST] rewrite com/sun/jdi shell tests to java version - step1
amenkov
parents: 47216
diff changeset
   117
}