001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.api.debugger;
043:
044: import org.netbeans.api.debugger.test.TestDICookie;
045: import org.netbeans.api.debugger.test.TestActionsManagerListener;
046: import org.netbeans.api.debugger.test.TestLazyActionsManagerListener;
047:
048: import java.util.*;
049:
050: /**
051: * Tests invocations of debugger actions.
052: *
053: * @author Maros Sandor
054: */
055: public class DebuggerActionsTest extends DebuggerApiTestBase {
056:
057: public DebuggerActionsTest(String s) {
058: super (s);
059: }
060:
061: public void testLookup() throws Exception {
062:
063: DebuggerManager dm = DebuggerManager.getDebuggerManager();
064: Map args = new HashMap();
065: TestDICookie tdi = TestDICookie.create(args);
066:
067: Object[] services = new Object[] { tdi, this };
068: DebuggerInfo di = DebuggerInfo
069: .create(TestDICookie.ID, services);
070:
071: DebuggerEngine engines[] = dm.startDebugging(di);
072: assertEquals("Wrong number of engines started", 1,
073: engines.length);
074: DebuggerEngine debugger = engines[0];
075:
076: ActionsManager am = debugger.getActionsManager();
077: TestActionsManagerListener tam = new TestActionsManagerListener();
078: am.addActionsManagerListener(tam);
079:
080: TestLazyActionsManagerListener laml = (TestLazyActionsManagerListener) debugger
081: .lookupFirst(null, LazyActionsManagerListener.class);
082: assertNotNull("Lazy actions manager listener not loaded", laml);
083:
084: am.doAction(ActionsManager.ACTION_CONTINUE);
085: am.doAction(ActionsManager.ACTION_FIX);
086: am.doAction(ActionsManager.ACTION_MAKE_CALLEE_CURRENT);
087: am.doAction(ActionsManager.ACTION_MAKE_CALLER_CURRENT);
088: am.doAction(ActionsManager.ACTION_PAUSE);
089: am.doAction(ActionsManager.ACTION_POP_TOPMOST_CALL);
090: am.doAction(ActionsManager.ACTION_RESTART);
091: am.doAction(ActionsManager.ACTION_RUN_INTO_METHOD);
092: am.doAction(ActionsManager.ACTION_RUN_TO_CURSOR);
093: am.doAction(ActionsManager.ACTION_STEP_INTO);
094: am.doAction(ActionsManager.ACTION_STEP_OUT);
095: am.doAction(ActionsManager.ACTION_STEP_OVER);
096: am.doAction(ActionsManager.ACTION_TOGGLE_BREAKPOINT);
097: dm.getCurrentSession().kill();
098:
099: am.removeActionsManagerListener(tam);
100:
101: assertTrue("Action was not performed", tdi
102: .hasInfo(ActionsManager.ACTION_START));
103: assertTrue("Action was not performed", tdi
104: .hasInfo(ActionsManager.ACTION_CONTINUE));
105: assertTrue("Action was not performed", tdi
106: .hasInfo(ActionsManager.ACTION_FIX));
107: assertTrue("Action was not performed", tdi
108: .hasInfo(ActionsManager.ACTION_MAKE_CALLEE_CURRENT));
109: assertTrue("Action was not performed", tdi
110: .hasInfo(ActionsManager.ACTION_MAKE_CALLER_CURRENT));
111: assertTrue("Action was not performed", tdi
112: .hasInfo(ActionsManager.ACTION_PAUSE));
113: assertTrue("Action was not performed", tdi
114: .hasInfo(ActionsManager.ACTION_POP_TOPMOST_CALL));
115: assertTrue("Action was not performed", tdi
116: .hasInfo(ActionsManager.ACTION_RESTART));
117: assertTrue("Action was not performed", tdi
118: .hasInfo(ActionsManager.ACTION_RUN_INTO_METHOD));
119: assertTrue("Action was not performed", tdi
120: .hasInfo(ActionsManager.ACTION_RUN_TO_CURSOR));
121: assertTrue("Action was not performed", tdi
122: .hasInfo(ActionsManager.ACTION_STEP_INTO));
123: assertTrue("Action was not performed", tdi
124: .hasInfo(ActionsManager.ACTION_STEP_OUT));
125: assertTrue("Action was not performed", tdi
126: .hasInfo(ActionsManager.ACTION_STEP_OVER));
127: assertTrue("Action was not performed", tdi
128: .hasInfo(ActionsManager.ACTION_TOGGLE_BREAKPOINT));
129: assertTrue("Action was not performed", tdi
130: .hasInfo(ActionsManager.ACTION_KILL));
131:
132: testReceivedEvents(tam.getPerformedActions(), false);
133: testReceivedEvents(laml.getPerformedActions(), true);
134: }
135:
136: private void testReceivedEvents(List eventActions,
137: boolean expectStartAction) {
138: if (expectStartAction)
139: assertTrue("ActionListener was not notified", eventActions
140: .remove(ActionsManager.ACTION_START));
141: assertTrue("ActionListener was not notified", eventActions
142: .remove(ActionsManager.ACTION_CONTINUE));
143: assertTrue("ActionListener was not notified", eventActions
144: .remove(ActionsManager.ACTION_FIX));
145: assertTrue("ActionListener was not notified", eventActions
146: .remove(ActionsManager.ACTION_MAKE_CALLEE_CURRENT));
147: assertTrue("ActionListener was not notified", eventActions
148: .remove(ActionsManager.ACTION_MAKE_CALLER_CURRENT));
149: assertTrue("ActionListener was not notified", eventActions
150: .remove(ActionsManager.ACTION_PAUSE));
151: assertTrue("ActionListener was not notified", eventActions
152: .remove(ActionsManager.ACTION_POP_TOPMOST_CALL));
153: assertTrue("ActionListener was not notified", eventActions
154: .remove(ActionsManager.ACTION_RESTART));
155: assertTrue("ActionListener was not notified", eventActions
156: .remove(ActionsManager.ACTION_RUN_INTO_METHOD));
157: assertTrue("ActionListener was not notified", eventActions
158: .remove(ActionsManager.ACTION_RUN_TO_CURSOR));
159: assertTrue("ActionListener was not notified", eventActions
160: .remove(ActionsManager.ACTION_STEP_INTO));
161: assertTrue("ActionListener was not notified", eventActions
162: .remove(ActionsManager.ACTION_STEP_OUT));
163: assertTrue("ActionListener was not notified", eventActions
164: .remove(ActionsManager.ACTION_STEP_OVER));
165: assertTrue("ActionListener was not notified", eventActions
166: .remove(ActionsManager.ACTION_TOGGLE_BREAKPOINT));
167: assertTrue("ActionListener was not notified", eventActions
168: .remove(ActionsManager.ACTION_KILL));
169: assertEquals("ActionListener notification failed", eventActions
170: .size(), 0);
171: }
172: }
|