001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anton V. Karnachuk
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 11.04.2005
026: */package org.apache.harmony.jpda.tests.jdwp.Events;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.EventPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for FIELD_ACCESS event.
037: */
038: public class FieldAccessTest extends JDWPEventTestCase {
039:
040: public static void main(String[] args) {
041: junit.textui.TestRunner.run(FieldAccessTest.class);
042: }
043:
044: protected String getDebuggeeClassName() {
045: return FieldDebuggee.class.getName();
046: }
047:
048: /**
049: * This testcase is for FIELD_ACCESS event.
050: * <BR>It runs FieldDebuggee that accesses to the value of its internal field
051: * and verify that requested FIELD_ACCESS event occurs.
052: */
053: public void testFieldAccessEvent() {
054:
055: logWriter.println("ExceptionTest started");
056:
057: //check capability, relevant for this test
058: logWriter.println("=> Check capability: canWatchFieldAccess");
059: debuggeeWrapper.vmMirror.capabilities();
060: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canWatchFieldAccess;
061: if (!isCapability) {
062: logWriter
063: .println("##WARNING: this VM doesn't possess capability: canWatchFieldAccess");
064: return;
065: }
066:
067: synchronizer
068: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
069:
070: String classSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/FieldDebuggee;";
071: ReplyPacket reply = debuggeeWrapper.vmMirror.setFieldAccess(
072: classSignature, JDWPConstants.TypeTag.CLASS,
073: "testIntField");
074: checkReplyPacket(reply, "Set FIELD_ACCESS event");
075:
076: synchronizer
077: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
078:
079: EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
080: ParsedEvent[] parsedEvents = ParsedEvent
081: .parseEventPacket(event);
082:
083: // assert that event is the expected one
084: assertEquals("Invalid number of events,", 1,
085: parsedEvents.length);
086: assertEquals("Invalid event kind,",
087: JDWPConstants.EventKind.FIELD_ACCESS, parsedEvents[0]
088: .getEventKind(), JDWPConstants.EventKind
089: .getName(JDWPConstants.EventKind.FIELD_ACCESS),
090: JDWPConstants.EventKind.getName(parsedEvents[0]
091: .getEventKind()));
092:
093: TaggedObject accessedField = ((ParsedEvent.Event_FIELD_ACCESS) parsedEvents[0])
094: .getObject();
095:
096: // assert that exception class is the expected one
097: long typeID = getObjectReferenceType(accessedField.objectID);
098: String returnedExceptionSignature = getClassSignature(typeID);
099: assertString("Invalid class signature,", classSignature,
100: returnedExceptionSignature);
101:
102: logWriter.println("FieldAccessTest done");
103: }
104: }
|