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
19package org.apache.harmony.jpda.tests.jdwp.Events;
20
21import org.apache.harmony.jpda.tests.framework.jdwp.EventBuilder;
22import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
23import org.apache.harmony.jpda.tests.framework.jdwp.Location;
24import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
25import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject;
26
27/**
28 * JDWP Unit test for caught EXCEPTION event with LocationOnly modifier.
29 */
30public class ExceptionWithLocationTest extends EventLocationEventTestCase {
31    private static final String EXCEPTION_SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/Events/DebuggeeException;";
32
33    // Cache exception class ID.
34    private long exceptionClassId = -1;
35
36    /**
37     * This testcase is for caught EXCEPTION event with LocationOnly
38     * modifier.<BR>
39     * It runs ExceptionWithLocationDebuggee that throws caught
40     * DebuggeeException in two different methods.
41     * The test verifies that requested EXCEPTION event occurs in the
42     * expected method.
43     */
44    public void testExceptionLocationEvent() {
45        logWriter.println("testExceptionLocationEvent STARTED");
46
47        runEventWithLocationTest(JDWPConstants.EventKind.EXCEPTION);
48
49        logWriter.println("testExceptionLocationEvent FINISHED");
50    }
51
52    @Override
53    protected String getDebuggeeClassName() {
54        return ExceptionWithLocationDebuggee.class.getName();
55    }
56
57    @Override
58    protected String getDebuggeeSignature() {
59        return "Lorg/apache/harmony/jpda/tests/jdwp/Events/ExceptionWithLocationDebuggee;";
60    }
61
62    @Override
63    protected String getExpectedLocationMethodName() {
64        return "expectedThrowException";
65    }
66
67    @Override
68    protected void createEventBuilder(EventBuilder builder) {
69        if (exceptionClassId == -1) {
70            exceptionClassId = getClassIDBySignature(EXCEPTION_SIGNATURE);
71        }
72        // Receive caught DebuggeeException.
73        builder.setExceptionOnly(exceptionClassId, true, false);
74    }
75
76    @Override
77    protected void checkEvent(ParsedEvent event) {
78        ParsedEvent.Event_EXCEPTION eventException =
79                (ParsedEvent.Event_EXCEPTION) event;
80
81        TaggedObject exception = eventException.getException();
82        assertEquals(JDWPConstants.Tag.OBJECT_TAG, exception.tag);
83
84        long thrownExceptionClassId = getObjectReferenceType(exception.objectID);
85        assertEquals("Received incorrect exception",
86                exceptionClassId, thrownExceptionClassId);
87
88        Location catchLocation = eventException.getCatchLocation();
89        assertNotNull("Incorrect catch location", catchLocation);
90    }
91}
92