Anonymous avatar Anonymous committed f87ec25

Added field breakpoints test

Comments (0)

Files changed (3)

debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/FieldBreakpointTest.java

+/*
+ *                 Sun Public License Notice
+ *
+ * The contents of this file are subject to the Sun Public License
+ * Version 1.0 (the "License"). You may not use this file except in
+ * compliance with the License. A copy of the License is available at
+ * http://www.sun.com/
+ *
+ * The Original Code is NetBeans. The Initial Developer of the Original
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package org.netbeans.api.debugger.jpda;
+
+import org.netbeans.spi.viewmodel.NoInformationException;
+
+/**
+ * Tests field breakpoints.
+ *
+ * @author Maros Sandor
+ */
+public class FieldBreakpointTest extends DebuggerJPDAApiTestBase {
+
+    private JPDASupport     support;
+    private JPDADebugger    debugger;
+
+    private static final String CLASS_NAME = "basic.FieldBreakpointApp";
+
+    public FieldBreakpointTest(String s) {
+        super(s);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void testFieldBreakpoints() throws Exception {
+        try {
+            FieldBreakpoint fb1 = FieldBreakpoint.create(CLASS_NAME, "x", FieldBreakpoint.TYPE_MODIFICATION);
+            // TODO: We have to set initial value of 2 because of bug #4984092, remove for Tiger
+            TestBreakpointListener tbl = new TestBreakpointListener("x", 2, new int [] { 31 });
+            fb1.addJPDABreakpointListener(tbl);
+            dm.addBreakpoint(fb1);
+
+            FieldBreakpoint fb2 = FieldBreakpoint.create(CLASS_NAME, "y", FieldBreakpoint.TYPE_MODIFICATION);
+            TestBreakpointListener tb2 = new TestBreakpointListener("y", 0, new int [] { 38, 41, 45 });
+            fb2.addJPDABreakpointListener(tb2);
+            dm.addBreakpoint(fb2);
+
+            FieldBreakpoint fb3 = FieldBreakpoint.create(CLASS_NAME + "$InnerStatic", "q", FieldBreakpoint.TYPE_MODIFICATION);
+            TestBreakpointListener tb3 = new TestBreakpointListener("InnerStatic.q", 0, new int [] { });
+            fb3.addJPDABreakpointListener(tb3);
+            dm.addBreakpoint(fb3);
+
+            FieldBreakpoint fb4 = FieldBreakpoint.create(CLASS_NAME + "$InnerStatic", "w", FieldBreakpoint.TYPE_MODIFICATION);
+            TestBreakpointListener tb4 = new TestBreakpointListener("InnerStatic.w", 0, new int [] { 75, 78, 82 });
+            fb4.addJPDABreakpointListener(tb4);
+            dm.addBreakpoint(fb4);
+
+            FieldBreakpoint fb5 = FieldBreakpoint.create(CLASS_NAME + "$Inner", "w", FieldBreakpoint.TYPE_MODIFICATION);
+            TestBreakpointListener tb5 = new TestBreakpointListener("Inner.w", 0, new int [] { 96, 99, 103 });
+            fb5.addJPDABreakpointListener(tb5);
+            dm.addBreakpoint(fb5);
+
+            support = JPDASupport.listen(CLASS_NAME, false);
+            debugger = support.getDebugger();
+
+            for (;;) {
+                support.waitStates(JPDADebugger.STATE_STOPPED, JPDADebugger.STATE_DISCONNECTED, 10000);
+                if (debugger.getState() == JPDADebugger.STATE_DISCONNECTED) break;
+                support.doContinue();
+            }
+            tbl.assertFailure();
+            tb2.assertFailure();
+            tb3.assertFailure();
+            tb4.assertFailure();
+            tb5.assertFailure();
+
+            dm.removeBreakpoint(fb1);
+            dm.removeBreakpoint(fb2);
+            dm.removeBreakpoint(fb3);
+            dm.removeBreakpoint(fb4);
+            dm.removeBreakpoint(fb5);
+        } finally {
+            support.doFinish();
+        }
+    }
+
+    private class TestBreakpointListener implements JPDABreakpointListener {
+
+        private int                 hitCount;
+        private int                 currentFieldValue;
+        private AssertionError      failure;
+        private String              variableName;
+        private int[]               hitLines;
+
+        public TestBreakpointListener(String variableName, int initialValue, int [] hitLines) {
+            this.variableName = variableName;
+            this.hitLines = hitLines;
+            currentFieldValue = initialValue;
+        }
+
+        public void breakpointReached(JPDABreakpointEvent event) {
+            try {
+                checkEvent(event);
+            } catch (AssertionError e) {
+                failure = e;
+            } catch (Throwable e) {
+                failure = new AssertionError(e);
+            }
+        }
+
+        private void checkEvent(JPDABreakpointEvent event) throws NoInformationException {
+            FieldBreakpoint fb = (FieldBreakpoint) event.getSource();
+
+            if (hitCount >= hitLines.length) throw new AssertionError("Breakpoint hit too many times for " + variableName + ": " + hitCount + " at " + getLine(event));
+            int hitLine = hitLines[hitCount++];
+            assertEquals("Breakpoint event: Condition evaluation failed", JPDABreakpointEvent.CONDITION_NONE, event.getConditionResult());
+            assertNotNull("Breakpoint event: Context thread is null", event.getThread());
+            assertEquals("Breakpoint event: Hit at wrong place", hitLine, getLine(event));
+            Variable var = event.getVariable();
+            assertNotNull("Breakpoint event: No variable information", var);
+
+            if (fb.getBreakpointType() == FieldBreakpoint.TYPE_ACCESS) {
+                assertEquals("Breakpoint event: Wrong field value", Integer.toString(currentFieldValue), var.getValue());
+            } else {
+                currentFieldValue ++;
+                assertEquals("Breakpoint event: Wrong field value of " + fb.getFieldName() + " at " + getLine(event), Integer.toString(currentFieldValue), var.getValue());
+            }
+        }
+
+        public void assertFailure() {
+            if (failure != null) throw failure;
+            assertEquals("Breakpoint hit count mismatch for: " + variableName, hitLines.length, hitCount);
+        }
+    }
+}

debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java

         }
     }
 
+    public void waitStates(int state1, int state2, int timeoutMillis) {
+        long t0 = System.currentTimeMillis();
+        while (debugger.getState() != state1 && debugger.getState() != state2) {
+            if (System.currentTimeMillis() - t0 > timeoutMillis)
+                throw new TimeoutException("Waitstate timeout: " + debugger.getState());
+            sleep(200);
+        }
+    }
+
     private void sleep(int time) {
         try {
             Thread.sleep(time);

debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/LineBreakpointTest.java

 
 package org.netbeans.api.debugger.jpda;
 
-import org.netbeans.api.debugger.DebuggerManager;
 import org.netbeans.api.debugger.Breakpoint;
 
 import java.net.URL;
 
     private JPDASupport     support;
     private JPDADebugger    debugger;
-    private DebuggerManager dm;
     private String          urlString;
 
     public LineBreakpointTest(String s) {
 
     protected void setUp() throws Exception {
         super.setUp();
-        dm = DebuggerManager.getDebuggerManager();
         ClassLoader cl = this.getClass().getClassLoader();
         URL url = cl.getResource("basic/LineBreakpointApp.class");
         urlString = url.toString();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.