001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anatoly F. Bondarenko
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 24.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
032: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034: /**
035: * JDWP Unit test for ReferenceType.Status command.
036: */
037: public class StatusTest extends JDWPSyncTestCase {
038:
039: static final int testStatusPassed = 0;
040: static final int testStatusFailed = -1;
041: static final String this CommandName = "ReferenceType.Status command";
042: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/StatusDebuggee;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.StatusDebuggee";
046: }
047:
048: /**
049: * This testcase exercises ReferenceType.Status command.
050: * <BR>The test starts StatusDebuggee class, requests referenceTypeId
051: * for this class by VirtualMachine.ClassesBySignature command, then
052: * performs ReferenceType.Status command and checks that returned
053: * status' bits are expected bits.
054: */
055: public void testStatus001() {
056: String this TestName = "testStatus001";
057: logWriter.println("==> " + this TestName + " for "
058: + this CommandName + ": START...");
059: synchronizer
060: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
061:
062: long refTypeID = getClassIDBySignature(debuggeeSignature);
063:
064: logWriter.println("=> Debuggee class = "
065: + getDebuggeeClassName());
066: logWriter.println("=> referenceTypeID for Debuggee class = "
067: + refTypeID);
068: logWriter.println("=> CHECK: send " + this CommandName
069: + " and check reply...");
070:
071: CommandPacket checkedCommand = new CommandPacket(
072: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
073: JDWPCommands.ReferenceTypeCommandSet.StatusCommand);
074: checkedCommand.setNextValueAsReferenceTypeID(refTypeID);
075:
076: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
077: .performCommand(checkedCommand);
078: checkedCommand = null;
079: checkReplyPacket(checkedReply, this CommandName);
080:
081: int returnedStatus = checkedReply.getNextValueAsInt();
082: logWriter.println("=> Returned status value = 0x"
083: + Integer.toHexString(returnedStatus));
084:
085: String statusBitsNames[] = { "VERIFIED", "PREPARED",
086: "INITIALIZED", "ERROR", };
087:
088: int statusBitsValues[] = { 0x01, 0x02, 0x04, 0x08, };
089:
090: int expectedStatusBits[] = { 0x01, 0x02, 0x04, 0x00, };
091:
092: String failMessage = "";
093: int checkedStatusBitsNumber = statusBitsNames.length;
094: logWriter
095: .println("=> CHECK for all returned bits of status...");
096: for (int i = 0; i < checkedStatusBitsNumber; i++) {
097: int returnedStatusBit = returnedStatus
098: & statusBitsValues[i];
099: if (expectedStatusBits[i] != returnedStatusBit) {
100: logWriter.println("\n## FAILURE: " + this CommandName
101: + " returns unexpected value for status bit \""
102: + statusBitsNames[i] + "\"");
103: logWriter.println("## Expected status bit = 0x"
104: + Integer.toHexString(expectedStatusBits[i]));
105: logWriter.println("## Returned status bit = 0x"
106: + Integer.toHexString(returnedStatusBit));
107: failMessage = failMessage + this CommandName
108: + " returns unexpected value for status bit \""
109: + statusBitsNames[i] + "\"" + ", Expected = 0x"
110: + Integer.toHexString(expectedStatusBits[i])
111: + ", Returned = 0x"
112: + Integer.toHexString(returnedStatusBit) + "; ";
113: } else {
114: logWriter
115: .println("\n=> Expected value for status bit \""
116: + statusBitsNames[i]
117: + "\" (0x"
118: + Integer
119: .toHexString(statusBitsValues[i])
120: + ") is returned: 0x"
121: + Integer
122: .toHexString(returnedStatusBit));
123: }
124: }
125:
126: if (failMessage.length() == 0) {
127: logWriter
128: .println("\n=> CHECK: PASSED: returned status value contains all expected status' bits");
129: }
130:
131: synchronizer
132: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
133: logWriter.println("==> " + this TestName + " for "
134: + this CommandName + ": FINISH");
135:
136: if (failMessage.length() > 0) {
137: fail(failMessage);
138: }
139:
140: assertAllDataRead(checkedReply);
141: }
142:
143: public static void main(String[] args) {
144: junit.textui.TestRunner.run(StatusTest.class);
145: }
146: }
|