jdk/test/com/sun/jdi/StringConvertTest.sh
author katleman
Thu, 05 Jan 2012 08:42:37 -0800
changeset 11376 075fe3928b7f
parent 5506 202f599c92aa
child 23046 0b0407b1e2a5
permissions -rw-r--r--
Added tag jdk8-b20 for changeset 90e14ec89395
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#!/bin/sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
#
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     4
# Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
#
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
# questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#  @test @(#)StringConvertTest.sh	1.6 03/04/09
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#  @bug 4511950 4843082
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#  @summary 1. jdb's expression evaluation doesn't perform string conversion properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#           2. TTY: run on expression evaluation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#  @author jim/suvasis mukherjee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#  @run shell StringConvertTest.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#  Run this script to see the bug.  See comments at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#  of the .java file for info on what the bug looks like.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
# These are variables that can be set to control execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#pkg=untitled7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
classname=StringConvertTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
compileOptions=-g
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#java=java_g
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#mode=-Xcomp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#jdbOptions=-dbgtrace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
createJavaFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    cat <<EOF > $1.java.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class $classname {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    String me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static JJ1 x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static JJ2 x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static JJ2[] x3 = new JJ2[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static String x4 = "abc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static int ii = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static String grower = "grower";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static StringBuffer sbGrower = new StringBuffer("sbGrower");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    int ivar = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    $classname(String xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        me = xx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static String fred() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return "a static method";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    void  gus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        int gusLoc = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        StringBuffer sbTim = new StringBuffer("tim");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        int kk = 1;                          //@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
    static String growit(String extra) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        grower += extra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return grower;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static String sbGrowit(String extra) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        sbGrower.append(extra);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return sbGrower.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        x1 = new JJ1("first JJ1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        x2 = new JJ2("first JJ2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        x3[0] = new JJ2("array0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        x3[1] = new JJ2("array1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        $classname  loc1 = new $classname("first me");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        // These just show what output should look like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        System.out.println("x1 = " + x1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        System.out.println("x2 = " + x2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        System.out.println("x3.toString = " + x3.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        System.out.println("x4.toString = " + x4.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // Dont want to call growit since it would change
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        // the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        System.out.println("loc1 = " + loc1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        System.out.println("-" + loc1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        loc1.gus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  // This does not have a toString method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  static class JJ1 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    String me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    JJ1(String whoAmI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        me = whoAmI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  // This has a toString method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  static class JJ2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    String me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    JJ2(String whoAmI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        me = whoAmI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public int meth1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
# This is called to feed cmds to jdb.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
dojdbCmds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    setBkpts @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    runToBkpt @1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    # Each print without the 'toString()' should print the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    # same thing as the following print with the toString().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    # The print 1s are just spacers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    cmd print $classname.x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    cmd print "$classname.x1.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    cmd print $classname.x2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    cmd print "$classname.x2.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    # An unreported bug: this isn't handled correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    # If we uncomment this line, we will get an 'instance of...'  line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    # which will cause the test to fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    #cmd print "(Object)($classname.x3)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    cmd print "((Object)$classname.x3).toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    cmd print $classname.x4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    cmd print "$classname.x4.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    # Make sure jdb doesn't call a method multiple times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    cmd print "$classname.growit(\"xyz\")"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    cmd eval  "$classname.sbGrower.append(\"xyz\")"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    cmd eval "sbTim.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    cmd print this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    cmd print "this.toString()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    # A possible bug is that this ends up with multiple "s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    cmd print '"--" + '$classname.x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    # This too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    cmd print "$classname.x4 + 2"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    cmd print "this.ivar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    cmd print gusLoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    cmd print 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    cmd quit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
mysetup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    if [ -z "$TESTSRC" ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        TESTSRC=.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    for ii in . $TESTSRC $TESTSRC/.. ; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if [ -r "$ii/ShellScaffold.sh" ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            . $ii/ShellScaffold.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
# You could replace this next line with the contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
# of ShellScaffold.sh and this script will run just the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
mysetup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
runit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
jdbFailIfPresent '""'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
jdbFailIfPresent 'instance of'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
jdbFailIfPresent 'xyzxyz'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
pass