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 24.02.2005
     25  */
     26 package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
     27 
     28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
     29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
     30 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
     31 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
     32 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     33 
     34 
     35 /**
     36  * JDWP Unit test for ReferenceType.Status command.
     37  */
     38 public class StatusTest extends JDWPSyncTestCase {
     39 
     40     static final int testStatusPassed = 0;
     41     static final int testStatusFailed = -1;
     42     static final String thisCommandName = "ReferenceType.Status command";
     43     static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/StatusDebuggee;";
     44 
     45     @Override
     46     protected String getDebuggeeClassName() {
     47         return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.StatusDebuggee";
     48     }
     49 
     50     /**
     51      * This testcase exercises ReferenceType.Status command.
     52      * <BR>The test starts StatusDebuggee class, requests referenceTypeId
     53      * for this class by VirtualMachine.ClassesBySignature command, then
     54      * performs ReferenceType.Status command and checks that returned
     55      * status' bits are expected bits.
     56      */
     57     public void testStatus001() {
     58         String thisTestName = "testStatus001";
     59         logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
     60         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     61 
     62         long refTypeID = getClassIDBySignature(debuggeeSignature);
     63 
     64         logWriter.println("=> Debuggee class = " + getDebuggeeClassName());
     65         logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID);
     66         logWriter.println("=> CHECK: send " + thisCommandName + " and check reply...");
     67 
     68         CommandPacket checkedCommand = new CommandPacket(
     69                 JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
     70                 JDWPCommands.ReferenceTypeCommandSet.StatusCommand);
     71         checkedCommand.setNextValueAsReferenceTypeID(refTypeID);
     72 
     73         ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
     74         checkedCommand = null;
     75         checkReplyPacket(checkedReply, thisCommandName);
     76 
     77         int returnedStatus = checkedReply.getNextValueAsInt();
     78         logWriter.println("=> Returned status value = 0x" + Integer.toHexString(returnedStatus));
     79 
     80         String statusBitsNames[] = {
     81                 "VERIFIED",
     82                 "PREPARED",
     83                 "INITIALIZED",
     84                 "ERROR",
     85         };
     86 
     87         int statusBitsValues[] = {
     88                 0x01,
     89                 0x02,
     90                 0x04,
     91                 0x08,
     92         };
     93 
     94         int expectedStatusBits[] = {
     95                 0x01,
     96                 0x02,
     97                 0x04,
     98                 0x00,
     99         };
    100 
    101         String failMessage = "";
    102         int checkedStatusBitsNumber = statusBitsNames.length;
    103         logWriter.println("=> CHECK for all returned bits of status...");
    104         for (int i = 0; i < checkedStatusBitsNumber; i++) {
    105             int returnedStatusBit = returnedStatus & statusBitsValues[i];
    106             if ( expectedStatusBits[i] != returnedStatusBit ) {
    107                 logWriter.println("\n## FAILURE: " + thisCommandName
    108                         + " returns unexpected value for status bit \"" + statusBitsNames[i] + "\"");
    109                 logWriter.println
    110                 ("## Expected status bit = 0x" + Integer.toHexString(expectedStatusBits[i]));
    111                 logWriter.println
    112                 ("## Returned status bit = 0x" + Integer.toHexString(returnedStatusBit));
    113                 failMessage = failMessage +
    114                     thisCommandName
    115                     + " returns unexpected value for status bit \"" + statusBitsNames[i] + "\"" +
    116                     ", Expected = 0x" + Integer.toHexString(expectedStatusBits[i]) +
    117                     ", Returned = 0x" + Integer.toHexString(returnedStatusBit) + "; ";
    118             } else {
    119                 logWriter.println("\n=> Expected value for status bit \"" + statusBitsNames[i]
    120                     + "\" (0x" + Integer.toHexString(statusBitsValues[i]) + ") is returned: 0x"
    121                     + Integer.toHexString(returnedStatusBit));
    122             }
    123         }
    124 
    125         if (failMessage.length() == 0) {
    126             logWriter.println
    127             ("\n=> CHECK: PASSED: returned status value contains all expected status' bits");
    128         }
    129 
    130         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    131         logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH");
    132 
    133         if (failMessage.length() > 0) {
    134             fail(failMessage);
    135         }
    136 
    137         assertAllDataRead(checkedReply);
    138     }
    139 }
    140