1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *
15 *  See the License for the specific language governing permissions and
16 *  limitations under the License.
17 */
18
19/**
20 * @author Anton V. Karnachuk
21 */
22
23/**
24 * Created on 06.04.2005
25 */
26package org.apache.harmony.jpda.tests.jdwp.Events;
27
28import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
29import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
30import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
31import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
32import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.EventThread;
33import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
34
35
36
37/**
38 * JDWP Unit test for METHOD_ENTRY event.
39 */
40public class MethodEntryTest extends JDWPEventTestCase {
41
42    protected String getDebuggeeClassName() {
43        return MethodEntryDebuggee.class.getName();
44    }
45
46    /**
47     * This testcase is for METHOD_ENTRY event.
48     * <BR>It runs MethodEntryDebuggee that executed its own method
49     * and verify that requested METHOD_ENTRY event occurs.
50     */
51    public void testMethodEntry() {
52        logWriter.println("testMethodEntry started");
53
54        String methodEntryClassNameRegexp = "org.apache.harmony.jpda.tests.jdwp.Events.MethodEntryDebuggee";
55        //String methodEntryClassNameSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/MethodEntryDebuggee;";
56
57        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
58
59        ReplyPacket reply = debuggeeWrapper.vmMirror.setMethodEntry(methodEntryClassNameRegexp);
60        checkReplyPacket(reply, "Set METHOD_ENTRY event");
61
62        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
63
64        CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
65        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
66
67        assertEquals("Invalid number of events,", 1, parsedEvents.length);
68        assertEquals("Invalid event kind,",
69                JDWPConstants.EventKind.METHOD_ENTRY,
70                parsedEvents[0].getEventKind(),
71                JDWPConstants.EventKind.getName(JDWPConstants.EventKind.METHOD_ENTRY),
72                JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind()));
73
74        long eventThreadID = ((EventThread) parsedEvents[0]).getThreadID();
75        checkThreadState(eventThreadID, JDWPConstants.ThreadStatus.RUNNING,
76                JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED);
77
78        logWriter.println("MethodEntryTest done");
79    }
80}
81