0N/A/**
0N/A * @test
0N/A * @bug 4390869
0N/A * @bug 4460328
0N/A * @summary Test Stepping in the new SourceDebugExtension facility
0N/A *
0N/A * @author Robert Field
0N/A *
0N/A * @library ..
0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
0N/A * @run compile MangleStepTest.java
0N/A * @run compile -g onion/pickle/Mangle.java
4764N/A * @run main/othervm MangleStepTest unset
4764N/A * @run main/othervm MangleStepTest Java
4764N/A * @run main/othervm MangleStepTest XYZ
4764N/A * @run main/othervm MangleStepTest Rats
4764N/A * @run main/othervm MangleStepTest bogus
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport com.sun.jdi.request.*;
0N/A
0N/Aimport java.util.*;
0N/Aimport java.io.File;
0N/A
0N/Apublic class MangleStepTest extends TestScaffold {
0N/A static final String op = "onion" + File.separator + "pickle" + File.separator;
0N/A ReferenceType targetClass;
0N/A final String stratum;
0N/A static boolean aTestFailed = false;
0N/A
0N/A MangleStepTest (String stratum) {
0N/A super(new String[0]);
0N/A this.stratum = stratum;
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A testSetUp();
493N/A new MangleStepTest(args[0]).startTests();
0N/A if (aTestFailed) {
0N/A throw new Exception("MangleStepTest: failed");
0N/A }
0N/A
0N/A }
0N/A
0N/A /********** test set-up **********/
0N/A
0N/A static void testSetUp() throws Exception {
0N/A InstallSDE.install(new File(System.getProperty("test.classes", "."),
0N/A op + "Mangle.class"),
0N/A new File(System.getProperty("test.src", "."),
0N/A "Mangle.sde"));
0N/A }
0N/A
0N/A /********** test assist **********/
0N/A
0N/A void lineMatch(Location loc, int javaLine, int defaultLine) {
0N/A if (loc.lineNumber() != defaultLine) {
0N/A failure("FAIL: at " + loc.lineNumber() +
0N/A ", expected " + defaultLine);
0N/A } else {
0N/A println("at: " + loc.lineNumber());
0N/A }
0N/A if (loc.lineNumber("Java") != javaLine) {
0N/A failure("FAIL: at Java line " + loc.lineNumber("Java") +
0N/A ", expected " + javaLine);
0N/A }
0N/A }
0N/A
0N/A /********** test core **********/
0N/A
0N/A protected void runTests() throws Exception {
0N/A /*
0N/A * Get to the top of main()
0N/A */
0N/A int[] lines;
0N/A int[] jLines;
0N/A String targetName = "onion.pickle.Mangle";
0N/A startUp(targetName);
0N/A if (!stratum.equals("unset")) {
0N/A vm().setDefaultStratum(stratum);
0N/A }
0N/A BreakpointEvent bpe = resumeTo(targetName, "main",
0N/A "([Ljava/lang/String;)V");
0N/A waitForInput();
0N/A
0N/A ThreadReference thread = bpe.thread();
0N/A
0N/A if (stratum.equals("Java")) {
0N/A lines = new int[] {4, 5, 6, 7, 8, 9};
0N/A jLines = new int[] {4, 5, 6, 7, 8, 9};
0N/A } else if (stratum.equals("Rats")) {
0N/A lines = new int[] {1000, 1111, 1112};
0N/A jLines = new int[] {4, 5, 7};
0N/A } else { /* XYZ (the class default) */
0N/A lines = new int[] {200, 210, 217, 218};
0N/A jLines = new int[] {4, 7, 8, 9};
0N/A }
0N/A
0N/A println("Testing stratum: " + stratum);
0N/A
0N/A lineMatch(bpe.location(), jLines[0], lines[0]);
0N/A
0N/A for (int i = 1; i < lines.length; ++i) {
0N/A StepEvent se = stepOverLine(thread);
0N/A lineMatch(se.location(), jLines[i], lines[i]);
0N/A }
0N/A
0N/A /*
0N/A * resume the target to completion
0N/A */
0N/A listenUntilVMDisconnect();
0N/A
0N/A /*
0N/A * deal with results of test
0N/A * if anything has called failure("foo") testFailed will be true
0N/A */
0N/A if (!testFailed) {
0N/A println("MangleStepTest (" + stratum + "): passed");
0N/A } else {
0N/A println("MangleStepTest (" + stratum + "): failed");
0N/A aTestFailed = true;
0N/A }
0N/A }
0N/A}