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.04.2005
25 */
26package org.apache.harmony.jpda.tests.jdwp.Events;
27
28import org.apache.harmony.jpda.tests.framework.jdwp.EventPacket;
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.TaggedObject;
33import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
34
35
36/**
37 * JDWP Unit test for FIELD_ACCESS event.
38 */
39public class FieldAccessTest extends JDWPEventTestCase {
40    protected String getDebuggeeClassName() {
41        return FieldDebuggee.class.getName();
42    }
43
44    /**
45     * This testcase is for FIELD_ACCESS event.
46     * <BR>It runs FieldDebuggee that accesses to the value of its internal field
47     * and verify that requested FIELD_ACCESS event occurs.
48     */
49    public void testFieldAccessEvent() {
50
51        logWriter.println("ExceptionTest started");
52
53        //check capability, relevant for this test
54        logWriter.println("=> Check capability: canWatchFieldAccess");
55        debuggeeWrapper.vmMirror.capabilities();
56        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canWatchFieldAccess;
57        if (!isCapability) {
58            logWriter.println("##WARNING: this VM doesn't possess capability: canWatchFieldAccess");
59            return;
60        }
61
62        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
63
64        String classSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/FieldDebuggee;";
65        ReplyPacket reply = debuggeeWrapper.vmMirror.setFieldAccess(classSignature, JDWPConstants.TypeTag.CLASS, "testIntField");
66        checkReplyPacket(reply, "Set FIELD_ACCESS event");
67
68        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
69
70        EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
71        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
72
73        // assert that event is the expected one
74        assertEquals("Invalid number of events,", 1, parsedEvents.length);
75        assertEquals("Invalid event kind,",
76                JDWPConstants.EventKind.FIELD_ACCESS,
77                parsedEvents[0].getEventKind(),
78                JDWPConstants.EventKind.getName(JDWPConstants.EventKind.FIELD_ACCESS),
79                JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind()));
80
81        TaggedObject accessedField =((ParsedEvent.Event_FIELD_ACCESS)parsedEvents[0]).getObject();
82
83        // assert that exception class is the expected one
84        long typeID = getObjectReferenceType(accessedField.objectID);
85        String returnedExceptionSignature = getClassSignature(typeID);
86        assertString("Invalid class signature,",
87                classSignature, returnedExceptionSignature);
88
89        logWriter.println("FieldAccessTest done");
90    }
91}
92