Home | History | Annotate | Download | only in ReferenceType
      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 package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
     20 
     21 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
     22 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
     23 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
     24 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
     25 import org.apache.harmony.jpda.tests.framework.jdwp.Value;
     26 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
     27 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     28 
     29 
     30 /**
     31  * JDWP Unit test for ReferenceType.GetValues command for static field of interface class.
     32  */
     33 public class GetValues006Test extends JDWPSyncTestCase {
     34 
     35     @Override
     36     protected String getDebuggeeClassName() {
     37         return GetValues006Debuggee.class.getName();
     38     }
     39 
     40     /**
     41      * This tests the ReferenceType.GetValues command on the static field of an interface.
     42      * <BR>The test starts GetValues006Debuggee and checks that the ReferenceType.GetValues
     43      * command runs correctly for a static field declared in an interface.
     44      * <BR>Test checks that expected value of this field is returned.
     45      */
     46     public void testGetValues006() {
     47         String thisTestName = "testGetValues006";
     48         logWriter.println("==> " + thisTestName +
     49             " for ReferenceType.GetValues command: START...");
     50         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     51 
     52         logWriter.println("\n=> Get debuggeeRefTypeID for debuggee class = "
     53             + getDebuggeeClassName() + "...");
     54         long debuggeeRefTypeID = getClassIDBySignature(getDebuggeeClassSignature());
     55         logWriter.println("=> debuggeeRefTypeID = " + debuggeeRefTypeID);
     56 
     57         logWriter.println(
     58             "\n=> Get implementerRefTypeID for implementer = GetValues006Implementer...");
     59         long implementerRefTypeID =
     60             getClassIDBySignature(getClassSignature(GetValues006Interface.class));
     61         logWriter.println("=> implementerRefTypeID = " + implementerRefTypeID);
     62 
     63         logWriter.println("\n=> Get interfaceFieldID for field of interface class...");
     64         String interfaceFieldName = "interfaceStaticIntVar";
     65         long interfaceFieldID = checkField(implementerRefTypeID, interfaceFieldName);
     66         logWriter.println("=> interfaceFieldID = " + interfaceFieldID);
     67 
     68         logWriter.println("\n=> CHECK ReferenceType::GetValues command for implementerRefTypeID," +
     69             " interfaceFieldID...");
     70         CommandPacket getValuesCommand = new CommandPacket(
     71                 JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
     72                 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
     73         getValuesCommand.setNextValueAsReferenceTypeID(implementerRefTypeID);
     74         getValuesCommand.setNextValueAsInt(1);
     75         getValuesCommand.setNextValueAsFieldID(interfaceFieldID);
     76         ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand);
     77         checkReplyPacket(getValuesReply, "ReferenceType::GetValues command");
     78 
     79         getValuesReply.getNextValueAsInt();
     80         Value fieldValue = getValuesReply.getNextValueAsValue();
     81         byte fieldTag = fieldValue.getTag();
     82         logWriter.println("=> Returned value tag = " + fieldTag
     83             + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
     84         assertTagEquals("Invalid value tag is returned,", JDWPConstants.Tag.INT_TAG, fieldTag);
     85 
     86         int intValue = fieldValue.getIntValue();
     87         logWriter.println("=> Returned value = " + intValue);
     88         // here expected value = 1 (staticIntField)
     89         int expectedIntValue = 1;
     90         assertEquals("Invalid int value,", expectedIntValue, intValue);
     91 
     92         assertAllDataRead(getValuesReply);
     93 
     94         logWriter.println("=> CHECK PASSED: Expected value is returned!");
     95 
     96         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     97         logWriter.println("==> " + thisTestName + " for ReferenceType::GetValues command: FINISH");
     98     }
     99 }
    100