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