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