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