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