1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import org.netbeans.api.debugger.DebuggerManager; 23 import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent; 24 import org.netbeans.api.debugger.jpda.event.JPDABreakpointListener; 25 import org.netbeans.junit.NbTestCase; 26 27 28 33 public class ClassBreakpointTest extends NbTestCase { 34 35 private JPDASupport support; 36 private JPDADebugger debugger; 37 private DebuggerManager dm = DebuggerManager.getDebuggerManager (); 38 39 private static final String CLASS_NAME = "org.netbeans.api.debugger.jpda.testapps.ClassBreakpointApp"; 40 41 42 public ClassBreakpointTest (String s) { 43 super (s); 44 } 45 46 public void testMethodBreakpoints() throws Exception { 47 try { 48 ClassLoadUnloadBreakpoint cb1 = ClassLoadUnloadBreakpoint.create("org.netbeans.api.debugger.jpda.testapps.ClassBreakpointTest1", false, ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED); 49 TestBreakpointListener tbl = new TestBreakpointListener("org.netbeans.api.debugger.jpda.testapps.ClassBreakpointTest1", 1); 50 cb1.addJPDABreakpointListener(tbl); 51 dm.addBreakpoint(cb1); 52 53 ClassLoadUnloadBreakpoint cb2 = ClassLoadUnloadBreakpoint.create("*", false, ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED); 54 TestBreakpointListener tb2 = new TestBreakpointListener(null, -1); 55 cb2.addJPDABreakpointListener(tb2); 56 dm.addBreakpoint(cb2); 57 58 support = JPDASupport.attach (CLASS_NAME); 59 debugger = support.getDebugger(); 60 61 for (;;) { 62 support.waitState (JPDADebugger.STATE_STOPPED); 63 if (debugger.getState() == JPDADebugger.STATE_DISCONNECTED) break; 64 support.doContinue(); 65 } 66 tbl.assertFailure(); 67 tb2.assertFailure(); 68 69 dm.removeBreakpoint(cb1); 70 dm.removeBreakpoint(cb2); 71 } finally { 72 support.doFinish(); 73 } 74 } 75 76 private class TestBreakpointListener implements JPDABreakpointListener { 77 78 private int hitCount; 79 private AssertionError failure; 80 private String className; 81 private int expectedHitCount; 82 83 public TestBreakpointListener(String className, int expectedHitCount) { 84 this.className = className; 85 this.expectedHitCount = expectedHitCount; 86 } 87 88 public void breakpointReached(JPDABreakpointEvent event) { 89 try { 90 checkEvent(event); 91 } catch (AssertionError e) { 92 failure = e; 93 } catch (Throwable e) { 94 failure = new AssertionError (e); 95 } 96 } 97 98 private void checkEvent(JPDABreakpointEvent event) { 99 ClassLoadUnloadBreakpoint cb = (ClassLoadUnloadBreakpoint) event.getSource(); 100 101 assertEquals("Breakpoint event: Condition evaluation failed", JPDABreakpointEvent.CONDITION_NONE, event.getConditionResult()); 102 assertNotNull("Breakpoint event: Context thread is null", event.getThread()); 103 assertNotNull("Breakpoint event: Reference type is null", event.getReferenceType()); 104 if (className != null) 105 { 106 assertEquals("Breakpoint event: Hit at wrong class", className, event.getReferenceType().name()); 107 } 108 109 hitCount++; 110 } 111 112 public void assertFailure() { 113 if (failure != null) throw failure; 114 if (expectedHitCount != -1) 115 { 116 assertEquals("Breakpoint hit count mismatch for: " + className, expectedHitCount, hitCount); 117 } 118 } 119 } 120 } 121 | Popular Tags |