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.4 $
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_MODIFICATION event.
037: */
038: public class FieldModificationTest extends JDWPEventTestCase {
039:
040: public static void main(String[] args) {
041: junit.textui.TestRunner.run(FieldModificationTest.class);
042: }
043:
044: protected String getDebuggeeClassName() {
045: return FieldDebuggee.class.getName();
046: }
047:
048: /**
049: * This testcase is for FIELD_MODIFICATION event.
050: * <BR>It runs FieldDebuggee that modifies the value of its own field
051: * and verify that requested FIELD_MODIFICATION event occurs.
052: */
053: public void testFieldModifyEvent() {
054:
055: logWriter.println("FieldModificationTest started");
056:
057: //check capability, relevant for this test
058: logWriter
059: .println("=> Check capability: canWatchFieldModification");
060: debuggeeWrapper.vmMirror.capabilities();
061: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canWatchFieldModification;
062: if (!isCapability) {
063: logWriter
064: .println("##WARNING: this VM doesn't possess capability: canWatchFieldModification");
065: return;
066: }
067:
068: synchronizer
069: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
070:
071: String classSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/FieldDebuggee;";
072: ReplyPacket reply = debuggeeWrapper.vmMirror
073: .setFieldModification(classSignature,
074: JDWPConstants.TypeTag.CLASS, "testIntField");
075: checkReplyPacket(reply, "Set FIELD_MODIFICATION event");
076:
077: synchronizer
078: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
079:
080: EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
081: ParsedEvent[] parsedEvents = ParsedEvent
082: .parseEventPacket(event);
083:
084: // assert that event is the expected one
085: assertEquals("Invalid number of events,", 1,
086: parsedEvents.length);
087: assertEquals(
088: "Invalid event kind,",
089: JDWPConstants.EventKind.FIELD_MODIFICATION,
090: parsedEvents[0].getEventKind(),
091: JDWPConstants.EventKind
092: .getName(JDWPConstants.EventKind.FIELD_MODIFICATION),
093: JDWPConstants.EventKind.getName(parsedEvents[0]
094: .getEventKind()));
095:
096: TaggedObject modifiedField = ((ParsedEvent.Event_FIELD_MODIFICATION) parsedEvents[0])
097: .getObject();
098:
099: // assert that exception class is the expected one
100: long typeID = getObjectReferenceType(modifiedField.objectID);
101: String returnedExceptionSignature = getClassSignature(typeID);
102: assertString("Invalid class signature,", classSignature,
103: returnedExceptionSignature);
104:
105: logWriter.println("FieldModificationTest done");
106: }
107: }
|