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