001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Aleksander V. Budniy
021: * @version $Revision: 1.3 $
022: */
023:
024: /**
025: * Created on 4.08.2005
026: */package org.apache.harmony.jpda.tests.jdwp.MultiSession;
027:
028: import org.apache.harmony.jpda.tests.framework.TestOptions;
029: import org.apache.harmony.jpda.tests.framework.TestErrorException;
030: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
032: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
033: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
034: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
035: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
036:
037: /**
038: * JDWP Unit test for verifying canceling of BREAKPOINT event after re-connection.
039: */
040: public class BreakpointTest extends JDWPSyncTestCase {
041:
042: private String DEBUGGEE_SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/MultiSessionDebuggee;";
043:
044: private String METHOD_NAME = "printWord";
045:
046: protected String getDebuggeeClassName() {
047: return "org.apache.harmony.jpda.tests.jdwp.MultiSession.MultiSessionDebuggee";
048: }
049:
050: /**
051: * This testcase verifies canceling of BREAKPOINT event after re-connection.
052: * <BR>It runs MultiSessionDebuggee, sets request for BREAKPOINT event
053: * and re-connects.
054: * <BR>It is expected that no any events, including BREAKPOINT, occur after re-connection
055: * and before MultiSessionDebuggee finish.
056: */
057: public void testClearBreakpoint001() {
058: logWriter.println("==> testClearBreakpoint001 started..");
059: synchronizer
060: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
061:
062: long classID = debuggeeWrapper.vmMirror
063: .getClassID(DEBUGGEE_SIGNATURE);
064:
065: //long requestID =
066: debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin(classID,
067: METHOD_NAME);
068:
069: logWriter.println("");
070: logWriter.println("=> CLOSE CONNECTION");
071: closeConnection();
072: logWriter.println("=> CONNECTION CLOSED");
073:
074: logWriter.println("");
075: logWriter.println("=> OPEN NEW CONNECTION");
076: openConnection();
077: logWriter.println("=> CONNECTION OPENED");
078:
079: //resuming debuggee
080: synchronizer
081: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
082: synchronizer
083: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
084: synchronizer
085: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
086:
087: // receive event
088: logWriter.println("=> Wait for event..");
089: CommandPacket event = null;
090: try {
091: event = debuggeeWrapper.vmMirror.receiveEvent();
092: } catch (TestErrorException thrown) {
093: logWriter.println("=> Exception while receiving event:"
094: + thrown);
095:
096: }
097: if (event == null) {
098: logWriter
099: .println("=> It's expected result, nothing was caught");
100: logWriter.println("=> Resuming debuggee");
101: //resuming debuggee
102: synchronizer
103: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
104: logWriter.println("==> testMethodEvent001 PASSED! ");
105: } else {
106:
107: logWriter.println("##FAILURE: Event was received");
108:
109: try {
110: ParsedEvent[] parsedEvents = ParsedEvent
111: .parseEventPacket(event);
112:
113: logWriter.println("=> Number of events = "
114: + parsedEvents.length);
115: for (int i = 0; i < parsedEvents.length; i++) {
116: logWriter.println("=> EventKind() = "
117: + parsedEvents[0].getEventKind()
118: + " ("
119: + JDWPConstants.EventKind
120: .getName(parsedEvents[0]
121: .getEventKind()) + ")");
122: logWriter.println("=> EventRequestID() = "
123: + parsedEvents[0].getRequestID());
124:
125: }
126: } catch (Throwable thrown) {
127: logWriter
128: .println("##FAILURE: Exception while analyzing received event:"
129: + thrown);
130: fail("Exception while analyzing received event: "
131: + thrown);
132: }
133:
134: synchronizer
135: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
136: synchronizer
137: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
138: logWriter.println("==> testClearBreakpoint001 PASSED");
139: }
140: }
141:
142: protected void beforeDebuggeeStart(
143: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
144: settings.setAttachConnectorKind();
145: if (settings.getTransportAddress() == null) {
146: settings
147: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
148: }
149: logWriter.println("ATTACH connector kind");
150: super .beforeDebuggeeStart(debuggeeWrapper);
151: }
152:
153: public static void main(String[] args) {
154:
155: junit.textui.TestRunner.run(BreakpointTest.class);
156:
157: }
158: }
|