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