1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
/**
* @test
* @bug 4390869
* @bug 4460328
* @summary Test the new SourceDebugExtension facility
* @author Robert Field
*
* @library ..
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
* @run compile MangleTest.java
* @run compile -g onion/pickle/Mangle.java
* @run driver MangleTest
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;
import java.util.*;
import java.io.File;
public class MangleTest extends TestScaffold {
static final String op = "onion" + File.separator + "pickle" + File.separator;
ReferenceType targetClass;
MangleTest (String args[]) {
super(args);
}
public static void main(String[] args) throws Exception {
testSetUp();
new MangleTest(args).startTests();
}
/********** test set-up **********/
static void testSetUp() throws Exception {
InstallSDE.install(new File(System.getProperty("test.classes", "."),
op + "Mangle.class"),
new File(System.getProperty("test.src", "."),
"Mangle.sde"));
}
/********** test assist **********/
void checkLocation(Location loc, String label,
String expectedSourceName,
String expectedSourcePath,
int expectedLinenumber) throws Exception {
String sourceName = loc.sourceName();
if (sourceName.equals(expectedSourceName)) {
println(label + " sourceName: " + sourceName);
} else {
failure("FAIL: " + label +
" expected sourceName " + expectedSourceName +
" got - " + sourceName);
}
String sourcePath = loc.sourcePath();
if (sourcePath.equals(expectedSourcePath)) {
println(label + " sourcePath: " + sourcePath);
} else {
failure("FAIL: " + label +
" expected sourcePath " + expectedSourcePath +
" got - " + sourcePath);
}
int ln = loc.lineNumber();
if (ln == expectedLinenumber) {
println(label + " line number: " + ln);
} else {
failure("FAIL: " + label +
" expected line number " + expectedLinenumber +
" got - " + ln);
}
}
void checkLocation(String stratum, Location loc, String label,
String expectedSourceName,
String expectedSourcePath,
int expectedLinenumber) throws Exception {
String sourceName = loc.sourceName(stratum);
if (sourceName.equals(expectedSourceName)) {
println(label + "(" + stratum + ")" +
" sourceName: " + sourceName);
} else {
failure("FAIL: " + label + "(" + stratum + ")" +
" expected sourceName " + expectedSourceName +
" got " + sourceName);
}
String sourcePath = loc.sourcePath(stratum);
if (sourcePath.equals(expectedSourcePath)) {
println(label + "(" + stratum + ")" +
" sourcePath: " + sourcePath);
} else {
failure("FAIL: " + label + "(" + stratum + ")" +
" expected sourcePath " + expectedSourcePath +
" got " + sourcePath);
}
int ln = loc.lineNumber(stratum);
if (ln == expectedLinenumber) {
println(label + "(" + stratum + ")" +
" line number: " + ln);
} else {
failure("FAIL: " + label + "(" + stratum + ")" +
" expected line number " + expectedLinenumber +
" got " + ln);
}
}
Location getLoc(int index, List locList) {
return ((Location)(locList.get(index)));
}
void lineMatch(int index, String stratum, Location loc, int line) {
int gotLine = loc.lineNumber(stratum);
if (gotLine != line) {
failure("FAIL: index=" + index +
" " + stratum + " line=" + gotLine +
" expected: " + line);
}
}
void lineMatch(int index, Location loc,
int javaLine, int xyzLine, int ratsLine) {
lineMatch(index, "Java", loc, javaLine);
lineMatch(index, "XYZ", loc, xyzLine);
lineMatch(index, "Rats", loc, ratsLine);
}
List listWith(String s1) {
List result = new ArrayList();
result.add(s1);
return result;
}
List listWith(String s1, String s2) {
List result = new ArrayList();
result.add(s1);
result.add(s2);
return result;
}
/********** test core **********/
protected void runTests() throws Exception {
/*
* Get to the top of main()
* to determine targetClass
*/
BreakpointEvent bpe = startToMain("onion.pickle.Mangle");
targetClass = bpe.location().declaringType();
// ref type source name
String sourceName = targetClass.sourceName();
if (sourceName.equals("Mangle.xyz")) {
println("ref type sourceName: " + sourceName);
} else {
failure("FAIL: unexpected ref type sourceName - " + sourceName);
}
// ref type source names /paths
List sourceNames;
sourceNames = targetClass.sourceNames("Java");
if (sourceNames.equals(listWith("Mangle.java"))) {
println("ref type Java sourceNames: " + sourceNames);
} else {
failure("FAIL: unexpected ref type Java sourceNames - " +
sourceNames);
}
sourceNames = targetClass.sourceNames("XYZ");
if (sourceNames.equals(listWith("Mangle.xyz", "Incl.xyz"))) {
println("ref type XYZ sourceNames: " + sourceNames);
} else {
failure("FAIL: unexpected ref type XYZ sourceNames - " +
sourceNames);
}
sourceNames = targetClass.sourceNames(null);
if (sourceNames.equals(listWith("Mangle.xyz", "Incl.xyz"))) {
println("ref type null sourceNames: " + sourceNames);
} else {
failure("FAIL: unexpected ref type null sourceNames - " +
sourceNames);
}
sourceNames = targetClass.sourceNames("Rats");
if (sourceNames.equals(listWith("Mangle.rats", "Incl.rats"))) {
println("ref type Rats sourceNames: " + sourceNames);
} else {
failure("FAIL: unexpected ref type Rats sourceNames - " +
sourceNames);
}
List sourcePaths;
sourcePaths = targetClass.sourcePaths("Java");
if (sourcePaths.equals(listWith(op + "Mangle.java"))) {
println("ref type Java sourcePaths: " + sourcePaths);
} else {
failure("FAIL: unexpected ref type Java sourcePaths - " +
sourcePaths);
}
sourcePaths = targetClass.sourcePaths("XYZ");
if (sourcePaths.equals(listWith("database14", op + "Incl.xyz"))) {
println("ref type XYZ sourcePaths: " + sourcePaths);
} else {
failure("FAIL: unexpected ref type XYZ sourcePaths - " +
sourcePaths);
}
sourcePaths = targetClass.sourcePaths(null);
if (sourcePaths.equals(listWith("database14", op + "Incl.xyz"))) {
println("ref type null sourcePaths: " + sourcePaths);
} else {
failure("FAIL: unexpected ref type null sourcePaths - " +
sourcePaths);
}
sourcePaths = targetClass.sourcePaths("Rats");
if (sourcePaths.equals(listWith(op + "Mangle.rats",
"bleep:bleep:Incl.rats"))) {
println("ref type Rats sourcePaths: " + sourcePaths);
} else {
failure("FAIL: unexpected ref type Rats sourcePaths - " +
sourcePaths);
}
Method main = findMethod(targetClass, "main",
"([Ljava/lang/String;)V");
List allLines = main.allLineLocations();
List javaLines = main.allLineLocations("Java", null);
List bogusLines = main.allLineLocations("bogus", null);
List nullLines = main.allLineLocations(null, null);
List xyzLines = main.allLineLocations("XYZ", null);
List ratsLines = main.allLineLocations("Rats", null);
List tl = new ArrayList(allLines);
tl.removeAll(xyzLines);
if (tl.isEmpty() && allLines.size() == xyzLines.size()) {
println("allLineLocations() is OK");
} else {
failure("FAIL: allLineLocations() wrong - " + allLines);
}
tl = new ArrayList(bogusLines);
tl.removeAll(xyzLines);
if (tl.isEmpty() && bogusLines.size() == xyzLines.size()) {
println("allLineLocations(\"bogus\") is OK");
} else {
failure("FAIL: allLineLocations(\"bogus\") wrong - " + bogusLines);
}
tl = new ArrayList(nullLines);
tl.removeAll(xyzLines);
if (tl.isEmpty() && nullLines.size() == xyzLines.size()) {
println("allLineLocations(null) is OK");
} else {
failure("FAIL: allLineLocations(null) wrong - " + nullLines);
}
if (!javaLines.get(0).equals(ratsLines.get(0))) {
failure("FAIL: locations should match - " + javaLines.get(0));
}
if (javaLines.get(0).equals(xyzLines.get(0))) {
failure("FAIL: locations should not match - " +
javaLines.get(0));
}
if (!javaLines.get(1).equals(ratsLines.get(1))) {
failure("FAIL: locations should match - " + javaLines.get(1));
}
if (!javaLines.get(1).equals(xyzLines.get(0))) {
failure("FAIL: locations should match - " + javaLines.get(1));
}
if (javaLines.get(2).equals(ratsLines.get(1))) {
failure("FAIL: locations should not match - " +
javaLines.get(1));
}
if (xyzLines.contains(javaLines.get(0))) {
failure("FAIL: xyz locations should not match - " +
javaLines.get(0));
}
if (xyzLines.contains(javaLines.get(2))) {
failure("FAIL: xyz locations should not match - " +
javaLines.get(2));
}
if (xyzLines.contains(javaLines.get(6))) {
failure("FAIL: xyz locations should not match - " +
javaLines.get(6));
}
if (ratsLines.contains(javaLines.get(2))) {
failure("FAIL: rats locations should not match - " +
javaLines.get(2));
}
if (ratsLines.contains(javaLines.get(4))) {
failure("FAIL: rats locations should not match - " +
javaLines.get(4));
}
if (ratsLines.contains(javaLines.get(5))) {
failure("FAIL: rats locations should not match - " +
javaLines.get(5));
}
println("*** Java");
for (Iterator it = javaLines.iterator(); it.hasNext(); ) {
Location loc = (Location)it.next();
print("" + loc.lineNumber("Java") + " - ");
print(loc.sourceName("XYZ") + " : ");
print("" + loc.lineNumber("XYZ") + " ... ");
print(loc.sourceName("Rats") + " : ");
println("" + loc.lineNumber("Rats"));
}
println("*** XYZ");
for (Iterator it = xyzLines.iterator(); it.hasNext(); ) {
Location loc = (Location)it.next();
print("" + loc.lineNumber("Java") + " - ");
print(loc.sourceName("XYZ") + " : ");
print("" + loc.lineNumber("XYZ") + " ... ");
print(loc.sourceName("Rats") + " : ");
println("" + loc.lineNumber("Rats"));
}
println("*** Rats");
for (Iterator it = ratsLines.iterator(); it.hasNext(); ) {
Location loc = (Location)it.next();
print("" + loc.lineNumber("Java") + " - ");
print(loc.sourceName("XYZ") + " : ");
print("" + loc.lineNumber("XYZ") + " ... ");
print(loc.sourceName("Rats") + " : ");
println("" + loc.lineNumber("Rats"));
}
checkLocation(getLoc(0, javaLines), "0",
"Incl.xyz",
op + "Incl.xyz", 200);
checkLocation(null, getLoc(0, javaLines), "0",
"Incl.xyz",
op + "Incl.xyz", 200);
checkLocation("bogus", getLoc(0, javaLines), "0",
"Incl.xyz",
op + "Incl.xyz", 200);
checkLocation("Java", getLoc(0, javaLines), "0",
"Mangle.java",
op + "Mangle.java", 4);
checkLocation("XYZ", getLoc(0, javaLines), "0",
"Incl.xyz",
op + "Incl.xyz", 200);
checkLocation("Rats", getLoc(0, javaLines), "0",
"Mangle.rats",
op + "Mangle.rats", 1000);
checkLocation(getLoc(3, javaLines), "3",
"Mangle.xyz",
"database14", 210);
checkLocation(null, getLoc(3, javaLines), "3",
"Mangle.xyz",
"database14", 210);
checkLocation("bogus", getLoc(3, javaLines), "3",
"Mangle.xyz",
"database14", 210);
checkLocation("Java", getLoc(3, javaLines), "3",
"Mangle.java",
op + "Mangle.java", 7);
checkLocation("XYZ", getLoc(3, javaLines), "3",
"Mangle.xyz",
"database14", 210);
checkLocation("Rats", getLoc(3, javaLines), "3",
"Incl.rats",
"bleep:bleep:Incl.rats", 1112);
checkLocation(getLoc(6, javaLines), "6",
"Mangle.xyz",
"database14", 218);
checkLocation(null, getLoc(6, javaLines), "6",
"Mangle.xyz",
"database14", 218);
checkLocation("bogus", getLoc(6, javaLines), "6",
"Mangle.xyz",
"database14", 218);
checkLocation("Java", getLoc(6, javaLines), "6",
"Mangle.java",
op + "Mangle.java", 10);
checkLocation("XYZ", getLoc(6, javaLines), "6",
"Mangle.xyz",
"database14", 218);
checkLocation("Rats", getLoc(6, javaLines), "6",
"Incl.rats",
"bleep:bleep:Incl.rats", 1112);
lineMatch(0, getLoc(0, javaLines), 4, 200, 1000);
lineMatch(1, getLoc(1, javaLines), 5, 200, 1111);
lineMatch(2, getLoc(2, javaLines), 6, 200, 1111);
lineMatch(3, getLoc(3, javaLines), 7, 210, 1112);
lineMatch(4, getLoc(4, javaLines), 8, 217, 1112);
lineMatch(5, getLoc(5, javaLines), 9, 218, 1112);
lineMatch(6, getLoc(6, javaLines), 10, 218, 1112);
/*
* resume the target listening for events
*/
listenUntilVMDisconnect();
/*
* deal with results of test
* if anything has called failure("foo") testFailed will be true
*/
if (!testFailed) {
println("MangleTest: passed");
} else {
throw new Exception("MangleTest: failed");
}
}
}
|