alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (MangleStepTest.java)

This example Java source code file (MangleStepTest.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

breakpointevent, exception, fail, java, jdi, manglesteptest, rats, referencetype, stepevent, string, testing, testscaffold, threadreference, util, xyz

The MangleStepTest.java Java example source code

/**
 *  @test
 *  @bug 4390869
 *  @bug 4460328
 *  @summary Test Stepping in the new SourceDebugExtension facility
 *
 *  @author Robert Field
 *
 *  @library ..
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
 *  @run compile MangleStepTest.java
 *  @run compile -g  onion/pickle/Mangle.java
 *  @run main/othervm MangleStepTest unset
 *  @run main/othervm MangleStepTest Java
 *  @run main/othervm MangleStepTest XYZ
 *  @run main/othervm MangleStepTest Rats
 *  @run main/othervm MangleStepTest bogus
 */
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;

import java.util.*;
import java.io.File;

public class MangleStepTest extends TestScaffold {
    static final String op = "onion" + File.separator + "pickle" + File.separator;
    ReferenceType targetClass;
    final String stratum;
    static boolean aTestFailed = false;

    MangleStepTest (String stratum) {
        super(new String[0]);
        this.stratum = stratum;
    }

    public static void main(String[] args)      throws Exception {
        testSetUp();
        new MangleStepTest(args[0]).startTests();
        if (aTestFailed) {
            throw new Exception("MangleStepTest: failed");
        }

    }

    /********** 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 lineMatch(Location loc, int javaLine, int defaultLine) {
        if (loc.lineNumber() != defaultLine) {
            failure("FAIL: at " + loc.lineNumber() +
                    ", expected " + defaultLine);
        } else {
            println("at: " + loc.lineNumber());
        }
        if (loc.lineNumber("Java") != javaLine) {
            failure("FAIL: at Java line " + loc.lineNumber("Java") +
                    ", expected " + javaLine);
        }
    }

    /********** test core **********/

    protected void runTests() throws Exception {
        /*
         * Get to the top of main()
         */
        int[] lines;
        int[] jLines;
        String targetName = "onion.pickle.Mangle";
        startUp(targetName);
        if (!stratum.equals("unset")) {
            vm().setDefaultStratum(stratum);
        }
        BreakpointEvent bpe = resumeTo(targetName, "main",
                                       "([Ljava/lang/String;)V");
        waitForInput();

        ThreadReference thread = bpe.thread();

        if (stratum.equals("Java")) {
            lines = new int[] {4, 5, 6, 7, 8, 9};
            jLines = new int[] {4, 5, 6, 7, 8, 9};
        } else if (stratum.equals("Rats")) {
            lines = new int[] {1000, 1111, 1112};
            jLines = new int[] {4, 5, 7};
        } else  {  /* XYZ (the class default) */
            lines = new int[] {200, 210, 217, 218};
            jLines = new int[] {4, 7, 8, 9};
        }

        println("Testing stratum: " + stratum);

        lineMatch(bpe.location(), jLines[0], lines[0]);

        for (int i = 1; i < lines.length; ++i) {
            StepEvent se = stepOverLine(thread);
            lineMatch(se.location(), jLines[i], lines[i]);
        }

        /*
         * resume the target to completion
         */
        listenUntilVMDisconnect();

        /*
         * deal with results of test
         * if anything has called failure("foo") testFailed will be true
         */
        if (!testFailed) {
            println("MangleStepTest (" + stratum + "): passed");
        } else {
            println("MangleStepTest (" + stratum + "): failed");
            aTestFailed = true;
        }
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java MangleStepTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.