0N/A/**
0N/A * @test
0N/A * @bug 4390869
0N/A * @bug 4460328
0N/A * @summary Test 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 TemperatureTableTest.java
0N/A * @run compile -g TemperatureTableServlet.java
0N/A * @run main TemperatureTableTest
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 TemperatureTableTest extends TestScaffold {
0N/A ReferenceType targetClass;
0N/A
0N/A TemperatureTableTest (String args[]) {
0N/A super(args);
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A testSetUp();
0N/A new TemperatureTableTest(args).startTests();
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 "TemperatureTableServlet.class"),
0N/A new File(System.getProperty("test.src", "."),
0N/A "TemperatureTable.sde"));
0N/A }
0N/A
0N/A /********** test assist **********/
0N/A
0N/A void checkLocation(Location loc, String label,
0N/A String expectedSourceName,
0N/A String expectedSourcePath,
0N/A int expectedLinenumber) throws Exception {
0N/A String sourceName = loc.sourceName();
0N/A if (sourceName.equals(expectedSourceName)) {
0N/A println(label + " sourceName: " + sourceName);
0N/A } else {
0N/A failure("FAIL: " + label +
0N/A " expected sourceName " + expectedSourceName +
0N/A " got - " + sourceName);
0N/A }
0N/A
0N/A String sourcePath = loc.sourcePath();
0N/A if (sourcePath.equals(expectedSourcePath)) {
0N/A println(label + " sourcePath: " + sourcePath);
0N/A } else {
0N/A failure("FAIL: " + label +
0N/A " expected sourcePath " + expectedSourcePath +
0N/A " got - " + sourcePath);
0N/A }
0N/A
0N/A int ln = loc.lineNumber();
0N/A if (ln == expectedLinenumber) {
0N/A println(label + " line number: " + ln);
0N/A } else {
0N/A failure("FAIL: " + label +
0N/A " expected line number " + expectedLinenumber +
0N/A " got - " + ln);
0N/A }
0N/A }
0N/A
0N/A void checkLocation(String stratum, Location loc, String label,
0N/A String expectedSourceName,
0N/A String expectedSourcePath,
0N/A int expectedLinenumber) throws Exception {
0N/A String sourceName = loc.sourceName(stratum);
0N/A if (sourceName.equals(expectedSourceName)) {
0N/A println(label + "(" + stratum + ")" +
0N/A " sourceName: " + sourceName);
0N/A } else {
0N/A failure("FAIL: " + label + "(" + stratum + ")" +
0N/A " expected sourceName " + expectedSourceName +
0N/A " got " + sourceName);
0N/A }
0N/A
0N/A String sourcePath = loc.sourcePath(stratum);
0N/A if (sourcePath.equals(expectedSourcePath)) {
0N/A println(label + "(" + stratum + ")" +
0N/A " sourcePath: " + sourcePath);
0N/A } else {
0N/A failure("FAIL: " + label + "(" + stratum + ")" +
0N/A " expected sourcePath " + expectedSourcePath +
0N/A " got " + sourcePath);
0N/A }
0N/A
0N/A int ln = loc.lineNumber(stratum);
0N/A if (ln == expectedLinenumber) {
0N/A println(label + "(" + stratum + ")" +
0N/A " line number: " + ln);
0N/A } else {
0N/A failure("FAIL: " + label + "(" + stratum + ")" +
0N/A " expected line number " + expectedLinenumber +
0N/A " got " + ln);
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 * to determine targetClass
0N/A */
0N/A BreakpointEvent bpe = startToMain("TemperatureTableServlet");
0N/A targetClass = bpe.location().declaringType();
0N/A
0N/A if (!vm().canGetSourceDebugExtension()) {
0N/A failure("FAIL: canGetSourceDebugExtension() is false");
0N/A } else {
0N/A println("canGetSourceDebugExtension() is true");
0N/A }
0N/A
0N/A checkLocation(bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("JSP", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("bogus", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation(null, bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("Java", bpe.location(), "main BP",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 11);
0N/A
0N/A // ref type source name
0N/A String sourceName = targetClass.sourceName();
0N/A if (sourceName.equals("TemperatureTable.jsp")) {
0N/A println("ref type sourceName: " + sourceName);
0N/A } else {
0N/A failure("FAIL: unexpected ref type sourceName - " + sourceName);
0N/A }
0N/A
0N/A List allLines = targetClass.allLineLocations();
0N/A for (Iterator it = allLines.iterator(); it.hasNext(); ) {
0N/A Location loc = (Location)it.next();
0N/A println("Location: " + loc);
0N/A }
0N/A
0N/A List locs = targetClass.locationsOfLine(7);
0N/A if (locs.size() != 1) {
0N/A failure("FAIL: expect on elocation, got " + locs.size());
0N/A }
0N/A Location loc7 = (Location)locs.get(0);
0N/A
0N/A checkLocation(loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("JSP", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("bogus", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation(null, loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("Java", loc7, "line7",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 28);
0N/A
0N/A List availSt = targetClass.availableStrata();
0N/A List avail = new ArrayList(availSt);
0N/A if (avail.size() == 2 &&
0N/A avail.remove("JSP") &&
0N/A avail.remove("Java") &&
0N/A avail.size() == 0) {
0N/A println("availableStrata: " + availSt);
0N/A } else {
0N/A failure("FAIL: unexpected availableStrata - " + availSt);
0N/A }
0N/A
0N/A String def = targetClass.defaultStratum();
0N/A if (def.equals("JSP")) {
0N/A println("defaultStratum: " + def);
0N/A } else {
0N/A failure("FAIL: unexpected defaultStratum - " + def);
0N/A }
0N/A
0N/A // Test HelloWorld
0N/A BreakpointEvent bpHello = resumeTo("HelloWorld", "main",
0N/A "([Ljava/lang/String;)V");
0N/A Location hello = bpHello.location();
0N/A
0N/A checkLocation(hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("JSP", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("bogus", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation(null, hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("Java", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A /******** test VM default *************/
0N/A
0N/A vm().setDefaultStratum("Java");
0N/A println("VM default set to Java");
0N/A
0N/A checkLocation(bpe.location(), "main BP",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 11);
0N/A
0N/A checkLocation("JSP", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("bogus", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation(null, bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("Java", bpe.location(), "main BP",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 11);
0N/A
0N/A checkLocation(loc7, "line7",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 28);
0N/A
0N/A checkLocation("JSP", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("bogus", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation(null, loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("Java", loc7, "line7",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 28);
0N/A
0N/A checkLocation(hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("JSP", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("bogus", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation(null, hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("Java", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A vm().setDefaultStratum(null);
0N/A println("VM default set to null");
0N/A
0N/A checkLocation(bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("JSP", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("bogus", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation(null, bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("Java", bpe.location(), "main BP",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 11);
0N/A
0N/A checkLocation(loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("JSP", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("bogus", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation(null, loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("Java", loc7, "line7",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 28);
0N/A
0N/A checkLocation(hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("JSP", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("bogus", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation(null, hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("Java", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A
0N/A vm().setDefaultStratum("bogus");
0N/A println("VM default set to bogus");
0N/A
0N/A checkLocation(bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("JSP", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("bogus", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation(null, bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("Java", bpe.location(), "main BP",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 11);
0N/A
0N/A checkLocation(loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("JSP", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("bogus", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation(null, loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("Java", loc7, "line7",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 28);
0N/A
0N/A
0N/A checkLocation(hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("JSP", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("bogus", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation(null, hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("Java", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A vm().setDefaultStratum("JSP");
0N/A println("VM default set to JSP");
0N/A
0N/A checkLocation(bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("JSP", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("bogus", bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation(null, bpe.location(), "main BP",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 1);
0N/A
0N/A checkLocation("Java", bpe.location(), "main BP",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 11);
0N/A
0N/A checkLocation(loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("JSP", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("bogus", loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation(null, loc7, "line7",
0N/A "TemperatureTable.jsp",
0N/A "tst" + File.separatorChar + "TemperatureTable.jsp", 7);
0N/A
0N/A checkLocation("Java", loc7, "line7",
0N/A "TemperatureTableServlet.java",
0N/A "TemperatureTableServlet.java", 28);
0N/A
0N/A checkLocation(hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("JSP", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("bogus", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation(null, hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A checkLocation("Java", hello, "hello BP",
0N/A "HelloWorld.java",
0N/A "HelloWorld.java", 3);
0N/A
0N/A /*
0N/A * resume the target listening for events
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("TemperatureTableTest: passed");
0N/A } else {
0N/A throw new Exception("TemperatureTableTest: failed");
0N/A }
0N/A }
0N/A}