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