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.6 $
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.jdwp.CommandPacket;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
032: import org.apache.harmony.jpda.tests.jdwp.Events.ExceptionDebuggee;
033: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
034: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036: /**
037: * JDWP Unit test for verifying canceling of EXCEPTION event after re-connection.
038: */
039: public class ExceptionTest extends JDWPEventTestCase {
040:
041: protected String getDebuggeeClassName() {
042: return ExceptionDebuggee.class.getName();
043: }
044:
045: /**
046: * This testcase verifies canceling of EXCEPTION event after re-connection.
047: * <BR>It runs ExceptionDebuggee, sets request for EXCEPTION event
048: * and re-connects.
049: * <BR>It is expected that only auto VM_DEATH event occurs after re-connection,
050: * but no any other event, including EXCEPTION event.
051: */
052: public void testException001() {
053: logWriter.println(">> testException001: STARTED...");
054:
055: synchronizer
056: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
057:
058: String exceptionSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/DebuggeeException;";
059: boolean isCatch = true;
060: boolean isUncatch = true;
061: logWriter
062: .println("\n>> testExceptionEvent: => setException(...)...");
063: debuggeeWrapper.vmMirror.setException(exceptionSignature,
064: isCatch, isUncatch);
065: logWriter
066: .println(">> testExceptionEvent: setException(...) DONE");
067:
068: logWriter.println("");
069: logWriter.println("=> CLOSE CONNECTION");
070: closeConnection();
071: logWriter.println("=> CONNECTION CLOSED");
072:
073: logWriter.println("");
074: logWriter.println("=> OPEN NEW CONNECTION");
075: openConnection();
076: logWriter.println("=> CONNECTION OPENED");
077:
078: logWriter.println("=> Resuming debuggee");
079:
080: // start the thread
081: synchronizer
082: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
083: synchronizer
084: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
085:
086: // receive event
087: logWriter.println("=> Wait for event..");
088: CommandPacket eventPacket = debuggeeWrapper.vmMirror
089: .receiveEvent();
090: ParsedEvent[] parsedEvents = ParsedEvent
091: .parseEventPacket(eventPacket);
092: int eventsCount = parsedEvents.length;
093: logWriter
094: .println("=> Received event set: count=" + eventsCount);
095:
096: // ckeck if received events are expected
097: int result = 0;
098: int autoEvents = 0;
099: int wrongEvents = 0;
100: for (int i = 0; i < eventsCount; i++) {
101: ParsedEvent event = parsedEvents[i];
102: logWriter.println("=> Event #" + i + ";");
103:
104: // print event info
105: byte eventSuspendPolicy = event.getSuspendPolicy();
106: logWriter.println("=> SuspendPolicy="
107: + eventSuspendPolicy
108: + "/"
109: + JDWPConstants.SuspendPolicy
110: .getName(eventSuspendPolicy));
111: byte eventKind = event.getEventKind();
112: logWriter.println("=> EventKind=" + eventKind + "/"
113: + JDWPConstants.EventKind.getName(eventKind));
114: int eventRequestID = event.getRequestID();
115: logWriter.println("=> RequestID=" + eventRequestID);
116:
117: // check if event is expected
118: if (eventKind == JDWPConstants.EventKind.VM_DEATH) {
119: if (parsedEvents[i].getRequestID() == 0) {
120: autoEvents++;
121: logWriter.println("=> found auto VM_DEATH event!");
122: // for automatical event suspend policy can be changed
123: } else {
124: logWriter.println("## FAILURE: VM_DEATH event "
125: + "with unexpected RequestID: "
126: + eventRequestID);
127: result = 1;
128: }
129: } else {
130: wrongEvents++;
131: logWriter.println("## FAILURE: unexpected event kind: "
132: + eventKind);
133: result = 2;
134: }
135: }
136:
137: if (1 == result)
138: fail("VM_DEATH event with unexpected RequestID");
139: else if (2 == result)
140: fail("Unexpected event kind");
141:
142: logWriter.println("==> testException001 PASSED!");
143: }
144:
145: protected void beforeDebuggeeStart(
146: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
147: settings.setAttachConnectorKind();
148: if (settings.getTransportAddress() == null) {
149: settings
150: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
151: }
152: logWriter.println("ATTACH connector kind");
153: super .beforeDebuggeeStart(debuggeeWrapper);
154: }
155:
156: public static void main(String[] args) {
157: junit.textui.TestRunner.run(ExceptionTest.class);
158: }
159: }
|