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.03.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
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.JDWPConstants;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for VirtualMachine.SetDefaultStratum command.
037: */
038: public class SetDefaultStratumTest extends JDWPSyncTestCase {
039:
040: static final int testStatusPassed = 0;
041: static final int testStatusFailed = -1;
042: static final String this CommandName = "VirtualMachine::SetDefaultStratum command";
043: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;";
044:
045: protected String getDebuggeeClassName() {
046: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
047: }
048:
049: /**
050: * This testcase exercises VirtualMachine.SetDefaultStratum command.
051: * <BR>At first the test starts HelloWorld debuggee.
052: * <BR>Then the test checks that VirtualMachine.SetDefaultStratum command runs
053: * without any error or returns NOT_IMPLEMENTED error.
054: * Any other error is considered as test' failure.
055: */
056: public void testSetDefaultStratum001() {
057: String this TestName = "testSetDefaultStratum001";
058:
059: //check capability, relevant for this test
060: logWriter.println("=> Check capability: canSetDefaultStratum");
061: debuggeeWrapper.vmMirror.capabilities();
062: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canSetDefaultStratum;
063: if (!isCapability) {
064: logWriter
065: .println("##WARNING: this VM dosn't possess capability: canSetDefaultStratum");
066: return;
067: }
068:
069: logWriter.println("==> " + this TestName + " for "
070: + this CommandName + ": START...");
071: synchronizer
072: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
073:
074: logWriter.println("=> CHECK1: send " + this CommandName
075: + " and check reply for ERROR...");
076: String stratumID = "C++";
077: CommandPacket checkedCommand = new CommandPacket(
078: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
079: JDWPCommands.VirtualMachineCommandSet.SetDefaultStratumCommand);
080: checkedCommand.setNextValueAsString(stratumID);
081:
082: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
083: .performCommand(checkedCommand);
084: checkedCommand = null;
085:
086: short errorCode = checkedReply.getErrorCode();
087: if (errorCode != JDWPConstants.Error.NONE) {
088: if (errorCode != JDWPConstants.Error.NOT_IMPLEMENTED) {
089: printErrorAndFail(this CommandName
090: + " returns unexpected ERROR = " + errorCode
091: + "(" + JDWPConstants.Error.getName(errorCode)
092: + ")");
093: } else {
094: logWriter
095: .println("=> CHECK PASSED: Expected error (NOT_IMPLEMENTED) is returned");
096: }
097: } else {
098: logWriter
099: .println("=> CHECK PASSED: No any error is received");
100: }
101: }
102:
103: public static void main(String[] args) {
104: junit.textui.TestRunner.run(SetDefaultStratumTest.class);
105: }
106: }
|