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 11.03.2005
25 */
26package org.apache.harmony.jpda.tests.jdwp.Events;
27
28import org.apache.harmony.jpda.tests.framework.Breakpoint;
29import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
30import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
31import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
32import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
33import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.EventThread;
34import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
35import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
36
37
38
39/**
40 * JDWP Unit test for BREAKPOINT event.
41 */
42public class BreakpointTest extends JDWPEventTestCase {
43    protected String getDebuggeeClassName() {
44        return BreakpointDebuggee.class.getName();
45    }
46
47    /**
48     * This testcase is for BREAKPOINT event.
49     * <BR>It runs BreakpointDebuggee and set breakpoint to its breakpointTest
50     * method, then verifies that requested BREAKPOINT event occurs.
51     */
52    public void testSetBreakpointEvent() {
53        logWriter.println("testSetBreakpointEvent started");
54
55        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
56
57        long classID = getClassIDBySignature(getDebuggeeClassSignature());
58        int requestID = debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin(classID,
59                "breakpointTest");
60
61        logWriter.println("starting thread");
62
63        // execute the breakpoint
64        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
65
66        CommandPacket event = null;
67        event = debuggeeWrapper.vmMirror.receiveEvent();
68        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
69
70        assertEquals("Invalid number of events,", 1, parsedEvents.length);
71        assertEquals("Invalid event kind,",
72                JDWPConstants.EventKind.BREAKPOINT,
73                parsedEvents[0].getEventKind(),
74                JDWPConstants.EventKind.getName(JDWPConstants.EventKind.BREAKPOINT),
75                JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind()));
76        assertEquals("Invalid request ID", requestID, parsedEvents[0].getRequestID());
77
78        long eventThreadID = ((EventThread) parsedEvents[0]).getThreadID();
79        checkThreadState(eventThreadID, JDWPConstants.ThreadStatus.RUNNING,
80                JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED);
81
82        logWriter.println("BreakpointTest done");
83    }
84}
85