jdk/test/com/sun/jdi/sde/SourceDebugExtensionTest.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 24973 8c4bc3fa4c4e
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *  @bug 4390869
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *  @bug 4460328
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *  @summary Test the new SourceDebugExtension facility
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *  @author Robert Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  @library ..
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *  @run compile SourceDebugExtensionTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *  @run compile -g SourceDebugExtensionTarg.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *  @run main SourceDebugExtensionTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
public class SourceDebugExtensionTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
    SourceDebugExtensionTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
        testSetUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
        new SourceDebugExtensionTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    /********** test set-up **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    static void testSetUp() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        InstallSDE.install(new File(System.getProperty("test.classes", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
                                    "SourceDebugExtensionTarg.class"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                           new File(System.getProperty("test.src", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                                    "testString"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
         * to determine targetClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        BreakpointEvent bpe = startToMain("SourceDebugExtensionTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (!vm().canGetSourceDebugExtension()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            failure("FAIL: canGetSourceDebugExtension() is false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            println("canGetSourceDebugExtension() is true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        String expected = "An expected attribute string";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        String sde = targetClass.sourceDebugExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (!sde.equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            failure("FAIL: got '" + sde +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    "' expected: '" + expected + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         * resume the target listening for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            println("SourceDebugExtensionTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new Exception("SourceDebugExtensionTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
}