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 /**
     20  * @author Anatoly F. Bondarenko
     21  */
     22 
     23 /**
     24  * Created on 13.07.2005
     25  */
     26 
     27 package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
     28 
     29 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
     30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
     31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
     32 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
     33 import org.apache.harmony.jpda.tests.framework.jdwp.Value;
     34 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
     35 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     36 
     37 
     38 /**
     39  * JDWP Unit test for ReferenceType.GetValues command for fields with null value.
     40  */
     41 public class GetValues005Test extends JDWPSyncTestCase {
     42 
     43     static final String thisCommandName = "ReferenceType.GetValues command";
     44     static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues005Debuggee;";
     45 
     46     @Override
     47     protected String getDebuggeeClassName() {
     48         return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues005Debuggee";
     49     }
     50 
     51     /**
     52      * This testcase exercises ReferenceType.GetValues command for fields with null value.
     53      * <BR>The test starts GetValues005Debuggee class and performs
     54      * ReferenceType.GetValues command for fields of different
     55      * referenceTypes with value=null for all fields.
     56      * <BR>The test expects the all returned values should be represented by expected
     57      * JDWP tag with null value.
     58      */
     59     public void testGetValues005() {
     60         String thisTestName = "testGetValues005";
     61         logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
     62         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     63 
     64         long debuggeeRefTypeID = getClassIDBySignature(debuggeeSignature);
     65 
     66         logWriter.println("=> Debuggee class = " + getDebuggeeClassName());
     67         logWriter.println("=> referenceTypeID for Debuggee class = " + debuggeeRefTypeID);
     68 
     69         String checkedFieldNames[] = {
     70                 "intArrayField",
     71                 "objectArrayField",
     72                 "objectField",
     73                 "stringField",
     74                 "threadField",
     75                 "threadGroupField",
     76                 "classField",
     77                 "classLoaderField",
     78         };
     79 
     80         long checkedFieldIDs[] = checkFields(debuggeeRefTypeID, checkedFieldNames);
     81         int checkedFieldsNumber = checkedFieldNames.length;
     82 
     83         logWriter.println
     84         ("=> CHECK: send " + thisCommandName
     85         + " for Debuggee class for fields of different referenceTypes with with null values...");
     86 
     87         CommandPacket checkedCommand = new CommandPacket(
     88                 JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
     89                 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
     90         checkedCommand.setNextValueAsObjectID(debuggeeRefTypeID);
     91         checkedCommand.setNextValueAsInt(checkedFieldsNumber);
     92         for (int i = 0; i < checkedFieldsNumber; i++) {
     93             checkedCommand.setNextValueAsFieldID(checkedFieldIDs[i]);
     94         }
     95         ReplyPacket checkedReply =
     96             debuggeeWrapper.vmMirror.performCommand(checkedCommand);
     97         checkedCommand = null;
     98 
     99         checkReplyPacket(checkedReply, thisCommandName);
    100 
    101         int returnedValuesNumber = checkedReply.getNextValueAsInt();
    102         logWriter.println("=> Returned values number = " + returnedValuesNumber);
    103         if ( checkedFieldsNumber != returnedValuesNumber ) {
    104             logWriter.println
    105             ("\n## FAILURE: ReferenceType::GetValues command returned unexpected number of values:");
    106             logWriter.println("## Expected number = " + checkedFieldsNumber);
    107             logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH");
    108             assertTrue(false);
    109         }
    110         byte expectedFieldTags[] = {
    111                 JDWPConstants.Tag.ARRAY_TAG,
    112                 JDWPConstants.Tag.ARRAY_TAG,
    113                 JDWPConstants.Tag.OBJECT_TAG,
    114                 JDWPConstants.Tag.STRING_TAG,
    115                 JDWPConstants.Tag.THREAD_TAG,
    116                 JDWPConstants.Tag.THREAD_GROUP_TAG,
    117                 JDWPConstants.Tag.CLASS_OBJECT_TAG,
    118                 JDWPConstants.Tag.CLASS_LOADER_TAG,
    119         };
    120         logWriter.println("=> CHECK for returned values...");
    121         for (int i=0; i < returnedValuesNumber; i++) {
    122             Value fieldValue = checkedReply.getNextValueAsValue();
    123             byte fieldTag = fieldValue.getTag();
    124             logWriter.println
    125             ("\n=> Check for returned value for field: " + checkedFieldNames[i] + " ...");
    126             logWriter.println("=> Returned value tag = " + fieldTag
    127                 + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
    128             if ( (fieldTag != expectedFieldTags[i]) && (fieldTag != JDWPConstants.Tag.OBJECT_TAG) ) {
    129                 logWriter.println("\n## FAILURE:  Unexpected value tag is returned");
    130                 logWriter.println("## Expected value tag = " + expectedFieldTags[i]
    131                 + "(" + JDWPConstants.Tag.getName(expectedFieldTags[i]) + ")"
    132                 + " or = " + JDWPConstants.Tag.OBJECT_TAG
    133                 + "(" + JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) + ")");
    134                 //testStatus = testStatusFailed;
    135                 fail("Unexpected value tag is returned");
    136             }
    137             long objectIDValue = fieldValue.getLongValue();
    138             logWriter.println("=> ObjectId value = " + objectIDValue);
    139             assertEquals("Invalid objectID value is returned,", 0, objectIDValue);
    140         }
    141 
    142         assertAllDataRead(checkedReply);
    143         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    144         logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK.");
    145     }
    146 }
    147