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.03.2005
25  */
26 package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
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.JDWPConstants;
31 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
32 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
33 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
34 
35 
36 /**
37  * JDWP Unit test for VirtualMachine.SetDefaultStratum command.
38  */
39 public class SetDefaultStratumTest extends JDWPSyncTestCase {
40 
41     static final int testStatusPassed = 0;
42     static final int testStatusFailed = -1;
43     static final String thisCommandName = "VirtualMachine::SetDefaultStratum command";
44     static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;";
45 
getDebuggeeClassName()46     protected String getDebuggeeClassName() {
47         return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
48     }
49 
50     /**
51      * This testcase exercises VirtualMachine.SetDefaultStratum command.
52      * <BR>At first the test starts HelloWorld debuggee.
53      * <BR>Then the test checks that VirtualMachine.SetDefaultStratum command runs
54      * without any error or returns NOT_IMPLEMENTED error.
55      * Any other error is considered as test' failure.
56      */
testSetDefaultStratum001()57     public void testSetDefaultStratum001() {
58         String thisTestName = "testSetDefaultStratum001";
59 
60         //check capability, relevant for this test
61         logWriter.println("=> Check capability: canSetDefaultStratum");
62         debuggeeWrapper.vmMirror.capabilities();
63         boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canSetDefaultStratum;
64         if (!isCapability) {
65             logWriter.println("##WARNING: this VM dosn't possess capability: canSetDefaultStratum");
66             return;
67         }
68 
69         logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
70         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
71 
72         logWriter.println("=> CHECK1: send " + thisCommandName + " and check reply for ERROR...");
73         String stratumID = "C++";
74         CommandPacket checkedCommand = new CommandPacket(
75                 JDWPCommands.VirtualMachineCommandSet.CommandSetID,
76                 JDWPCommands.VirtualMachineCommandSet.SetDefaultStratumCommand);
77         checkedCommand.setNextValueAsString(stratumID);
78 
79         ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
80         checkedCommand = null;
81 
82         short errorCode = checkedReply.getErrorCode();
83         if ( errorCode != JDWPConstants.Error.NONE ) {
84             if ( errorCode != JDWPConstants.Error.NOT_IMPLEMENTED ) {
85                 printErrorAndFail(thisCommandName
86                     + " returns unexpected ERROR = " + errorCode
87                     + "(" + JDWPConstants.Error.getName(errorCode) + ")");
88             } else {
89                 logWriter.println("=> CHECK PASSED: Expected error (NOT_IMPLEMENTED) is returned");
90             }
91         } else {
92             logWriter.println
93             ("=> CHECK PASSED: No any error is received");
94         }
95     }
96 }
97