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 Ruslan A. Scherbakov
021: * @version $Revision: 1.4 $
022: */
023:
024: /**
025: * Created on 14.06.2006
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.framework.jdwp.Value;
034: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036: /**
037: * JDWP Unit test for FIELD_MODIFICATION event.
038: */
039: public class FieldModification002Test extends JDWPEventTestCase {
040:
041: public static void main(String[] args) {
042: junit.textui.TestRunner.run(FieldModification002Test.class);
043: }
044:
045: protected String getDebuggeeClassName() {
046: return FieldModification002Debuggee.class.getName();
047: }
048:
049: /**
050: * This testcase is for FIELD_MODIFICATION event.
051: * <BR>It FieldModification002Debuggee that modifies the value of its own fields
052: * and verifies that requested FIELD_MODIFICATION events occur and
053: * correct type tag is returned for each event.
054: */
055: public void testFieldModifyEvent() {
056:
057: logWriter.println("FieldModification002Test started");
058:
059: //check capability, relevant for this test
060: logWriter
061: .println("=> Check capability: canWatchFieldModification");
062: debuggeeWrapper.vmMirror.capabilities();
063: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canWatchFieldModification;
064: if (!isCapability) {
065: logWriter
066: .println("##WARNING: this VM doesn't possess capability: canWatchFieldModification");
067: return;
068: }
069:
070: synchronizer
071: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
072: String classSignature = "L"
073: + getDebuggeeClassName().replace('.', '/') + ";";
074:
075: hookFieldModification(classSignature, "testBoolField",
076: JDWPConstants.Tag.BOOLEAN_TAG);
077: hookFieldModification(classSignature, "testByteField",
078: JDWPConstants.Tag.BYTE_TAG);
079: hookFieldModification(classSignature, "testCharField",
080: JDWPConstants.Tag.CHAR_TAG);
081: hookFieldModification(classSignature, "testShortField",
082: JDWPConstants.Tag.SHORT_TAG);
083: hookFieldModification(classSignature, "testIntField",
084: JDWPConstants.Tag.INT_TAG);
085: hookFieldModification(classSignature, "testLongField",
086: JDWPConstants.Tag.LONG_TAG);
087: hookFieldModification(classSignature, "testFloatField",
088: JDWPConstants.Tag.FLOAT_TAG);
089: hookFieldModification(classSignature, "testDoubleField",
090: JDWPConstants.Tag.DOUBLE_TAG);
091: hookFieldModification(classSignature, "testObjectField",
092: JDWPConstants.Tag.OBJECT_TAG);
093: hookFieldModification(classSignature, "testThreadField",
094: JDWPConstants.Tag.THREAD_TAG);
095: hookFieldModification(classSignature, "testThreadGroupField",
096: JDWPConstants.Tag.THREAD_GROUP_TAG);
097: hookFieldModification(classSignature, "testClassField",
098: JDWPConstants.Tag.CLASS_OBJECT_TAG);
099: hookFieldModification(classSignature, "testClassLoaderField",
100: JDWPConstants.Tag.CLASS_LOADER_TAG);
101: hookFieldModification(classSignature, "testStringField",
102: JDWPConstants.Tag.STRING_TAG);
103: hookFieldModification(classSignature, "testIntArrayField",
104: JDWPConstants.Tag.ARRAY_TAG);
105: hookFieldModification(classSignature, "testStringArrayField",
106: JDWPConstants.Tag.ARRAY_TAG);
107: hookFieldModification(classSignature, "testObjectArrayField",
108: JDWPConstants.Tag.ARRAY_TAG);
109:
110: logWriter.println("FieldModification002Test done");
111: }
112:
113: /**
114: * Sets FIELD_MODIFICATION breakpoint,
115: * synchrinizes debuggee,
116: * expects field notification event,
117: * verifies new value assigned to the field
118: * and clears set breakpoint.
119: *
120: * @param classSignature signature of class containing the given field
121: * @param fieldName the name of field to break on modification
122: * @param expectedTag expected type tag of new values assigned to the field
123: */
124: public void hookFieldModification(String classSignature,
125: String fieldName, byte expectedTag) {
126:
127: // set breakpoint
128: logWriter.println("Set hook for: " + fieldName);
129: ReplyPacket reply = debuggeeWrapper.vmMirror
130: .setFieldModification(classSignature,
131: JDWPConstants.TypeTag.CLASS, fieldName);
132: checkReplyPacket(reply, "Set FIELD_MODIFICATION event");
133: int requestID = reply.getNextValueAsInt();
134: assertAllDataRead(reply);
135:
136: synchronizer
137: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
138:
139: EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
140: ParsedEvent[] parsedEvents = ParsedEvent
141: .parseEventPacket(event);
142:
143: // assert that event is the expected one
144: assertEquals("Invalid number of events,", 1,
145: parsedEvents.length);
146: assertEquals(
147: "Invalid event kind,",
148: JDWPConstants.EventKind.FIELD_MODIFICATION,
149: parsedEvents[0].getEventKind(),
150: JDWPConstants.EventKind
151: .getName(JDWPConstants.EventKind.FIELD_MODIFICATION),
152: JDWPConstants.EventKind.getName(parsedEvents[0]
153: .getEventKind()));
154:
155: Value value = ((ParsedEvent.Event_FIELD_MODIFICATION) parsedEvents[0])
156: .getValueToBe();
157: byte tag = value.getTag();
158: assertEquals("Invalid value tag,", expectedTag, tag,
159: JDWPConstants.Tag.getName(expectedTag),
160: JDWPConstants.Tag.getName(tag));
161:
162: TaggedObject modifiedField = ((ParsedEvent.Event_FIELD_MODIFICATION) parsedEvents[0])
163: .getObject();
164:
165: // assert that exception class is the expected one
166: long typeID = getObjectReferenceType(modifiedField.objectID);
167: String returnedExceptionSignature = getClassSignature(typeID);
168: assertString("Invalid class signature,", classSignature,
169: returnedExceptionSignature);
170:
171: logWriter.println("Field: " + fieldName
172: + ", tag of new value: " + value + ", tag: "
173: + (char) tag + " - OK");
174:
175: // clear breakpoint
176: clearEvent(JDWPConstants.EventKind.FIELD_MODIFICATION,
177: requestID, false);
178:
179: // and resume target VM
180: resumeDebuggee();
181: }
182: }
|