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 Anton V. Karnachuk
021: * @version $Revision: 1.4 $
022: */
023:
024: /**
025: * Created on 11.03.2005
026: */package org.apache.harmony.jpda.tests.jdwp.Events;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.Event;
030: import org.apache.harmony.jpda.tests.framework.jdwp.EventMod;
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.framework.jdwp.ReplyPacket;
034: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.*;
035: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
036:
037: /**
038: * JDWP Unit test for THREAD_END event.
039: */
040: public class ThreadEndTest extends JDWPEventTestCase {
041:
042: public static void main(String[] args) {
043: junit.textui.TestRunner.run(ThreadEndTest.class);
044: }
045:
046: /**
047: * This testcase is for THREAD_END event.
048: * <BR>It runs EventDebuggee and verifies that requested
049: * THREAD_END event occurs.
050: */
051: public void testThreadEndEvent001() {
052: logWriter.println("==> testThreadEndEvent001 - STARTED...");
053:
054: synchronizer
055: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
056:
057: logWriter.println("=> set ThreadEndEvent...");
058: ReplyPacket reply;
059: byte eventKind = JDWPConstants.EventKind.THREAD_END;
060: byte suspendPolicy = JDWPConstants.SuspendPolicy.NONE;
061: EventMod[] mods = new EventMod[0];
062: Event eventToSet = new Event(eventKind, suspendPolicy, mods);
063:
064: reply = debuggeeWrapper.vmMirror.setEvent(eventToSet);
065: checkReplyPacket(reply, "Set THREAD_END event");
066:
067: logWriter.println("=> set ThreadEndEvent - DONE");
068:
069: // start the thread
070: synchronizer
071: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
072:
073: // wait for thread start and finish
074: synchronizer
075: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
076:
077: logWriter.println("=> vmMirror.receiveEvent()...");
078: CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
079:
080: assertNotNull("Invalid (null) event received", event);
081: logWriter.println("=> Event received!");
082:
083: ParsedEvent[] parsedEvents = ParsedEvent
084: .parseEventPacket(event);
085: logWriter.println("=> Number of events = "
086: + parsedEvents.length);
087: assertEquals("Invalid number of events,", 1,
088: parsedEvents.length);
089: logWriter.println("=> EventKind() = "
090: + parsedEvents[0].getEventKind()
091: + " ("
092: + JDWPConstants.EventKind.getName(parsedEvents[0]
093: .getEventKind()) + ")");
094: assertEquals("Invalid event kind,",
095: JDWPConstants.EventKind.THREAD_END, parsedEvents[0]
096: .getEventKind(), JDWPConstants.EventKind
097: .getName(JDWPConstants.EventKind.THREAD_END),
098: JDWPConstants.EventKind.getName(parsedEvents[0]
099: .getEventKind()));
100: logWriter.println("=> EventRequestID() = "
101: + parsedEvents[0].getRequestID());
102:
103: long threadID = ((Event_THREAD_DEATH) parsedEvents[0])
104: .getThreadID();
105: logWriter.println("=> threadID = " + threadID);
106: String threadName = debuggeeWrapper.vmMirror
107: .getThreadName(threadID);
108: logWriter.println("=> threadName = " + threadName);
109: assertEquals("Invalid thread name",
110: EventDebuggee.testedThreadName, threadName);
111:
112: synchronizer
113: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
114: logWriter.println("==> testThreadEndEvent001 - OK");
115: }
116: }
|