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