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 8.7.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 some events after re-connection.
039: */
040: public class MethodEntryExitTest 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: String classNameRegexp = "org.apache.harmony.jpda.tests.jdwp.MultiSession.MultiSessionDebuggee";
047:
048: protected String getDebuggeeClassName() {
049: return "org.apache.harmony.jpda.tests.jdwp.MultiSession.MultiSessionDebuggee";
050: }
051:
052: /**
053: * This testcase verifies canceling of some events after re-connection.
054: * <BR>It runs MultiSessionDebuggee, sets requests for BREAKPOINT, METHOD_ENTRY
055: * and METHOD_EXIT events and then re-connects.
056: * <BR>It is expected that no any events, including requested events, occur after re-connection
057: * and before MultiSessionDebuggee finish.
058: */
059: public void testMethodEvent001() {
060: logWriter.println("==> testMethodEvent001 started..");
061:
062: synchronizer
063: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
064:
065: long classID = debuggeeWrapper.vmMirror
066: .getClassID(DEBUGGEE_SIGNATURE);
067:
068: logWriter.println("=> Set breakpoint at method begin");
069: //long requestID =
070: debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin(classID,
071: METHOD_NAME);
072:
073: logWriter.println("=> Set request for METHOD_ENTRY event");
074: debuggeeWrapper.vmMirror.setMethodEntry(classNameRegexp);
075:
076: logWriter.println("=> Set request for METHOD_EXIT event");
077: debuggeeWrapper.vmMirror.setMethodExit(classNameRegexp);
078:
079: logWriter.println("");
080: logWriter.println("=> CLOSE CONNECTION..");
081: closeConnection();
082: logWriter.println("=> CONNECTION CLOSED");
083:
084: logWriter.println("");
085: logWriter.println("=> OPEN NEW CONNECTION..");
086: openConnection();
087: logWriter.println("=> CONNECTION OPENED");
088:
089: //resuming debuggee
090: synchronizer
091: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
092: synchronizer
093: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
094: synchronizer
095: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
096:
097: // receive event
098: logWriter.println("=> Wait for event..");
099: CommandPacket event = null;
100: try {
101: event = debuggeeWrapper.vmMirror.receiveEvent();
102: } catch (TestErrorException thrown) {
103: logWriter.println("=> Exception while receiving event:"
104: + thrown);
105:
106: }
107: if (event == null) {
108: logWriter
109: .println("=> It's expected result, nothing was caught");
110: logWriter.println("=> Resuming debuggee");
111: //resuming debuggee
112: synchronizer
113: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
114: logWriter.println("==> testMethodEvent001 PASSED! ");
115: } else {
116:
117: logWriter.println("##FAILURE: Event was received");
118:
119: try {
120: ParsedEvent[] parsedEvents = ParsedEvent
121: .parseEventPacket(event);
122:
123: logWriter.println("=> Number of events = "
124: + parsedEvents.length);
125: for (int i = 0; i < parsedEvents.length; i++) {
126: logWriter.println("=> EventKind() = "
127: + parsedEvents[0].getEventKind()
128: + " ("
129: + JDWPConstants.EventKind
130: .getName(parsedEvents[0]
131: .getEventKind()) + ")");
132: logWriter.println("=> EventRequestID() = "
133: + parsedEvents[0].getRequestID());
134:
135: }
136: } catch (Throwable thrown) {
137: logWriter
138: .println("##FAILURE: Exception while analyzing received event:"
139: + thrown);
140: fail("Exception while analyzing received event:"
141: + thrown);
142: }
143:
144: synchronizer
145: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
146: synchronizer
147: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
148: logWriter.println("==> testMethodEvent001 failed");
149: }
150: }
151:
152: protected void beforeDebuggeeStart(
153: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
154: settings.setAttachConnectorKind();
155: if (settings.getTransportAddress() == null) {
156: settings
157: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
158: }
159: logWriter.println("ATTACH connector kind");
160: super .beforeDebuggeeStart(debuggeeWrapper);
161: }
162:
163: public static void main(String[] args) {
164: junit.textui.TestRunner.run(MethodEntryExitTest.class);
165: }
166: }
|